var OcParams = {
	baseWidth:null,
	baseHeight:null,
	interval:5
}

Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7;

document.observe("dom:loaded", function() {  
	var baseDimensions = $('OcMasque').getDimensions();
	var OcBandeauActive = null;

	OcParams.baseWidth = baseDimensions.width;
	OcParams.baseHeight = baseDimensions.height;
	
	// On masque les 'Tip Content'
	$$('.OcTipContent').each(function(elm, index) {
		elm.hide();
	});

	// Initialisation de la taille du masque
	$('OcMasque').style.width = OcParams.baseWidth;
	$('OcMasque').style.height = OcParams.baseHeight;
  
	// Initialisation de chaque bandeau
	$$('div.OcBandeau').each(function(elm, index) {
		// alert(elm);
		elm.style.width = OcParams.baseWidth+'px';
		elm.style.height = OcParams.baseHeight+'px';

		//initlialisation des liens de bandeau
		var link = new Element('a', { 'style': 'line-height:'+$('OcNavig').getHeight()+'px', href: 'javascript:void(0)' }).update(index+1);
		$('OcNavigLinks').insert(link);
		
		// Evenements
		link.observe('click', function(event) {
			OcSetBandeauActive(index);
		});
		link.observe('mouseover', function(event) {
			OcSetTip(index);
		});
		link.observe('mouseout', function(event) {
			// OcClearTip();
			OcRestoreTip();
		});

		// Initialisation de la hauteur du 'Tip' de lien
		$('OcNavigTip').style.lineHeight = $('OcNavig').getHeight()+'px';
		
		// On masque les div de contenu du titre du bandeau, si celui-ci ne contient
		// aucun texte
		elm.select('.OcTitleContent:empty').each(function(elm, index) {
			elm.up('.OcBandeauTitle').hide();
		});
		
		// Initialisation de la hauteur du div contenant la transparence derrire le texte
		// Uniquement sur cette merde de IE
		if(Prototype.Browser.IE6) {
			elm.select('div.OcTitleBg').each(function(elm, index) {
				elm.style.height = elm.up('.OcBandeauTitle').getHeight()+'px';
			});
		}
	});
	
	// On entre dans la zone du bandeau, désactivation du timer
	$('OcBandeau').observe('mouseenter', function(event) {
		if(typeof(pe) != "undefined") {	
			pe.stop();
		}
	});
	
	// On quitte la zone du bandeau, activation du timer
	$('OcBandeau').observe('mouseleave', function(event) {
		pe = new PeriodicalExecuter(OcNextBandeau, OcParams.interval);

	});
	
	// Activation du bandeau repéré par 'index'
	function OcSetBandeauActive(index) {
		OcBandeauActive = index;

		var a_elms = $('OcNavigLinks').childElements();
		for (var i=0; i< a_elms.length; i++) {
			if(i == index) {
				a_elms[i].addClassName('activ');
			} else {
				a_elms[i].removeClassName('activ');
			}
		}
		
		// Mouvement
		new Effect.Move(
			'OcBandeaux'
			,{ 	x: (-OcParams.baseWidth * index)
				, y: 0
				, duration: 0.3
				, mode:'absolute'
				, transition: Effect.Transitions.sinoidal
			}
		);
		OcSetTip(index);
	}
	
	function OcNextBandeau() {
		var index = OcBandeauActive;
		var a_elms = $$('div.OcBandeau');
		index++;
		if (index > a_elms.length - 1) {
			index = 0;
		}
		OcSetBandeauActive(index);
	}
	
	function OcSetTip(index) {
		var a_elms = $$('.OcTipContent');
		$('OcNavigTip').update( a_elms[index].innerHTML );
	}
	
	function OcClearTip() {
		$('OcNavigTip').update(null);
	}
	
	function OcRestoreTip() {
		var index = OcBandeauActive;
		OcSetTip(index);
		
	}

	$('OcLoading').hide();
	OcSetBandeauActive(0);
	var pe = new PeriodicalExecuter(OcNextBandeau, OcParams.interval);
});




