 $(document).ready(function(){
    //sIFR
	//$.sifr({path:'http://micro-printing.com/assets/fonts/'});

	//$('.sifr').sifr({ font: 'HelveticaNeue LT 43 LightEx'});
	
	$('#product_box_links a, #header a').hover(
		function(){
			var img = $(this).attr('alt');
			$('#billboard_'+img).fadeIn();
		},
		function (){
			var img = $(this).attr('alt');
			$('#billboard_'+img).fadeOut();
		}
	);

	//TABLE
	$('.orderTable td:nth-child(1)').addClass('col_1'); 
	$('.orderTable td:nth-child(2)').addClass('col_2');
	$('.orderTable td:nth-child(3)').addClass('col_3');
	$('.orderTable td:nth-child(4)').addClass('col_4');
	$('.orderTable td:nth-child(5)').addClass('col_2');
	$('.orderTable td:nth-child(6)').addClass('col_3');
	$('.orderTable td:nth-child(7)').addClass('col_4');
	$('.orderTable td:nth-child(8)').addClass('col_2'); 
	$('.orderTable td:nth-child(9)').addClass('col_3');
	
	$('.orderTable th:nth-child(1)').addClass('th_1'); 
	$('.orderTable th:nth-child(2)').addClass('th_2');
	$('.orderTable th:nth-child(3)').addClass('th_3');
	$('.orderTable th:nth-child(4)').addClass('th_4');
	$('.orderTable th:nth-child(5)').addClass('th_2');
	$('.orderTable th:nth-child(6)').addClass('th_3');
	$('.orderTable th:nth-child(7)').addClass('th_4');
	$('.orderTable th:nth-child(8)').addClass('th_2'); 
	$('.orderTable th:nth-child(9)').addClass('th_3');


	$('#add_note').toggle(
		function(){
			$('#note').show();
			$('#job_note').focus();
		},
		function(){
			$('#note').hide();
		}
	);

	$('#job_note').keyup(
		function(){
			$('.note').val($(this).val());
		}
	);

	$('#job_description').keyup(
		function(){
			$('.job_description').val($(this).val());
		}
	);


	$('#upload').submit(function(){
		$('#upload_form').hide();
		$('#progress_bar').show();
	});

	$("a.g").fancybox(); 	
	$("a.order_detail").fancybox({
		'autoDimensions': false,
		'height':550,
		'width':860});
		
	if($("#video").length > 0 ){
			$("a#inline").fancybox({frameWidth: 674,frameHeight: 397,overlayShow: true,centerOnScroll:true});
	}
	
	$('#print_invoice').click(function(){
		window.open( $(this).attr('href'), null, "height=600,width=600,status=yes,toolbar=no,menubar=no,location=no" );
		   return false;
	});

	if($(".proof_options:checked")) {
			$('.proof_description').html(proof_option($(".proof_options:checked").val()));
			$('.total').html(calculate($(".proof_options:checked").attr('alt')*1, $('#product_price').val()*1));
			$('.cost').val(calculate($(".proof_options:checked").attr('alt')*1, $('#product_price').val()*1));
			$('.proof_option').val($(".proof_options:checked").val());
	};
	$(".proof_options").click(
		function(){
			$('.proof_description').html(proof_option($(this).val()));
			$('.total').html(calculate($(this).attr('alt')*1, $('#product_price').val()*1));
			$('.cost').val(calculate($(".proof_options:checked").attr('alt')*1, $('#product_price').val()*1));
			$('.proof_option').val($(".proof_options:checked").val());
		}
	);

 });

function calculate($a,$b){
	$total = $a*1 + $b*1;
	return formatCurrency($total);
}

function proof_option($option){
	switch($option){
		case 'proof_none':
			$str = ' <br />- No Proof I take full responsibility'; break;
		case 'proof_email':
			$str = ' <br />- Email Proof'; break;
		case 'proof_pickup':
			$str = ' <br />- Pickup Proof'; break;
		case 'proof_mail':
			$str = ' <br />- Mail Proof $25 Service Charge'; break;
		default: $str = '';}
	return $str;
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if (isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	cents = num % 100;
	num = Math.floor(num / 100).toString();
	
	if (cents < 10) cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
	
	num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
	return (((sign) ? '' : '-') + '$' + num + '.' + cents);
}