/* 

 * [a] Dries Van haver

 * [c] Oskar D

 * [w] www.oskard.be

*/



/*--------------------------------------------------------------------------------------------------------

*

* HANDLE INIT 

*

--------------------------------------------------------------------------------------------------------*/

$(document).ready(function(){

	$("ul#sliding-navigation li").hide();

	$("ul.sliding-subnavigation li").hide();

	$("ul.sliding-subsubnavigation li").hide();

	$("ul.sliding-subsubsubnavigation li").hide();

	document.getElementById("sliding-navigation").style.display = "block";

	$("ul#sliding-navigation li").show(0);	

	

	$("#nav ul#sliding-navigation li a").click(function () { 

		$("#nav ul li a").removeClass("sel");

     	$(this).addClass("sel");

    });	

    $("#nav ul.sliding-subnavigation li a").click(function () { 

		$("#nav ul.sliding-subnavigation li a").removeClass("sel");

     	 $(this).addClass("sel");

    });	



    $("#nav ul.sliding-subsubnavigation li a").click(function () { 

		$("#nav ul.sliding-subsubnavigation li a").removeClass("sel");

     	 $(this).addClass("sel");

    });	



    $("#nav ul.sliding-subsubsubnavigation li a").click(function () { 

		$("#nav ul.sliding-subsubsubnavigation li a").removeClass("sel");

     	 $(this).addClass("sel");

    });	

	/*--------------------------------------------------------------------------------------------------------

	* Handle blue blocks

	--------------------------------------------------------------------------------------------------------*/   

	var searchString = "boek"; // the page on which the blocks are shown

	var searchable = document.location.href;

	

	if($("jcarousel-container")){

		$("ul#items li a").fadeTo("slow", 0.5);

		

		$("ul#items li a").mouseover(function(){

			$(this).fadeTo("slow", 1);

		});



	 	$("ul#items li a").mouseout(function(){

			$(this).fadeTo("slow", 0.5);

		}); 



		$("ul#items li a").click(function(){

			getPhoto($(this));

		});

	}

});

/*--------------------------------------------------------------------------------------------------------

*

* HANDLE GET PHOTO 

*

--------------------------------------------------------------------------------------------------------*/

function getPhoto(photo){

	$("ul#items li a").css({background: "#999999" });

		var caption = photo.attr('caption');

  	  	var source = photo.attr('src');

  	  	

  	  	$("div#info p").fadeTo("slow",0, function(){

			$(this).text(caption);

  	  		$(this).fadeTo("slow",1);

 		});



		/*$("#foto").fadeTo("slow",0, function(){

			$(this).attr('src',source);

  	  		$(this).fadeTo("slow",1);

 		});*/

 		//$("#foto").fadeTo("slow",0), $("#foto").attr('src',source).fadeTo("slow",1);	

 		$("#foto").attr('src',source);	

  	   photo.css({background: "#0099ff" });

}

/*--------------------------------------------------------------------------------------------------------

*

* HANDLE NAVIGATION 

*

--------------------------------------------------------------------------------------------------------*/

var mycarousel_itemList=[];

/*--------------------------------------------------------------------------------------------------------

* Build a submenu

--------------------------------------------------------------------------------------------------------*/

function buildSubnav(page,parent){

	var currentMenu = "ul#"+page;

	document.getElementById(page).style.display = "block";

	var theListitem = "ul#"+page+" li";

	if(parent){

		$(theListitem).show(0);

	}else{

		$(theListitem).show(400);

	}

	

}

/*--------------------------------------------------------------------------------------------------------

* Rebuild the navigation

--------------------------------------------------------------------------------------------------------*/

function rebuildSubnav(page){

	currentMenu = "ul#"+page;

	document.getElementById(page).style.display = "block";

	var theListitem = "ul#"+page+" li";

	$(theListitem).show(0);

}

/*--------------------------------------------------------------------------------------------------------

*

* HANDLE CAROUSEL 

*

--------------------------------------------------------------------------------------------------------*/
var goScroll = true;

function buildCarousel(page,list){ // it's an image gallery

	document.getElementById(page).style.display = "block";

	mycarousel_itemList = list;

	var theCarousel = '#'+page;

	var currentMenu = "ul#"+page;

	jQuery(theCarousel).jcarousel({
       	size: mycarousel_itemList.length+1,
       	animation: "slow",
       	 //start: 15,
      	itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback, onAfterAnimation:mycarousel_initCallback}

   	});

   	/* set the carousel width */
   	var navigationOffset = $("div#nav").offset();

  	var navigationWidth= $("div#nav").width();

   	var carouselWidth =$(currentMenu).width();

   	var carouselOffset =$(currentMenu).offset();

   	var newWidth = Math.round((navigationOffset.left + navigationWidth) - carouselOffset.left)-10;

   	//if(carouselWidth >newWidth){ // only resize the carousel if you need to

   	var theWidth = $(".jcarousel-list").css("width");

   	var theWidthNr = Number(theWidth.substring(0, theWidth.length-2));

   	if(theWidthNr > newWidth){

   		$("div.jcarousel-clip").css("width",newWidth);

   	}else{

   		$("div.jcarousel-clip").css("width",theWidthNr);

   		$('div.jcarousel-prev').hide();

   		$('div.jcarousel-next').hide();

   	}
   	
   	if(mycarousel_itemList.length <= 7) {
   	
   		$('div.jcarousel-prev').hide();

   		$('div.jcarousel-next').hide();
   	}
	
}

function mycarousel_initCallback(carousel) {
	// SCROLL TO SPECIFIC ITEM 
	if(goScroll){
  	var scrollTo = jQuery("li.jcarousel-item a.sel").attr('id');
  		if(scrollTo != undefined && scrollTo > 7){ /* > 7 -> maw de thumb was init nog niet visible */
  			carousel.scroll(jQuery.jcarousel.intval(scrollTo)+1);
   		}
  		goScroll = false;
  		}
  	}


/*--------------------------------------------------------------------------------------------------------

* Callback

--------------------------------------------------------------------------------------------------------*/

function mycarousel_itemLoadCallback(carousel, state){

    for (var i = 0; i < mycarousel_itemList.length; i++) {

        carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i],i));  

    }
    
};


/*--------------------------------------------------------------------------------------------------------



* Return html



--------------------------------------------------------------------------------------------------------*/

function mycarousel_getItemHTML(item,nr){

    result= '<a href="'+item.link+'"';if(location.href==item.link){

    	result+='class="sel"';

    }

    result +='id="'+nr+'"><img src="' + item.thumb + '" width="80" height="80" alt=""/></a>';

    return result;

};