/*******************************************************************************
 * Basket
 ******************************************************************************/
iBsk = function() {
}

iBsk.init = function(args) {
	this.uname = args.uname || $('#sysAccount').val();
}

iBsk.doLock = function() {
	var $text = $('#progress').val() || "In processing, please wait...";
	$('#BskCtrFull').block( {
		message :$text,
		css : {
			'padding' :'3px',
			'border' :'1px solid #FFFFE1',
			'color' :'#FFF',
			'background' :'#600'
		}
	});
}

iBsk.unLock = function() {
	$('#BskCtrFull').unblock();
}



/*******************************************************************************
 * Listing
 ******************************************************************************/
iBsk.listing = function() {
	loadUrl = USERS_URI_SERVER_APP + 'uname/'+this.uname+'/shopping?action=bsk&rnd='+getStringRandom();
	$.get(loadUrl, function(data) {
		$('#bskList').empty().html(data);
		iBsk.totalUpdate();
		bskItemColorCycle();
		bskItemPreview();
	});
	this.unLock();
}

iBsk.ListRefresh = function() {
	this.doLock();
	this.listing();
}

/*******************************************************************************
 * Add to Basket
 ******************************************************************************/
iBsk.into = function(id, img, name)
{
	if(1 != isUser)
	{
		//return sDialog.pds('error', "Member function, Please login first!");
		return top.location=USERS_URI_SERVER_APP + 'uname/'+this.uname+'/shopping?&action=basket&rnd='+getStringRandom();
	}

	if ($.cookie('BskCtrSetMenu') == "light" || $.cookie('BskCtrSetMenu') == "close")
	{
		$("#BskCtrMenu .BskCtr2").click();
	}

	this.doLock();

	/*
	$("#ProductImage_" + id).effect("transfer", {
		to :"#BskCtrMenu"
	}, 800);
	*/
	$("#ProductImage_" + id)
	.fadeTo("fast", 0.6)
	.animate({queue:true, duration:5000})
	.animate({borderTopColor:"green"}, 80)
	.animate({borderRightColor:"blue"}, 70)
	.animate({borderBottomColor:"red"}, 60)
	.animate({borderLeftColor:"black"}, 50)

	.animate({borderTopColor:"aqua"}, 50)
	.animate({borderRightColor:"azure"}, 60)
	.animate({borderBottomColor:"gold"}, 70)
	.animate({borderLeftColor:"indigo"}, 80)

	.animate({borderTopColor:"green"}, 70)
	.animate({borderRightColor:"blue"}, 60)
	.animate({borderBottomColor:"red"}, 50)
	.animate({borderLeftColor:"black"}, 40)

	.animate({borderTopColor:"lightgrey"}, 60)
	.animate({borderRightColor:"lightgrey"}, 60)
	.animate({borderBottomColor:"lightgrey"}, 60)
	.animate({borderLeftColor:"lightgrey"}, 60)
	.fadeTo("slow", 1);

	loadUrl = USERS_URI_SERVER_APP + 'uname/'+this.uname+'/shopping?action=bsk&do=new&rnd='+getStringRandom();

	$('#bskList>li').each( function() {
		if ("bskListRecord_" + id == $(this).attr('id')) {
			loadParam = 'do=more&p_id=' + id + '&rnd=' + getStringRandom();
		}
	});

	$.post(loadUrl, {
		'uniqid' :$("#uniqid_" + id).val()
	}, function(data) {
		iBsk.listing();
		//$("#bskListRecord_" + id).animate({backgroundColor:"green"}, 80);
	});


}

/*******************************************************************************
 * Remove from basket
 ******************************************************************************/
iBsk.itemRemove = function(id) {
	this.doLock();
	loadUrl = USERS_URI_SERVER_APP + 'uname/' + this.uname
			+ '/shopping?action=bsk&do=remove&p_id=' + id + '&rnd='
			+ getStringRandom();

	$.get(loadUrl, function(data) {
		iBsk.listing();
	});
}

/*******************************************************************************
 * Update Basket Total
 ******************************************************************************/
iBsk.totalUpdate = function() {
	loadUrl = USERS_URI_SERVER_APP + 'uname/' + this.uname + '/shopping?action=bsk&';
	loadParam = 'do=total&rnd=' + getStringRandom();

	$.getJSON(loadUrl + loadParam, function(json) {
		$('#bskTotalQty').text(json.Q);
		$('#bskTotalMoeny').text(json.M);
	});
}

/*******************************************************************************
 * MoreLess
 ******************************************************************************/
iBsk.moreless = function(id, act) {
	this.doLock();
	loadUrl = USERS_URI_SERVER_APP + 'uname/' + this.uname + '/shopping?action=bsk&';
	loadParam = 'do=' + act + '&p_id=' + id + '&rnd=' + getStringRandom();

	$.get(loadUrl + loadParam, function(data) {
		iBsk.listing();
		//$("#bskListRecord_" + id).effect("pulsate", {}, 100);
	});
}

/*******************************************************************************
 * View detail
 ******************************************************************************/
iBsk.viewDetail = function(id) {
	$url = USERS_URI_SERVER_APP + 'uname/' + this.uname + '/pdetail_' + id + '.html';
	window.open($url,"bskItemPreviewWindow","height="+
		$(window).height()+",width="+$(window).width()+
		",top=0,left=0,toolbar=1,menubar=1,scrollbars=1,resizable=1,location=1,status=1");
}

