/**************************************************************************************************************************************************************************************************/
/* CONSTANTE */
/**************************************************************************************************************************************************************************************************/
	window.CONST_BGCOLORFILTER = '#000';
	window.CONST_PATH_IMG = '/templates/altima/images/';
	
/**************************************************************************************************************************************************************************************************/

/**************************************************************************************************************************************************************************************************/
/* Scintillement des backgrounds sous IE */
/**************************************************************************************************************************************************************************************************/
try{document.execCommand('BackgroundImageCache', false, true);}catch(e){};
	
/**************************************************************************************************************************************************************************************************/

/**************************************************************************************************************************************************************************************************/
/* VARIABLES GLOBALES */
/**************************************************************************************************************************************************************************************************/
/**************************************************************************************************************************************************************************************************/

function RecupVariant(id,type){
	var url = '/index2.php?option=com_virtuemart&page=shop.ajaxvariantpanier&product_id='+id+'&type='+type+'&no_html=1';
	$ShowPopup(url);
	return false;
}

/**************************************************************************************************************************************************************************************************/
/* Evenements */
/**************************************************************************************************************************************************************************************************/
//window.addEvent('domready', initAll);

function initAll(){
	calendrier_jardin();
	initRounded();
	initAddCart();
	initTg();
	initFAQ();
	initCarroussel();
	initCarrousselZoom();
	initOnglets();
	initAccordion();
	initFicheConseil();
	initFamille();
	initSFamille();
	
	initLexique();
	initPng();
	setMsgError();
	setMsgConf();
	
	
	if(!isset('popupload'))
		initOPNewsletter();
}

function initLoad(){
	//initAjaxRecherche();  PLUS UTILE
}
	
/**************************************************************************************************************************************************************************************************/

/**************************************************************************************************************************************************************************************************/
/* Scintillement des backgrounds sous IE */
/**************************************************************************************************************************************************************************************************/
try{document.execCommand('BackgroundImageCache', false, true);}catch(e){};
/**************************************************************************************************************************************************************************************************/

/**************************************************************************************************************************************************************************************************/
/* Fonctions */
/**************************************************************************************************************************************************************************************************/
function calendrier_jardin(){
	if( !$('calendrier_jardin_0_0_2') || !$('calendrier_jardin_0_0') ){return;}
	$('calendrier_jardin_0_0_2').setStyle('height', $('calendrier_jardin_0_0').getSize().size.y.toInt());
}
function locationHref(TsUrl, TsEvent){
	var event = new Event(TsEvent);

	window.location.href = TsUrl;

	event.stopPropagation();
	event.stop();
}
function initPng(){
	if ( !window.IElt7 ){return;}
	var tsElementsIMG = $$('img.png');
	for(var i=0, x=tsElementsIMG.length;i<x;i++){
		var tsSrcImg = tsElementsIMG[i].getProperty('src');
		var tsWidthImg = tsElementsIMG[i].getProperty('width');
		var tsHeightImg = tsElementsIMG[i].getProperty('height');
		
		tsElementsIMG[i].setStyles({
			'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+tsSrcImg+'",sizingMethod="scale")',
			'background': 'none'
		});
		
		
		
		tsElementsIMG[i].setProperty('src', window.CONST_PATH_IMG + 'bg-blank.gif');
		if(parseInt(tsWidthImg)>0){ tsElementsIMG[i].setProperty('width', parseInt(tsWidthImg)); }
		if(parseInt(tsHeightImg)>0){ tsElementsIMG[i].setProperty('height', parseInt(tsHeightImg)); }
		tsElementsIMG[i].setStyle('visibility', 'visible');
	}
	
}
function initRounded(){
	var TsElementsRounded = $ES('div.rounded', document.body);

	if( TsElementsRounded.length > 0){
		var coins_H = new Element('div', {'class': 'coins'});
		new Element('div', {'class': 'coin coinHG'}).inject(coins_H);
		new Element('div', {'class': 'coin coinHD'}).inject(coins_H);
		var coins_B = new Element('div', {'class': 'coins'});
		new Element('div', {'class': 'coin coinBG'}).inject(coins_B);
		new Element('div', {'class': 'coin coinBD'}).inject(coins_B);
	}

	for(var i=0, x=TsElementsRounded.length; i<x; i++){
		coins_H.clone().injectTop(TsElementsRounded[i]);
		coins_B.clone().inject(TsElementsRounded[i]);
	}
}
function initOnglets(){
	var TsTabElementsUL = $$('ul.onglets');
	for(var j=0, y=TsTabElementsUL.length;j<y;j++){
		var TsTabElementsA = $ES('a', $(TsTabElementsUL[j]));
		for(var i=0, x=TsTabElementsA.length;i<x;i++){
			if( TsTabElementsA[i].hasClass('selected') ){
				if( $(TsTabElementsA[i].getProperty('id')+'_content') ){
					$(TsTabElementsA[i].getProperty('id')+'_content').setStyle('display', 'block');
				}
			}else{
				if( $(TsTabElementsA[i].getProperty('id')+'_content') ){
					$(TsTabElementsA[i].getProperty('id')+'_content').setStyle('display', 'none');
				}
			}
			TsTabElementsA[i].addListener('click', toggleOnglets);
		}
	}
}
function initTg(){
	if( !$('tgs') ){return;}

	// D�sactive les eboutiques sauf celle active par default
	var TsElementA = $ES('a','tgs_ul');
	for(var i=0,x=TsElementA.length;i<x;i++){
		var tsElement = $(TsElementA[i].getProperty('id')+'_content');
		if( tsElement ){
			if( !TsElementA[i].hasClass('selected') ){
				$(TsElementA[i].getProperty('id')+'_content').setStyle('display','none');
			}
		}
	}
}
function initCarroussel(){
	if( !$('carroussel') ){return;}
	
	var tsTabElementAPrevious = $E('a.previous', 'carroussel'); // Lien precedent
	var tsTabElementDiv = $E('div', 'carroussel'); // Conteneur avec les dimensions visibles

	var tsTabElementsA = $ES('a', tsTabElementDiv); // Lien dans la liste
	var tsTabElementANext = $E('a.next', 'carroussel'); // Lien suivant

	if( tsTabElementAPrevious ){
		tsTabElementAPrevious.addEvent('click', moveCarroussel);
	}
	if( tsTabElementANext ){
		tsTabElementANext.addEvent('click', moveCarroussel);
	}

	var tsTabElementsLI = $ES('li', tsTabElementDiv);
	if( tsTabElementsLI.length > 0){
		if(tsTabElementAPrevious)
			tsTabElementAPrevious.setStyle('visibility', 'hidden');
		var tsTabElementLILast = $(tsTabElementsLI[tsTabElementsLI.length-1]); // Recupere le dernier LI du UL
		var tsElementLIWidth = tsTabElementLILast.getSize().size.x.toInt() + tsTabElementLILast.getStyle('margin-left').toInt() + tsTabElementLILast.getStyle('margin-right').toInt();
		if( tsTabElementANext && (tsTabElementLILast.offsetLeft.toInt() + tsElementLIWidth) <= (tsTabElementDiv.getSize().size.x.toInt()) ){
			tsTabElementANext.setStyle('visibility', 'hidden');
		}
		var tsElementULWidth = tsElementLIWidth.toInt() * tsTabElementsLI.length;
		var tsTabElementUL = $E('ul', tsTabElementDiv); // Recheche le UL des miniatures
		tsTabElementUL.setStyle('width', tsElementULWidth); // Mise a jour de la largeur du UL

		tsTabElementDiv.setProperty('LIWidth', tsElementLIWidth); // Memorise la largeur d'une image dans le carroussel
		tsTabElementDiv.setProperty('ULWidth', tsElementULWidth); // Memorise la largeur du UL contenant les images miniatures

		var TsPreloadImg = new Array(); // Preload des images des les a.href
		for(var i=0, x=tsTabElementsA.length;i<x;i++){
			TsPreloadImg[i] = new Image();
			TsPreloadImg[i].src = tsTabElementsA.getProperty('href');
			if( i == 0){tsTabElementsA[i].addClass('selected');}
			tsTabElementsA[i].addEvent('mouseover', showProductVisuel);
		}
	}else{ // Cache la partie carroussel
		$('carroussel').setStyle('display', 'none');
	}
}
function initCarrousselZoom(){
	if( !$('carroussel_zoom') ){return;}
	
	var tsTabElementDiv = $E('div', 'carroussel_zoom'); // Conteneur avec les dimensions visibles
	var tsTabElementsA = $ES('a', tsTabElementDiv); // Lien dans la liste
	var TsPreloadImg = new Array(); // Preload des images des les a.href
	for(var i=0, x=tsTabElementsA.length;i<x;i++){
		TsPreloadImg[i] = new Image();
		TsPreloadImg[i].src = tsTabElementsA.getProperty('href');
		if( i == 0){tsTabElementsA[i].addClass('selected');}
		tsTabElementsA[i].addEvent('mouseover', showProductVisuelZoom);
	}
}
function initAccordion(){
	var TstabElementDIV_SLIDE = $$('div.slide');
	for(var i=0, x=TstabElementDIV_SLIDE.length;i<x;i++){
		titreaccueil = $$('div.slide_0_0');
		displaynum = 0;
		for(var j=0; j<titreaccueil.length	;j++){
			if(titreaccueil[j].hasClass("slide_accueil"))
				displaynum = j;
		}
			
		var accordion = new Accordion('div.slide_0_0', 'div.slide_0_1', {
			opacity: false,
			display: displaynum,
			onActive: function(toggler, element){
				toggler.addClass('slide_on');
			},
			onBackground: function(toggler, element){
				toggler.removeClass('slide_on');
			}},
			$(TstabElementDIV_SLIDE[i].getProperty('id'))
		);
	}
}


function toggleOnglets(TsEvent){
	var event = new Event(TsEvent);
	event.stopPropagation();
	event.stop();

	var el_a = $(event.target).getParentTag('a');	
	var elParent = el_a.getParentTag('ul');

	if( elParent ){
		var TsTabElementsA = $ES('a.selected', elParent);
		for(var i=0, x=TsTabElementsA.length;i<x;i++){
			if( $(TsTabElementsA[i].getProperty('id')+'_content') ){$(TsTabElementsA[i].getProperty('id')+'_content').setStyle('display', 'none');}
			$(TsTabElementsA[i]).removeClass('selected');
		}
	}

	if( el_a ){
		el_a.addClass('selected');
		if( $(el_a.getProperty('id')+'_content') ){
			$(el_a.getProperty('id')+'_content').setStyle('visibility', 'hidden');
			$(el_a.getProperty('id')+'_content').setStyle('display', 'block');
			new Fx.Style(el_a.getProperty('id')+'_content', 'opacity', {duration:500}).start(0,1);
			calculFamille();
		}
	}

	
}
function moveCarroussel(TsEvent){
	var event = new Event(TsEvent);

	var tsTabElementDiv = $E('div', 'carroussel'); // Conteneur avec les dimensions visibles
	var tsTabElementUL = $E('ul', tsTabElementDiv); // Mise a jour de la largeur du UL
	var tsTabElementAPrevious = $E('a.previous', 'carroussel'); // Lien precedent
	var tsTabElementANext = $E('a.next', 'carroussel'); // Lien suivant

	var el = $(event.target).getParentTag('a');
	var marginChange = new Fx.Style(tsTabElementUL, 'margin-left', {duration:500, onStart: hideCarroussel, onComplete: showCarroussel});
	if( el.hasClass('previous') ){
		if( tsTabElementUL.getStyle('marginTop') > 0 ){
			marginChange.start(tsTabElementUL.getStyle('margin-left').toInt(), -(Math.abs(tsTabElementUL.getStyle('margin-left').toInt()-tsTabElementDiv.getProperty('LIWidth').toInt())));
		}else{
			marginChange.start(tsTabElementUL.getStyle('margin-left').toInt(), 0);
		}
	}
	if( el.hasClass('next') ){
	if( (Math.abs(tsTabElementUL.getStyle('margin-left').toInt())+(tsTabElementDiv.getStyle('width').toInt())) < tsTabElementDiv.getProperty('ULWidth').toInt() ){
			marginChange.start(tsTabElementUL.getStyle('margin-left').toInt(), -(Math.abs(tsTabElementUL.getStyle('margin-left').toInt())+tsTabElementDiv.getProperty('LIWidth').toInt()));
		}else{
			marginChange.start(tsTabElementUL.getStyle('margin-left').toInt(), -(tsTabElementDiv.getProperty('ULWidth').toInt()-tsTabElementDiv.getProperty('width').toInt()));
		}
	}

	event.stopPropagation();
	event.stop();
}
function showCarroussel(){
	var tsTabElementAPrevious = $E('a.previous', 'carroussel'); // Lien precedent
	var tsTabElementDiv = $E('div', 'carroussel'); // Conteneur avec les dimensions visibles
	var tsTabElementUL = $E('ul', tsTabElementDiv); // Mise a jour de la largeur du UL
	var tsTabElementANext = $E('a.next', 'carroussel'); // Lien suivant

	if( tsTabElementUL.getStyle('margin-left').toInt() == 0 ){
		tsTabElementAPrevious.setStyle('visibility', 'hidden');
	}else{
		tsTabElementAPrevious.setStyle('visibility', 'visible');
	}
	if( (Math.abs(tsTabElementUL.getStyle('margin-left').toInt())+(tsTabElementDiv.getStyle('width').toInt())) < tsTabElementDiv.getProperty('ULWidth').toInt() ){
		tsTabElementANext.setStyle('visibility', 'visible');
	}else{
		tsTabElementANext.setStyle('visibility', 'hidden');
	}
}
function hideCarroussel(){
	var tsTabElementAPrevious = $E('a.previous', 'carroussel'); // Lien precedent
	var tsTabElementANext = $E('a.next', 'carroussel'); // Lien suivant

	tsTabElementAPrevious.setStyle('visibility', 'hidden');
	tsTabElementANext.setStyle('visibility', 'hidden');
}
function showProductVisuel(TsEvent){
	var event = new Event(TsEvent);
	if( $('carroussel') ){
		var tsTabElementDiv = $E('div', 'carroussel'); // Conteneur avec les dimension visible
		var tsTabElementsA = $ES('a.selected', tsTabElementDiv); // desactive l'ancien lien actif
		for(var i=0, x=tsTabElementsA.length;i<x;i++){tsTabElementsA[i].removeClass('selected');}
		
		var el = $(event.target).getParentTag('a');
		if( el ){
			el.addClass('selected');
			if( $('product_image') ){$('product_image').setProperty('src', el.href);}
		}
	}

	event.stopPropagation();
	event.stop();
}
function showProductVisuelZoom(TsEvent){
	var event = new Event(TsEvent);
	if( $('carroussel_zoom') ){
		var tsTabElementDiv = $E('div', 'carroussel_zoom'); // Conteneur avec les dimension visible
		var tsTabElementsA = $ES('a.selected', tsTabElementDiv); // desactive l'ancien lien actif
		for(var i=0, x=tsTabElementsA.length;i<x;i++){tsTabElementsA[i].removeClass('selected');}
		
		var el = $(event.target).getParentTag('a');
		if( el ){
			el.addClass('selected');
			if( $('product_image_zoom') ){$('product_image_zoom').setProperty('src', el.href);}
		}
	}

	event.stopPropagation();
	event.stop();
}
function showTg(TsEvent){
	var event = new Event(TsEvent);

	// D�sactive onglet actif
	var TsElementA = $ES('a','tgs_ul');
	for(var i=0,x=TsElementA.length;i<x;i++){
		TsElementA[i].removeClass('selected');
		if( $(TsElementA[i].getProperty('id')+'_content') ){$(TsElementA[i].getProperty('id')+'_content').setStyle('display','none');}
	}

	var el = $(event.target).getParentTag('a');

	if( el ){el.addClass('selected');}
	if( $(el.getProperty('id')+'_content') ){
		$(el.getProperty('id')+'_content').setStyle('display','block');
	}

	event.stopPropagation();
	event.stop();
}
function showDetailProduit(TsEvent){
	var event = new Event(TsEvent);

	var TsElements = $$('div.tg00_0');
	for(var i=0,x=TsElements.length;i<x;i++){TsElements[i].setStyles({'zIndex': 1});}
	var TsElements = $$('div.tg00_0_1');
	for(var i=0,x=TsElements.length;i<x;i++){TsElements[i].setStyles({'display': 'none'});TsElements[i].removeEvent('mouseleave', hideDetailProduit);}

	var el = $(event.target);
	el = el.getParentTag('div.tg00_0_0');
	el = el.getNext();

	el.addEvent('mouseleave', hideDetailProduit);
	el.setStyles({'display': 'block'});
	el = el.getParentTag('div.tg00_0');
	el.setStyles({'zIndex': 2});

	event.stopPropagation();
	event.stop();
}
function hideDetailProduit(TsEvent){
	var event = new Event(TsEvent);

	var TsElements = $$('div.tg00_0');
	for(var i=0,x=TsElements.length;i<x;i++){TsElements[i].setStyles({'zIndex': 1});}
	var TsElements = $$('div.tg00_0_1');
	for(var i=0,x=TsElements.length;i<x;i++){TsElements[i].setStyles({'display': 'none'});TsElements[i].removeEvent('mouseleave', hideDetailProduit);}

	event.stopPropagation();
	event.stop();
}
function nothing(TsEvent){
	var event = new Event(TsEvent);
	event.stopPropagation();
	event.stop();
}
function initFamille(){
	calculFamille();
}

function calculFamille(){
	lignes = $$('div.familles_0');
	
	for(var i=0;i<lignes.length;i++){
		height = lignes[i].offsetHeight.toInt();
		if(height>0){
			
			cellules = $ES('div.famille_0', lignes[i]);
			for(var j=0;j<cellules.length;j++){
				pheight = height - cellules[j].getStyle('paddingTop').toInt() - cellules[j].getStyle('paddingBottom').toInt();
				cellules[j].setStyle("height",pheight);
			} 
		}
	}
}

function initSFamille(){
	lignes = $$('div.sous-famille');
	
	for(var i=0;i<lignes.length;i++){
		height = lignes[i].offsetHeight.toInt();
		if(height>0){
			cellules = $ES('div.sous_famille_0', lignes[i]);
			for(var j=0;j<cellules.length;j++){
				pheight = height - cellules[j].getStyle('paddingTop').toInt() - cellules[j].getStyle('paddingBottom').toInt();
				cellules[j].setStyle("height",pheight+10);
			} 
		}
	}
}

function initAjaxRecherche(){
	spanRech = $('ajaxnumber_search');
	if(spanRech){
		selects = $$('select.select_sf_search');
		selects.each(function(select){
			select.addListener("change", countProducts);
		});
		countProducts();
	}
}

function countProducts(){
	spanRech = $('ajaxnumber_search');
	if(spanRech){
		selects = $$('select.select_sf_search');
		url = "/index2.php?";
		url += Object.toQueryString({
							 option: "com_virtuemart",
							 page: "shop.ajaxnumbersearch",
							 no_html : "1"
							 });
		selects.each(function(select){
			url += "&"+select.getProperty("name");
			url += "="+select.options[select.selectedIndex].value;
		});
		
		url+= "&category_id="+$('search_category_id').value;
		url+= "&role="+$('search_role').value;
		url+= "&Itemid="+$('search_Itemid').value;
		new Ajax(url,{
			method: 'post',
			update: spanRech

		 }).request();
	}
}
function showFormes(tsUrlImg, tsTitle, tsIntro, tsTexte, TsEvent){
	//$GestionSelect('hidden');
	var event = new Event(TsEvent);

	var TsFormes = new Element('div').inject(document.body);
	TsFormes.setStyles({'display':'none'});
	TsFormes.setProperty('id', 'popup_formes');

	var TsFormes_0 = new Element('div').inject(TsFormes);
	TsFormes_0.setProperty('id', 'popup_formes_0');
	
	var TsFormes_Img = new Element('img').inject(TsFormes_0);
	TsFormes_Img.setProperty('src', tsUrlImg);
	TsFormes_Img.setProperty('alt', tsTitle);
	TsFormes_Img.setProperty('width', 52);
	TsFormes_Img.setProperty('height', 115);
	
	var TsFormes_Title = new Element('p').inject(TsFormes_0);
	TsFormes_Title.addClass('title');
	TsFormes_Title.setHTML(tsTitle);
	
	var TsFormes_Intro = new Element('p').inject(TsFormes_0);
	TsFormes_Intro.addClass('intro');
	TsFormes_Intro.setHTML(tsIntro);
	
	var TsFormes_texte = new Element('p').inject(TsFormes_0);
	TsFormes_texte.addClass('texte');
	TsFormes_texte.setHTML(tsTexte);

	var el = $(event.target).getParentTag('a');
	if( el){
		var tsTop = el.getTop() - 35;
		var tsLeft = el.getLeft() + el.getSize().size.x + 10;
		$('popup_formes').setStyles({'top':tsTop, 'left':tsLeft});
	}

	$('popup_formes').setStyles({'display':'block'});

	event.stopPropagation();
	event.stop();
}
function hideFormes(TsEvent){
	//$GestionSelect('visible');
	var event = new Event(TsEvent);

	if( $('popup_formes') ){document.body.removeChild($('popup_formes'));}

	event.stopPropagation();
	event.stop();
}
function print_popup(href){
	window.open(href, 'Comparateur', 'menubar=no, status=no, scrollbars=yes, menubar=no, width=1000, height=600');
}
function print_on(){
	window.print();
}
function print_off(){
	window.close();
}
/**************************************************************************************************************************************************************************************************/

/**************************************************************************************************************************************************************************************************/
/* Popup Thomas SEGOND */
/**************************************************************************************************************************************************************************************************/
if(document.documentElement && document.documentElement.clientWidth){window.TsDocRef = document.documentElement;}else{window.TsDocRef = document.body;}
if( (window.ie || window.ie6) && !window.ie7){window.IElt7=true;}else{window.IElt7=false;}

function $SetFilterPopup(){

	if( !$('filter') ){return;}

	if( $('filter').getStyle('display') == 'block' ){
		setTimeout('$SetFilter()', 20);
		setTimeout('$SetPopup()', 20);
	}
}
function $ShowFilter(TsBgColorFilter){
	TsBgColorFilter = TsBgColorFilter || window.CONST_BGCOLORFILTER;

	if( !$('filter') ){$CreateFilter(TsBgColorFilter);}

	if( $('filter').getStyle('display') == 'block' ){return;}

	if ( window.IElt7 ){$GestionSelect('hidden');}

	$SetFilter();
	$('filter').setStyle('display', 'block');

	// Evenements pour gestion du filtre et de la popup
	window.addEvent('resize', $SetFilterPopup);
}
function $HideFilter(){
	if( !$('filter') ){return;}
	
	$('filter').setStyle('display', 'none');
	if( window.IElt7 ){$GestionSelect('visible');}
}
function $SetFilter(){
	if( !$('filter') ){return;}

	$('filter').setStyles({'width': 0, 'height': 0});

	var TsLargeur = parseInt(window.TsDocRef.clientWidth) + parseInt(window.TsDocRef.scrollLeft);
	var TsHauteur = parseInt(window.TsDocRef.clientHeight) + parseInt(window.TsDocRef.scrollTop);

    if( $('global') ){
        if( $('global').offsetHeight >  TsHauteur){TsHauteur = parseInt($('global').offsetHeight);}
        if( $('global').offsetWidth  >  TsLargeur){TsLargeur = parseInt($('global').offsetWidth);}
    }

	if( $('filter') ){$('filter').setStyles({'width':TsLargeur, 'height':TsHauteur})}
}
function $CreateFilter(TsBgColorFilter){
	var TsFilter = new Element('div').inject(document.body);
	TsFilter.setStyles({'top':0, 'left':0, 'width':0, 'height':0, 'background':TsBgColorFilter, 'opacity':0.75});
	TsFilter.setProperty('id', 'filter');
}
function $GestionSelect(TsOption){
	var TsElementsSelect = document.getElementsBySelector('select', false);
	for(var i=0,l=TsElementsSelect.length;i<l;i++){TsElementsSelect[i].setStyle('visibility', TsOption);}
}
function $ShowPopup(TsUrl, TsEvent){
	if($chk(TsEvent)){
		var event = new Event(TsEvent);
		event.stopPropagation();
		event.stop();
	}

	$ShowFilter();
	if( !$('popup') ){$CreatePopup();}else{$HidePopup();}
	var TsUrl = $UrlRamdom(TsUrl);

	var myAjax = new Ajax(TsUrl, {method: 'get', onRequest:$CreateLoader, onComplete:$SetPopupComplete, onFailure:$HideAll}).request();
	return false;
}

function $HidePopup(){
	if( !$('popup') ){return;}

	$('popup').setHTML('');
	$('popup').setStyle('display', 'none');
}
function $SetPopupComplete(tsContent){
	if( !$('popup') ){return;}
	
	var tsStart = '<!-- Start POPUP -->';
	var tsEnd = '<!-- End POPUP -->';
	if( tsContent.indexOf(tsStart) > -1 && tsContent.indexOf(tsEnd) > -1 ){
		$('popup').innerHTML = tsContent.substring(tsContent.indexOf(tsStart), tsContent.indexOf(tsEnd)+(tsEnd.length));
	}else{
		$('popup').innerHTML = tsContent;
	}

	TsEvalScripts($('popup').innerHTML);

	var tsElementA = $ES('.close', 'popup');
	for(var i=0, x=tsElementA.length;i<x;i++){tsElementA[i].setStyle('visibility', 'visible');}
	setTimeout('$SetPopup()', 20);
}
function TsEvalScripts(evalResponse){
	var script, scripts;
	scripts = [];

	var regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;

	while ((script = regexp.exec(evalResponse))){scripts.push(script[1])};

	scripts = scripts.join('\n');

	if (scripts) (window.execScript) ? window.execScript(scripts) : window.setTimeout(scripts, 0);
}
function $SetPopup(){
	if( !$('popup') ){return;}

	$SetPosition('popup')
	$HidePopupLoader();
}
function $SetPosition(TsElement){
	$(TsElement).setStyles({'visibility':'hidden', 'display':'block'});

	var TsScrollTop     = parseInt(window.TsDocRef.scrollTop);
	var TsScrollLeft    = parseInt(window.TsDocRef.scrollLeft);
	var TsClientHeight  = parseInt(window.TsDocRef.clientHeight);
	var TsClientWidth   = parseInt(window.TsDocRef.clientWidth);


	// Calcule la résolution de l'utilisateur pour le scroll des caractéristiques
	
	if( $('comparateur_content_0a') && parseInt($(TsElement).offsetHeight) > TsClientHeight ){
		$('comparateur_content_0a').setStyle('height', ( parseInt($('comparateur_content_0a').getStyle('height')) - (parseInt($(TsElement).offsetHeight) - TsClientHeight) ) );
	}

	var TsElementHeight = parseInt($(TsElement).offsetHeight);
	var TsElementWidth  = parseInt($(TsElement).offsetWidth);
	var TsBlockTop      = Math.round( TsScrollTop + (TsClientHeight - TsElementHeight) / 2)+'px';
	var TsBlockLeft     = Math.round( TsScrollLeft + (TsClientWidth - TsElementWidth) / 2)+'px';

	if( parseInt(TsBlockTop) < 0 ){ TsBlockTop = '0';}
	if( parseInt(TsBlockLeft) < 0 ){ TsBlockLeft = '0';}

	if( $(TsElement) ){$(TsElement).setStyles({'top':TsBlockTop, 'left':TsBlockLeft, 'visibility':'visible'})}
}
function $CreatePopup(){
	var TsPopup = new Element('div').inject(document.body);
	TsPopup.setStyles({'top':0, 'left':0});
	TsPopup.setProperty('id', 'popup');
}
function $CreatePopupLoader(){
	var TsPopup = new Element('div').inject(document.body);
	TsPopup.setStyles({'position':'absolute', 'top':0, 'left':0, 'z-index':3, 'display':'none', 'overflow':'hidden'});
	TsPopup.setProperty('id', 'popup_loader');
}
function $CreateLoader(){
	if( !$('popup_loader') ){
		$CreatePopupLoader();
	}else{
		$SetPosition('popup_loader');
		return;
	}

	var TsLoader = new Element('div');
	TsLoader.setStyles({'position':'relative', 'width':250, 'overflow':'hidden', 'text-align':'center', 'background': '#fff', 'padding-top':10, 'padding-bottom':10});
	TsLoader.setProperty('id', 'loader');

	var TsImage = new Element('img').inject(TsLoader);
	TsImage.setProperty('src', window.CONST_PATH_IMG + 'img-loader.gif');
	TsImage.setProperty('alt', 'Chargement en cours ...');

	var TsTexte = new Element('p').inject(TsLoader);
	TsTexte.setStyles({'padding-left':10, 'padding-right':10});
	TsTexte.setHTML('Chargement en cours ...');
	
	TsLoader.inject($('popup_loader'));
	$SetPosition('popup_loader');
}
function $HidePopupLoader(){
	if( !$('popup_loader') ){return;}
	$('popup_loader').setStyle('display', 'none');
}
function $HideAll(TsEvent){
	if($chk(TsEvent))
		var event = new Event(TsEvent);

	$HidePopupLoader();
	$HidePopup();
	$HideFilter();

	if($chk(TsEvent)){	
		event.stopPropagation();
		event.stop();
	}
}
function $UrlRamdom(TsUrl){
	if( TsUrl.contains('?') ){
		return TsUrl + '&nocache='+Math.random();
	}else{
		return TsUrl + '?nocache='+Math.random();
	}
}
function reviews(TsEvent){
	if($chk(TsEvent))
		var event = new Event(TsEvent);

	if( $('review_content_0') && $('form_review') ){
		if( $('review_content_0').getStyle('display') == 'none'){
			$('review_content_0').setStyle('display','block');
			$('form_review').setStyle('display','none');
		}else{
			$('review_content_0').setStyle('display','none');
			$('form_review').setStyle('display','block');
		}
	}
	
	if($chk(TsEvent)){
		event.stopPropagation();
		event.stop();
	}
}

/**************************************************************************************************************************************************************************************************/
/* Addon MOOTOOLS */
/**************************************************************************************************************************************************************************************************/

Fx.Morph = Fx.Styles.extend({
	start: function(className){
		var to = {};
 
		$each(document.styleSheets, function(style){
			
			var rules = style.rules || style.cssRules;
			$each(rules, function(rule){
				if (!rule.selectorText.test('\.' + className + '$')) return;
				Fx.CSS.Styles.each(function(style){
					if (!rule.style || !rule.style[style]) return;
					var ruleStyle = rule.style[style];
					to[style] = (style.test(/color/i) && ruleStyle.test(/^rgb/)) ? ruleStyle.rgbToHex() : ruleStyle;
				});
			});
			
		});
		return this.parent(to);
	}
 
});

Fx.CSS.Styles = ["backgroundColor", "backgroundPosition", "color", "width", "height", "left", "top", "bottom", "right", "fontSize", "letterSpacing", "lineHeight", "textIndent", "opacity"];
 
	Fx.CSS.Styles.extend(Element.Styles.padding);
	Fx.CSS.Styles.extend(Element.Styles.margin);
	 
	Element.Styles.border.each(function(border){
		['Width', 'Color'].each(function(property){
			Fx.CSS.Styles.push(border + property);
		});
	});

var myMorph = new Fx.Morph('panier_ajax', {wait: false});
var cartTransition = new Fx.Transition(Fx.Transitions.linear, 3);
var myMorph = new Fx.Style('panier_ajax', 'opacity', {duration:500,transition: cartTransition});
var onglet_panier;
var coinBD_panier;
var lockpanier = 0;
var lockongpanier = 0;

function initAddCart(is_variant){
	onglet_panier = $('mon_panier');
	if(!onglet_panier) return;
	coinBD_panier = $$('div.panier div.coinBD');
	myMorph.hide();
	$('panier_ajax').removeClass("withoutjs");
	onglet_panier.removeClass("hover");
	coinBD_panier.setStyle("display","block");
				
	if(coinBD_panier.length > 0)
		coinBD_panier = coinBD_panier[0];
	
	$('mon_panier').addEvent('mouseenter', function(e){
		new Event(e).stop();
		lockongpanier = 1;
		onglet_panier.addClass("hover");
		myMorph.start(1);
		coinBD_panier.setStyle("display","none");
	});
	 
	$('mon_panier').addEvent('mouseleave', function(e){
		new Event(e).stop();
		lockongpanier = 0;
		cache = function(){
			if(lockpanier == 0){
				myMorph.start(0);
				onglet_panier.removeClass("hover");
				coinBD_panier.setStyle("display","block");
			}
		};
		cache.delay(500);
	});
	
	$('panier_ajax').addEvent('mouseenter', function(e){
		new Event(e).stop();
		lockpanier=1;
		myMorph.start(1);
		onglet_panier.addClass("hover");
		coinBD_panier.setStyle("display","none");
	});
	
	$('panier_ajax').addEvent('mouseleave', function(e){
		new Event(e).stop();	
		lockpanier = 0;
		cache = function(){			
			if(lockongpanier == 0){
				myMorph.start(0);
				onglet_panier.removeClass("hover");
				coinBD_panier.setStyle("display","block");
			}
		};
		cache.delay(500);
	});

	adds = $$("form").filterByAttribute("name","=","addtocart");
	for(var i=0;i<adds.length;i++){
	adds[i].addEvent("submit",function(e) {
			new Event(e).stop();
			scroool = new Fx.Scroll(window,{
				wait: false,
				duration: 1000,
				transition: Fx.Transitions.Quad.easeInOut
				}
			);
			scroool.toTop();
			var panier_ajax = $('panier_ajax');
			myMorph.start(1);
			onglet_panier.addClass("hover");
			coinBD_panier.setStyle("display","none");

			this.send({
				update: panier_ajax,
				async:true,
				onComplete: function(){
					new Ajax("/index2.php?option=com_virtuemart&page=shop.ajaxnumbercart&no_html=1",
						{
							update: $('number_art')
							
						}
					).request();
					change = function(){
						if(lockongpanier == 0 && lockpanier == 0 ){
							myMorph.start(0);
							onglet_panier.removeClass("hover");
							coinBD_panier.setStyle("display","block");
						}
					};
					change.delay(3000);
				}
			});	
			$HideAll(e);
		});
	}
}

function initLexique(){
	if($('lexique')){
		$$('ul.liste_termes a').each(function(lien){
			lien.addEvent("click",function(e){
				new Event(e).stop();
				$$('ul.liste_termes li').each(function(lia){
					lia.removeClass("selected");
				});
				lien.getParentTag("li").addClass("selected");
				tabHref = this.getProperty("href").split("#");
				if(tabHref.length == 2){
					scrooling = new Fx.Scroll(window,{
						wait: false,
						duration: 1000,
						transition: Fx.Transitions.Quad.easeInOut
						}
					);
					res = $$("#lexique a.ancre").filterByAttribute("name","=",tabHref[1]);

					if(res.length>0){
						scrooling.toElement(res[0]);
					}
				}
			});
		});
	}
}
/****************************************/
/* Yoann BRIEUX */
/****************************************/
function initFicheConseil(){
	if( !$('list_fiches_conseils') ){return;}

	var list = $$('ul#list_fiches_conseils li div.collapse');
	var headings = $$('ul#list_fiches_conseils li h3 span');
	
	
	headings.each( function(heading, i) {
		var collapsible = new Fx.Slide(list[i],{duration: 500,transition: Fx.Transitions.linear});
		
		heading.addEvent('click', function(e){
			new Event(e).stop();
			if(heading.hasClass('ouvert')){
				heading.removeClass('ouvert');
				collapsible.slideOut();
			}else{
				heading.addClass('ouvert');
				collapsible.slideIn();
			}
		});
		
		//if(i==0){
			heading.addClass('ouvert');
		/*}else{
			collapsible.hide();
		}
*/		
	});
}

function initFAQ(){
	if( !$('list_faq') ){return;}

	var list = $$('ul#list_faq li div.collapse');
	var headings = $$('ul#list_faq li h4 span');
	
	
	headings.each( function(heading, i) {
		var collapsible = new Fx.Slide(list[i],{duration: 500,transition: Fx.Transitions.linear});
		
		heading.addEvent('click', function(e){
			new Event(e).stop();
			if(heading.hasClass('ouvert')){
				heading.removeClass('ouvert');
				collapsible.slideOut();
			}else{
				heading.addClass('ouvert');
				collapsible.slideIn();
			}
		});
		
		if(i==0){
			heading.addClass('ouvert');
		}else{
			heading.removeClass('ouvert');
			collapsible.hide();
		}
		
	});
}

function RecupComparateur(event){
	var url = '/index2.php?option=com_virtuemart&page=shop.ajaxcomparator&no_html=1&style=on';
	var list = $$('div.comparer_0 input');

	var valeur = new Array();
	
	list.each( function(inputt, i) {
		if(inputt.checked){
			valeur.push(inputt.value)
			inputt.setProperty('checked', false);
		}
	});
	
	if(valeur.length>5) { 
		alert("Nombre maximum de produits à sélectionner : 5.");
		return false;
	}
	
	if( url.contains('?') ){
		url = url + '&valeurs='+valeur.toString();
	}else{
		url = url + '?valeurs='+valeur.toString();
	}

	$ShowPopup(url, event);
	return false;
}



function setMsgError(msg){
	if ( !$('isError') ){return;}

	if(msg){$('isError').innerHTML = msg;}
	if($('isError').innerHTML!=""){
		Message($('isError').innerHTML,"erreur");
	}
	return;
}

function setMsgConf(msg){
	if ( !$('isConf') ){return;}

	if(msg){$('isConf').innerHTML = msg;}
	
	if($('isConf').innerHTML!=""){
		Message($('isConf').innerHTML,"confirmation");
	}
	return;
}

function Message(msg,type){
		
		$ShowFilter();
		$CreatePopup();
		$CreateLoader();
		var tsElementsHTML = $$('html');
		//for(var i=0,x=tsElementsHTML.length;i<x;i++){tsElementsHTML[i].setStyle('overflow', 'hidden');}
		var out = '<div class="popup alert"><div class="coins"><div class="coin coinHG"></div><div class="coin_content00"></div></div><div class="popup_content">';
			out = out +'<a href="#" title="" class="close" onclick="$HideAll(event);"><img src="/templates/altima/images/img-icon-close.gif" alt="Fermer" /></a>';
		if(type && type!="undefined") { msg = '<img class="icon" src="/templates/altima/images/img-icon-'+type+'.gif" alt="Erreur" align="left" />'+msg; }
			out = out +'<div class="message">'+msg+'</div>';
			out = out +'</div><div class="coins"><div class="coin_content01"></div><div class="coin coinBD"></div></div></div>';
		$SetPopupComplete(out);
}

function RecupVariantComparateur(event,id){
	var url = '/index2.php?option=com_virtuemart&page=shop.ajaxvariantpanier&product_id='+id+'&comparateur=1&no_html=1';
	$ShowPopup(url, event);
	return false;
}

function ComparateurSupprimerAll(){
		url = "/index2.php?";
		url += Object.toQueryString({
							 option: "com_virtuemart",
							 page: "shop.ajaxcomparator",
							 no_html: "1",
							 del: "all"
							 });
		new Ajax (url,{
			method: 'post'
		 }).request();
		 	
}

function ComparateurSupprimer(id){

		url = "/index2.php?";
		url += Object.toQueryString({
							 option: "com_virtuemart",
							 page: "shop.ajaxcomparator",
							 no_html: "1",
							 del: id
							 });
		new Ajax (url,{
			method: 'post',
			async: false
		 }).request();
		 
		 return true;
}

function OPCOAjoutPanier(sku,qtt){
        var result='';
    
		url = "/addToCart.php?";
		url += Object.toQueryString({
							 id: sku,
							 quantity: qtt
		});
                             
		new Ajax (url,{
			method: 'post',
			async: false,
            update: result
		 }).request();
         
         document.location.reload();
         
         return true;
}

function AjouterSelection(id){
		url = "/index2.php?";
		url += Object.toQueryString({
							 option: "com_virtuemart",
							 page: "shop.ajaxcomparator",
							 no_html: "1",
							 ajsel: id
							 });
		new Ajax (url,{
			method: 'post',
			update: $('selection_prodid_'+id)
		 }).request();
		 
		 return false;
}
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { 
				dumped_text += level_padding + "'" + item + "' ...\n";
				//if(level<500){dumped_text += dump(value,level+1);}
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { 
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

/*
 *	NEWSLETTER
 */


var sondage=false;
var newsletter=false;
var newsletter_hp=false;
function initOPNewsletter(){
	// Ouverture du calque en page d'accueil
	if(document.URL.test('http:\/\/[^\/]*\/$')){
		if(newsletter_hp)
			calqueAccueilNewsletter();
	}
}

function unloadBody(){
	// Initialisation de la pop-under en fermeture de page, sondage ou newsletter
	if(!Cookie.get('popundernewsletter')){
		if(sondage)
			popUnderSondage();
		else if(newsletter)
			popUnderNewsletter();
		
	}
	Cookie.set('popundernewsletter',1);
}

function popUnderNewsletter(){
	win1 = window.open("/index2.php?option=com_virtuemart&page=shop.inscription_newsletter_popup&no_html=1", "bw", 'scrollbars=no, resizable=no, toolbar=no, menubar=no, status=no, location=no, height=335 ,width=600');
	//if(!win1) return;
	win1.blur();
	window.focus();
}

function popUnderSondage(){
	win2 = window.open("/index2.php?option=com_virtuemart&page=shop.sondage_popup&no_html=1", "bw", 'scrollbars=yes, resizable=no, toolbar=no, menubar=no, status=yes, location=no, left=85, top=20, height=800 ,width=916');
	//if(!win2) return;
	win2.blur();
	window.focus();
}


function calqueAccueilNewsletter(){
	
	if(Cookie.get('calquenewsletter')==1) return;
	Cookie.set('calquenewsletter',1);
	
	var TsUrl = '/index2.php?option=com_virtuemart&page=shop.inscription_newsletter_calque&no_html=1';
	if(!$('popup'))
		$CreatePopup();
	else
		$HidePopup();
	var myAjax = new Ajax(TsUrl, {method: 'get', onRequest:$CreateLoader, onComplete:$SetPopupComplete, onFailure:$HideAll}).request();
	
	
}

function isset(varname)  {
  if(typeof( window[ varname ] ) != "undefined") return true;
  else return false;
}

/****************************************/
/* Fin de Yoann BRIEUX */
/****************************************/

/**************************************************************************************************************************************************************************************************/

/**************************************************************************************************************************************************************************************************/
/* Addon MOOTOOLS */
/**************************************************************************************************************************************************************************************************/


if(Element){
	Element.extend({
		getParentTag: function(parent){ // Retourne le premier parent avec le tag demand� et/ou la id et/ou class -> div#monid.maclass
			var TsTagName, TsClassName , TsId;
			var TsParentClass = parent.split('.');
			TsParentClass.length > 1 ? TsClassName = TsParentClass[1] : TsClassName = '';
			var TsParentId = TsParentClass[0].split('#');
			if( TsParentId.length > 1 ){TsId = TsParentId[1];}else{TsId = '';}
			TsTagName = TsParentId[0];
			var TsElement = this;
			while( $(TsElement) ){
				if(TsElement.getTag() == 'body'){break;}

				var TsFlag = true;
				if( TsElement.getTag() != TsTagName ){TsFlag = false;}
				if( TsId != '' && TsElement.getProperty('id') != TsId ){TsFlag = false;}
				if( TsClassName != '' && !TsElement.hasClass(TsClassName) ){TsFlag = false;}
				if( TsFlag ){break;}

				TsElement = TsElement.parentNode;
			}
			return $(TsElement);
		}
	})
}
initAll();
//window.addListener("load",initLoad)
/**************************************************************************************************************************************************************************************************/

