var blank = new Image();
blank.src = 'images/spacer.gif';

var lastImage;
var crossFadeTimer;
var TIMERLENGTH = 9000;
function crossFade() {
	if (lastImage == null) {
		lastImage = $("#spiffs").children(":first");
		$("#spiffs").children().not(":first").hide();
		
	}
	var nextImage = lastImage.next();
	if (nextImage.length == 0) nextImage = $("#spiffs").children(":first");	
	lastImage.css("z-index", 1);
	nextImage.css("z-index", 5);
		
	nextImage.fadeIn(500, 
		function() {
			if (nextImage.find("span").length != 0) $("#caption").html(nextImage.find("span").html());
			lastImage.hide();
			lastImage = nextImage;
			crossFadeTimer = setTimeout('crossFade();', TIMERLENGTH);
		});	
}

$(document).ready(function() {

  //finds and fixed all png images for IE 6
  var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
  if (badBrowser) {
    // get all pngs on page
    $('img[src$=.png]').each(function() {
      if (!this.complete) {
        this.onload = function() { fixPng(this) };
      } else {
        fixPng(this);
      }
    });
  }


$('.shortsBucket').toggle(function() {
  $(this).find(".vDetails").show();
   $(this).find(".vScroller").show();
  $(this).find("span.icon").css("background-image", "url(images/icon_sss_ON.png)");
}, function() {
 $(this).find("span.icon").css("background-image", "url(images/icon_sss_OFF.png)");
 $(this).find(".vDetails").hide();
 $(this).find(".vScroller").hide();
});

	//crossFade();
    crossFadeTimer = setTimeout('crossFade();', TIMERLENGTH);
   

    $("a.cf-trigger").click(
        function() {
            clearTimeout(crossFadeTimer);
            $("#spiffs").children().hide();
            $("#" + $(this).attr("rel")).show();
    });


});

function showPromo(code){
	//alert(code + " clicked");
	$(".couponPromo").fadeIn(200);
}

function homePreview(section){
	
	//alert("It works" + section + "is what i chose");
	//Change span rollover color in nav ul
	//Change background-image to contentBlurb
	if(section == 'home'){ alert(section + " is what i chose"); }
	if(section == 'store'){ alert(section + " is what i chose"); }
	if(section == 'shorts'){ 
		//alert(section + " is what i chose"); 
	}
	if(section == 'contact') { }
	//$('#contentBlurb').css();
	
	if(section == 'books'){ 
		$('#contentBlurb').css('background-image', '../images/content_bg.jpg');
		$('#subnav').fadeIn();
	}

};

function fixPng(png) {
  // get src
  var src = png.src;
  // set width and height
  if (!png.style.width) { png.style.width = $(png).width(); }
  if (!png.style.height) { png.style.height = $(png).height(); }
  // replace by blank image
  png.onload = function() { };
  png.src = blank.src;
  // set filter (display original image)
  png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}; 

function showShort(story){
	$().click
};

	/*----------------------------------------------------------------------------------------------------------------------------*/
	/*----------------------------------------------------------------------------------------------------------------------------*/
	/* artisan overlay animation */
	$(function(){
		$('#hp-pod-list li a').hover(function(){
			$(this).children('.overlay').stop().animate({
				top : '0'
			}, 300);
		}, function(){
	
			$('#hp-pod-list li a').children('.overlay').stop().animate({
				top : '162px'
			}, 300);
	
		});
	});
	

