// JavaScript Document
document.observe("dom:loaded", function() {
	
    application.enableZoom();
   	
    // scrolling de la zone d'intro
    introAutoScroll();

    // menu texte vers menu images
    menuInit();
    
    // lancement du defilement automatique des programmes
    wtiprog=window.setTimeout(function(){bandeauNav(1)},5000);
    
    
    if ((slideshowImgs != null) && (slideshowImgs.length>1)){
        for (i=1; i<slideshowImgs.length; i++){
            var _img=new Element('img',{'src':slideshowImgs[i],'alt':'Victoria Promotion : Promotion Immobilière en Normandie'})
            $('slideshowElements').appendChild(_img)
        }
        var _img=new Element('img',{'src':slideshowImgs[0],'alt':'Victoria Promotion : Promotion Immobilière en Normandie'})
        $('slideshowElements').appendChild(_img)
        wtiss=window.setInterval(function(){
            var ss=$('slideshowElements');
            var left=(parseInt(ss.style.left)-350)+'px';
            
            var effectss=new Effect.Morph($('slideshowElements'),{
                style:'left:'+left,
                duration:1,
                afterFinish:function(){
                    if ((parseInt(left)-10)<=-slideshowImgs.length*350){
                        ss.style.left='0px';
                    }
                }
            })
        },5000)
    }
});


introAutoScroll=function(){
    var _ict=$$('div.introContent')[0];
    _ict.style.top='80px';
    _ict.show();
    new Effect.Morph(_ict, {
        style: 'top:-'+_ict.offsetHeight+'px',
        duration: 22,
        afterFinish:function(){
            introAutoScroll();
            return;
        }
    });
}

// défilement automatique des programmes
bandeauNav=function(sens){
    //debug.print(1);
    window.clearTimeout(wtiprog);
	if(typeof(wtoBE)!='undefined')window.clearTimeout(wtoBE);
	if(typeof(sens)=='undefined') sens=1; else bandeauAutoSlide=false;
	if (tmp=$$('div.bandeau div.actif')[0])	var idxn = $$('div.bandeau_element').indexOf(tmp)+sens; else idxn=0;
	if (idxn<0) idxn=$$('div.bandeau_element').length-1;
	if (idxn>$$('div.bandeau_element').length-1) idxn=0;
	var ben=$$('div.bandeau_element')[idxn];
	new Effect.Appear(ben, {	
		duration:.5, from:0, to:1.0,
		beforeStart: function() {
			ben.setOpacity(0);
			ben.setStyle({'zIndex':'11'});			
		},
		afterFinish: function() {
			ben.setStyle({'zIndex':'10'});
			if (bea=$$('div.bandeau div.actif')[0]){
				bea.setStyle({'zIndex':'9'});
				bea.removeClassName('actif');
			}
			ben.addClassName('actif');
			(idxn<$$('div.bandeau_element').length-1)?idxn++:idxn=0;
			wtiprog=window.setTimeout(function(){bandeauNav(1)},4000);
		}
	});
}
var wtiss;
var wtiprog;
