$(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='725' height='400'></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'></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 - no javascript button
  $('.no_javascript').hide();

  //forms - autoclear
  $('form#form_search input[type="text"]').attr({ value: 'Zoeken...' }).focus(function(){ 
    if($(this).val()=="Zoeken..."){
      $(this).val("");
    }
  }).blur(function(){
    if($(this).val()==""){
      $(this).val("Zoeken...");
    }
  });
  
 	//forms - multi select -> Woningaanbod
	$('#add').click(function() {
		return !$('#list1 option:selected').remove().appendTo('#list2');
	});
	$('#remove').click(function() {
		return !$('#list2 option:selected').remove().appendTo('#list1');
	});
	$('#add,select#list1 option').dblclick(function() {
		return !$('#list1 option:selected').remove().appendTo('#list2');
	});
	$('#removed,select#list2 option').dblclick(function() {
		return !$('#list2 option:selected').remove().appendTo('#list1');
	});
	http://hypodomusexclusief.nl/woningaanbod/overzicht/detail/7888/pesaken-26-gulpen#tab-5
	$('#form_advanced_search').submit(function(){
		$('#list2 option').attr('selected','selected');
	});
  
 	//Tabs Woningaanbod
	$(function () {
		var tabContainers = $('div#tabs > div');
		tabContainers.hide().filter(':first').show();
		$('div#tabs ul.tabs_menu a, dl.details dt a.tab, dl.details dd a.tab').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();
	});  
	
	// Image Slider Hoofdpagina (jcarousel libary)
	function mycarousel_initCallback(carousel)
	{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
	};


  $('#slideshow').jcarousel({
      vertical: true,
      auto: 3,
      scroll: 1,
      wrap: 'last',
      initCallback: mycarousel_initCallback

  });
  
	$("#slideshow_house").jcarousel(
	{
      horizontal: true,
      auto: 3,
      scroll: 1,
      wrap: 'last',
      initCallback: mycarousel_initCallback
	}
	);

	$("div#slideshow_house ul li a").hover(function(){
		var imgHref = $(this).attr('href');
		$('div#large_picture img').attr('src',imgHref);
	},function(){
	});
	$("div#slideshow_house ul li a").click(function(){
		return false;
	});


 
});

