$(document).ready(function() {
	
	//$(window).konami(function(){ window.location = "http://www.meatspin.com"});
  
  /******** SLIDER **********/
	
	 $('.image_thumb li a').each(function() {
	 	$(document.body).append('<img src="'+$(this).attr('href')+'" style="display: none" alt="hidden"/>')
	   })	
 
	$(".image_thumb ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
	$(".image_thumb ul li").click(function(){
		window.clearInterval(timer);
	    //Set Variables
	    var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
	    var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
	
	    if ($(this).is(".active")) {  //If the list item is active/selected, then...
	        return false; // Don't click through - Prevents repetitive animations on active/selected list-item
	    } else { //If not active then...
	        //Animate the Description
			$('.main_image').css('background-image', 'url('+imgTitle+')');
			$('.main_image img').hide("slide",400, function() { $(".main_image img").attr({ src: imgTitle}); }).fadeIn(0)
	    }
	    //Show active list-item
	    $(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
	    $(this).addClass('active');  //Add class of 'active' on the selected list
	    return false;
	
	})

	function sliderTimeOut() {
      timer = window.setInterval( function()
      {
         slideToNext();
      }, 5000);
	}
	  
	 sliderTimeOut()
	 
	 function slideToNext() {
	 	var item = $('.image_thumb ul').find('li.active');
		var next = $(item).next().length ? $(item).next().find('a').attr('href') : $('.image_thumb ul li:first').find('a').attr('href');
		var nextItem = $(item).next().length ? $(item).next(): $('.image_thumb ul li:first');
		var prevItem = $(item).prev().length ? $(item).prev(): $('.image_thumb ul li:last');
		
		$('.main_image img').hide("slide",400, function() { $(".main_image img").attr({ src: next}); }).fadeIn(0)
		$(".image_thumb ul li").removeClass('active');
		$(nextItem).addClass('active');
		$('.main_image').css('background-image', 'url('+$(nextItem).find('a').attr('href')+')');
	 }
	 
	 $('.main_image').click(function() {
		 document.location = $('.image_thumb li.active').find('a.hidden').attr('href')
	 })
  
});
