var myAccordion ;

// ----- Rollover Input Image -----
var RollInputImage = function(){
	var input = $$('input[type=image]','img.rollover');
	input.each(
		function(e,index){
			var chemin = input[index].src;
			var pos_debut = chemin.lastIndexOf('/')+1;
			var pos_fin = chemin.lastIndexOf('.');
			var chemin_fichier = chemin.substring(0,pos_debut);
			var nom_fichier = chemin.substring(pos_debut,pos_fin);
			var ext_fichier = chemin.substr(pos_fin);
			if(!e.hasClass('no_roll')){
				$(e).addEvent('mouseover', function () {
					e.src = chemin_fichier+nom_fichier+'_on'+ext_fichier;
				});			 
				$(e).addEvent('mouseout', function () {
					e.src = chemin_fichier+nom_fichier+ext_fichier;
				});
			}
		}
	);
};

// ----- Create tabProducts -----
function tabProducts () {				
	if ( $('b_informations_produits') ) toggleonglet ('b_informations_produits','affiche');
	if ( $('diapo_etiquette') ) toggleonglet ('diapo_etiquette','a_la_une');
}

// ---- Create sliderProducts -----
function sliderProducts () {
	if ( $('sliderproduits') ) {
		var produitpublic = new noobSlide({
			mode: 'vertical',
			box: $('sliderproduits'),
			size: 179,
			autoPlay: true,
			interval : 5000,
			items: $$('#sliderproduits span'),
			addButtons: {
				previous: $('bt_haut'),
				next: $('bt_bas')
			},
			onWalk: function(currentItem){
			}
		});
	}
}

// ---- Create A la Une -----
function CreateALaUne () {
	if ( $('laune') ) {
	//$$('#laune div').getProperty ( "width" ) ;
		var alaune = new noobSlide({
			box: $('laune'),
			items: $$('#laune div'),
			size:  170,
			interval : 5500,
			autoPlay: true,
			handles: $$('#launepanels span'),
			onWalk: function(currentItem,currentHandle){
				//$('launeinfo').set('html',currentItem.getFirst().innerHTML);
				this.handles.removeClass('active');
				currentHandle.addClass('active');
			}
		});
	}
}

// ---- Create our Accordion instance -----
function accordionProducts () {
	if ( document.getElementById ( 'accordeon' ) ) {
		var i  = 0 ;
		myAccordion = new Accordion($('accordeon'), 'div.liste', 'div.detail', {
			opacity: false,
//			alwaysHide: true,					
			onActive: function(toggler, element){
				toggler.getFirst ( 'a' ).setProperty ( 'class','in' ) ;								
				element.setStyle ( "display","block" ) ;
				if ( !toggler.getParent ().getProperty ( "rel" ) )
					toggler.getParent ().setProperty ( "rel",0 ) ;
				
			},
			onBackground: function(toggler, element) {				
				if ( toggler.getFirst ( 'a' ).getProperty ( 'class' ) == 'in' ) {
					if ( !toggler.getParent ().getProperty ( "rel" ) )
						toggler.getParent ().setProperty ( "rel",i + 1 ) ;
				}
				toggler.getFirst ( 'a' ).setProperty ( 'class','off' ) ;
				element.setStyle ( "display","block" ) ;								
				i  = i + 1 ;
			}
		});
	}
	//adjustSlideDemonstration ("fr") ;
}

// ---- Open an accordion element -----
function accordionOpen ( num ) {
	if ( myAccordion )
		myAccordion.display ( num ) ;
}

// ---- adjustSlideDemonstration -----
function adjustSlideDemonstration (currentLanguage) {
	 
	var fmtimg = "s" ;
	if ( screen.height > 760 ) fmtimg = "n" ;
	
	// ----- Correction du code: Insértion de la lightbox pour visualiser les écrans -----
	$$('.demoslide a').each(function (el,i){
		var href =  el.getProperty ( 'href' ) ;
		var pathimg = href.replace ( /.png/gi ,"_" + currentLanguage + "_" + fmtimg + ".png" ) ;
		//alert ( pathimg ) ;
		//el.setProperty ( 'href',pathImg ) ;
	});
}

function CreateImageMenu () {
	if ( document.getElementById ( 'imageMenu' ) ) {
		var myMenu = new ImageMenu($$('#imageMenu a'),{openWidth:310, border:2, onOpen:function(e,i){alert(e);}});
	}
}

function CreateCustomElements ()
{
	var radioTest = new mooVirtualRadio ($$('.radioClass'), "../../images/common/radio.gif", { wrapHeight: 20, wrapWidth: 20 });
}

// ---- Create CreateZoomProducts -----
function CreateZoomProducts () {
	
	/*if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 		var ieversion=new Number(RegExp.$1) ;
 		if (ieversion >=8 )
 			return ;
 	}*/
 	
	$$('.photo a img').each ( function ( el ) {
		if (  el.getProperty ( 'class' ).contains ( 'zoomproduit' ) ) {
			return new mooZoomMenu ( { zoomlevel: 1.2, imgClass: "zoomproduit" } ) ;
		}
	}.bind ( this ) ) ;
}

// ---- AddLightBox2ShootScreen -----
function AddLightBox2ShootScreen (currentLanguage) {

	CB_AllowedToRun = 'on' ;
	CB_RoundPix = 12 ;
	
	// ----- Fermeture de tous détails -----
	$$('.liste a').each(function (el,i){
	});

	// ----- Correction du code: Insértion de la lightbox pour visualiser les écrans -----
	$$('.detail').each(function (el,i){
		var Img = el.getChildren ( 'img' ) ;
		if ( Img ) {
			var rel = String ( Img.getProperty ( "rel" ) ) ;
			var src = String ( Img.getProperty ( "src" ) ) ;						
			if ( src.length ) {
			
				var myLink,srclng ;
				
				if ( rel == "newfmt" ) {
					srclng = src.replace ( /small/gi ,currentLanguage ) ;
					//alert ( srclng ) ;
				}
				else {
					srclng = src.replace ( /.gif/gi ,"_" + currentLanguage + ".gif" ) ;
				}
				
				Img.destroy () ;						
			
				if ( rel == "newfmt" ) {
				}
				else if ( rel == "nolang" ) {	
					srclng = src.replace ( /.gif/gi ,"_big.gif" ) ;
				}
				else {
					srclng = src.replace ( /.gif/gi ,"_" + currentLanguage + ".gif" ) ;
				}
								
				if ( rel == "nolightwindow" ) {
					myLink = new Element('a', {
						'href': 'javascript:void(0);',
						'style': 'cursor:default;'
					}).inject ( el,'top' ) ;				
				}
				else {
					myLink = new Element('a', {
						'href': srclng,
						'class': 'lightwindow',
						'rel': 'clearbox',
						'title': 'Demonstration'
					}).inject ( el,'top' ) ;
				}
								
				var myImg = new Element('img', {
					'src': src
				}).inject ( myLink ) ;
				
				myLink.setStyle ( "float","left" ) ;
			}
			else
				Img.destroy () ;
		}
	});
}

var toggleonglet = function(conteneur,classe){	
	$$("#"+conteneur+" ul#onglet li a").each(
	function(a_e, a_i) {
		$(a_e).addEvent('click', function () {
			changeContenu ( a_e,a_i,conteneur,classe );
		});
	});
} ;

var changeContenu = function ( a_e,a_i,conteneur,classe ) {
	initToggle ( a_e,a_i,conteneur,classe ) ;
	$$("#"+conteneur+" div."+classe).each(
	function ( div_e, div_i ) {						  		
		
		if ( a_i == div_i ) {		
		
			if ( !a_e.hasClass ( "in" ) ) {
				a_e.setProperty ( "class","in" ) ;	
				div_e.setStyle ( "display","block" ) ;				
				if ( myAccordion )
					myAccordion.display ( div_e.getProperty ( "rel" ) ) ;
			}			
		}
	});
} ;

var initToggle = function ( a_e,a_i,conteneur,classe ) {
	$$("#"+conteneur+" ul#onglet li a").each(
	function ( o_e,o_i ) {		
		$$("#"+conteneur+" div."+classe).each(			
			function ( div_e,div_i ){									
				if ( o_i == div_i && o_e.hasClass ( "in" ) && o_i != a_i ) {					
					o_e.setProperty ( "class","out" ) ;	
					div_e.setStyle ( "display","none" ) ;
				}
		});
	});
} ;

/*Boutons affiche/cache*/
function afficheFormInscription() {
	document.getElementById('inscrire').style.display = 'none';
	document.getElementById('frm_3').style.display = 'block';
}

function afficheMdp() {
	document.getElementById('mdp_oublie').style.display = 'none';
	document.getElementById('frm_2').style.display = 'block';
}

function DreamduColorRows() 
{
	var dreamdurows = document.getElementsByTagName('tr');
	for ( var i = 0; i < dreamdurows.length; i++ ) 
	{
		if ( 'dreamdu' != dreamdurows[i].className.substr(0,7) ) 
		{
			continue;
		}
		if ( navigator.appName == 'Microsoft Internet Explorer' )
		{
			// ie not support hover,so...
			dreamdurows[i].onmouseover = function() 
			{
				this.className += ' hover';
			}

			dreamdurows[i].onmouseout = function() 
			{
				this.className = this.className.replace( ' hover', '' );
			}
		}       
	}
}
window.onload=DreamduColorRows;

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_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_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];}
}
