var miniloader = '<img src="./imgs/minloader.gif" />';
var loader = '<p>&nbsp</p><center><embed src="./imgs/ls.swf" quality="best" wmode="transparent" bgcolor="#ffffff" width="78" height="78" name="ls" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></center>';

var Cart = {
	request : function(a,b,c){
		new Ajax.Request('cart-ajax.php', {
			method :  'post',
			parameters : a,
			onSuccess :  function(transport) {
				var r = transport.responseText;
				switch(b){
					case 1 : 
						c.update(r);
						break;
					case 2 : 
						c(r);
						break;
				}
			},
			onFailure :  function() {
				alert('Something went wrong...');
			}
		});
	},
	add : function(a,b){
		$(b).update(miniloader);
		this.request({action:'add',pid:a},1,$(b));
	},
	remove : function(a){
		$('cart-list').update(loader);
		this.request({action:'remove',pid:a},1,$('cart-list'));
	},
	update : function(a){
		this.request($('form-cart').serialize(),1,$('cart-list'));
		$('cart-list').update(loader);
	},
	view : function(){
		$('cart-list').update(loader);
		this.request({action:'checkout'},2,this.viewResponse);
		
	},
	viewResponse : function(r){
		$('checkout').update(r);
		Cart.request({action:'view'},1,$('cart-list'));
	}
	,
	products : function(a,b){
		$('products').update(loader);
		this.request({action:'products',cid:a,start:b},1,$('products'));
	},
	product_view : function(p){
		$('products-img').src = p.img;
		$('products-img').style.width = p.w+'px';
		$('products-img').style.height = p.h+'px';
		$('products-desc').update(p.desc);
		Dialogs.showOverlay();
		Dialogs.showDialog('products-display',p.w,p.h);
	},
	product_close : function(){
		Dialogs.closeDialog('products-display');
		$('products-img').src = 'http://www.divadudz.com/imgs/trans.png';
		$('products-desc').update();
	}
}
