$(function() {
	intervalID = setInterval( "slideShow()", 5000 );
});

$(document).ready(function() {
	
	/** Rewrite target = _blank **/
	
	$("a.blank").click(function() {
		window.open(this.href);
		return false;							
	});
	
	/** End rewrite **/
	
	/** Toggle sitemap **/
	
	$("#top .btn a").toggle(function() {
		if ($.browser.msie && $.browser.version <=6) {
			$("#top #sitemap").show();
		}
		else {
			$("#top #sitemap").slideDown();
		}
		$(this).addClass("active");
		
		return false;
	},
	function() {
		if ($.browser.msie && $.browser.version <=6) {
			$("#top #sitemap").hide();
		}
		else {
			$("#top #sitemap").slideUp();
		}
		$(this).removeClass("active");
		
		return false;
	});
	
	/** End toggle sitemap **/
	
	/** Hover subnav **/
	
	$("#nav li.main").mouseover(function() {
		$("#nav li ul").hide();									// hide all other subnavs
		$("#nav li a.active").addClass("inactive");		// add temporary class to active nav item
		$("#nav li a.active").removeClass("active");	// remove active class from active av item
		$("#nav a.hover").removeClass("hover");			// remove hover state of other nav items
		$(this).children("a").addClass("hover");			// add hover class to current hovered nav item
		$(this).children("ul").show();						//	show subnav
	});
	
	$("#nav").mouseout(function() {
		$("#nav a.hover").removeClass("hover");
		$("#nav li a.inactive").addClass("active");		
		$("#nav li a.inactive").removeClass("inactive");
		$("#nav li ul").hide();	
    $("#nav li ul.active").show();
	});
	
	 
  $("#nav li ul.active").show();
			
	/** End hover subnav **/
	
	/** Social links balloons **/
	
	$("#social-links li").hover(function() {
		var src = $(this).attr("id");
		var trg = src + "-balloon";
		$("#" + trg).show();
	},
	function() {
		var src = $(this).attr("id");
		var trg = src + "-balloon";
		$("#" + trg).hide();
	});
	
	/** End social links balloons **/
	
	/** Project pictures **/     
  
  $("#pic-pager a").click(function() {
    if ($(this).attr("class") != "active") {
  		stopSlideShow();
      var imageID = $(this).attr("ref");
  	  var active = $("#project-images .project-image.active");
  	  $(active).fadeOut();
      $("#project-images .project-image.active").removeClass("active");
      $("#project-images #" + imageID).fadeIn();
      $("#project-images #" + imageID).addClass("active");
      $("#pic-pager a.active").removeClass("active");
      $(this).addClass("active");
      
      /*
      $(".project-img-link").attr("src", "/theme/img/project-pager.jpg");
      $(this).attr("src", "/theme/img/project-pager-active.jpg");
      $("#project-picture .active").removeClass("active");
      $(this).addClass("active");
      var url = "/media/projects/" + $(this).attr("alt");
      $("#project-main-image").attr("src", url);
      */
			setTimeout("startSlideShow()", 12000); 
    }
    return false;
  });

	/** End project pictures **/
	
	/** Stappenplan werkwijze **/
   
	$("#steps img").click(function() {
     if (!$(this).hasClass("active")) {
       var targetImg = $(this).attr("class");
       $("#content .steps").hide();
       $("#content #" + targetImg + ".steps").show();
       $("#steps img.active").attr("src", $("#steps img.active").attr("src").replace("active.png", "a.png"));
       $("#steps img.active").removeClass("active");
       $(this).addClass("active");
       $(this).attr("src", $(this).attr("src").replace("a.png", "active.png"));       
       return false;
    }
   });
   
   $("#steps img").hover(function() {
    if (!$(this).hasClass("active")) {
      $(this).attr("src", $(this).attr("src").replace("a.png", "active.png"));
     }
   },
   function() {
    if (!$(this).hasClass("active")) {
       $(this).attr("src", $(this).attr("src").replace("active.png", "a.png"));
     }
   });
   
   /** End stappenplan **/    

  /** FAQ **/
   
  $("#faq a.question").toggle(function() {
    $(this).next(".answer").slideDown();
    $(this).addClass("active");
  },
  function() {
    $(this).next(".answer").slideUp();
    $(this).removeClass("active");
  });       

  $("#faqs .link-more.open").click(function() {
    $(this).next().slideDown();
    $(this).hide();
  });

  $("#faqs .link-more.close").click(function() {
    $(this).parent().slideUp();
    $(this).parent().prev().show();
  });
  
  /** End FAQ **/  
	
	/** Clear offer textarea **/
	
	$("#offer-form textarea").click(function() {
	  var testContent = $(this).css("font-style");
		if (testContent == "italic") {
			$(this).text("");	
			$(this).css("font-style", "normal");
		}																					 
	});
	
	/** End clear **/
	
	/** E-shop checkboxes **/
	
	if ($("#radio-shop").attr("checked")) {
		$("#offer-form div.opties.eshop input.input-checkbox").css("visibility", "visible");
		$("#offer-form div.opties.eshop .hide").css("visibility", "visible");									
	}
	
	$("#radio-shop").click(function() {
		$("#offer-form div.opties.eshop input.input-checkbox").css("visibility", "visible");	
		$("#offer-form div.opties.eshop .hide").css("visibility", "visible");																						
	});
	
	$("#radio-noshop").click(function() {
		$("#offer-form div.opties.eshop input.input-checkbox").css("visibility", "hidden");		
		$("#offer-form div.opties.eshop .hide").css("visibility", "hidden");													
	});
	
	/** End e-shop check **/
	
	/** Spreekballonen **/     
	
	//if (!($.browser.name == "msie" && $.browser.indexOf("6"))) {
	
  $(".project a.normal").trackStar( {
    displayID: this.id,
    xOffset: 100,  // display 20 pixels right of the cursor
    yOffset: -3   // display 10 pixels above the cursor
  });
  
  $(".project a.invert").trackStar( {
    displayID: this.id,
    xOffset: 100,  // display 20 pixels right of the cursor
    yOffset: -242   // display 10 pixels above the cursor
  });
	
//	}
	
	/** End spreekballon **/
});

function slideShow() {
	var active = $("#project-images .project-image.active");
	$(active).fadeOut();
	$(active).removeClass("active");
	if ($(active).next().length != 0) {
		$(active).next().fadeIn();
		$(active).next().addClass("active");/*
		var activeID = $(active).attr("id").replace("project-image-", "");
		var nextID = parseInt(activeID) + 1;*/
		var activeLink = $("#pic-pager a.active");
		$(activeLink).removeClass("active");
		$(activeLink).parent().next().children("a").addClass("active");
	}
	else {
		$("#project-image-0").fadeIn();
		$("#project-image-0").addClass("active");
		$("#pic-pager a.active").removeClass("active");
		$("#pic-pager li.first a").addClass("active");
	}
}

function stopSlideShow() {
	intervalID = clearInterval(intervalID);	
}

function startSlideShow() {
	intervalID = clearInterval(intervalID);	
	intervalID = setInterval( "slideShow()", 5000 );
}