/**
 * Moolenaar Makelaardij scripts
 * Author: Rutger Laurman
 */

/* Document loaded */
$(function(){

  // Fix to prevent dropkick on search property
  if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))) {
    $("html").removeClass("dk_fouc");
    $("#searchproperty select.stylize").removeClass("stylize");
  }
  
  /* Add dropkick selectbox styling to search house block */
  $("#searchproperty select.stylize").dropkick();

  // Loving that breadcrumb
  $("#breadcrumb a").each(function(){
	  if($(this).attr("title")=="Ga naar Aanbod.") {
		  $(this).remove();
	  }
  });

  /**
   * Twitter stream on homepage
   */
  /* Disable on dev before 150request/hour is met */
  var twitterUsername = "mikelmoolenaar";
  var disableTwitter  = false;

  if(!disableTwitter && $("body").hasClass('home')){
    $.jTwitter(twitterUsername, 5,
      function(data){
        // Empty current contents
        $('#twitterstream').empty();

        // Load all tweets in and format them properly
        $.each(data, function(i, post){
          $('#twitterstream').append(
            '<div class="tweet">'
            +'  <div class="bird ir"></div>'
            +'  <p>'
            +'    <strong><a href="http://twitter.com/'+twitterUsername+'" title="Volg ons op Twitter">Volg ons: @'+twitterUsername+'</a></strong>'
            +'    <q>'+post.text+'</q>'
            +'  </p>'
            +'</div>'
          );
        });

        // Make the stream scroll over the window
        $("#twitterstream").liScroll();

        // Convert all url's to clickable links
        $("#twitterstream div.tweet q").linkify();
    });
  }

  /**
   * Add menu first and last classes, for IE
   */
   $("#access li:first-child").addClass("first");
   $("#access li:last-child").addClass("last");

   // Real estate property listing
   $("article.property").click(function(){
      window.location=$(this).find("a").attr("href"); return false;
   })

   // Toggle more images button
   $("#btn_meerfotos").click(function(e){
     $("#moreimages").toggle();
     e.preventDefault();
   })


  /**
   * Simple page tabs
   */
	$(".tab_content").hide();
	$("ul.tabs li:first").addClass("active").show();
	$(".tab_content:first").show();

	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn();
		return false;
	});

  // Activate FancyBox
  $("a[rel=gallery]").fancybox();

  // Fix for easier clicking on iPad and iPhone
  if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))) {
	  $('body').find('*').hover(
		  function(){$(this).click();}
		);
	}

});

