$(document).ready(function(){

	//loading du theme
	Galleria.loadTheme('/fileadmin/templates_cac_v2/scripts/classic/galleria.classic.js');

	//aller chercher la classe du body pour savoir la gallery qu'on affiche	
	var bodyclass = $('body').attr('class');
	loadAlbum(bodyclass);
	
	//loader une nouvelle galerie en passant le nom de la galerie que nous voulons
	function loadAlbum(name){  
		var data = 'gallery='+name;
		//$("#images").html("loading "+name+"...");
		$.ajax({
				url: "/fileadmin/templates_cac_v2/showcase.php",
				data: data,
				dataType:"html",
				cache: false,
				success: function(html){ 
				
					$("#images").html(html);
					
					$("#images").galleria({
						//debug: false,
						autoplay: 5000,
						transition:'fade',
						transitionSpeed:1000,
						width: 860,
						height: 570,			
						clicknext:true,
						_toggleInfo: false,
						thumbnails:false,
						showCounter:false,
						extend: function(options) {		
									
							this.bind("fullscreen_enter", function(e) {
								$("#showcase").addClass("open");
								$(".galleria-fullscreen").addClass("open");
							});
							this.bind("fullscreen_exit", function(e) {
								$("#showcase").removeClass("open");
								$(".galleria-fullscreen").removeClass("open");
							});
							
						}
					});
					
				}  
		});  
	}
	
	//FullScreen button
	$('.galleria-fullscreen').click(function() {
    var gallery = Galleria.get(0);
		gallery.toggleFullscreen();		
	});		
	
	/*Pour pogner la variable GET*/	
	function getPath (){
			return  location.href.substring( 25 , location.href.length);
	}
	
	switch(getPath()){
		case '/fr/produits/cuisines/index.html':
		case '/en/products/kitchens/index.html':
			document.getElementById('menu_cui').className = 'act';
		break;
		case '/fr/produits/cuisines/contemporaines/index.html':
		case '/en/products/kitchens/contemporary/index.html':
			document.getElementById('menu_cui').className = 'act';
			document.getElementById('ss_co').className = 'act';
		break;
		case '/fr/produits/cuisines/classiques/index.html':
		case '/en/products/kitchens/classic/index.html':
			document.getElementById('menu_cui').className = 'act';
			document.getElementById('ss_cla').className = 'act';
		break;
		case '/fr/produits/cuisines/champetres/index.html':
		case '/en/products/kitchens/country-style/index.html':
			document.getElementById('menu_cui').className = 'act';
			document.getElementById('ss_ch').className = 'act';
		break;
		case '/fr/produits/cuisines/transitionnelles/index.html':
		case '/en/products/kitchens/transitional/index.html':
			document.getElementById('menu_cui').className = 'act';
			document.getElementById('ss_tr').className = 'act';
		break;
		case '/fr/produits/cuisines/urbaines/index.html':
		case '/en/products/kitchens/urban/index.html':
			document.getElementById('menu_cui').className = 'act';
			document.getElementById('ss_urb').className = 'act';
		break;
		
		case '/fr/produits/salles_de_bain/index.html':
		case '/en/products/bathrooms/index.html':
			document.getElementById('menu_sb').className = 'act';        
		break;
		case '/fr/produits/meubles_integres/index.html':
		case '/en/products/built_in_furniture/index.html':
			document.getElementById('menu_mi').className = 'act';        
		break;            
		default: 
			//document.getElementById('menu_cui').className = 'act';
		break; 
	}
	
	
	
});
//old stuff
// JavaScript Document
// Permalinks option
function flashPutHref(href) { location.href = href; }

/*Pour pogner la variable GET*/	
function getVar (nomVariable)
	{
		var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&"
		if (infos.indexOf("#")!=-1)
			infos = infos.substring(0,infos.indexOf("#"))+"&"
		var variable=0
		{
			nomVariable = nomVariable + "="
			var taille = nomVariable.length
			if (infos.indexOf(nomVariable)!=-1)
				variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"))
		}
		return variable
	}



function loadSSAlbum(inAlbum){
	loadAlbum(inAlbum);
	document.getElementById('ss_urb').className = '';
	document.getElementById('ss_cla').className = '';
	document.getElementById('ss_co').className = '';
	document.getElementById('ss_ch').className = '';
	document.getElementById('menu_cui').className = 'act';
	document.getElementById('menu_sb').className = '';
	document.getElementById('menu_mi').className = '';
	
	document.getElementById('ss_'+inAlbum).className = 'act';
}

//function initAlbum(){

//}


// section pour player youtube

	function onYouTubePlayerReady(playerId) {
		ytplayer = document.getElementById("myytplayer");
		ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
	}
	
	function onytplayerStateChange(newState) {
		if(newState == '0' ){
		 document.getElementById('flash').innerHTML = '<div id="flashcontent"></div>';
		 initAlbum();
		}
			 
	}

	function initYouTube(){
		var params = { allowScriptAccess: "always" };
		var atts = { id: "myytplayer" };
		swfobject.embedSWF("http://www.youtube.com/e/vxfD2zxouCs?enablejsapi=1&playerapiid=ytplayer&theme=dark&autoplay=1&autohide=1","flashcontent", "854", "527", "8", null, null, params, atts);
	}




