if ( $.cookie("candycanes") == "" ) { $.cookie("candycanes", 0); } 
candycanes = 0;

function showHide() {
	
	$('.hide').css('display', 'block');
	$('.tool').css('display','inline');
	
	if ( $('#qty').val() == 10 ) $('#choose-table').css('display','block').attr('class', 'required');
	else $('#choose-table').css('display', 'none').attr('class','');
	
	if ( $('#quantitycc-0').val() != 0 ) { 
		$('.show').css('display', 'block'); 
		$('#add-candycane').css('display', 'none'); 
		
	} else {
		$('.show').css('display', 'none');
	}
	
	
	$('#total').css('display', 'block');

}

function displayTotal() {
	
	// preview party tickets
	var quantity = $('#qty').val(); 
	var price = 0;
	
	if ( discount != 1 ) {
		if ( quantity < 10 ) { price = quantity * 50; $('#choose-table').css('display', 'none').attr('class', ''); } 
		else if ( quantity == 10 ) { price = 400; $('#choose-table').css('display', 'block').attr('class', 'required'); }
	} else {

		if ( quantity < 10 ) { price = quantity * 40; $('#choose-table').css('display', 'none').attr('class', ''); } 
		else if ( quantity == 10 ) { price = 400; $('#choose-table').css('display', 'block').attr('class', 'required'); }			
	}
	
	// candy canes
	if ( candycanes >= 0 ){
		var candycanetotal = 0;
	
		for ( m = 0; m <= candycanes; m++ ) {
			tempqty = $('#quantitycc-'+m).val();
			color = $('#amount-'+m).val();
			
			switch ( color ) {
				case "blue":
					tempprice = 5;
					break;
				case "green":
					tempprice = 10;
					break;
				case "red":
					tempprice = 25;
					break;
				case "gold":
					tempprice = 100;
					break;
			}
			
			temptotal = tempprice * tempqty;
			
			candycanetotal += temptotal;
		}
	
		price += candycanetotal;
	}
	
	$('.price').text("$"+price+".00");
}

function addrow(check) {
	var style;
	
	candycanes++;
	
	if ( candycanes % 2 != 0 ) style = "rowone";
	else style = "rowtwo"; 
	
	if ( candycanes >= 1 ) {
	
		var $lastgrouping = $("#purchase").find("tbody").find("tr:last-child");
		var $newgrouping = $lastgrouping.clone();
		$newgrouping.find("input").val("");
		$("#purchase").find("tbody").append($newgrouping);
	
	}
	
	//if ( check != true ) $.cookie("candycanes", candycanes);

}

function removerow() {
		//if ( candycanes < 1 ) {
			
		// KLS
		var rowCount = $("#purchase tbody tr").length;
		if (rowCount == 1) {
			$('#candycaneform').slideUp(500, function() {
				$('#add-candycane').fadeIn(500, function() {
					//$('#purchase-row-'+candycanes).remove();
					//candycanes--;
				});	
	
			});
			
		} else {
			
			// KLS 
			var rowCount = $("#purchase tbody tr").length;
			if (rowCount > 1) {
				var $lastgrouping = $("#purchase").find("tbody").find("tr:last-child");
				$('#purchase-row').remove();
			}
			
			//$('#purchase-row-'+candycanes).remove();
			//candycanes--;
			//$.cookie("candycanes", candycanes);
		
		}
		

}

function showtooltip(id, text, type) {
	if ( type == 1 || type == null ) {
		$('#'+id).qtip({
			  content: text, 
			  style: { border: { width: 1, radius: 5, color: '#499AC8' }, background: '#499AC8', color: 'white', fontSize: '85%', lineHeight: '1.5em',
						letterSpacing: 'normal', width: { max: 350, min: 350 }, name: 'blue' },
			  position: { corner: { target: 'rightMiddle', tooltip: 'bottomLeft' } }
		 });	
	} else if ( type == 2 ) { 
		$('.'+id).qtip({
			  content: text, 
			  style: { border: { width: 1, radius: 5, color: '#499AC8' }, background: '#499AC8', color: 'white', fontSize: '85%', lineHeight: '1.5em',
						letterSpacing: 'normal', width: { max: 350, min: 350 }, name: 'blue' },
			  position: { corner: { target: 'rightMiddle', tooltip: 'bottomLeft' } }
		 });
	}
}
