/*
	javascript for home page.

	store.js v1.0
	create on 2010-02-10 by Oscar Woo

*/


$(document).ready(function() {


	var url = window.location.href;
	switch(url.substring(url.indexOf("#"))){
			case "#idocument":{
				$("#selected_arrow").animate({ left: '238px' }, 300);
				$(".carousel .items").animate({ left: '0px' }, 300);
				$(".carousel").animate({height: '860px'},300);
				break;
			}
			case "#sparkbox":{
				$("#selected_arrow").animate( { left: '465px' }, 300);
				$(".carousel .items").animate({ left: '-960px' }, 300);
				$(".carousel").animate({height: '620px'},300);
				break;
			}
			case "#package":{
				$("#selected_arrow").animate( { left: '688px' }, 300);
				$(".carousel .items").animate({ left: '-1920px' }, 300);
				$(".carousel").animate({height: '260px'},300);
				break;
			}
	}
	

	$('#buy_adademic_license').click(function(){	

		$('.academic_desc .note').show();
		return false;

	});
	
	$('.product').click(function(){
		switch($(this).attr("href")){
			case "#idocument":{
				$("#selected_arrow").animate({ left: '238px' }, 300);
				$(".carousel .items").animate({ left: '0px' }, 300);
				$(".carousel").animate({height: '860px'},300);
				break;
			}
			case "#sparkbox":{
				$("#selected_arrow").animate( { left: '465px' }, 300);
				$(".carousel .items").animate({ left: '-960px' }, 300);
				$(".carousel").animate({height: '620px'},300);
				break;
			}
			case "#package":{
				$("#selected_arrow").animate( { left: '688px' }, 300);
				$(".carousel .items").animate({ left: '-1920px' }, 300);
				$(".carousel").animate({height: '260px'},300);
				break;
			}
		}
	})
	

$(".order_optional form").live("submit", function(){ 
	
//	alert($(this).parent().attr("id"));
	
	$(this).ajaxSubmit({beforeSubmit: presubmit});
	
	return false;
});

// Prepear to submit
function presubmit(formData, jqForm, options) { 
	$('.sending').show();
	
	//post data to server by json
	$.getJSON(options.url,formData,submitResponse);
	
	//stop jquery form submit.
  return false; 
}


//json callback
function submitResponse(data){
	$('.sending').hide();
	$('.btn_submit').attr("disabled",false);
	
	var prefix = ""
	switch(data.p){
		case '1':
			prefix = "#p1 "
			break;
		case '4':
			prefix = "#p4 "		
			break;
	}
	


	switch(data.status)
	{
		case 0:
			msg = "<span style=\"color: #ff6f70\">Coupon code is invalid.</span>";
			$(prefix+'.msg_box').html(msg);	
			$(prefix+'.msg_box').show();
			break;
		case 1:
			msg = "";
			$(prefix+'.msg_box').html(msg);	
			$(prefix+'.msg_box').show();
			changeprice(data.url,data.price,prefix);
	  		break;
		case 2:
			msg = "<span style=\"color: #ff6f70\">Coupon code is invalid.</span>";
			$(prefix+'.msg_box').html(msg);	
			$(prefix+'.msg_box').show();
	  		break;
		case 3:
			msg = "<span style=\"color: #ff6f70\">Coupon code is invalid.</span>";
			$(prefix+'.msg_box').html(msg);	
			$(prefix+'.msg_box').show();
	  		break;
	}

/*
			0 = can not empty
    		1 = Successful	
    		2 = is not exist
    		3 = code is invalid
*/
}


function changeprice(url,price,prefix){
	$(prefix+'.coupon .price span').html('$'+price);
	$(prefix+'.coupon .price span').css('background','gold');
	$(prefix+'.coupon .price span').pulse({ opacity: [0,1]}, {times: 3, complete: function(){
		$(prefix+'.coupon .price span').css('background','#fff');
	}});

	$(prefix+'.coupon .buy_btn').attr("href",url);
}

});


