$(document).ready(function(){
   $('input:radio').click(function(e){
		var tt = $(this).attr('tt');
		var id = $(this).attr('idt');
		getSum();
    });

	$('input[tn="hosting"]').click(function(e){
		if ($(this).attr('checked')){
			var itdval = $(this).attr("itd");
			$('input[tn="hosting"][itd="'+itdval+'"]').each(function(e){
				$(this).attr('checked', false);
			})
			$(this).attr('checked', true);
		}
		getSum();
	});
	$("input.opt").click(function(e){
		getSum();
	});
	$("input.input1").blur(function(e){
		//sum calc
	});
	$('#continue_shopping').click(function(e){
		$('#shcart_act').attr('value', 'continue_shopping');
	});
	$('#apply_but').click(function(e){
		$('#shcart_act').attr('value', 'apply_coupon');
	});
	$('#checkout').click(function(e){
		$('#shcart_act').attr('value', 'checkout');
	});
	/* price type popup */
	$('.price_desc').hover(function(e){
		var t = $(this).attr('type');
		switch (t){
			case 'm':
				data = '<b>Multiple commercial license</b><br />\
				allows to use the template for commercial websites or other multimedia projects. By purchasing this license you are entitled to install the template on up to 5 domain names.';
				break;
			case 'u':
				return false;
				data = 'un';
				break;
			case 'v':
				return false;
				data = 'vp';
				break;
			case 'r':
			default:
				data = '<b>Single commercial license</b><br />\
				allows to use the template for personal non-commercial website or other multimedia project. By purchasing this license you are entitled to install the template on 1 domain only.';
				break;
		}
		var pop = $('<div id="pdpop">' +data+ '</div>').css({
			"position": "absolute",
			"left": (e.pageX + 5)+"px",
			"top": (e.pageY + 5)+"px" 
		});
		$('body').append(pop);
	}, function(e){
		$('#pdpop').remove();
	});
});

function getSum() {
	var opt_sum = 0;
	var sum = 0;
	var sum2 = 0;
	var sum3 = 0;
	$('.opt').each(function(e){
		if ($(this).attr('checked')){
			opt_sum += new Number($(this).val());
		}
	});
	$('input[tn="hosting"]').each(function(e){
		if ($(this).attr('checked')){
			opt_sum += new Number($(this).val());
		}
	});
	$('input[tn="price"]').each(function(e){
		if ($(this).attr('checked')){
			if ($(this).attr('tt') == 'vip'){
				s1 = new Number($(this).val());
				sum3 += s1;
			} else {
				var idt = $(this).attr('idt');
				s1 = (new Number($(this).val()))*$('#qty'+idt).val();
				sum2 += s1;
			}
			sum += s1;
			$('#totalsum').text('$'+(sum+opt_sum).toFixed(2));
			if ($('#disc').val() > 0)
			{
				var sum1 = sum2 * (1-new Number($('#disc').val())/100)+sum3+opt_sum;
				$('#totalsum').text('$'+sum1.toFixed(2));
				$('#old_price').text('$'+(sum+opt_sum).toFixed(2));
				//$('#totalsum_wdisc').text((sum+opt_sum).toFixed(2));

			}
		}
	});
	
}