var cartItems="";
$(document).ready(function(){
	var actionToDo="check-cart";
	var totalItems=0;
	$.post('check_canasta.php', {action: ""+actionToDo+""}, function(dataResult){
		if(dataResult!=""){
			if(dataResult==0){
				var shoppingCartHTML =
					'<div style="background-color:#0d2447; float:right; width:100px; height:29px;" class="cart_itmes">'
					+'<div style="float: left; width: 100px; text-align: center;">&nbsp;<a href="e_cotizar.php" class="enlaceCotizador"  title="Solicitar Cotizaci&oacute;n" ><span style="color:#f9b907;font-family:arial;font-size:12px;height:26px;line-height:26px;">COTIZAR</span></a></div>'
					+'</div>'
					+'<div style="background-color:#233147; float:right; width:150px; height:29px;" class="cart_itmes">'
					+'<div style="float:left;height:29px;">&nbsp;<a href="#" class="" ><img src="images/cart_empty.gif" border="0" width="26" height="26" class="pb_thumb" /></a></div>'
					+'<div style="float:left;height:29px;"><span style="color:#FFFFFF;display:block;font-family:arial;font-size:12px;height:26px;line-height:26px;">&nbsp;&nbsp;'+dataResult+' Productos</span></div>'
					+'<br style="clear:both" />';
			}else{
				$("a.viewCart").colorbox({iframe:true, innerWidth:960, innerHeight:600});
				var terminacion="";
				if(dataResult==1){
					terminacion="Producto";
				}else{
					terminacion="Productos";
				}
				totalItems=dataResult;
				if(isNaN(totalItems)==false && totalItems>=1){
					$.post('canasta_items.php', {action: ""+actionToDo+""}, function(cartContent){
						if(cartContent!=""){
							$(cartContent).appendTo("#cartResume");
						}
					});
				}
				
				var shoppingCartHTML =
					'<div style="background-color:#0d2447; float:right; width:100px; height:29px;" class="cart_itmes">'
					+'<div style="float: left; width: 100px; text-align: center;">&nbsp;<a href="e_cotizar.php" class="enlaceCotizador"  title="Solicitar Cotizaci&oacute;n" ><span style="color:#f9b907;font-family:arial;font-size:12px;height:26px;line-height:26px;">COTIZAR</span></a></div>'
					+'</div>'
					+'<div style="background-color:#233147; float:right;width:150px;" height:29px;" class="cart_itmes" id="minicart_reference">'
					+'<div style="float:left;height:29px;">&nbsp;<a class="enlaceFullCart" title="Ver Canasta de Cotizaci&oacute;n Completa" onmouseout="hideMiniCart();" onmouseover="showMiniCart();" onclick="openCart();" class="viewCart" ><img src="images/cart_items.gif" border="0" width="26" height="26" class="pb_thumb" /></a></div>'
					+'<div style="float:left;height:29px;"><a id="showCart" class="enlaceMiniCart"  onmouseout="hideMiniCart();" onclick="openCart();" onmouseover="showMiniCart();"><span style="color:#FFFFFF;display:block;font-family:arial;font-size:12px;height:26px;line-height:26px;">&nbsp;&nbsp;'+dataResult+' '+terminacion+'</span></a></div>'
					+'<br style="clear:both" />'
					+'</div>'
					+'<br style="clear:both" />';
			}
			$(shoppingCartHTML).appendTo("#cartMini");
			/* Posicionar el Elemento */
			


		}
	});
	
	
	
});

function openCart(){
	$.colorbox({href:'e_canasta_2.php', iframe:true, innerWidth:960, innerHeight:600, overlayClose:false});
}
function closeFullCart(){
	$.colorbox.close();
}

function showMiniCart(){
	var p = $("#minicart_reference");
	var offset = p.offset();
	
	$("#cartResume").css({"left":offset.left+"px"});
	
	$("#cartResume").toggle();
	$("#showCart").toggleClass("active");
	return false;
}

function hideMiniCart(){
	$("#cartResume").toggle();
}

function getCartItems(){
	var actionToDo="check-cart";
	$.post('canasta_items.php', {action: ""+actionToDo+""}, function(dataResult){
		alert(dataResult);
		if(dataResult!=""){
			window.cartItems=dataResult;
			return true;
		}
	});
}

function updateCartContent(){
	//alert('Entro');
	var actionToDo="check-cart";
	var totalItems=0;
	$("#cartResume").empty();
	$("#cartMini").empty();
	$.post('check_canasta.php', {action: ""+actionToDo+""}, function(dataResult){
		if(dataResult!=""){
			if(dataResult==0){
				var shoppingCartHTML =
					'<div style="background-color:#0d2447; float:right; width:100px; height:29px;" class="cart_itmes">'
					+'<div style="float: left; width: 100px; text-align: center;">&nbsp;<a href="e_cotizar.php" class="enlaceCotizador"  title="Solicitar Cotizaci&oacute;n" ><span style="color:#f9b907;font-family:arial;font-size:12px;height:26px;line-height:26px;">COTIZAR</span></a></div>'
					+'</div>'
					+'<div style="background-color:#233147; float:right; width:150px; height:29px;" class="cart_itmes">'
					+'<div style="float:left;">&nbsp;<a href="#" class="" ><img src="images/cart_empty.gif" border="0" width="26" height="26" class="pb_thumb" /></a></div>'
					+'<div style="float:left;"><span style="color:#FFFFFF;display:block;font-family:arial;font-size:12px;height:26px;line-height:26px;">&nbsp;&nbsp;'+dataResult+' Productos</span></div>'
					+'<br style="clear:both" />';
			}else{
				$("a.viewCart").colorbox({iframe:true, innerWidth:960, innerHeight:600});
				var terminacion="";
				if(dataResult==1){
					terminacion="Producto";
				}else{
					terminacion="Productos";
				}
				totalItems=dataResult;
				if(isNaN(totalItems)==false && totalItems>=1){
					$.post('canasta_items.php', {action: ""+actionToDo+""}, function(cartContent){
						if(cartContent!=""){
							$(cartContent).appendTo("#cartResume");
						}
					});
				}
				
				var shoppingCartHTML =
					'<div style="background-color:#0d2447; float:right; width:100px; height:29px;" class="cart_itmes">'
					+'<div style="float: left; width: 100px; text-align: center;">&nbsp;<a href="e_cotizar.php" class="enlaceCotizador"  title="Solicitar Cotizaci&oacute;n" ><span style="color:#f9b907;font-family:arial;font-size:12px;height:26px;line-height:26px;">COTIZAR</span></a></div>'
					+'</div>'
					+'<div style="background-color:#233147; float:right;width:150px;" height:29px;" class="cart_itmes" id="minicart_reference">'
					+'<div style="float:left;">&nbsp;<a class="enlaceFullCart" title="Ver Canasta de Cotizaci&oacute;n Completa" onmouseout="hideMiniCart();" onmouseover="showMiniCart();" onclick="openCart();" class="viewCart" ><img src="images/cart_items.gif" border="0" width="26" height="26" class="pb_thumb" /></a></div>'
					+'<div style="float:left;"><a id="showCart" class="enlaceMiniCart"  onmouseout="hideMiniCart();" onclick="openCart();" onmouseover="showMiniCart();"><span style="color:#FFFFFF;display:block;font-family:arial;font-size:12px;height:26px;line-height:26px;">&nbsp;&nbsp;'+dataResult+' '+terminacion+'</span></a></div>'
					+'<br style="clear:both" />'
					+'</div>'
					+'<br style="clear:both" />';
			}
			$(shoppingCartHTML).appendTo("#cartMini");
			/* Posicionar el Elemento */
		}
	});
}

