﻿/**

**/

window.addEvent('domready', function() {
    _Load();
});
function _Load() {
    window.setTimeout(_flash, 0);
    window.setTimeout(_preload, 0);
    window.setTimeout(_flashPrix, 0);
    window.setTimeout(_imgLoader, 0);
    window.setTimeout(_actionImg, 0);
    window.setTimeout(_imgCssLoader, 0);
    _enSavoirPlusPortail();  
}

function _flash() {
    if ($("flash")) {

        var flashvars = {};
        var params = { wmode: "opaque" };
        var attributes = {};
        var animationName;

        if (document.getElementById("Animation_Name")) {
            animationName = $("Animation_Name").value;
        }
        swfobject.embedSWF(animationName, "flash", "950", "380", "8", "js/expressinstall.swf", flashvars, params, attributes);

        if (animationName != "/img/animation/anim.swf")
            setTimeout("switchSwf()", 10000);
            
            
        //window.setInterval(alert($("flash").outerHTML));
        
    }
}

function switchSwf(animationName) {
    var flashvars = {};
    var params = { wmode: "opaque" };
    var attributes = {};
    var animationName;
    swfobject.embedSWF("/img/animation/anim.swf", "flash", "950", "380", "8", "js/expressinstall.swf", flashvars, params, attributes);
 }


//On suppose que la date entrée a été validée auparavant
//au format dd/mm/yyyy
function getDate(strDate) {
    day = strDate.substring(0, 2);
    alert(day);
    month = strDate.substring(3, 5);
    alert(month);
    year = strDate.substring(6, 10);
    alert(year);
    d = new Date();
    d.setDate(day);
    d.setMonth(month);
    d.setFullYear(year);
    return d;
}

//Retourne:
//   0 si date_1=date_2
//   1 si date_1>date_2
//  -1 si date_1<date_2	  
function compare(date_1, date_2) {
    diff = date_1.getTime() - date_2.getTime();
    return (diff == 0 ? diff : diff / Math.abs(diff));
}

function _preload() {
    MM_preloadImages('/img/interface/passer-commande-over.gif', '/img/interface/precedent-over.gif', '/img/interface/suivant-over.gif')
}

function _flashPrix() {
    var texte = $("flashPrixTexte");
    if (!texte) return;
    texte = texte.value;

    var flashvars = { TitreFlash: texte };
    var params = { wmode: "transparent", quality: "high" };
    var attributes = {};
    var animationName = "BOUTON-FINAL";
    swfobject.embedSWF("/img/animation/BOUTON-FINAL.swf", "flashPrixConteneur", "242", "40", "9", "", flashvars, params, attributes);
    var version = swfobject.getFlashPlayerVersion();
    try {
        if ((version) && (version.major > 8)) {
            $("flashPrix").style.backgroundImage = "none";
        }
    }
    catch (e) { }
}

function _imgLoader() {

    $(document.body).getElements('td.tablegaleriephoto').each(function(e) {
        e.getElement("img").src = e.getElement("a").href;
    });

    $(document.body).getElements("div.encart").each(function(e) {
        try {
            e.getElement("img").src = e.getElement("input").value;
        }
        catch (e) { };
    });
}

function _imgCssLoader() {

    window.setTimeout(function() {
        try {
            _imgCssLoaderSync();
        }
        catch (e) { }
    }, 500);
}
function _imgCssLoaderSync() {
    var oDivElement = document.createElement("div");
    oDivElement.style.display = "none";
    document.body.appendChild(oDivElement);    
    var re = new RegExp("[\\w./]+\\/[\\w./]+\\.(bmp|png|jpg|gif)", "ig");    
    for (var indexCss = 0; indexCss < window.document.styleSheets.length; indexCss++) {
        var cssText = new String();
        cssText = window.document.styleSheets[indexCss].cssText;
        _imgCssLoader2(oDivElement, cssText);

        if (window.document.styleSheets[indexCss].imports){
            for (var i = 0; i < window.document.styleSheets[indexCss].imports.length; i++) {
                _imgCssLoader2(oDivElement, window.document.styleSheets[indexCss].imports[i].cssText);        
            }
        }
        if(window.document.styleSheets[indexCss].cssRules){
            for (var i = 0; i < window.document.styleSheets[indexCss].cssRules.length; i++) {
                try{
                    var obj = window.document.styleSheets[indexCss].cssRules[i].styleSheet.cssRules;
                    for (var j = 0; j < obj.length; j++) {

                        _imgCssLoader2(oDivElement, obj[j].cssText);
                    }
                }
                catch(e){}
            }
        }
        
        
    }
}
function _imgCssLoader2(oDiv, textCss) {
    if (!textCss) return;
    var re = new RegExp("[\\w./]+\\/[\\w./]+\\.(bmp|png|jpg|gif)", "ig");
    var tab = textCss.match(re);

    if (tab) {
        for (var i = 0; i < tab.length; i++) {
            
            var oImg = document.createElement("img");
            oDiv.appendChild(oImg);
            oImg.src = tab[i];
            //MM_preloadImages(tab[i]);
            /*alert(tab[i]);
            var image = new image();
            image.src = tab[i];
            */
        }
    }
}
function _actionImg() {
    var tabImages = ["/img/interface/savoir-plus.gif",
                     "/img/interface/passer-commande2.gif",
                     "/img/interface/demander-demo.gif",
                     "/img/interface/s-abonner.gif"];
    var tab;

    for (var j = tabImages.length - 1; j > -1; j--) {

        var img = tabImages[j];
        var tab = $$('img[src="' + img + '"]');
        var imgOver = tabImages[j].replace('\.gif', '-over.gif');
        var name = "imgAct-" + j;
        for (var i = tab.length - 1; i > -1; i--) {
            var obj = tab[i];
            if (obj.id == "") {
                obj.id = name + i;
            }
            obj.img = img;
            obj.imgOver = imgOver;
            obj.addEvent("mouseover", function() { MM_swapImage(this.id, this.img, this.imgOver, 1) });
            obj.addEvent("mouseout", function() { MM_swapImgRestore(); });
        }
    }


}

function _enSavoirPlusPortail() {
    var obj = $("detailPortail");

    var MyFx = new Fx.Morph('portails', { duration: 'long', transition: Fx.Transitions.Sine.easeOut });
    if (obj) {
        obj.addEvent("click", function() { MyFx.start({ height: "635" }); $("detailPortailCont").setStyle('display', 'none'); });
    }

}

/**fixhover.js**/
sfHover = function() {
	var sfEls = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/*Preload.js*/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*utils.js*/
window.addEvent('domready', function(){
	
	var el = $('profil-home');
	color = el.getStyle('background-position');

	$('profil-home').addEvents({
		'mouseenter': function(){
			this.setStyle("background-position", "right top");
			
			this.set('tween', {
				duration: 500,
				transition: Fx.Transitions.Expo.easeOut
			}).tween('height', '170px');
		},
		'mouseleave': function(){
			this.set('tween', {}).tween('height', '30px');
			this.setStyle("background-position", "left top");
		}
	});
});
/*utils.js*/

function favoris() {
    if (navigator.appName != 'Microsoft Internet Explorer') {
        window.sidebar.addPanel("ELEPHANTBIRD SOFTWARE", "http://www.elephantbird.fr", "");
    }
    else {
        window.external.AddFavorite("http://www.elephantbird.fr", "ELEPHANTBIRD SOFTWARE");
    }
}
/*remplace div*/
function affiche(elem)
{
	document.getElementById(elem).style.visibility="visible";
	document.getElementById(elem).style.display="block";
	
	document.getElementById("elephantbirdContenu").style.visibility="hidden";
	document.getElementById("elephantbirdContenu").style.display="none";

}

function masque(elem)
{
	document.getElementById(elem).style.visibility="hidden";
	document.getElementById(elem).style.display="none";
	
	document.getElementById("elephantbirdContenu").style.visibility="visible";
	document.getElementById("elephantbirdContenu").style.display="block";
}
/*Google analytics*/
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-2340093-6']);
  _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);
  })();


