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 ) {
	
		$('#purchase').append('<tr id="purchase-row-' + candycanes + '"> \n' +
							  '<td> \n' +
							  '<ul> \n' +
							  '<li> \n' +
							  '<input name="wording[]' + candycanes + '" type="radio" id="wording-' + candycanes + '" value="honor" checked="checked" /> \n' +
							  '<label for="wording-' + candycanes + '" class="inline">In honor of:</label> \n' +
							  '</li> \n' + 
							  '<li> \n' +
							  '<input type="radio" name="wording[]' + candycanes + '" id="memory-' + candycanes + '" value="memory" /> \n' + 
							  '<label for="memory-' + candycanes + '" class="inline">In memory of:</label> \n' +  
							  '</li> \n' + 
							  '<li>&nbsp;</li> \n' + 
							  '<li> \n' + 
							  '<input type="radio" name="wording[]' + candycanes + '" id="heartspring-' + candycanes + '" value="heartspring" /> \n' + 
							  '<label for="heartspring-' + candycanes + '" class="inline">To help Heartspring</label> \n' + 
							  '</li> \n' + 
							  '</ul> \n' + 
							  '<ul> \n' + 
							  '<li> \n' + 
							  '<label for="ccname_rec-' + candycanes + '">Name: </label> \n' + 
							  '<input name="ccname_rec[]" type="text" id="ccname_rec-' + candycanes + '" size="15" value=" " /> \n' + 
							  '</li>  \n' +
							  '<li>  \n' +
							  '<label for="ccemail_rec-' + candycanes + '">Email: </label>  \n' + 
							  '<input name="ccemail_rec[]" type="text" id="ccemail_rec-' + candycanes + '" size="15" value=" " />  \n' +  
							  '<img src="images/help.png" id="recipient-email-' + candycanes + '" class="recipient-email" height="16" width="16" alt="More Info" style="vertical-align: middle;" /> \n' +   
							  '</li> \n' + 
							  '</ul> \n' + 
							  '</td>  \n' + 
							  '<td>  \n' +
							  '<ul>  \n' +
							  '<li>  \n' +
							  '<input name="ccanon[]' + candycanes + '" type="radio" id="anon-n-' + candycanes + '" value="n" checked="checked" />  \n' +
							  '<input name="ccname[]" type="text" id="ccname-' + candycanes + '" size="15" value=" " />  \n' +
							  '<img src="images/help.png" id="from-name" class="from-name" height="16" width="16" alt="More Info" style="vertical-align: middle;" /> \n' +
							  '</li> \n' + 
							  '<li>  \n' +
							  '<input name="ccanon[]' + candycanes + '" type="radio" id="ccanon-y-' + candycanes + '" value="y" />  \n' +
							  '<label for="ccanon-y-' + candycanes + '" class="inline">Anonymous</label> \n' +
							  '</li>  \n' +
							  '</ul> \n' +
							  '</td>  \n' +
							  '<td> \n' +
							  '<p class="center"> \n' +
							  '<select name="amount[]" id="amount-' + candycanes + '" class="calculate">  \n' +
							  '<option value="blue">Blue ($5 each)</option>  \n' +
							  '<option value="green">Green ($10 each)</option> \n' +
							  '<option value="red">Red ($25 each)</option>  \n' +
							  '<option value="gold">Gold ($100 each)</option>  \n' +
							  '</select> \n' +
							  '</p>  \n' +
							  '<ul> \n' +
							  '<li>  \n' +
							  '<label for="quantitycc-0" style="width: 9em;">Quantity: </label> \n' +
							  '<select name="quantitycc[]" id="quantitycc-' + candycanes + '" class="calculate"> \n' +
							  '<option value="0">0</option> \n' +
							  '<option value="1">1</option> \n' +
							  '<option value="2">2</option> \n' +
							  '<option value="3">3</option> \n' +
							  '<option value="4">4</option> \n' +
							  '<option value="5">5</option> \n' +
							  '</select> \n' +
							  '</li>  \n' +
							  '</ul>  \n' +
							  '</td>  \n' +
							  '</tr>');

	}
	
	if ( check != true ) $.cookie("candycanes", candycanes);

}

function removerow() {
		if ( candycanes < 1 ) {
			
			$('#candycaneform').slideUp(500, function() {
				$('#add-candycane').fadeIn(500, function() {
					//$('#purchase-row-'+candycanes).remove();
					//candycanes--;
				});	
	
			});
			
		} else {
			
			$('#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' } }
		 });
	}
}