// Au démmarage de la fenetre
$(document).ready(function() {	
	// Si on clique sur la page, l'autocomplete de recherche disparait
	$(document).click(function() { $('#autocomplete_recherche').css('display','none'); });
	$("#autocomplete_recherche").click(function() {return false;});
	$("#recherche").keyup(function() {
		$('#autocomplete_recherche').css('display','block');
		$('#autocomplete_recherche').page({urlTarget:'_content/_ajax/recherche.php',reqSend:''});
	});	
	
	$('[name="nav_link"]').each(function() {
		// creation menus
		if($('#men' + this.id).length == 0) {
			if(this.id == 149) {
				$(this).html($(this).html()+'<div id="men'+this.id+'" class="discovmenu_top flash"></div>');
			} else {
				$(this).html($(this).html()+'<div id="men'+this.id+'" class="discovmenu_top"></div>');
			}
		}
		
		// mouse out
		$('#' + this.id).mouseover(function() {
			$('#men'+this.id).css('display','block');
	
			if($('#men'+this.id).html() == '') {
				$('#'+'men' + this.id).page({urlTarget:'_content/_ajax/menu_top.php',reqSend:'id_cat=' + this.id});
			}
		});
		
		$('#' + this.id).mouseout(function() { $('#men'+this.id).css('display','none'); });
	});
});

function changeTopProduits(div) { 
	var divs = $('div[name="top_produits"]');

	for(o=0;o<divs.length;o++) {
		divs[o].style.display = 'none';
	}
	$('#top_produits' + div).css({"display" : "block"});
}



function calculTotalCases() {
	var tab = $('input[name="idArticle[]"]');
	var nombre = 0;

	for(o=0;o<tab.length;o++) {
		if(tab[o].checked == true) { nombre++; }
	}
	return nombre;
}


function fullcases(check) {
	var tab = $('input[name="idArticle[]"]');
	for(o=0;o<tab.length;o++) {
		if(check == true) {
			tab[o].checked = true;
		} else {
			tab[o].checked = false;
		}
	}

	if(check == true) {
		$('#checkall1').attr("checked", "checked");
		$('#checkall2').attr("checked", "checked");
	} else {
		$('#checkall1').removeAttr("checked");
		$('#checkall2').removeAttr("checked");
	}
}



function verifIntermediaire(id) {
	if(calculTotalCases() > 5) { 
		$('#' + id).removeAttr("checked");
		
		alert("Vous ne pouvez pas comparer plus de 5 produits");
	}

	var tab = $('input[name="idArticle[]"]');

	for(o=0;o<tab.length;o++) {
		if(tab[o].checked == false) { var false_value = 0; }
	}

	if(false_value == 0) { 
		$('#checkall1').removeAttr("checked");
		$('#checkall2').removeAttr("checked");
	} else {
		$('#checkall1').attr("checked", "checked");
		$('#checkall2').attr("checked", "checked");
	}
}

// ouverture d'une popup
function ouverturePopUp(url, name, width, height) {
	//$(document).
	var x = (screen.width - width) / 2;
	var y = ((screen.height - height) / 2) - 450;
	
	if(width == '') { var width = screen.width - 50; }
	if(height == '') { var height = screen.height - 150; }

	window.open(url, name, 'width='+width+',height='+height+',left='+x+',top='+y+',screenX='+x+',screenY='+y+'');
}

// Affichage popup alert
function alertViewCustom(type, lang) {
	$("#alert").page({reqSend:'&type='+type+'&id_var='+lang,urlTarget:'_content/_ajax/alert.php'});
	enabledScroolBar();
	
	$('#alert').fadeIn('10');
}

// Reaffichage à retardement

function FinAlertViewCustom() {
	$('#alert').fadeOut('10');

	setTimeout('disableScroolBar()',450);	
}

function enabledVisualImages() {
	$('#visual_images').fadeIn('10');
}

function disabledVisualImages() {
	$('#visual_images').fadeOut('10');
}


function enabledScroolBar() {
	$("html, body").css("overflow", "visible");
	$("html, body").css("overflow-x", "visible");
	$("html, body").css("height", "100%");
	$("html, body").css("overflow", "hidden");	
}


// Reaffichage scroolbar
function disableScroolBar() {
	$("html, body").css("height", "auto");
	$("html, body").css("overflow", "auto");
	$("html, body").css("overflow-x", "hidden");
}

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-6310623-3']);
_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);
})();
