Cufon.replace('#main-menu li a', {hover: true});

$(document).ready(function()  {

	$(".external").attr("target","_blank");

	var h = window.location.host.toLowerCase();
	$("a[href^='http']:not([href^='http://" + h + "']):not([href^='http://www." + h + "'])").attr("target", "_blank");

	
	$("a").focus(function() {
		$(this).blur();
	});

	var active = $("body").attr("class");
	$("#main-menu a." + active).addClass("active");


	/*Queness.com Modal jquery window*/
	
	//select all the a tag with name equal to modal
	$('a[rel=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(750);	
		$('#mask').fadeTo(500, 0.30);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(1250); 
		
		//return false;
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});
	
	//end modal

	/*smooth scroll*/
	$('a[href*=#]').click(function() { //:not(attr("rel","modal"))'
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 750);
				return false;
			}
		}
	});
	
	//tienda 
	$('#cart').hide();
	
	$(".add-list").click(function() {
		$('#instructions').hide();	
		$('#cart').show();
		
		var source = $(this).parent('form').attr("id")
		var id = $('#'+source + ' select').attr('id');
		var text = $('#'+source + ' select').val();
		$("#cart-list").append('<li class="'+id+'"><a href="#delete" title="eliminar" class="cart-remove"></a> '+ text +'</li>');
		$('#'+source + ' input').attr('disabled', true);
		
		var qty = text.substring(0,1);
		var total = $('#'+source + ' input:hidden[name=price]').val();
		total = parseInt(total) * parseInt(qty)
		if ($('#cart .total').text()!=''){ total = parseInt(total) + parseInt($('#cart .total').text()); }
		$('.total').empty();
		$('.total').append(total);	
		
		$('#frmPedido').append('<input type="hidden" value="'+ qty +'" name="'+ id +'" />')	
	});
	
	$('#custom-mark').click(function() {
		var total = $('#cart .total').text();
		if ($(this).is(':checked')) {
			$('#frmPedido input:hidden[name=marca]').attr('value', 'Con');
			total = parseInt(total) + 100
			$('.total').empty();
			$('.total').append(total);		
		} else { 
			$('#frmPedido input:hidden[name=marca]').attr('value', 'Sin');
			total = parseInt(total) - 100
			$('.total').empty();
			$('.total').append(total);		
		}
		if (total==0){
			$('#cart').hide();	
			$('#instructions').show();
		}
	});
	
	$(".cart-remove").live('click', function(){	
		var source = $(this).parent('li').attr('class');
		$('li.'+source).remove();
		$('#frm'+source + ' input').removeAttr('disabled');	
		
		var qty = $('#frmPedido input:hidden[name='+ source +']').val();
		var price = $('#frm'+source+' input:hidden[name=price]').val();
		var total = $('#cart .total').text();
		total = parseInt(total) - parseInt(qty) * parseInt(price);
		$('.total').empty();
		$('.total').append(total);	
	
		if (total==0){
			$('#cart').hide();	
			$('#instructions').show();
		}
	
		$('#frmPedido input:hidden[name='+ source +']').remove();
	
		return false;
	});

}); 


