function pause(milliseconds) {
	var dt = new Date();
	while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
}

jQuery(function(){
	(function(jQuery){
		jQuery.fn.jcartTooltip=function(o,i){
			o=jQuery.extend({
				content:null,
				follow:true,
				auto:true,
				fadeIn:0,
				fadeOut:0,
				appendTip:document.body,
				offsetY:25,
				offsetX:-10,
				style:{},
				id:'jcart-tooltip'
			},o||{});
			if(!o.style&&typeof o.style!="object"){
				o.style={};
				o.style.zIndex="1000"
			}
			else{
				o.style=jQuery.extend({},o.style||{})
			}
			o.style.display="none";
			o.style.position="absolute";
			var j={};
			var k=false;
			var l=document.createElement('div');
			l.id=o.id;
			
			for(var p in o.style){
				l.style[p]=o.style[p]
			}
			
			function fillTooltip(a){
				if(a){
					jQuery(l).html(o.content)
				}
			}
			
			fillTooltip(o.content&&!o.ajax);
			jQuery(l).appendTo(o.appendTip);
			return this.each(function(){
				this.onclick=function(b){
					function _execute(){
						var a;
						if(o.content){
							a="block"
						}
						else{
							a="none"
						}
						if(a=="block"&&o.fadeIn){
							jQuery(l).fadeIn(o.fadeIn);
							setTimeout(function(){
								jQuery(l).fadeOut(o.fadeOut)
							},1000)
						}
					}
					_execute()
				};
				
				this.onmousemove=function(a){
					var e=(a)?a:window.event;
					j=this;if(o.follow){
						var b=jQuery(window).scrollTop();
						var c=jQuery(window).scrollLeft();
						var d=e.clientY+b+o.offsetY;
						var f=e.clientX+c+o.offsetX;
						var g=jQuery(window).width()+c-jQuery(l).outerWidth();
						var h=jQuery(window).height()+b-jQuery(l).outerHeight();
						k=(d>h||f>g)?true:false;
						if(f-c<=0&&o.offsetX<0){
							f=c
						}
						else if(f>g){
							f=g
						}
						if(d-b<=0&&o.offsetY<0){
							d=b
						}
						else if(d>h){
							d=h
						}
						l.style.top=d+"px";
						l.style.left=f+"px"
					}
				};
				
				this.onmouseout=function(){
					jQuery(l).css('display','none')
				}
			})
		}
	})
	
	(jQuery);
	jQuery('.jcart input[name="my-add-button"]').jcartTooltip({
		content:'Item added!',fadeIn:500,fadeOut:350
	});
	var m=jQuery('td.jcart-item-qty').html();if(m===null){
		jQuery('#jcart-paypal-checkout').attr('disabled','disabled')
	}
	jQuery('.jcart-hide').remove();
	var n=jQuery('#jcart-is-checkout').val();
	if(n!=='true'){
		n='false'
	}
	
	
	jQuery('form.jcart').submit(function(){
	 	var b=jQuery(this).find('input[name=my-item-id]').val();
		var c=jQuery(this).find('input[name=my-item-price]').val();
		var d=jQuery(this).find('input[name=my-item-name]').val();
		var e=jQuery(this).find('input[name=my-item-qty]').val();
		var f=jQuery(this).find('input[name=my-add-button]').val();
		var g=jQuery(this).find('select[name=my-item-size]').val();
		var h=jQuery(this).find('select[name=my-item-color]').val();
		var i=jQuery(this).find('input[name=my-item-warna]').val();
		var j=jQuery(this).find('input[name=my-item-id-head]').val();
		var k=jQuery(this).find('input[name=my-item-price1]').val();
		var l=jQuery(this).find('input[name=my-item-bv]').val();
		var m=jQuery(this).find('input[name=my-item-category]').val();
		
		
		if(h==''){
			alert("Please select color");
		}
		else{
			if(g==''){
				alert("Please select size");
			}
			else{
				if(b==''){
					alert("The product is unavailable/out of stock");
				}
				else{
				
					jQuery.post('scripts/jcart/jcart-relay.php',{
						"my-item-id":b,
						"my-item-price":c,
						"my-item-name":d,
						"my-item-qty":e,
						"my-add-button":f,
						"my-item-size":g,
						"my-item-color":h,
						"my-item-warna":i,
						"my-item-id-head":j,
						"my-item-price1":k,
						"my-item-bv":l,
						"my-item-category":m
						},
						function(a){
							jQuery('#jcart').html(a);
							jQuery('.jcart-hide').remove()
						}
					);
					ajax_cart();
				}	
			}
		}
		return false
	});
		
	jQuery('#jcart').keydown(function(e){
		if(e.which==13){
			return false
		}
	});
	jQuery('#jcart a').live('click',function(){
		var b=jQuery(this).attr('href');
		b=b.split('=');
		var c=b[1];jQuery.get('scripts/jcart/jcart-relay.php',{
			"jcart_remove":c,"jcart_is_checkout":n
			},
			function(a){
				jQuery('#jcart').html(a);
				jQuery('.jcart-hide').remove()
				
			}
		);
		setTimeout("ajax_cart()",1000);
		return false
	});
		
	jQuery('#jcart input[type="text"]:not(#cash_amount,#commission_amount)').live('keyup',function(){
		var b=jQuery(this).attr('id');
		b=b.split('-');
		b=b[3];
		var c=jQuery(this).val();
		if(c!==''){
			var d=setTimeout(function(){
				jQuery.post('scripts/jcart/jcart-relay.php',{
					"item_id":b,
					"item_qty":c,
					"jcart_update_item":'update',
					"jcart_is_checkout":n
					},
					function(a){
						jQuery('#jcart').html(a);
						jQuery('.jcart-hide').remove()
					}
				)
			},1000)
			setTimeout("ajax_cart()",1500);
		}
		jQuery(this).keydown(function(){
			window.clearTimeout(d)
		})
		
	})
	
});	

