/* ================================ +
		NATIONAAL GLASMUSEUM
 + ================================ */



/* 
** Made by: Thomas Lievestro
** Email:	info@lievestro.com
** Website:	www.lievestro.com
*
** PATCHED BY PICTURA DATABASE PUBLISHING
*/


/* ================================ +
               GENERAL
 + ================================ */


/* variables */
//var CollectionFlash_xmlPath = "xml/content.xml"
//var CollectionFlash_imagePath = "footage/img/"
	
var CollectionFlash_xmlPath = escape(cmsSettings.live_site + 'index.php?option=com_memorixbeeld&view=thema&format=collectie&id=' + cmsSettings.theme_id);
var CollectionFlash_imagePath = "";

// Function for toggle extended search
function toggleExtendedSearch() {
	
	if ($('#extended_search').is(":hidden")) { 
		$('#extended_search').slideDown(300);    	
    } 
    else if ($('#extended_search').not(":hidden")) { 
		$('#extended_search').slideUp(300);    	
    } 		
		
}

// Function for toggle content slider on collection detail page
function toggleSlider(item){
	
	$(".content_slider_nav_item").removeClass('active');
	
	//get contentItem
	contentItem = (item.id).split('_')[0]+'_item';	
	
	if ($('#'+contentItem).is(":hidden")) { 
		$(item).addClass('active');
		
		$(".content_slider_content_item").slideUp(300).css('z-index','1').css('display','none');
		$('#'+contentItem).css('z-index','2');
		$('#'+contentItem).slideDown(300);    	
    } 
    else if ($('#'+contentItem).not(":hidden")) { 		
		$('#'+contentItem).slideUp(300);    	
    } 	
	
}




// Function for display lightboxes
function displayLightbox(overlay,foto){		
			
	//Fade in overlay background
	$('#overlay_bg_container').fadeIn();									

	if(overlay=='foto'){
		if(!foto.attr('src')) {
			return;
		}
		
		var src = foto.attr('src').replace('/detail/', '/lightbox/');
		var imageObj = new Image();
		imageObj.src = src;   
		
		//If image is loaded
		imageObj.onload = function() {  
			$('#overlay_image').html('<a id="close_overlay_image" class="close_lightbox" href="javascript:;" onclick="hideLightbox(\'foto\');" title="sluiten" ></a><img src="'+src+'" width="750" />');
			//Fade in overlay
			
			window.setTimeout("$('#overlay_image').fadeIn()", 600);	
		}
		
	}
	
	else if(overlay=='video1'){
				
		//Fade in overlay
		window.setTimeout("$('#overlay_video_1').fadeIn()", 600);
	}	
	else if(overlay=='video2'){
				
		//Fade in overlay
		window.setTimeout("$('#overlay_video_2').fadeIn()", 600);
	}
	else if(overlay=='video3'){
				
		//Fade in overlay
		window.setTimeout("$('#overlay_video_3').fadeIn()", 600);
	}
	else if(overlay=='video3'){
				
		//Fade in overlay
		window.setTimeout("$('#overlay_video_3').fadeIn()", 600);
	}
	
	else if(overlay=='newletter'){	
		
		//Fade in overlay
		window.setTimeout("$('#overlay_newsletter').fadeIn()", 600);
		
		//IE6 FIX - activate png fix
		if((OS == "Windows") && (browser == "Explorer") && (version == "6")){ 
			window.setTimeout("$('#overlay_newsletter').css('behavior','url(htc/iepngfix.htc)')", 650);
		}
			
	}
	
	//IE6 FIX - activate png fix
	if((OS == "Windows") && (browser == "Explorer") && (version == "6")){ 
		window.setTimeout("$('.close_lightbox').css('behavior','url(htc/iepngfix.htc)')", 650);
		window.setTimeout("$('#overlay_bg_container').css('behavior','url(htc/iepngfix.htc)')", 650);
	}
			
}

// Function for hide lightboxes
function hideLightbox(overlay){
	
	if(overlay=='foto'){ 
		//Fade out overlay
		$('#overlay_image').fadeOut();							
	}
	else if(overlay=='video1'){		
	 	//Fade out overlay
		$('#overlay_video_1').fadeOut();										
	}
	else if(overlay=='video2'){		
	 	//Fade out overlay
		$('#overlay_video_2').fadeOut();										
	}
	else if(overlay=='video3'){		
	 	//Fade out overlay
		$('#overlay_video_3').fadeOut();										
	}
	else if(overlay=='video3'){		
	 	//Fade out overlay
		$('#overlay_video_3').fadeOut();										
	}
	else if(overlay=='newletter'){		
	 	//Fade out overlay
		$('#overlay_newsletter').fadeOut();										
	}
		
	//Fade out overlay background
	window.setTimeout("$('#overlay_bg_container').fadeOut();", 400);
} 



function initFotoZoomer(){
	
	if((OS == "Windows") && (browser == "Explorer") && (version == "6")){ 
	
		$('#photo_zoomer').css("height",(getBrowserSize()[1]-165)+'px');			//Make the height 100
		$('body').css("height",(getBrowserSize()[1]-5)+'px');						//Make the height 100%
	}else{
	
		//$('#photo_zoomer').css("height",(getBrowserSize()[1]-50)+'px');			//Make the height 100
		$('#photo_zoomer').css("height",(getBrowserSize()[1]-160)+'px');				// Patched by pictura
		$('body').css("height",(getBrowserSize()[1]-5)+'px');						//Make the height 100%
	}
	$('#photo_zoomer_catalogpages').css("height", (parseInt($('body').css("height")) - 25) +'px'); // Patched by Pictura
	
	var resizeTimer = null;
	
	$(window).bind('resize', function() {
	
		if (resizeTimer) clearTimeout(resizeTimer);
			resizeTimer = setTimeout(function(){
				if((OS == "Windows") && (browser == "Explorer") && (version == "6")){ 
	
					$('#photo_zoomer').css("height",(getBrowserSize()[1]-165)+'px');			//Make the height 100
					$('body').css("height",(getBrowserSize()[1]-5)+'px');						//Make the height 100%
				}else{
				
					//$('#photo_zoomer').css("height",(getBrowserSize()[1]-50)+'px');			//Make the height 100
					$('#photo_zoomer').css("height",(getBrowserSize()[1]-160)+'px');				// Patched by pictura
					$('body').css("height",(getBrowserSize()[1]-5)+'px');						//Make the height 100%
				}
				$('#photo_zoomer_catalogpages').css("height", (parseInt($('body').css("height")) - 30) +'px'); // Patched by Pictura
			}, 100);
	});

}



/* ================================ +
           SKILFUL FUNCTIONS
 + ================================ */

function getBrowserSize() {
	        
    var theWidth, theHeight;
	// Window dimensions: 
	if (window.innerWidth) {
	theWidth=window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
	theWidth=document.documentElement.clientWidth;
	}
	else if (document.body) {
	theWidth=document.body.clientWidth;
	}
	if (window.innerHeight) {
	theHeight=window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
	theHeight=document.documentElement.clientHeight;
	}
	else if (document.body) {
	theHeight=document.body.clientHeight;
	}

	return [theWidth,theHeight];
}

function getPageSize() {
	        
    var xScroll, yScroll;
    
    var OS = BrowserDetect.OS;
	var browser = BrowserDetect.browser;
	var version = BrowserDetect.version;
	
	if((OS == "Windows") && (browser == "Explorer") && (version == "7")){    	
		xScroll = document.body.parentNode.scrollWidth;
		yScroll = document.body.parentNode.scrollHeight;
    }else{ 
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
	}
	
	var windowWidth, windowHeight;
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}




var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};












var OS;





/* parse the Jquery functions after document ready */
$(document).ready(function(){

	//Get browser details
	BrowserDetect.init();

	//Set browser details in variables
	OS = BrowserDetect.OS;
	browser = BrowserDetect.browser;
	version = BrowserDetect.version;


	/* FLASH */

	if($('.collection_flash_block').length == 1){
		
		//WINDOWS FIREFOX 2.0 FIX
		if((OS == "Windows") && (browser == "Firefox") && (version == "3")){  
			browserCheck = 0;
		}else{
			browserCheck = 1;
		}
		
	
		var flashvars = {  		
	  		browserCheck: ""+browserCheck+"",
	  		xmlPath: ""+CollectionFlash_xmlPath+"",
	  		imagePath: ""+CollectionFlash_imagePath+""
		}
		
		var params = { wmode: "transparent" }
				
		swfobject.embedSWF(cmsSettings.live_site + "templates/gla/flash/Controller.swf", "flashcontent", "960", "500", "9.0.0", "flash/expressInstall.swf", flashvars, params);				
	}


	if($('#photo_zoomer').length == 1){	
	
		initFotoZoomer();
	}



	/* BUTTONS */

	// extended search button
	$("#expand_extended_search")
	.click(function(){
		toggleExtendedSearch();
		return false;
	});
	

	// extended search button
	$(".content_slider_nav_item")
	.click(function(){
		toggleSlider(this);
		return false;
	});	
	
	
	
	// open video lightbox
	$("#play_video1")
	.click(function(){ 
   		displayLightbox('video1');
		return false;
	});
	
	// Close image lightbox
    $("#close_overlay_video_1")
   .click(function(){
		hideLightbox('video1');
		return false;
   	});
   	
   	// open video lightbox
	$("#play_video2")
	.click(function(){ 
   		displayLightbox('video2');
		return false;
	});
	
	// Close image lightbox
    $("#close_overlay_video_2")
   .click(function(){
		hideLightbox('video2');
		return false;
   	});
   	
   	// open video lightbox
	$("#play_video3")
	.click(function(){ 
   		displayLightbox('video3');
		return false;
	});
	
	// Close image lightbox
    $("#close_overlay_video_3")
   .click(function(){
		hideLightbox('video3');
		return false;
   	});
   	
   	// open video lightbox
	$("#play_video2")
	.click(function(){ 
   		displayLightbox('video4');
		return false;
	});
	
	// Close image lightbox
    $("#close_overlay_video_4")
   .click(function(){
		hideLightbox('video4');
		return false;
   	});
	
	
	
	
	
	// open image lightbox
	$("#plus_button")
	.click(function(){ 
   		displayLightbox('foto',($(this).prev()));
		return false;
	});
	
	// Close image lightbox
    $("#close_overlay_image")
   .click(function(){
		hideLightbox('user_image');
		return false;
   	});
   	
   		
	// open newsletter lightbox
	$("#newsletter_button")
	.click(function(){ 
   		displayLightbox('newletter');
		return false;
	});
	
	// Close newsletter lightbox
    $("#close_overlay_newsletter")
   .click(function(){
		hideLightbox('newletter');
		return false;
   	});
   	
   	
   	
   	// Send registration
   	$("#verstuur_button")
   	.click(function(){
   		$('#newsletter_form').submit();
   	});
   	
   	
   	
   	
   	/* related object */
    $('.related_object')
	.mouseover(function(){
		$('.related_object.active').removeClass('active');
		$(this).addClass('active');
	})
   	
   	/* featured object */
    $('.featured_object')
	.mouseover(function(){
		$('.featured_object.active').removeClass('active');
		$(this).addClass('active');
	})
	
	

	/* TOOLTIPS */
	if($('.related_object img').length == 1){
		$('.related_object img').tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - ",
			top: 20,
			left: -10
		});	
	}
	
	if($('.featured_object img').length == 1){
		$('.featured_object img').tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - ",
			top: 20,
			left: -10
		});
	}
		
	if($('.featured_object img').length == 1){
		$('.navigation_item img').tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - ",
	    	extraClass: "top", 
			top: -35,
			left: -10
		});
	}
	
	/* search filter */
    $('.remove_button')
	.mouseover(function(){
		$(this).prev().css('textDecoration','line-through');
	})	
	.mouseout(function(){
		$(this).prev().css('textDecoration','none');
	})	
	
   	$(".show_more_filter_options")
   	.click(function(){
		var hideTRs = $(this).prev().find('.hideTR');
		var item = this;
		for (var j=0;j<hideTRs.length;j++)	{
			setTimeout(function(){
				$(item).prev().find('.hideTR:first').removeClass('hideTR');
			},30*j);
		}		
		$(this).hide();
		$(this).next().show();
   	});	
	
   	$(".show_less_filter_options")
   	.click(function(){
		var TRs = $(this).prev().prev().find('tr');
		var item = this;
		for (var j=4;j<TRs.length;j++)	{
			setTimeout(function(){
				$(item).prev().prev().find('tr:not(.hideTR):last').addClass('hideTR');
			},30*j);
		}		
		$(this).hide();
		$(this).prev().show();
   	});
   		
});