(function($) {
$(function() {
	
	$('#sideHowToBuy').click(
	
		function () {
		if($('#sideHowToBuyRight').css('display') == 'none') {
			$('#sideTab').css('margin','0 20px 0 0');
			$('#sideShipping').css('display','none');
			$('#sideContacts').css('display','none');
			$('#sideHowToBuyRight').show(1000);		
	 $.get("ajax.text.php", { id : '55' }, function(result){
    $("#zakazik").html(result);
	}); 
			}
		else {	
			$('#sideTab').css('margin','0');
			$('#sideShipping').css('display','block');
			$('#sideContacts').css('display','block');
			$("#sideHowToBuyRight").hide(1000);		}
		}
	);

	$('#sideShipping').click(
		function () {
		if($('#sideShippingRight').css('display') == 'none') {
			$(this).css('top','175px');
			$('#sideTab').css('margin','0 20px 0 0');
			$('#sideHowToBuy').css('display','none');
			$('#sideContacts').css('display','none');
			$('#sideShippingRight').show(1000);		
			$.get("ajax.text.php", { id : '56' }, function(result){
    $("#dostavochka").html(result);
	}); 
			}
		else {
			$(this).css('top','0px');
			$('#sideTab').css('margin','0');
			$('#sideHowToBuy').css('display','block');
			$('#sideContacts').css('display','block');
			$("#sideShippingRight").hide(1000);		}
		}
	);

	$('#sideContacts').click(
		function () {
		if($('#sideContactsRight').css('display') == 'none') {
			$(this).css('top','355px');
			$('#sideTab').css('margin','0 20px 0 0');
			$('#sideShipping').css('display','none');
			$('#sideHowToBuy').css('display','none');
			$('#sideContactsRight').show(1000);		
			$.get("ajax.text.php", { id : '53' }, function(result){
		$("#kontactiki").html(result);
	}); 
			
			}
		else {
			$(this).css('top','0px');
			$('#sideTab').css('margin','0');
			$('#sideShipping').css('display','block');
			$('#sideHowToBuy').css('display','block');
			$("#sideContactsRight").hide(1000);		}
		}
	);
	
	$('#HowToBuyClose').click(
		function () {
			$(this).css('top','0px');
			$('#sideTab').css('margin','0');
			$('#sideShipping').css('display','block');
			$('#sideContacts').css('display','block');
			$("#sideHowToBuyRight").hide(1000);
		}
	);
	
	$('#ShippingClose').click(
		function () {
			$('#sideShipping').css('top','0px');
			$('#sideTab').css('margin','0');
			$('#sideHowToBuy').css('display','block');
			$('#sideContacts').css('display','block');
			$("#sideShippingRight").hide(1000);
		}
	);
	
	$('#ContactsClose').click(
		function () {
			$('#sideContacts').css('top','0px');
			$('#sideTab').css('margin','0');
			$('#sideShipping').css('display','block');
			$('#sideHowToBuy').css('display','block');
			$("#sideContactsRight").hide(1000);
		}
	);

	function mycarousel_initCallback(carousel)
	{
		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	};

	jQuery('#mycarousel').jcarousel({
		auto: 2,
		wrap: 'circular',
		initCallback: mycarousel_initCallback
	});

	$('ul.tabs').delegate('li:not(.current)', 'click', function() {
		$(this).addClass('current').siblings().removeClass('current')
			.parents('div.section').find('div.box').hide().eq($(this).index()).fadeIn(150);
	})

})
})(jQuery)


$(document).ready(function(){ 


	//$("#basketItemsWrap li:first").hide();

	jQuery("#add_carton img").click(function() {
		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];
		
		var productX 		= jQuery("#IDP_" + productIDVal).offset().left;
		var productY 		= jQuery("#IDP_" + productIDVal).offset().top;
		
		// if( $("#productID_" + productIDVal).length > 0){
			// var basketX 		= $("#productID_" + productIDVal).offset().left;
			// var basketY 		= $("#productID_" + productIDVal).offset().top;			
		// } else {
			var basketX 		= jQuery("#basket").offset().left;
			var basketY 		= jQuery("#basket").offset().top;
		//}
		
		var gotoX 			= basketX - productX;
		var gotoY 			= basketY - productY;
		
		var newImageWidth 	= jQuery("#IDP_" + productIDVal).width() / 3;
		var newImageHeight	= jQuery("#IDP_" + productIDVal).height() / 3;
		
		jQuery("#IDP_" + productIDVal + " img")
		.clone()
		.prependTo("#IDP_" + productIDVal)
		.css({'position' : 'absolute','z-index' : '9999'})
		//.animate({opacity: 0.4}, 50 )
		//.animate({opacity: 0.1, marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1200, function() {
		.css({'opacity':0.75})
		.animate({marginLeft: gotoX, marginTop: gotoY, width: '3%'}, 1200, function() {
			jQuery(this).remove();
	
			//$("#notificationsLoader").html('<img src="images/loader.gif">');
		
			jQuery.ajax({  
				type: "GET",  
				url: "/filter/basket-"+productIDVal+'?t='+ (Math.random())*10,  
				//data: { productID: productIDVal, action: "addToBasket"},  
				success: function(theResponse) {
					jQuery("#basket").html(theResponse);
					
				}  
			});  
		
		});
		
	});

});
