$(document).ready( function() {

	//external window
//	$('a[class="external"]').click( function() {
//		window.open( $(this).attr('href') );
//		return false;
//	});

  //external window
  $('a[class="external"]').click(function() {
    this.target = "_blank";
  });

	//popup window
	$('a[class="popup"]').click(function(){
		window.open(this.href,'Popup','height=540,width=1055,scrollTo,resizable=0,scrollbars=1,location=0,left=50,top=50','false');
		return false;
	});

	//print link
	$('a[class="print"]').click(function() {
		window.print();
		return false;
	});
	


	//iframe replacement
	$('a[class="iframebig"]').each(
	function (i) {
		$(this).replaceWith("<iframe src='" + this.getAttribute("href") + "' frameborder='0' scrolling='no' width='725' height='1400'></iframe>");
	});
	$('a[class="iframesmall"]').each(
	function (i) {
		$(this).replaceWith("<iframe src='" + this.getAttribute("href") + "' frameborder='0' scrolling='no' width='470' height='660'></iframe>");
	});
	$('a[class="iframehuge"]').each(
	function (i) {
		$(this).replaceWith("<iframe src='" + this.getAttribute("href") + "' frameborder='0' scrolling='no' width='990' height='900'></iframe>");
	});
	$('a[class="iframeextreme"]').each(
	function (i) {
		$(this).replaceWith("<iframe src='" + this.getAttribute("href") + "' frameborder='0' scrolling='no' width='990' height='2000'></iframe>");
	});
	

	//back link
	$('a[class="back"]').click(function() {
		history.back(-1);
		return false;
	});

	//flash
//  $("div#flash_banner").jmedia(
//    {
//      mode:"replace"
//    },
//    {
//      src:"/interactive/flash/acties.swf",
//      width:200,
//      height:200
//  });

	//image rollover
	$("img.rollover").hover(function() {
		this.src = this.src.replace("_off.","_on.");
	}, function() {
		this.src = this.src.replace("_on.","_off.");
	});

	//dropdown menu - hover IE6
	$('ul.main_menu li').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});

	//forms - focus
	$("input[type=password], input[type=text], textarea").focus(function() {
		$(this).addClass("focus");
	});
	$("input[type=password], input[type=text], textarea").blur(function() {
		if ($(this).find(".focus")) { $(this).removeClass("focus"); }
	});

	//forms - hover
	$("input.submit").hover(function() {
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");
	});

	//forms - auto submit
	$(".auto_submit").change(function()
	{
		window.location = $(this).val();
	});

	//forms - no javascript button
	$('.no_javascript').hide();

	//forms - autoclear
	
	$("form#form_search input#searchstring").attr({ value: 'Zoeken' }).focus(function(){
		if($(this).val()=="Zoeken"){
			$(this).val("");
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).val("Zoeken");
		}
	});
	
	$("form#form_advisor_zipcode input#form_advisor_zipcode_content").attr({ value: 'Zoek op postcode' }).focus(function(){
		if($(this).val()=="Zoek op postcode"){
			$(this).val("");
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).val("Zoek op postcode");
		}
	});
	
	$("form#form_advisor_name input#form_advisor_name_content").attr({ value: 'Zoek op naam' }).focus(function(){
		if($(this).val()=="Zoek op naam"){
			$(this).val("");
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).val("Zoek op naam");
		}
	});
	
  $('form#form_actuele_rentes input[type="text"]').attr({ value: 'Uw email-adres' }).focus(function(){ 
    if($(this).val()=="Uw email-adres"){
      $(this).val("");
    }
  }).blur(function(){
    if($(this).val()==""){
      $(this).val("Uw email-adres");
    }
  });
	
  //lightbox
  if($('a.lightbox').length > 0 )
  {
    $('a.lightbox').lightBox();
  }

	//tabs
	$(function () {
		var tabContainers = $('div#tabs > div');
		tabContainers.hide().filter(':first').show();
		$('div#tabs ul.tabs_menu a').click(function () {
			tabContainers.hide();
			tabContainers.filter(this.hash).show();
			$('div#tabs ul.tabs_menu a').removeClass('selected');
			$(this).addClass('selected');
			return false;
		}).filter(':first').click();
	});

	//smooth scrolling
	//$('a[href*=#]').click(function() {
	//	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
	//		var $target = $(this.hash);
	//		$target = $target.length && $target || $('[id=' + this.hash.slice(1) + ']');
	//		if ($target.length) {
	//			var targetOffset = $target.offset().top; $('html,body').animate({scrollTop: targetOffset}, 400);
	//			return false;
	//		}
	//	}
	//});

	//slideshow
	//$(function() {
	// $(".slideshow").jCarouselLite({
	//   btnNext: ".next",
	//   btnPrev: ".prev"
	//   });
	//});

	//Google Analytics code
	//var gaTrackCode = "UA-6911197-1";
	//var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");

	//jQuery.getScript(gaJsHost + "google-analytics.com/ga.js", function(){
	//var pageTracker = _gat._getTracker(gaTrackCode);
	//pageTracker._initData();
	//pageTracker._trackPageview();
	//});

	
	/*************************************
  * alle anchors laten smooth scrollen *
  *************************************/	
  /*$.localScroll();*/

  /*****************
   * jbanner fade  *
   *****************/
  $('#jbanner').cycle('fade');
  $('#bannerSlider').cycle({
    fx:       'fade',
    speed:    800,
    timeout:  5000
  });
  
	/*************************
  * autocomplete uitzetten *
  *************************/
  $("form#form_auto_insurance").attr("autocomplete", "off");
  
	//toggle content / link
	$("dd.content").hide();
	$("dt.toggle a").click(function(){
		$(this).parent().next("dd").toggle();
		return false;
	});
	
  $('.slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		next : '#fotovolgende',
		prev : '#fotovorige'
	});

 /** Tooltip **/
	$(".ffitooltip").click(function (e) {
		$('#tooltipffi').remove();
		$(this).ffitooltip(e);
	});
	
});

/* Tool tip */
jQuery.fn.ffitooltip = function (e) {
	bodyTag = document.body;
	x = e.pageX;
	y = e.pageY;

	newel = document.createElement('div');
	newel.id = 'tooltipffi';
	newel.innerHTML = '<p class="tooltiptitle">'+this.attr('title')+' <span onclick="removeTooltip();">X</span></p><p>'+this.attr('alt')+'</p>';

	var cssObj = {
	'position' 		: 'absolute',
	'top' 				:	y ,
	'left' 				: x + 5,
	'width' 			: '250px',
	'background'	:	'background: #7d7d7d;',
	'margin'			:	'10px 0 0 -250px',
	'z-index' 		: '100'
	}
	newel.style.display = 'none';
	bodyTag.appendChild(newel);

	$('#tooltipffi').css(cssObj);
	$('#tooltipffi').addClass('tooltipstyle');
	$('#tooltipffi').fadeIn(300);
}
/** Bad remove **/
function removeTooltip()
{
	$('#tooltipffi').fadeOut(300).remove();
	return false;
}
