
$(document).ready(function(){

//SOCIAL BOOKMARKS
$('#social_bookmarks').bookmark({sites: ['facebook','delicious', 'digg','stumbleupon'],icons: 'images/bookmarks.png',compact:true,addEmail:true,emailText:'Send to a friend',emailSubject:'Check out Sock Puppet Theater',emailBody:'Check out these sock puppets: {u}'});

//SHOW HIDES

	$('.hide_me').css({display:"none"});
	$('body#make_tombstone div#tombstone_preview').hide();
	$('p#alert').hide();
	
//MEDIA PAGES

	$('body#webisodes div#main div#left ul#media_category li:even').addClass("even");
	$('body#tv_spots div#main div#left ul#media_category li:even').addClass("even");
	$('body#tv_spots #media_category li').biggerlink();
	$('body#video_main div#main div#bump ul li').biggerlink();
	$('body#video_main div#main div#bump ul li').addClass("even");

	
//tombstone preview page
	$('a#preview_tombstone').click(function () { 
	  var recipient_name = $('#recipient_name').val();
	  var recipient_date = $('#recipient_month').val() + ". " + $('#recipient_day').val() + ", " + $('#recipient_year').val() + " - too soon";
	   var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  	   var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  	   if (!reg1.test($('#recipient_email').val()) && reg2.test($('#recipient_email').val()) && !reg1.test($('#sender_email').val()) && reg2.test($('#sender_email').val())) { // if syntax is valid
  	   		if (recipient_name != "" && recipient_date != "" && $('#sender_name').val() != "") {
  	   			if ($('#gender_male:checked').length > 0) {
  	   				var gender = "m";
  	   			}//close if
  	   			else {
  	   				var gender = "f";	
  	   			}
  	   			var image = "url('images/epitaph" + $('#tombstone_message').val() + gender + ".jpg')";
		      	$('h2#tombstone_name').html(recipient_name); 
		      	$('h2#tombstone_date').html(recipient_date); 
		      	$('ul#tombstone_fields').slideUp();
		      	$('div#tombstone_preview').css("background-image",image);
		      	$('div#tombstone_preview').slideDown();
		      	$('h2#tombstone_date').sifr({ path: 'resources/' , color: '#ffffff', save: false, font: 'requiem'});
	      		$('h2#tombstone_name').sifr({ path: 'resources/' , color: '#ffffff', save: false, font: 'requiem'});
	      		$('p#alert').hide();
  	   		}//close if
  	   		else {
  	   			$('p#alert').html("Looks like you forgot to enter a few things.").hide().fadeIn();	   			
  	   		}//close else
  	   }//close if
	   else {
	   		$('p#alert').html("We found a problem with an e-mail address you entered.").hide().fadeIn();
	   }//close else
    });

	$('a#make_changes').click(function () { 
      $('ul#tombstone_fields').slideDown();
      $('div#tombstone_preview').slideUp();
    });


//RADIO SELECTS FOR TOMBSTONE

	$('a#tombstone_option_1').click(function () { 
		$('#tombstone_image').val("1");
		$('li.tombstone_images a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
    
    $('a#tombstone_option_2').click(function () { 
		$('#tombstone_image').val("2");
		$('li.tombstone_images a.active').removeClass("active");
		$(this).addClass("active"); 
		return false;
    });
   
	$('a#tombstone_option_3').click(function () { 
		$('#tombstone_image').val("3");
		$('li.tombstone_images a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
    
	$('a#tombstone_option_4').click(function () { 
		$('#tombstone_image').val("4");
		$('li.tombstone_images a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
	
	$('a#tombstone_option_5').click(function () { 
		$('#tombstone_image').val("5");
		$('li.tombstone_images a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
	
	$('a#tombstone_option_6').click(function () { 
		$('#tombstone_image').val("6");
		$('li.tombstone_images a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
	
	$('a#tombstone_option_7').click(function () { 
		$('#tombstone_image').val("7");
		$('li.tombstone_images a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });

    
    
    
	$('a#tombstone_epitaph_1').click(function () { 
		$('#tombstone_message').val("1");
		$('li.epitaphs a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
    
    $('a#tombstone_epitaph_2').click(function () { 
		$('#tombstone_message').val("2");
		$('li.epitaphs a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
   
	$('a#tombstone_epitaph_3').click(function () { 
		$('#tombstone_message').val("3");
		$('li.epitaphs a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
    
	$('a#tombstone_epitaph_4').click(function () { 
		$('#tombstone_message').val("4");
		$('li.epitaphs a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
    
    $('a#tombstone_epitaph_5').click(function () { 
		$('#tombstone_message').val("5");
		$('li.epitaphs a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
	
	$('a#tombstone_epitaph_6').click(function () { 
		$('#tombstone_message').val("6");
		$('li.epitaphs a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
	
	$('a#tombstone_epitaph_7').click(function () { 
		$('#tombstone_message').val("7");
		$('li.epitaphs a.active').removeClass("active");
		$(this).addClass("active");
		return false;
    });
    



//SIFR


	//$.sifr({ path: 'resources/' , color: '#ffffff', save: true, font: 'requiem' });
	//$('#message').sifr();
	
	$('.sifr_gold_grunge').sifr({ path: 'resources/' , color: '#eecb7d', save: true, font: 'grunge'});
	$('.sifr_black_grunge').sifr({ path: 'resources/' , color: '#000000', save: true, font: 'grunge'});

	
	$('h2#tombstone_date').sifr({ path: 'resources/' , color: '#ffffff', save: true, font: 'requiem'});
	$('h2#tombstone_name').sifr({ path: 'resources/' , color: '#ffffff', save: true, font: 'requiem'});

    
    
//calculator

//show/hides
      //$('ul.answer_list li#sandwiches').hide();
      $('ul.answer_list li#movie').hide();
	  $('ul.answer_list li#dvds').hide();
	  $('ul.answer_list li#mp3').hide();
   	  //$('ul.answer_list li#shoes').hide();
  	  //$('ul.answer_list li#sheep').hide();
  	  //$('ul.answer_list li#honda').hide();

  	  
  	  $('ul.answer_list li#minutes').hide();
   	  $('ul.answer_list li#hours').hide();
  	  $('ul.answer_list li#days').hide(); 
  	  $('ul.answer_list li#years').hide();
	

//start calculator change function
$('body#calculator_money select').change(function () { 
	
	//$('ul.answer_list li#sandwiches').hide();
	$('ul.answer_list li#movie').hide();
	$('ul.answer_list li#dvds').hide();
	$('ul.answer_list li#mp3').hide();
	//$('ul.answer_list li#shoes').hide();
	//$('ul.answer_list li#sheep').hide();
	//$('ul.answer_list li#honda').hide();

	
	
      var n = $('select#n').attr("value");
      var f = $('select#f').attr("value");
      var g1 = $('select#g1').attr("value");
      var g2 = $('select#g2').attr("value");
   	  var g = g1 * g2;
   	  
   	  var t = round(n * .35 * f * g, 2);
   	  
	  //var sandwiches = Math.floor(t/5.5); 
	  var movie = Math.floor(t/8);   
	  var dvds = Math.floor(t/22);  
	  var mp3 = Math.floor(t/139); 
   	  //var shoes = Math.floor(t/70);
   	  //var sheep = Math.floor(t/45);  
   	  //var honda = Math.floor(t/15000);  

   	       	  
  	  /*if (sandwiches > 0) {
  	  	if (sandwiches == 1) {
    	  	$('ul.answer_list li#sandwiches').empty().hide().html(sandwiches + " Sandwich").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
  	  	}//close if
  	  	else {
    	  	$('ul.answer_list li#sandwiches').empty().hide().html(sandwiches + " Sandwiches").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
  	  	}
  	  }//close if
  	  	  else {
  	  		$('ul.answer_list li#sandwiches').empty().hide().html("----------------------").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });	  	
	  }//close else
	  */
	  
	if (movie > 0) {
  	  	if (movie == 1) {
  	  		$('ul.answer_list li#movie').sifr(false);
    	  	$('ul.answer_list li#movie').empty().hide().html(movie + " Movie Ticket").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
  	  	}//close if
  	  	else {
  	  		$('ul.answer_list li#movie').sifr(false);
    	  	$('ul.answer_list li#movie').empty().hide().html(movie + " Movie Tickets").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
  	  	}//close else
  	  }//close if
  	  	  else {
  	  	  	$('ul.answer_list li#movie').sifr(false);
  	  		$('ul.answer_list li#movie').empty().hide().html("----------------").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });	  	
	  }//close else
	  
	  
  	  
    if (dvds > 0) {
  	  	if (dvds == 1) {
  	  		$('ul.answer_list li#dvds').sifr(false);
    	  	$('ul.answer_list li#dvds').empty().hide().html("OR "+dvds + " NEW DVD").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
  	  	}//close if
  	  	else {
  	  		$('ul.answer_list li#dvds').sifr(false);
    	  	$('ul.answer_list li#dvds').empty().hide().html("OR "+dvds + " NEW DVDs").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
  	  	}//close else
  	  }//close if
  	  else {
  	  		$('ul.answer_list li#dvds').sifr(false);
  	  		$('ul.answer_list li#dvds').empty().hide().html("-------------------").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });	  	
	  }//close else
	  
	  
	  
	if (mp3 > 0) {
  	  	if (mp3 == 1) {
  	  		$('ul.answer_list li#mp3').sifr(false);
    	  	$('ul.answer_list li#mp3').empty().hide().html("OR "+mp3 + " MP3 PLAYER").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
  	  	}//close if
  	  	else {
  	  		$('ul.answer_list li#mp3').sifr(false);
    	  	$('ul.answer_list li#mp3').empty().hide().html("OR "+mp3 + " MP3 PLAYERS").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
  	  	}//close else
  	  }//close if
  	  else {
  	  		$('ul.answer_list li#mp3').sifr(false);
  	  		$('ul.answer_list li#mp3').empty().hide().html("-------------------").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });	  	
	  }//close else
	  
	  
  	  
  	 /* if (shoes > 0) {
  	  	if (shoes == 1) {
   	  		$('ul.answer_list li#shoes').empty().hide().html(shoes + " Pair of Shoes").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });  	  
  	  	}//close if
  	  	else {
   	  		$('ul.answer_list li#shoes').empty().hide().html(shoes + " Pairs of Shoes").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
  	  	}//close else
  	  }//close if
  	  	  else {
  	  		$('ul.answer_list li#shoes').empty().hide().html("----------------------").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });	  	
	  }//close else
  	  
  	  if (sheep > 0) {
  	  	$('ul.answer_list li#sheep').empty().hide().html(sheep + " Sheep").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
	  }//close if
	  else {
  	  	$('ul.answer_list li#sheep').empty().hide().html("----------------------").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });	  	
	  }//close else
	  
  	  if (honda > 0) {
  	  	if (honda == 1) {
   	  		$('ul.answer_list li#honda').empty().hide().html(honda + " Honda Civic").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });  	  
  	  	}//close if
  	  	else {
   	  		$('ul.answer_list li#honda').empty().hide().html(honda + " Honda Civics").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
  	  	}//close else
  	  }//close if
  	  else {
  	  		$('ul.answer_list li#honda').empty().hide().html("----------------------").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });	  	
	  }//close else
	  */
	  
	  //total line
	  $('ul.answer_list li#total_line').sifr(false);
	  $('ul.answer_list li#total_line').empty().hide().html("-------------------").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
	  
	  
	  //calculate total
	  $('ul.answer_list li#total').sifr(false);
	  $('ul.answer_list li#total').empty().hide().html("TOTAL: $" + CommaFormatted(CurrencyFormatted(t))  ).show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
	  	  
	  return false;

  	  
  	});//end calculator money change function
    
    
//start calculator life change function    
$('body#calculator_life select').change(function () { 
	
	  $('ul.answer_list li#minutes').hide();
	  $('ul.answer_list li#hours').hide();
	  $('ul.answer_list li#days').hide();
	  $('ul.answer_list li#years').hide();

	
      var n = $('select#n').attr("value");
      var f = $('select#f').attr("value");
      var g1 = $('select#g1').attr("value");
      var g2 = $('select#g2').attr("value");
   	  var g = g1 * g2;
   	  
   	  var t = round(n * 11 * f * g, 2);
   	  
	  //var minutes = t;   
   	  //var hours = Math.floor(t/60);
   	 var days = round(t/1440,1);  
   	 console.log(days);
   	 //var years = round(t/525600,1);
   	  
   	 //var weeks = round(t/1440,1);  
   	// var years = round(t/525600,1);
   	     
      //$('h3#answer').empty().hide().html("The answer is $" + t);
  	  
  	  //if (minutes > 0) {
  	  	//if (minutes == 1) {
    	  	//$('ul.answer_list li#minutes').empty().hide().html("<span>" + minutes + "</span> Minute").fadeIn();
  	  	//}//close if
  	  	//else {
    	  	//$('ul.answer_list li#minutes').empty().hide().html("<span>" + minutes + "</span> Minutes").fadeIn();
  	  	//}
  	  //}//close if
  	  //if (hours > 0) {
  	  	//if (hours == 1) {
   	  		//$('ul.answer_list li#hours').empty().hide().html("<span>" + hours + "</span> Hour").fadeIn();  	  
  	  	//}//close if
  	  	//else {
   	  		//$('ul.answer_list li#hours').empty().hide().html("<span>" + hours + "</span> Hours").fadeIn();
  	  	//}//close else
  	  //}//close if
  	  //if (days > 0) {
  	  	//if (days == 1) {
   	  		//$('ul.answer_list li#days').empty().hide().html("<span>" + days + "</span> Day").fadeIn(); 	  		
  	  	//}//close if
  	  	//else {
  	  		//$('ul.answer_list li#days').empty().hide().html("<span>" + days + "</span> Days").fadeIn();
  	  	//}//close else
	  //}//close if
	  
  	  if (days > 0) {
  	  
  	  	if (days == 1) {
  	  		$('ul.answer_list li#years').sifr(false);
   	  		$('ul.answer_list li#years').empty().hide().html(days + " Day Lost").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' }); 	  		
  	  	} else {
  	  		$('ul.answer_list li#years').sifr(false);
  	  		$('ul.answer_list li#years').empty().hide().html(days + " Days Lost").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });
  	  	}//close else
	  
	  } else {
	  		$('ul.answer_list li#years').sifr(false);
  	  		$('ul.answer_list li#years').empty().hide().html("----------------------").show().sifr({ path: 'resources/' , color: '#FFFFF', save: true, font: 'digital' });	  	
	  }
	  
	  
	  return false;
  	  
    });//end calculator life change function    

    
 });//close on ready
 
 
// rounds number to X decimal places, defaults to 2
function round(number,X) {
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

//format dollar amounts
function CommaFormatted(amount){
	var delimiter = ","; // replace comma if desired
	amount = new String(amount);
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}


function CurrencyFormatted(amount){
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}


