


$(document).ready(function(){
	
	$(document).pngFix();
	
	// fix "external" links to open in new window									 
	$('a[rel="external"]').click(function(){
		window.open(this.href);
		return false;
	}).attr('title', 'Opens in New Window or Tab');
	
	// load slide from # (hash)
	var hashSlide = parseInt(window.location.hash.slice(1, window.location.hash.length) );
	if ( hashSlide > 0 ) {
		hashSlide--;
	} else {
		hashSlide = 0;
	}
	$("#home-slideshow").cycle({
		pause:1,
		speed:500,
		timeout:5000,
		after:onAfterHome,
		startingSlide:hashSlide
	});
	
	// slideshow nav buttons
	$("#slideshow-nav a").click(function(){
	});
	$("#slideshow-nav.home a").click(function(){
		var newSlide = parseInt( $(this).attr("rel") );
		$("#home-slideshow").cycle( newSlide-1 );
		return false;
	});
	
	// home random images
	$("div.anim").each(function(){	
		var indx = $(this).index();
		var speed_rdm = Math.floor(Math.random()*501);
		var delay_rdm = Math.floor(Math.random()*4001);
		var timeout_rdm = Math.floor(Math.random()*5001);
		$(this).fadeIn(speed_rdm);
		$(this).delay( 2000+delay_rdm ).cycle({
			speed: speed_rdm+200,
			timeout:2000+timeout_rdm
		});
	});
	
	// gallery fancybox
	if($("a.gallery-thumb").length) {
	$("a.gallery-thumb").fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	}
	
	setTimeout(toggleOffer,3000);
	
});

function onAfterHome(curr,next,opts) {
	var curSlide = opts.currSlide + 1;
	$("#slideshow-nav a").removeClass("active");
	$("#slideshow-nav-"+curSlide).addClass("active");
}

function toggleOffer(){
				$("#specialOfferBanner").animate({width:'toggle'},237,function(){
					if($("#specialOfferClose").hasClass("active")){
						$("#specialOfferClose").removeClass("active");
						$("#specialOfferOpen").addClass("active");
					}else{
						$("#specialOfferOpen").removeClass("active");
						$("#specialOfferClose").addClass("active");
					}
				});
			}
