var xlang = $('html').attr("lang");
var xbase = $('base').attr('href');

var xhover = new Array(	"div.pbImg", "span.bal", "span.LKmb", "td div img.cycle", "span.vendeur",
						"td.a_decouvrir img.image", "div.simil_bkg div img",
						"div.apercu_produit td.apercu_produit_photo img.center",
						"div.ic_print_fr", "div.ic_memorise_fr", "div.presse_accueil", "div.pub_droiteclient", "div.liDivimg");

jQuery.each(xhover, function(index,value)
{
	$(value).hover(
		function()
		{
			this.style.cursor = 'pointer';
		},
		function()
		{
			this.style.cursor = 'default';
		});
});
	
$('#s1').cycle('fade');

var x = $("span.bal");
if(x)
{
	x.each(function(index)
	{
		var y = $(this).attr("id");
		if (y) {
			if ("membre" == y)
			{
				$(this).click(function()
				{
					document.location.href=xbase+"index.php/membre/membre";
				});
			}
			else if (y.indexOf('bas_')>=0)
			{
				var str = y.replace('bas_', '');
				$(this).click(function()
				{
					document.location.href=xbase+"index.php/produit/menu_bas/"+str;
				});
			}
			else if (y.indexOf('vie_')>=0)
			{
				var str = y.replace('vie_', '');
				$(this).click(function()
				{
					document.location.href=xbase+"index.php/produit/menu_vie/"+str;
				});
			}
		}
	});
};

$('#s2').cycle({
	fx:'scrollUp',
	timeout:7000,
	delay: -1000,
	pause: 1
});

$('#adec01').cycle({
	fx:'fade',
	timeout:21000
});

var xlightBox = new Array('#zoom_aide a', '#zoom a', '#gallery a');
jQuery.each(xlightBox, function(index, value) {
	$(function()
	{
		$(value).lightBox();
	});
});

$("div.apercu_produit img.memoriser").hover(
	function(){
		this.style.cursor = 'pointer';
		this.src = "imgs_kbs/"+xlang+"/memoriser_over.jpg";
		},
	function(){
		this.style.cursor = 'default';
		this.src="imgs_kbs/"+xlang+"/memoriser.jpg";
		}
	);


var ximg = $("div.TopBox div.liDivimg img.apercu_produit_photo");
if(ximg)
{
	ximg.each(function(index)
	{
		var xhref = $(this).parent().parent().children("div a").children("a.Ref_listes").attr("href");
		if(xhref)
		{
			$(this).click(function()
			{
				document.location.href = xbase+xhref;
			});
		}
	});
};

var xScat_accueil = $("div#produits div.prodBox div.pbImg");
if(xScat_accueil)
{
	xScat_accueil.each(function(index)
	{
		var xobj = this;
		var xhref = $(xobj).parent().children("div a").children("a").attr("href");
		if(xhref)
		{
			$(xobj).click(function()
			{
				document.location.href = xbase+xhref;
			});
		}
	});
};

var xSimil = $("div.simil div.simil_cadre div.simil_bkg div img");
if(xSimil)
{
	xSimil.each(function(index)
	{
		var xhref = $(this).parent().parent().parent().children("a").attr('href');
		if(xhref)
		{
			$(this).click(function()
			{
				document.location.href = xbase+xhref;
			});
		}
	});
};

var xA_decouvrir = $("table td.a_decouvrir img");
if(xA_decouvrir)
{
	xA_decouvrir.each(function(index)
	{
		var xhref = $(this).parent().parent().parent().find("td.a_decouvrir_txt a").attr('href');
		if(xhref)
		{
			$(this).click(function()
			{
				document.location.href = xbase+xhref;
			});
		}
	});
};

var xPhotos_cycles = $("table div img.cycle");
if(xPhotos_cycles)
{
	xPhotos_cycles.each(function(index)
	{
		var xhref = $(this).parent().parent().parent().parent().find("tr td div.lkcycle a").attr('href');
		if(xhref)
		{
			$(this).click(function()
			{
				document.location.href = xbase+xhref;
			});
		}
	});
};

var xvendeur = $("span.vendeur");
if(xvendeur)
{
	xvendeur.each(function(index)
	{
		var tmp = $(this).attr("class");
		var xclass = tmp.split(' ');
		if('vendeur' == xclass[0])
		{
			$(this).click(function() {
				document.location.href = xbase+xclass[1];
			});
		}
	});
}

var selects = new Array('a.sscategoriesSelect', 'a.scategoriesSelect', 'a.categoriesSelect');
var xhref = '';
jQuery.each(selects, function(index, value)
{
	var tmp = $(value).attr('href');
	if(tmp)
	{
		xhref = tmp;
		return false; // break
	};
});

if(xhref)
{
	var xMemo = new Array('div.BtnMemoriser_fr', 'div.BtnMemoriser_en');
	jQuery.each(xMemo, function(index,value)
	{
		var x = $(value);
		if(x)
		{
			x.each(function(index) {
				var xid = $(this).attr('id');
				$(this).click(function()
				{
					document.location.href = xbase+xhref+'?memo='+xid.substr(1,xid.length); // on retire le premier caractere de ID
				});
			});
		}
	});
}

var xheader = new Array("div#BtnIndex");

jQuery.each(xheader, function(index,value)
{
	$(value).hover(
		function()
		{
			this.style.cursor = 'pointer';
		},
		function()
		{
			this.style.cursor = 'default';
		});
	$(value).click(function()
		{
			document.location.href = xbase;
		});
});

