$(document).ready(function()
{
	if (screen.width<=1440) {
		$('#pestana').animate({width: 'toggle'},"slow").delay(1300).animate({width: '15px'},"slow");
		$("div#pestana").mouseenter( function(){$('#pestana').animate({width: '124px'},"slow");});
		$("div#contenido").mouseenter(	function(){$('#pestana').animate({width: '15px'},"slow");});
		}
		else
			{$('#pestana').animate({width: 'toggle'},"slow");}
	
	$("a#tab").click(function(){
							 if($(this).is(".off")){
										$(this).toggleClass("off").children("img").attr("src", "imagenes/up.png");
								 		$("#panel").animate({top: '-3px'}).animate({top: '-10px'});
								 }
								 else{
										$(this).toggleClass("off").children("img").attr("src", "imagenes/down.png");
								 		$("#panel").animate({top: '-300px'}).animate({top: '-280px'});
									 }
	});

	
	$("span#avisoh").mouseenter(function(){
		if ( $("div#shoppingtime").text() == ""){
			$("div#shoppingtime").text("cargando..").fadeIn("slow");
			$.ajaxSetup({ 'beforeSend' : function(xhr) { xhr.overrideMimeType('text/html; charset=ISO-8859-1');	},});
			$.get("shopping.php", {}, function(results){
				$("div#shoppingtime").html(results);
			});
		}
		$("div#shoppingtime").fadeIn();
	});

	$("div#dmenu").mouseenter(function(){ $("div#shoppingtime").fadeOut();} );

	$("div#contenido").mouseenter(function(){ $("div#shoppingtime").fadeOut();} );

	$("div#loginform").mouseleave(function(){ control=0; }).mouseenter(function(){control=1;});
	
	$("div#login").click(function(){if(control ==0) $("div#login").fadeOut(); });
			
});

function getintouch(){
	var nombre=document.forms["contacto"]["nombre"].value;
	var email=document.forms["contacto"]["email"].value;
	var telefono=document.forms["contacto"]["telefono"].value;
	if (nombre==null || nombre=="")
		{ $("span#nombreerror").fadeIn("slow");  return false;  }   
	else
		{
			$("span#nombreerror").fadeOut("slow");
			$.get("SendContact.php",{"nombre" : nombre, "email" : email, "telefono" : telefono}, function() { 
				$("#contacto").fadeOut();
				$(".contbut").fadeOut();
				$('#graciascont').html("<h2>Gracias por ponerse en contacto</h2>");
				});
			return false; 
			}	
	}


function remove(element){
	var sku=$(element).attr("title");
	$.ajaxSetup({ 'beforeSend' : function(xhr) {	xhr.overrideMimeType('text/html; charset=ISO-8859-1');	},});
	$.ajax({
	   type: "GET",
	   url: "cajera.php",
	   data: "action=remove&sku="+sku,
	   success: function(results) {				  
			$.get("shopping.php", {}, function(results2){
				$("div#shoppingtime").html(results2);
			});
		   },
		   async: false
			});
    }

function reduce(element){
	var sku=$(element).attr("title");
	$.ajaxSetup({ 'beforeSend' : function(xhr) {	xhr.overrideMimeType('text/html; charset=ISO-8859-1');	},});
	$.ajax({
	   type: "GET",
	   url: "cajera.php",
	   data: "action=reduce&sku="+sku,
	   success: function(results) {				  
			$.get("shopping.php", {}, function(results2){
				$("div#shoppingtime").html(results2);
			});
		   },
		   async: false
			});
    }
function qty(element){
	var sku=$(element).attr("title");
	var qty=$(element).val();
	$.ajaxSetup({ 'beforeSend' : function(xhr) {	xhr.overrideMimeType('text/html; charset=ISO-8859-1');	},});
	$.ajax({
	   type: "GET",
	   url: "cajera.php",
	   data: "action=qty&sku="+sku+"&qty="+qty,
	   success: function(results) {				  
			$.get("shopping.php", {}, function(results2){
				$("div#shoppingtime").html(results2);
			});
		   },
		   async: false
			});
    }

function increment(element){
	var sku=$(element).attr("title");
	$.ajaxSetup({ 'beforeSend' : function(xhr) {	xhr.overrideMimeType('text/html; charset=ISO-8859-1');	},});
	$.ajax({
	   type: "GET",
	   url: "cajera.php",
	   data: "action=increment&sku="+sku,
	   success: function(results) {				  
			$.get("shopping.php", {}, function(results2){
				$("div#shoppingtime").html(results2);
			});
		   },
		   async: false
			});
    }
	
function registrar(){
    $(".popit").fadeOut(); 	
	$("div#login").fadeIn("slow");
	$('#loginform').load('login.html', function(){
												control =0;
												$("a.depop").mouseenter(function(){$(this).html('Cerrar <img src="imagenes/x.png" alt="X" align="absmiddle">');});
												$("a.depop").mouseleave(function(){$(this).html('<img src="imagenes/x.png" alt="X" align="absmiddle">');});
												});
    }
	
function ship(){
	var nombre=document.forms["pedido"]["nombre"].value;
	var email=document.forms["pedido"]["email"].value;
	var telefono=document.forms["pedido"]["telefono"].value;
	if (nombre==null || nombre=="")
		{ $("span#nombreerror").fadeIn("slow");  return false;  }   
	else
		{
			$("span#nombreerror").fadeOut("slow");
			$.get("SendMail.php",{"nombre" : nombre, "email" : email, "telefono" : telefono}, function() { $('#loginform').load('gracias.html'); } );
			return false; 
			}	
	}
	
	
function cierralogin(){
    $("div#login").fadeOut();
	location.reload();
    }
