$(document).ready(function() {
  var esc = false;  //used for cheat system
  
  if ($.browser.safari) //webkit browser check for image replacement
  {  					
	var webkit = setInterval(function()
	{
      clearInterval(webkit);
      FLIR.init();
      $('.entry-title,#home-video-content h3,.sub-header,.recent h3,.monthly h3,.overlay h2,#video-content h3,#video-comments h4,#crew-description h3,#about-header a,#crew-thumbnails-header a,#featured-content h3, .visit a, .post a, .video-prev-next a, .view-more-news a, .read-more a,').each( function() { FLIR.replace(this); } );
    }, 55);
  }
  
  if (!$.browser.safari) 
  {
    FLIR.init();
    $('.entry-title,#home-video-content h3,.sub-header,.recent h3,.monthly h3,.overlay h2,#video-content h3,#video-comments h4,#crew-description h3,#about-header a,#crew-thumbnails-header a,#featured-content h3, .visit a, .post a, .video-prev-next a, .view-more-news a, .read-more a,').each( function() { FLIR.replace(this); });
  }
  
  if($.browser.msie && $.browser.version == '6.0') $('#navigation').prepend('<div id="ie6"></div>');
  
  /******************************************
  *  Start code for special hidden section
  ******************************************/
  
  //add cheat code to site
  $('body').append('<div class="cheat"><div class="cheat-body"></div><input type="text" value="#" id="cheat-input" /></div>');
  
  //capture keydown events
  $(window).keydown(function(e)
  {
	  //alert('esc = ' + esc);
    if(e.which == 192 && esc == false)  // '`' key
	{ 
		$('.cheat').slideToggle();
		$('#cheat-input').focus();
		return false;
	}
	
	if(e.which == 27 && esc == true)  // 'esc' key
	{
		$('.cheat-body').html('').slideToggle();
		esc = false;
	}
  });
  
  //capture keydown events in Internet Explorer
  if ($.browser.msie)
  {
  	$('body').keydown(function(e)
	  {
		  //alert('esc = ' + esc);
		if(e.which == 192 && esc == false)  // '`' key
		{ 
			$('.cheat').slideToggle();
			$('#cheat-input').focus();
			return false;
		}
		
		if(e.which == 27 && esc == true)  // 'esc' key
		{
			$('.cheat-body').html('').slideToggle();
			esc = false;
		}
	  });
  }
  
  //determine if passcode is legit
  $('input').keydown(function(e)
  { 
	  if(e.which == 13 && esc == false)
	  {
		var height = $(window).height();
		var val = this.value;
		
		//if passcode is #sketchyarms
		if(val == '#sketchyarms')
		{
		  $('.cheat-body').height(height-40).slideDown('fast', function()
		  {
			  $('.cheat-body').html('<div style="margin:0 auto; padding-top:100px; width:425px;"><h2>Take On Me: Literal Video Version</h2><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/8HE9OQ4FnkQ&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/8HE9OQ4FnkQ&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object></div>');
		  });
		  $('.cheat').animate({height: '100%'});
		  esc = true;
		}
		
		//if passcode is #goatse
		if(val == '#goatse')
		{
		  $('.cheat-body').height(height-40).slideDown('fast', function()
		  {
			  $('.cheat-body').html('<div style="margin:0 auto; padding-top:100px; width:640px;"><img src="/images/cheats/lolgoatse.jpg" /></div>');
		  });
		  $('.cheat').animate({height: '100%'});
		  esc = true;
		}
		  
		  //if passcode is #iatedit
		if(val == '#iatedit')
		{
		  $('.cheat-body').height(height-40).slideDown('fast', function()
		  {
			  $('.cheat-body').html('<div style="margin:0 auto; padding-top:100px; width:600px;"><img src="/images/cheats/iatedit.jpg" /></div>');
		  });
		  $('.cheat').animate({height: '100%'});
		  esc = true;
		}
		  
		  //if passcode is #buttz
		if(val == '#buttz')
		{
		  $('.cheat-body').height(height-40).slideDown('fast', function()
		  {
			  $('.cheat-body').html('<div style="margin:0 auto; padding-top:100px; width:500px;"><img src="/images/cheats/usaidbuttz.jpg" /></div>');
		  });
		  $('.cheat').animate({height: '100%'});
		  esc = true;
		}
	  } 
  });
});
