/****************************************************** 
	Title:   Midea 
	Author:  Wizzard Bulgaria 
******************************************************/

$(function() 
{
	emptyInput('#headerEmailInput');
	emptyInput('#headerPassInput');
	
	
	 /****************
	 Shopping cart
	 *****************/

	$('a.buy').click(function() {
		
		tmp = (this.id).split('_');
		var productID = tmp[1];
		var price = tmp[2];
		var productX = $("#productimage_" + productID).offset().left;
		
		var productY = $("#productimage_" + productID).offset().top;
		
		var cartX = $("a.cartIcon").offset().left;
		var cartY = $("a.cartIcon").offset().top;
	
		var gotoX = cartX - productX;
		var gotoY = cartY - productY;
	
		var newImageWidth 	= $("#productimage_" + productID).width() / 3;
		var newImageHeight	= $("#productimage_" + productID).height() / 3;
		
		$("#productimage_" + productID)
		.clone().hide()
		.prependTo('#wrapper')
		.css({'position' : 'absolute'})
		.show()
		.css({top: productY, left: productX, zIndex: '1000'})
		.animate({opacity: 0.7}, 100 )
		.animate({opacity: 0.1, marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1200, function() {
				
		$(this).remove();
		
		$.ajax({
				type: "POST",
		        url: controller + 'xml_http_request/?method=add_to_cart',
		        data: 'product=' + productID + '&price=' + price,
		        success: function(data) {
					$("span#cart_quantity").fadeOut('slow', function() {
						$(this).html(data).fadeIn('slow');
					});
				}
			});   
		});
		
		return false;
	});
	
	$('a.change_cart').click(function() {
		
		productID = (this.id).split('_')[1];
	
		quantity = $("#quantity_" + productID).val();
		
		$.ajax({
				type: "POST",
		        url: controller + 'xml_http_request/?method=change_cart',
		        data: 'product=' + productID + '&quantity=' + quantity,
		        dataType: 'json',
		        success: function(data) {						
					$("span#cart_quantity").fadeOut('slow', function() {
						$(this).html(data.cart_quantity).fadeIn('slow');
						$("#product_total_" + productID).text(data.product_total);
						$("#total_cart").text(data.total_price);
					});
				}
			});
		
		return false;
	});
});

function emptyInput(input) 
{
	var inputData = new String($(input).val());
	
	$(input).focus(function() {
		if ($(this).val() == inputData)
			$(this).val('');
	});
	
	$(input).blur(function() {
		if ($(this).val() == '') 
			$(this).val(inputData);
	});
}

function accordion()
{
	$('#accordion').accordion();
}
