﻿var MorphUtils = {
	sizeWin: function() {
		if (document.body) return {w: document.body.clientWidth, h: document.body.clientHeight} ;
		else return {w: window.innerWidth, h: window.innerHeight} ;
	}
}
function fixed_ie6(el, posY){
	el.style.position = "absolute" ;
	var h = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight
	return Number(posY + h + document.documentElement.scrollTop+document.body.scrollTop)+'px';
}
var MyPage = {
	initialized: false,
	currentM: 0,
	timerSSM: null,
	ssmActu: null,
	callbackPageLoaded: null,
	afficherPlusDInfoEnCours: false,
	pageLoaded: function() {
		if (jQuery.browser.safari) MyPage.init();
		if (MyPage.callbackPageLoaded) MyPage.callbackPageLoaded();
	},
	ouvrirSSM: function(ssm) {
		ssm.animate({height:"show"},1000,"linear", MyPage.deplacerSMenuFlecheDefaut);
	},
	fermerSSM: function(ssm) {
		//ssm.animate({height:"hide"},1000,"linear", MyPage.deplacerSMenuFlecheDefaut);
	},
	initOnce: function() {
		for (var i=1 ; i<=7 ; i++) {
			$("#menu"+i).mouseover(MyPage.deplacerMenuFleche) ;
			$("#menu"+i).mouseout(MyPage.deplacerMenuFlecheDefaut) ;
		}
		for (var i=1 ; i<=10 ; i++) {
			if ($("#sm"+i).length>0) {
				$("#sm"+i).mouseover(MyPage.deplacerSMenuFleche) ;
				$("#sm"+i).mouseout(MyPage.deplacerSMenuFlecheDefaut) ;
			}
			
			$("#ssmOf_sm"+i).each(function(){
				if ($("#"+this.id+" #smActuel").length==0) {
					$(this).css("display","none") ;
					$(this).bind("mouseleave",function() {
						//$(this).animate({height:"hide"},500,"linear");
						MyPage.timerSSM = window.setTimeout(MyPage.fermerSSM, 50, $(this)) ;
					}) ;
					$(this).bind("mouseenter",function() {
						//$(this).animate({height:"show"},500,"linear");
						window.clearTimeout(MyPage.timerSSM) ;
					}) ;
					
					var sm = this.id.substring(6,this.id.length) ;
					$("#"+sm).bind("mouseenter",function() {
						//$("#ssmOf_"+this.id).animate({height:"show"},500,"linear");
						window.clearTimeout(MyPage.timerSSM) ;
						MyPage.ouvrirSSM($("#ssmOf_"+this.id)) ;
					}) ;
					$("#"+sm).bind("mouseleave",function() {
						MyPage.timerSSM = window.setTimeout(MyPage.fermerSSM, 50, $("#ssmOf_"+this.id)) ;
						//window.clearTimeout(MyPage.timerSSM) ;
					}) ;
					
				}
			}) ;
			
		}
		$("#smtitre").mouseover(MyPage.deplacerSMenuFleche) ;
		$("#smtitre").mouseout(MyPage.deplacerSMenuFlecheDefaut) ;
		
		$('#animImage').cycle({ 
			fx: 'fade',
			//easing: 'easeOutBounce',
			speed:    300,
			//delay:  -2000,
			timeout:  4000
		});
		
		$(".plus_d_info").hide().wrap(document.createElement("div")).parent().append("<a href='javascript:void(0);' onmouseover='MyPage.afficherPlusDInfo(this);'><img src='/images/3fleche_bas.gif' border='0' /></a>") ;
	
		//if(reflexOnload) reflexOnload(); if(isIE){addIEReflex(); }else {addReflex(); }
		/*
		var children = document.getElementsByTagName('img'); 
		var elements = new Array(); var i = 0;
		var child; var classNames; var j = 0;
		for (i=0;i<children.length;i++) {
			child = children[i];
			classNames = child.className.split(' ');
			for (var j = 0; j < classNames.length; j++) {
				if (classNames[j] == "reflex") {
					cvi_reflex.add(child, {tilt:"none", transparency:40, distance:0});
				}
			}
		}
		*/
		$('#ex2').jqm({
			onShow: function(h) {
				h.w.css({
					opacity: 1.0
				})/*.animate({
					opacity: 1.0
				}, 1000, "linear", function() {
				}
				)*/.show();
			},
			onHide: function(h) {
				if(h.o) h.o.remove();
				h.w.animate({
					opacity: .0
				}, 100, "linear", function() { if(h.o) h.o.remove(); h.w.hide();}) ;
			} ,
			//overlay:0,
			ajax: '@href',
			target: '#targetActu',
			trigger: '.triggerActu'
	      });

	},
	init: function() {
		//if (!MyPage.initialized) {
			this.initFlechesMenu() ;
			this.initNewsTicker() ;
		//}
		MyPage.initialized = true ;
	},
	initFlechesMenu: function() {
		var el = $("#menu"+MyPage.currentM) ;
		var offset = el.offset() ;
		var w2 = Math.ceil((el.width()/2)-8) ;
		$("#menufleche").css({left:(offset.left+w2)+"px", top:(offset.top+35)+"px"}) ;
		var offset2 = null ;
		var w3 = 0 ;
		if ($("#smActuel").length>0) {
			offset2 = $("#smActuel").offset() ;
			w3 = Math.ceil($("#smActuel").width()+5) ;
		} else {
			if ($("#smtitre").length==0) {
				$("#menufleche2").hide() ;
				return ;
			}
			offset2 = $("#smtitre").offset() ;
			w3 = Math.ceil($("#smtitre").width()+5) ;
		}
		if (jQuery.browser.msie) w3-=2;
		$("#menufleche2").css({left:(offset2.left+w3)+"px", top:(offset2.top)+"px"}) ;
	},
	initNewsTicker: function() {
		if ($("#divActualitesCycle div").length==0) {
			$("#divActualites").css({ position:'absolute', left:-1000, top:-1000, width:100, height:100 });
		} else {
			if ($.browser.msie ){//&& parseInt($.browser.version)==6
				$("#divActualites").css('position', 'absolute');
			} else {
				$("#divActualites").css({ position: 'fixed', top:(MorphUtils.sizeWin().h-85)+"px" }) ;
			}
			$("#divActualites").css({ display: "block", left:0, height:"85px" }) ;//, width:($(window).width())+"px"
			$("#divActualites").fadeTo("fast", 0.8);
			$('#divActualitesCycle').css ({ display: "block", left:0, top:0, height:"65px", width:'100%'}) ;

			if (MyPage.initialized) return ;
			$('#divActualitesCycle').cycle({ 
				fx: 'fade',
				easing: 'linear',
				next: "#flecheactusuivante",
				prev: "#flecheactuprecedente",
				//easing: 'easeOutBounce',
				speed:    10,
				//delay:  -2000,
				timeout:  5000
			});
			/*
			$('#divActualitesCycle').hover(
				function() {
					$('#divActualitesCycle').cycle('pause') ;
				},
				function() {
					$('#divActualitesCycle').cycle('resume') ;
				}
			) ;
			*/
			$('#divActualites').bind('mouseenter', function() {
				$('#divActualitesCycle').cycle('pause') ;
				$('#flechesactu').show() ;
			}) ;
			$('#divActualites').bind('mouseleave', function() {
				$('#divActualitesCycle').cycle('resume') ;
				$('#flechesactu').hide() ;
			}) ;
		}
		
	},
	actuSuivante: function() {
		
	},
	actuPrecedente: function() {
		
	},
	/*
	displayCredit: function() {
		//alert(document.body.clientHeight) ;
		var divCredit = $("#divCredits") ;
		divCredit.show() ;
		var leftPos = (jQuery(window).width() - divCredit.outerWidth()) / 2 + jQuery(window).scrollLeft(), 
		topPos = (jQuery(window).height() - divCredit.outerHeight()) / 2 + jQuery(window).scrollTop();
		leftPos = (leftPos < 0) ? 0 : leftPos;
		topPos = (topPos < 0) ? 0 : topPos;
		divCredit.css({left: leftPos +'px', top: topPos +'px', zIndex: '1000'});		
	},
	closeCredit: function() {
		var divCredit = $("#divCredits") ;
		divCredit.hide() ;
	},
	*/
	afficherPlusDInfo: function(el) {
		//$(el).siblings("~ p:first").show() ;
		if (MyPage.afficherPlusDInfoEnCours) return ;
		MyPage.afficherPlusDInfoEnCours = true ;
		if ($(el).prev().is(':hidden')) {
			$(el).html("<img src='/images/3fleche_haut.gif' border='0' />").prev().slideDown(500, function() {
				MyPage.afficherPlusDInfoEnCours = false ;
			}) ;
		} else {
			$(el).html("<img src='/images/3fleche_bas.gif' border='0' />").prev().slideUp(500, function() {
				MyPage.afficherPlusDInfoEnCours = false ;
			}) ;
		}
	},
	deplacerMenuFlecheAction: function(el, easing) {
		if (el.length==0) return ;
		var duration = 500 ;
		if (easing=="easeOutBounce") duration=1000 ;
		var w2 = Math.ceil((el.width()/2)-8) ;
		var offset = el.offset();
		$("#menufleche").stop() ;
		$("#menufleche").animate({left:(offset.left+w2)+"px"},{easing: easing, duration: duration}) ;
	},
	deplacerMenuFleche: function() {
		MyPage.deplacerMenuFlecheAction($(this), "swing") ;
	},
	deplacerMenuFlecheDefaut: function() {
		MyPage.deplacerMenuFlecheAction($("#menu"+MyPage.currentM), "easeOutBounce") ;
	},
	
	deplacerSMenuFlecheAction: function(el, easing) {
		if(!el) return ;
		var duration = 500 ;
		if (easing=="easeOutBounce") duration=1000 ;
		var offset = el.offset();
		$("#menufleche2").stop() ;
		$("#menufleche2").animate({top:offset.top+"px"},{easing: easing, duration: duration}) ;
	},
	deplacerSMenuFleche: function() {
		//alert("#ssmOf_"+this.id) ;
		//$("#ssmOf_"+this.id).animate("hide",) ;
		MyPage.deplacerSMenuFlecheAction($(this), "swing") ;
	},
	deplacerSMenuFlecheDefaut: function() {
		//$("#ssmOf_"+this.id).slideUp() ;
		if ($("#smActuel").length>0) MyPage.deplacerSMenuFlecheAction($("#smActuel"), "easeOutBounce") ;
		else MyPage.deplacerSMenuFlecheAction($("#smtitre"), "easeOutBounce") ;
	}
} ;
