// On stock le carousel pour réutilisation ultérieur
var we_carousel;

$(document).ready(function() {
  	//adjust size to viewport
	adjustToViewPort();
	
	$(window).bind('resize', function() {
 		adjustToViewPort();
 	});

	
	// SWF du logo
	var attributes = {};
	var params = {wmode:'transparent'}; 	
	swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/logo.swf", "logo", "960", "160", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
	
	// SI on est sur la home ou sur une des pages portfolio
	if(page == "index") 
	{
		var flashvars = {};
		var attributes = {};
		var params = {wmode:'transparent'}; 
		 
		// Ajout des flèches pour le carrousel
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/fleche_gauche.swf", "mycarousel-prev", "50", "90", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/fleche_droite.swf", "mycarousel-next", "50", "90", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
		
		// Ajout des 5 bouton Suite
		flashvars = {url:$("#call_test_0").parent().attr("href")};
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/suite.swf", "call_test_0", "38", "12", "9.0.0", "expressInstall.swf", flashvars);	
		
		flashvars = {url:$("#call_test_1").parent().attr("href")};
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/suite.swf", "call_test_1", "38", "12", "9.0.0", "expressInstall.swf", flashvars);	
		
		flashvars = {url:$("#call_test_2").parent().attr("href")};		
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/suite.swf", "call_test_2", "38", "12", "9.0.0", "expressInstall.swf", flashvars);	
		
		flashvars = {url:$("#call_test_3").parent().attr("href")}; 
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/suite.swf", "call_test_3", "38", "12", "9.0.0", "expressInstall.swf", flashvars);
		
		flashvars = {url:$("#call_test_4").parent().attr("href")};		
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/suite.swf", "call_test_4", "38", "12", "9.0.0", "expressInstall.swf", flashvars);
		
		// Ajout des écouteur pour le rollover des ref
		$("#stage").bind("mouseover",function(){
			$(".carmeta").animate({"opacity": "1"}, "slow");
		});
		
		// Ajout des écouteur pour le rollover des ref
		$("#stage").bind("mouseout",function(){
			$(".carmeta").animate({"opacity": "0.45"}, "slow"); 
		});	 
		
		// Ajout d'un écouteur pour le survol de l'image
		$(".img_masque").mouseover(function(){
			$(this).children("img").animate({ "height": "250", "width": "430"}, 500);		 	
			
		});
		

		$(".img_masque").mouseout(function(){
			$(this).children("img").animate({ "height": "220", "width": "400"}, 500);		 	
			
		});
		
		
		// Affichage du menu
		var flashvars = {page:"index"}; 
		var attributes = {};
		var params = {wmode:'transparent'};   	
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/MainNav.swf", "mainnav", "200", "380", "9.0.0", "expressInstall.swf", flashvars, params, attributes);		
		
		// Ajout des rollover sur la sidebar
		$("#sidebar.news li").mouseover(function(){
			$(this).css("background", "url(http://www.walter-ego.fr/wp-content/themes/walterego/images/news_bg_over.png) left top no-repeat");
			$(this).children("p").children("span").children("img").css("margin-top", "-65px");
			$(this).children("p").css("color", "#FFFFFF"); 			
			$(this).children("p").children("a").css("color", "#FFFFFF"); 			
			
			
		});
		
		$("#sidebar.news li").mouseout(function(){ 
			$(this).css("background", "url(http://www.walter-ego.fr/wp-content/themes/walterego/images/news_bg.png) left top no-repeat");
			$(this).children("p").children("span").children("img").css("margin-top", "0px");
			$(this).children("p").css("color", "#898989");
			$(this).children("p").children("a").css("color", "#898989"); 			
		});		
	}
	
	// SI on est sur la page agence
	if(page=="agence") 
	{
		var flashvars = {page:"agence"}; 
		var attributes = {};
		var params = {wmode:'transparent'}; 	
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/MainNav.swf", "mainnav", "200", "380", "9.0.0", "expressInstall.swf", flashvars, params, attributes);		

		
		var flashvars = {page:"agence"}; 
		var attributes = {};
		var params = {}; 
		 
		// Ajout des flèches pour le carrousel
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/Video_TimeLapse.swf", "stage", "720", "396", "9.0.0", "expressInstall.swf");
		
		// Ajout des rollover sur la sidebar
		$("#sidebar.news li").mouseover(function(){
			$(this).css("background", "url(http://www.walter-ego.fr/wp-content/themes/walterego/images/news_bg_over.png) left top no-repeat");
			$(this).children("p").children("span").children("img").css("margin-top", "-65px");
			$(this).children("p").css("color", "#FFFFFF"); 			
			$(this).children("p").children("a").css("color", "#FFFFFF"); 			
			
			
		});
		
		$("#sidebar.news li").mouseout(function(){ 
			$(this).css("background", "url(http://www.walter-ego.fr/wp-content/themes/walterego/images/news_bg.png) left top no-repeat");
			$(this).children("p").children("span").children("img").css("margin-top", "0px");
			$(this).children("p").css("color", "#898989");
			$(this).children("p").children("a").css("color", "#898989"); 			
		});			
	}

	// SI on est sur la page agence
	if(page=="contact") 
	{
		var flashvars = {page:"contact"}; 
		var attributes = {};
		var params = {wmode:'transparent'}; 	
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/MainNav.swf", "mainnav", "200", "380", "9.0.0", "expressInstall.swf", flashvars, params, attributes);		
	}
	
	// SI on est sur la page references
	if(page=="references") 
	{
		var flashvars = {page:"references"}; 
		var attributes = {};
		var params = {wmode:'transparent'}; 		
		swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/MainNav.swf", "mainnav", "200", "380", "9.0.0", "expressInstall.swf", flashvars, params, attributes);		
	
		$(".posts li .post p a").each( function(){
			var flashvars = {url:$(this).attr("href")};
			var attributes = {};
			var params = {};		
			
			// On ajoute un attribut id sur chaque lien
			$(this).attr("id", $(this).parent().parent().children("h3").text());
			swfobject.embedSWF("http://www.walter-ego.fr/wp-content/themes/walterego/swf/suite.swf", $(this).parent().parent().children("h3").text(), "38", "12", "9.0.0", "expressInstall.swf", flashvars);
		});
	}		
});

function opengmap()
{
	zoombox.open("http://maps.google.fr/maps?f=q&source=s_q&hl=fr&geocode=&q=340+rue+Saint-Honor%C3%A9+75001+Paris+-+France+&sll=46.75984,1.738281&sspn=11.215826,28.54248&ie=UTF8&hq=&hnear=340+Rue+Saint-Honor%C3%A9,+75001+Paris,+Ile-de-France&t=h&z=16",zoombox.windowW(),zoombox.windowH());
}

function mycarousel_itemLoadCallback(carousel, state)
{
	// On stock le carousel
	we_carousel = carousel;
	
	if (state != 'init')
	   	return;

	jQuery('#mycarousel-next').bind('click', function() {
    	carousel.next();
    	return false;
	});

	jQuery('#mycarousel-next').show();

	jQuery('#mycarousel-prev').bind('click', function() {
    	carousel.prev();
    	return false;
	});

	jQuery('#mycarousel-prev').show();
};

function asCall_carousel_prev()
{
	we_carousel.prev();
}

function asCall_carousel_next()
{
	we_carousel.next();
}

function adjustToViewPort()
{
	// we want the main width to fill the right portion of the viewport
	
	// |   ###[         ]|
	
	// | are viewport borders
	// the left margin of the 960px content is auto
	// ### is the 240px main left margin (sidebar)
	// [  ] is the main div
	
	//main left margin
	var mainmargin = 240;
	
	//viewport width
	var vwidth = $(window).width(); 
	var vmargin = Math.floor((vwidth - 960 )/2);
	
	var mainwidth = vwidth-mainmargin-vmargin;
	//main width = 1040 px max
	
	if (mainwidth > 1040 )
		mainwidth = mainwidth;
		
	$("#main").width(Math.floor(mainwidth));
	
	$(".liquid").each( function(){
		var total = Math.floor(mainwidth)-1-parseInt($(this).css("padding-left"), 10)-parseInt($(this).css("padding-right"), 10);
		$(this).width(total);
	});
	
	// On met le gmap en plein ecran
	$("#gmaps").width($(window).width());
}


function initCarousel()
{
		jQuery('#mycarousel').jcarousel({
		scroll: 1,
		wrap: 'circular',
     			itemLoadCallback: mycarousel_itemLoadCallback,
       			itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
       			itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
  				buttonNextHTML: null,
     			buttonPrevHTML: null   
  		});
	    
}

function mycarousel_getItemHTML(item)
{
	strhtml = item.htmlcode;
    return strhtml;
};

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
	var idx = carousel.index(i, mycarousel_itemList.length);
	carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
	carousel.remove(i);
};
