var $j = jQuery.noConflict();

$j(document).ready(function(){
	if($j.browser.msie){
		$j(".overhead img").hover(
		   function(){
			   var link = $j(".jcarousel-control a.act").text();
			   if($j(".jcarousel-list li:eq("+(parseInt(link-1))+") h2 a").size() > 0){
				  $j(".jcarousel-list li:eq("+(parseInt(link-1))+") h2 a").addClass("h2link");
				  $j(this).css("cursor","pointer");
   				}
		   },
		   function(){
			   var link = $j(".jcarousel-control a.act").text();
			   if($j(".jcarousel-list li:eq("+(parseInt(link-1))+") h2 a").size() > 0){
				  $j(".jcarousel-list li:eq("+(parseInt(link-1))+") h2 a").removeClass("h2link");
				  $j(this).css("cursor","normal");
			   }
		   }
	   );             
	   $j(".overhead img").click(function(){
		   var link = $j(".jcarousel-control a.act").text();
		   if($j(".jcarousel-list li:eq("+(parseInt(link-1))+") h2 a").size() > 0){
				document.location.href=$j(".jcarousel-list li:eq("+(parseInt(link-1))+") h2 a").attr("href");
		   }
	   });
	}

	
	$j("#content .left").css("min-height",$j("#content").height()/16+"em");
	
	$j("ul.size li a").click(function(){
		switch($j(this).parent("li").index()){
			case 0:
				maj_cook("normal");
				break;
			case 1:
				maj_cook("medium");
				break;
			case 2:
				maj_cook("big");
				break;
			default:
				maj_cook("normal");
				break;
		}
		return false;
	});
	
	habillage();
	
	$j("select#habillage").change(function(){
		habillage($j(this).val());
	});

	
	/*$j("ul.size li").click(function(){
		var pos = ($j("ul.size li").index(this));
		switch(pos){
			case 0:
				$j("div.topleft").css("min-height","11.1em");
				$j("body").css("font-size","100%")
				break;
			case 1:
				$j("div.topleft").css("min-height","11.1em");
				$j("body").css("font-size","110%")
				break;
			case 2:
				$j("div.topleft").css("min-height","11em");
				$j("body").css("font-size","120%");
				break;
		}
	});*/

	$j('.menu-ville ul').superfish(); 
	
	$j("#carousel").jcarousel({
		scroll: 1,
		auto: 8,
		wrap: 'last',
		initCallback: mycarousel_initCallback,
		itemVisibleInCallback: mycarousel_itemVisibleInCallback,
		itemVisibleOutCallback: mycarousel_itemVisibleOutCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null
	}); 	
	
	
	if(litCook("vfr-mobile") == false){
		if(isMobile())
		{
			var UrlToRedirect = window.location.href.replace("/pub/","/pub/mobile/").replace("/intra/","/intra/mobile/");
			cre_cook('vfr-mobile','mobile');
			document.location.href = UrlToRedirect;
		}else{
			cre_cook('vfr-mobile','normal');
		}
	}
});
function mycarousel_itemVisibleOutCallback(carousel,li,idx){
	idx = idx -1;
	jQuery('.jcarousel-control a:eq(' + idx + ')').removeClass("act");
}
function mycarousel_itemVisibleInCallback(carousel,li,idx){
	idx = idx -1;
	jQuery('.jcarousel-control a:eq(' + idx + ')').addClass("act");
}
function mycarousel_initCallback(carousel) {

	carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });

    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		jQuery(".jcarousel-control a").removeClass("act");
		jQuery(this).addClass("act");
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

function maj_cook(size){
	var cook = litCook("vfr");
	tue_cook("vfr");
	if(cook != "" && cook != undefined && cook !== false){
		cook = cook.split(",");
		cre_cook("vfr",cook[0]+","+size);
	}
	else
		cre_cook("vfr","1,"+size);
	habillage();
}


function habillage(val){
	/* si pas de cookie, on le creer par defaut*/
		var cook = litCook("vfr");
		if(cook == "" || cook == undefined || cook === false)
			cre_cook("vfr",",");
			
	/* on gere le cookie */
		if(val != "" && val != undefined && cook !== false){
			tue_cook("vfr");
			if(cook.length == 1){
				cre_cook("vfr",val+",normal");
			}
			else{
				cook = cook.split(",");	
				cre_cook("vfr",val+","+cook[1]);
			}
			var css = 1;
		}
		else{
			if(cook === false || cook == undefined || cook[0] == "" || cook == ",")
				var css = 0;
			else{
				var css = 1;
				cook = cook.split(",");	
				val = cook[0];
			}
		}
	if(css == 1){
		/* on active les css */
			for (i=0;i<document.styleSheets.length;i++)
				void(document.styleSheets.item(i).disabled=false); 
			$j("body").removeClass();

			switch(cook[1]){
				case "big":
					$j("#wrap2 .left > *").css("font-size","150%");
					$j("#wrap2 .right > *").css("font-size","150%");
					$j("#wrap2 .sidebar > *").css("font-size","150%");
					$j("#wrap2 .middle > *").css("font-size","150%");
					$j("#content .left").css("min-height",$j("#content > .right").height()/16+"em");
					/*$j("#wrap2 .right > *").removeAttr("style");*/
					break;
				case "medium":
					$j("#wrap2 .left > *").css("font-size","120%");
					$j("#wrap2 .right > *").css("font-size","120%");
					$j("#wrap2 .sidebar > *").css("font-size","120%");
					$j("#wrap2 .middle > *").css("font-size","120%");
					$j("#content .left").css("min-height",$j("#content > .right").height()/16+"em");
					/*$j("#wrap2 .right > *").removeAttr("style");*/
					break;
				case "normal":
					$j("#wrap2 .left > *").removeAttr("style");
					$j("#wrap2 .right > *").removeAttr("style");
					$j("#wrap2 .sidebar > *").removeAttr("style");
					$j("#wrap2 .middle > *").removeAttr("style");
					$j("#content .left").css("min-height",$j("#content > .right").height()/16+"em");
					/*$j("#wrap2 .right > *").removeAttr("style");*/
					break;
				default:
					$j("#wrap2 .left > *").removeAttr("style");
					$j("#wrap2 .right > *").removeAttr("style");
					$j("#wrap2 .sidebar > *").removeAttr("style");
					$j("#wrap2 .middle > *").removeAttr("style");
					$j("#content .left").css("min-height",$j("#content > .right").height()/16+"em");
					break;
			}
		
		/* on selectionne le option correspondant a val */
			$j("select#habillage option[value=\""+val+"\"]").attr("selected","selected");
			
		/* on d?sactive les bonnes feuilles de styles */
			switch(val){
				case "2":
					for (i=0;i<document.styleSheets.length;i++)
						void(document.styleSheets.item(i).disabled=true); 
					break;
				case "3":
					$j("body").addClass("min");
					break;
				case "4":
					$j("body").addClass("black");
					break;
				default: 
					for (i=0;i<document.styleSheets.length;i++)
						void(document.styleSheets.item(i).disabled=false); 
					$j("body").removeClass();
				break;
			}
	}
}

function cre_cook0(nom,contenu) {
	document.cookie = nom + "=" + escape(contenu)+";domain="+document.location.host+";path=/";
}

function cre_cook(name, value){
	var aujourdhui = new Date() ;
	var expdate = new Date() ;
	expdate.setTime( aujourdhui.getTime() + ( 365*24*60*60*1000 ) )
	document.cookie = name + "=" + value + ";expires=" + expdate.toGMTString()+";domain="+document.location.host+";path=/";
}


function lit_cook(nom) {
	var deb = "";
	var fin = "";
	deb = document.cookie.indexOf(nom + "=");
	if (deb >= 0) {
		deb += nom.length + 1;
		fin = document.cookie.indexOf(";",deb);
		if (fin < 0)
			fin = document.cookie.length;
		return unescape(document.cookie.substring(deb,fin));
	}
	return "";
}

function tue_cook(nom) { 
	cre_cook0(nom,"",-1);
}

function litCook(nom) {
	c=lit_cook(nom);
	if(c=="")
		return false;
	else 
		return c;
}


function isMobile(){
    var a=navigator.userAgent||navigator.vendor||window.opera;
		
	if(navigator.userAgent.match(/Android/i)){return true;}
    if(/avantgo|android|Android|blackberry|blazer|compal|elaine|fennec|hiptop|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile|o2|opera mini|palm( os)?|plucker|pocket|pre\/|psp|smartphone|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce; (iemobile|ppc)|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))return true;
	return false;
}
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23459924-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
