$(document).ready( function() {
  //lightbox
  if($('a.lightbox').length > 0 )
  {
    $('a.lightbox').lightBox();
  }
  
  //external window
  $('a[class="external"]').click(function() {
    this.target = "_blank";
  });

  //popup window
  $('a[class="popup"]').click(function(){
    window.open(this.href,'Popup','height=550,width=980,scrollTo,resizable=0,scrollbars=1,location=0,left=50,top=50','false');
    return false;
  });

  //close popup window link
  $('a[class="popup_close"]').click(function() {
    window.close();
    return false;
  }); 

  //print link
  $('a[class="print"]').click(function() {
    window.print();
    return false;
  });

  //back link
  $('a[class="back"]').click(function() {
    history.back();
    return false;
  }); 

  //forward link
  $('a[class="forward"]').click(function() {
    history.forward();
    return false;
  }); 
  
  //confirm link
  $('a[class="confirm"]').click(function() {
    return confirm(this.title);
  });

  //bookmark link 
  $("a.bookmark").click(function(event){ 
      event.preventDefault();  
      var url = this.href;
      var title = this.title; 
      if (window.sidebar) {  
          window.sidebar.addPanel(title, url,""); 
      } else if( window.external ) {  
          window.external.AddFavorite( url, title); 
      } else {
        alert('Uw browser ondersteunt helaas niet deze optie.'); 
      } 
  });



	
	//iframe replacement
	$('a[class="iframenormal"]').each(
	function (i) {
		$(this).replaceWith("<iframe src='" + this.getAttribute("href") + "' frameborder='0' scrolling='no' width='540' height='400' allowtransparency='true' ></iframe>");
	});
	
	$('a[class="iframebig"]').each(
	function (i) {
		$(this).replaceWith("<iframe src='" + this.getAttribute("href") + "' frameborder='0' scrolling='no' width='725' height='700'></iframe>");
	});
	$('a[class="iframelong"]').each(
	function (i) {
		$(this).replaceWith("<iframe src='" + this.getAttribute("href") + "' frameborder='0' scrolling='no' width='725' height='4000' allowtransparency='true'></iframe>");
	});
	$('a[class="iframesmall"]').each(
	function (i) {
		$(this).replaceWith("<iframe src='" + this.getAttribute("href") + "' frameborder='0' scrolling='no' width='470' height='1900'></iframe>");
	});
	$('a[class="iframehuge"]').each(
	function (i) {
		$(this).replaceWith("<iframe src='" + this.getAttribute("href") + "' frameborder='0' scrolling='no' width='990' height='900'></iframe>");
	});

  //image rollover
  $("img.rollover").hover(function() {
    this.src = this.src.replace("_off.","_on.");
  }, function() {
    this.src = this.src.replace("_on.","_off.");
  });

  //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() {
	  //this.submit();
		//window.location = $(this).val();
	});
	
//  $("#form_appointment select#questiontype").change(function() {
//    $("#form_appointment").submit();
//  });

  //forms - no javascript button
  $('.no_javascript').hide();

  //toggle
  $("dd.content").hide();
  $("dt.toggle a").click(function(){
    $(this).parent().next("dd").toggle();
    return false;
  });


  //flash
  if($('div#flash_banner').length > 0)
  {
    $("div#flash_banner").jmedia(
      {
        mode:"replace"
      },
      {
        src:"flash/corporate_banner.swf",
        width:390,
        height:250
    });
  }

  //sifr
//  $("h2.flash").jmedia(
//    {
//      mode:"sifr"
//    },
//		{
//      src:"flash/eurostile-bol.swf",
//      wmode: "transparent",
//      flashVars:"textcolor=#000&linkcolor=#ff0000&hovercolor=#00f00"
//  });

  //dropdown menu - hover IE6
  $('div#footer ul li').hover(function() {
    $(this).addClass('hover');
  }, function() {
    $(this).removeClass('hover');
  });

  //forms - autoclear
  $('form#form_search input[type="text"]').attr({ value: 'Voer hier uw zoekopdracht in' }).focus(function(){ 
    if($(this).val()=="Voer hier uw zoekopdracht in"){
      $(this).val("");
    }
  }).blur(function(){
    if($(this).val()==""){
      $(this).val("Voer hier uw zoekopdracht in");
    }
  });
  
  $('form#form_search_zip input[type="text"]').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_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");
    }
  });
  
  
  //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;
  //    }
  //  }
  //});

  //tabs
  var tabContainers = $('div#tabs > div');
  $('div#tabs ul.tab_options a').click(function () {
    tabContainers.hide().filter(this.hash).show();
    $('div#tabs ul.tab_options a').removeClass('selected');
    $(this).addClass('selected');
    return false;
  }).filter(':first').click();

  //Google Analytics code
  /*
  var gaTrackCode = "VOER TRACKCODE IN";
  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();
  });
  */

   
  if($('a[rel*=facebox]').length > 0 )
  {
    $('a[rel*=facebox]').facebox() 
  }
  
  if($('.slideshow').length > 0 )
  {
    $('.slideshow').cycle({
  		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
  		next : '#fotovolgende',
  		prev : '#fotovorige'
  	});
  }
});
