function shopEvents(){
	var allPageTags=document.getElementsByTagName("*");
	var divs=document.getElementsByTagName("*");

	for (var i=0;i<allPageTags.length;i++) {
		if (allPageTags[i].className=='article') {
			allPageTags[i].onmouseover = function()	{
				var divTrans = this.getElementsByTagName("div");
				if (divTrans[0] !=null) divTrans[0].style.display = "block";

				var info = this.getElementsByTagName("a");
				if (info[0] != null) info[0].style.display = "block";
			};
			allPageTags[i].onmouseout = function()	{
				var divTrans = this.getElementsByTagName("div");
				if(divTrans[0] != null) divTrans[0].style.display = "none";

				var info = this.getElementsByTagName("a");
				if(info[0] !=null) info[0].style.display = "none";
			};
		}
	}
};
function removeAllinput(x) {
	if (x.value != '') {
		x.value = '';
	}
}
function removeinput(x,val) {
	if (x.value == val) {
		x.value = '';
	}
}
function setTextInput(x,val){
	if (x.value == '') {
		x.value = val;
	}
}
function resetFormEnvia(id){
	document.getElementById('user1_'+id).value = su_nombre_texto;
	document.getElementById('mail1_'+id).value = su_nombre_mail;
	document.getElementById('user2_'+id).value = tu_nombre_texto;
	document.getElementById('mail2_'+id).value = tu_nombre_mail;
	document.getElementById('message1_'+id).value="";
}
function resetFormNewsletter(){
	document.getElementById('name').value = tu_nombre_texto;
	document.getElementById('mail').value = tu_nombre_mail;
}
function submitNewsletter(){

	tu_nombre = document.getElementById('name').value;
	tu_mail = document.getElementById('mail').value;
	tu_nombre		=		tu_nombre.htmlEntities();
	tu_mail			=		tu_mail.htmlEntities();

	var filter=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

	mailok=filter.test(tu_mail);


	if((tu_nombre!="")&&(tu_nombre!=tu_nombre_texto)&&(tu_mail!="")&&(tu_mail!=tu_nombre_mail)&&(mailok)){

		$.ajax({
			type: "POST",
			url: "frontoffice/secciones/comunes/submit_newsletter.php",
			data: "ajax=1&OP_1=submit"+
			"&tu_nombre="+tu_nombre+
			"&tu_mail="+tu_mail,


			success: function(msg){

				switch(msg){
					default:
					document.getElementById("message_news").innerHTML = msg;
					$('#message_news').fadeIn("slow");
					break;
					case "ok":
					document.getElementById("message_news").innerHTML = ok_newsletter;
					$('#message_news').fadeIn("slow");
					resetFormNewsletter();
					break;
				}
			}
		});
	}else{
		if((!mailok)&&(tu_mail!="")&&(tu_mail!=tu_nombre_mail)){
			document.getElementById("message_news").innerHTML = mail_ko;
			$('#message_news').fadeIn("slow");
		}else{
			document.getElementById("message_news").innerHTML = campos_obligatorios;
			$('#message_news').fadeIn("slow");
		}

	}
}
function showInfoNews(){

	if($('#infonews').is(":hidden")){
		$('#infonews').fadeIn("slow");
	}else{
		$('#infonews').fadeOut("slow");
	}
}
function showCredits(){

	if($('#infocredits').is(":hidden")){
		$('#infocredits').fadeIn("slow");
	}else{
		$('#infocredits').fadeOut("slow");
	}
}

function enviaPais(valor_pais){
	alert(valor_pais);
	splitter = valor_pais.split("_");
	tieneEstados= splitter[0];
	valor= splitter[1];
	alert(tieneEstados);
	if((primera_vez)&&(valor==6)){
		$("#capa_provincias").show();
	}else if(tieneEstados==1){
		primera_vez=false;
		alert('entro a tieneEstados');
			$.ajax({
			type: "POST",
			url: "frontoffice/secciones/shop/provincias.php",
			data: "ajax=1"+
			"&pais_seleccionado="+valor,
			


			success: function(msg){
				alert(msg);
				
					document.getElementById("capa_provincias").innerHTML = msg;
					$("#capa_provincias").show();
				
			}
		});
		
	}else{
		alert('entro a ocultar');
		$.ajax({
			type: "POST",
			url: "frontoffice/secciones/shop/calculaCosteEnvio.php",
			data: "ajax=1&tipo=donde"+
			"&pais_seleccionado="+valor,
			


			success: function(msg){
				alert(msg);
				
					document.getElementById("precio_pais").innerHTML = msg;
					
				
			}
		});
		$("#capa_provincias").hide();
	}
}
$(document).ready(function () {

	// initialize scrollable together with the autoscroll plugin
	$("div.scrollable").scrollable({size:1,speed:2000}).circular().autoscroll({autoplay: true,	interval:10000, api: true});
	$("div.scrollable_peq").scrollable({size:1,speed:2000}).circular().autoscroll({autoplay: true,	interval:10000, api: true});
	//$("div.paraslide_tabs").tabs().play();
	if(addBasquetAvalaible){
		unidades_inicial = parseInt(document.getElementById('unidades_producto').innerHTML);
	}

	$(".slide").hide();
	$(".share").hide();
	$(".footer_news").hide();
	$('#infonews').click(function () {
		$(this).fadeOut("slow");
	});
	$('#infocredits').click(function () {
		$(this).fadeOut("slow");
	});
	$(".cambiar").click(function () {
		$(this).parent().parent().next(".slide").slideToggle("slow");
	});
	$(".a_share").click(function () {
		$(this).next().slideToggle("slow");
	});
	$("#tickerTextHolder").newsTicker({
            effect: "fade"
        });
	if(addBasquetAvalaible){
		$(".addBasquet").click(function () {
			cantidadVal=0;
			unidades_antes = parseInt(document.getElementById('unidades_producto').innerHTML);
			cantidadVal				= parseInt(document.getElementById('cantidad').value);
			if((unidades_antes>0)&&(unidades_antes - cantidadVal>=0)){

				var productIDValSplitter 	= (this.id).split("_");
				var productIDVal 			= productIDValSplitter[1];


				var atributoVal				= document.getElementById('atributo').value;
				var productX 		= $("#productImageWrapID_" + productIDVal).offset().left;
				var productY 		= $("#productImageWrapID_" + productIDVal).offset().top;

				if( $("#productID_" + productIDVal).length > 0){
					var basketX 		= $("#productID_" + productIDVal).offset().left;
					var basketY 		= $("#productID_" + productIDVal).offset().top;
				} else {
					var basketX 		= $("#basketTitleWrap").offset().left;
					var basketY 		= $("#basketTitleWrap").offset().top;
				}

				var gotoX 			= basketX - productX;
				var gotoY 			= basketY - productY;

				var newImageWidth 	= $("#productImageWrapID_" + productIDVal).width() / 4;
				var newImageHeight	= $("#productImageWrapID_" + productIDVal).height() / 4;


				$("#productImageWrapID_" + productIDVal + " img")
				.clone()
				.prependTo("#productImageWrapID_" + productIDVal)
				.css({'position' : 'absolute'})
				.attr('id','productImageWrapIDCopy_'+ productIDVal)
				.animate({opacity: 0.4}, 100 )
				.animate({opacity: 0.1, marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1200, function() {

					$("#notificationsLoader").html('<img src="frontoffice/imgs/loader.gif">');

					$.ajax({
						type: "POST",
						url: "frontoffice/secciones/shop/basket.php?origen=ajax",
						data: { productID: productIDVal,cantidad: cantidadVal,atributo: atributoVal, action: "addToBasket"},
						success: function(theResponse) {

							splitter = theResponse.split("___");

							n_items = splitter[0];
							total_ventas = splitter[1];
							total_ventas = splitter[1];
							varhtml = splitter[2];


							document.getElementById('unidades_producto').innerHTML = unidades_antes - cantidadVal;
							document.getElementById('precio_total').innerHTML = total_ventas;
							document.getElementById('cesta_header').innerHTML =n_items +" items / "+total_ventas +moneda;

							if(parseFloat(total_ventas)>0){
								$("#checkout_button").show();
							}else{
								$("#checkout_button").hide();
							}
							$("#basketItemsWrap").hide();
							$("#productImageWrapIDCopy_"+productIDVal).remove();
							document.getElementById('basketItemsWrap').innerHTML = varhtml;

							$("#basketItemsWrap").show();
							$("#notificationsLoader").empty();

						}

					});



				});

			}
		});

	}
	if(delBasquetAvalaible){
		$("#basketItemsWrap a").live("click", function(event) {
			var productIDValSplitter 	= (this.id).split("_");
			var productIDVal 			= productIDValSplitter[1];
			var atributoVal				= productIDValSplitter[2];
			$("#notificationsLoader").html('<img src="frontoffice/imgs/loader.gif">');
			$.ajax({
				type: "POST",
				url: "frontoffice/secciones/shop/basket.php?origen=ajax",
				data: { productID: productIDVal,atributo: atributoVal, action: "deleteFromBasket"},
				success: function(theResponse) {
					splitter = theResponse.split("___");
					n_items = splitter[0];
					total_ventas = splitter[1];
					varhtml = splitter[2];
					document.getElementById('unidades_producto').innerHTML = unidades_inicial;
					document.getElementById('precio_total').innerHTML = total_ventas;
					document.getElementById('cesta_header').innerHTML =n_items +" items / "+total_ventas +moneda;
					if(parseFloat(total_ventas)>0){
						$("#checkout_button").show();
					}else{
						$("#checkout_button").hide();
					}
					$("#basketItemsWrap").hide();
					document.getElementById('basketItemsWrap').innerHTML = varhtml;
					$("#basketItemsWrap").show();
					$("#notificationsLoader").empty();
					return false;

				}
			});

		});
	}
	if(decBasquet){
		$(".less").live("click", function(event) {
			var productIDValSplitter 	= (this.id).split("_");
			var productIDVal 			= productIDValSplitter[1];
			var atributoVal				= productIDValSplitter[2];
			$("#notificationsLoader").html('<img src="frontoffice/imgs/loader.gif">');
			$.ajax({
				type: "POST",
				url: "frontoffice/secciones/shop/basket.php?origen=ajax",
				data: { productID: productIDVal,atributo: atributoVal, action: "deleteFromBasket"},
				success: function(theResponse) {
					splitter = theResponse.split("___");
					n_items = splitter[0];
					total_ventas = splitter[1];
					varhtml = splitter[2];
					document.getElementById('unidades_producto').innerHTML = unidades_inicial;
					document.getElementById('precio_total').innerHTML = total_ventas;
					document.getElementById('cesta_header').innerHTML =n_items +" items / "+total_ventas +moneda;
					if(parseFloat(total_ventas)>0){
						$("#checkout_button").show();
					}else{
						$("#checkout_button").hide();
					}
					$("#basketItemsWrap").hide();
					document.getElementById('basketItemsWrap').innerHTML = varhtml;
					$("#basketItemsWrap").show();
					$("#notificationsLoader").empty();
					return false;

				}
			});

		});
	}
	if(incBasquet){
		$(".more").click(function () {
			cantidadVal=0;
			unidades_antes = parseInt(document.getElementById('unidades_producto').innerHTML);
			cantidadVal				= parseInt(document.getElementById('cantidad').value);
			if((unidades_antes>0)&&(unidades_antes - cantidadVal>=0)){

				var productIDValSplitter 	= (this.id).split("_");
				var productIDVal 			= productIDValSplitter[1];


				var atributoVal				= document.getElementById('atributo').value;
				var productX 		= $("#productImageWrapID_" + productIDVal).offset().left;
				var productY 		= $("#productImageWrapID_" + productIDVal).offset().top;

				if( $("#productID_" + productIDVal).length > 0){
					var basketX 		= $("#productID_" + productIDVal).offset().left;
					var basketY 		= $("#productID_" + productIDVal).offset().top;
				} else {
					var basketX 		= $("#basketTitleWrap").offset().left;
					var basketY 		= $("#basketTitleWrap").offset().top;
				}

				var gotoX 			= basketX - productX;
				var gotoY 			= basketY - productY;

				var newImageWidth 	= $("#productImageWrapID_" + productIDVal).width() / 4;
				var newImageHeight	= $("#productImageWrapID_" + productIDVal).height() / 4;


				$("#productImageWrapID_" + productIDVal + " img")
				.clone()
				.prependTo("#productImageWrapID_" + productIDVal)
				.css({'position' : 'absolute'})
				.attr('id','productImageWrapIDCopy_'+ productIDVal)
				.animate({opacity: 0.4}, 100 )
				.animate({opacity: 0.1, marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1200, function() {

					$("#notificationsLoader").html('<img src="frontoffice/imgs/loader.gif">');

					$.ajax({
						type: "POST",
						url: "frontoffice/secciones/shop/basket.php?origen=ajax",
						data: { productID: productIDVal,cantidad: cantidadVal,atributo: atributoVal, action: "addToBasket"},
						success: function(theResponse) {

							splitter = theResponse.split("___");

							n_items = splitter[0];
							total_ventas = splitter[1];
							total_ventas = splitter[1];
							varhtml = splitter[2];


							document.getElementById('unidades_producto').innerHTML = unidades_antes - cantidadVal;
							document.getElementById('precio_total').innerHTML = total_ventas;
							document.getElementById('cesta_header').innerHTML =n_items +" items / "+total_ventas +moneda;

							if(parseFloat(total_ventas)>0){
								$("#checkout_button").show();
							}else{
								$("#checkout_button").hide();
							}
							$("#basketItemsWrap").hide();
							$("#productImageWrapIDCopy_"+productIDVal).remove();
							document.getElementById('basketItemsWrap').innerHTML = varhtml;

							$("#basketItemsWrap").show();
							$("#notificationsLoader").empty();

						}

					});



				});

			}
		});
	}

	$(".share .send").click(function () {
		objeto = this;
		id = this.id.replace("id_","");
		$('#message_enviar_'+id).hide();
		su_nombre = document.getElementById('user1_'+id).value;
		su_mail = document.getElementById('mail1_'+id).value;
		tu_nombre = document.getElementById('user2_'+id).value;
		tu_mail = document.getElementById('mail2_'+id).value;
		url = document.getElementById('url_post_'+id).value;
		title = document.getElementById('title_post_'+id).value;
		mensaje = document.getElementById('message1_'+id).value;
		su_nombre		=		su_nombre.htmlEntities();
		su_mail			=		su_mail.htmlEntities();
		tu_nombre		=		tu_nombre.htmlEntities();
		tu_mail			=		tu_mail.htmlEntities();
		title			=		title.htmlEntities();
		mensaje			=		mensaje.htmlEntities();
		if((su_nombre!="")&&(su_nombre!=su_nombre_texto)&&(su_mail!="")&&(su_mail!=su_nombre_mail)&&(tu_nombre!="")&&(tu_nombre!=tu_nombre_texto)&&(tu_mail!="")&&(tu_mail!=tu_nombre_mail)&&(mensaje!="")){
			$.ajax({
				type: "POST",
				url: "frontoffice/secciones/blog/envia_amigo.php",
				data: "ajax=1&OP_1=submit"+
				"&su_nombre="+su_nombre+
				"&su_mail="+su_mail+
				"&tu_nombre="+tu_nombre+
				"&tu_mail="+tu_mail+
				"&mensaje="+mensaje+
				"&url="+url+
				"&title="+title,


				success: function(msg){

					switch(msg){
						default:
						document.getElementById("message_enviar_"+id).innerHTML = msg;
						$('#message_enviar_'+id).fadeIn("slow");
						break;
						case "ok":
						resetFormEnvia(id);
						$(objeto).parents(".share").slideToggle("slow");
						break;
					}
				}
			});
		}else{
			document.getElementById("message_enviar_"+id).innerHTML = campos_obligatorios;
			$('#message_enviar_'+id).fadeIn("slow");
		}


	});

	/* Añadir eventos en la lista de artículos para internet explorer */
	jQuery.each(jQuery.browser, function(i) {
		if($.browser.msie){
			var versionParts = jQuery.browser.version.split('.');
			if( parseInt(versionParts[0])>=6 ) shopEvents();
		}
	});




});


//	prototipo htmlentity en javascript
String.prototype.htmlEntities = function (){
	return this.replace(/&/g,'_AMP_').replace('>','_GRAN_').replace('<','_PETIT_').replace(/[+]/g,'_PLUS_').replace(/#/g,'_ALMO_');
};