var Q = jQuery.noConflict();

Q(document).ready(function() {
    // do this stuff when the HTML is all ready

	var lang = getLanguage();						// set global language identifier
	var currentpage = 'about.php';					// set global active page
	var currentgallery = 'defaultgallery.html';		// set global active page	
	if (lang == "fr"){Q('#cartoons').html('Annotations');} // translate
	
	//	init
	Q("a").filter("#"+lang).addClass("active");
	Q("a").filter("#about").addClass("active");
	if (lang != "nl"){
		Q('#content').load(currentpage+'?lang='+lang, updateScrollbars); // load default content
	}
	Q('#slideshow').load(currentgallery, startGallery);
	
	// behaviour
	Q('#menu > a').click(function() {
		Q('#menu > a').removeClass("active");
    	Q(this).addClass("active");
		currentpage = Q(this).attr("href");
		return false;
   	});
	
	//navigation
	Q('#menu > a').click(function() {
		if (Q(this).attr("id") == "cartoons"){
			if (currentgallery != "cartoongallery.html"){
				currentgallery = "cartoongallery.html";
				Q('#slideshow').load(currentgallery, startGallery);
			}
		}
		else{
			if (currentgallery != "defaultgallery.html"){
				currentgallery = "defaultgallery.html";
				Q('#slideshow').load(currentgallery, startGallery);
			}
		}
		Q('#content').load(Q(this).attr("href")+'?lang='+lang, updateScrollbars);
		Q(this).blur();
	});
	
	// language select
	Q('#language > a').click(function() {
		Q('#language > a').removeClass("active");
    	Q(this).addClass("active");
		Q(this).blur();
		if ( lang != (Q(this).attr("id"))){
			lang = Q(this).attr("id");
			if (lang == "nl"){Q('#cartoons').html('Kanttekeningen');}
			if (lang == "fr"){Q('#cartoons').html('Annotations');}
			if (lang == "en"){Q('#cartoons').html('Sidesteps');}
			Q('#content').load(currentpage+'?lang='+lang, updateScrollbars); // get current page in correct lang
		}
		return false;
   	});	

	// refresh scrollbar height to content
	function updateScrollbars(){
		Q('.scroll-pane').jScrollPane({showArrows:true, scrollbarWidth:16, scrollbarMargin:0});	
	}

	// get language function
	function getLanguage() {

		if (navigator.userLanguage) {
			lang = navigator.userLanguage;
		} 
		else if (navigator.language) {
			lang = navigator.language;
		} 
		else if (navigator.browserlanguage) {
			lang = navigator.browserlanguage;	
		} 
		if (lang.indexOf('fr') > -1) {
		return('fr');
		}
		else {
			return('nl');
		}
	}



	// start gallery
	function startGallery() {
		if(currentpage == "cartoons.php"){
			var myGallery = new gallery($('myGallery'), {
				timed: true,
				useThumbGenerator: true,
				textShowCarousel: 'INDEX',
				lightbox: true,
				showInfopane: false
			});			
		}
		else{
			var myGallery = new gallery($('myGallery'), {
				timed: true,
				useThumbGenerator: true,
				textShowCarousel: 'INDEX',
				lightbox: true
			});
		}
	// ini thickbox zoomin		
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
	
}

});


