$(window).load(function(){
	var winw = $(window).width();
	var winh = $(window).height();
	var infoffset = $(".info").offset().top;
	var galw = $(".gallery").width();
	resize();
	$(".popup").css("width",1);	
	$(".popup").css("height",1);
	$(".glow").hide();	
	$(".glow").css("width",winw);	
	$(".glow").css("height",winh);	
	$(".info").css("left",-winw);
	$(".info").show();
	$(".info").animate({left:0}, 4000,"easeOutQuint",function(){
		$('.gallery').show("slow");
		$('.gallery').scrollingCarousel({
		looped:true,
		scrollSpeed:'slow',
		ScrollerOffset:0
		});
		$(".glow").fadeOut(2000);
	});
	$("a").live("mouseover mouseout", function(event) {
  		if ( event.type == "mouseover" ) {$(".glow").fadeIn(1000);} else {$(".glow").fadeOut(500);}
	});
	$(".image").css("width",100);
	$(".image").css("height",100);
	$(".gallery").mouseenter(function(){
		$(this).animate({maxWidth:winw}, "slow","easeOutQuint");
	});
	$(".info").mouseleave(function(){
		$(".gallery").animate({maxWidth:660}, "slow","easeOutQuint");
	});

	var navswitch = true;

	$(".nav").live("mouseover mouseout", function(event) {
  		if ( event.type == "mouseover" ) { navswitch = false; } else { navswitch = true; }
	});

	$(".popup").click(function(){
		if(navswitch){
			$(this).fadeOut();
		}		
	});

});
function prev(arr,count){
	current = $(".popup").attr("id");
	current = parseInt(current);
	if(current == 1){ var prev = count; } else { var prev = current - 1; }
	$(".popup").attr("id",prev);
	$(".popup").css("background","url("+ arr[prev] +") right center no-repeat");
	if(winw > 1000){
		$(".popup").css("width",(winw/4)*3);
		$(".popup").css("background","url("+ arr[prev] +") right center no-repeat");
	}else{
		$(".popup").css("width",winw);
		$(".popup").css("background","url("+ arr[prev] +") center center no-repeat");
	}
}
function next(arr,count){
	current = $(".popup").attr("id");
	current = parseInt(current);
	if(current == count){ var next = 1; } else { var next = current + 1; }
	$(".popup").attr("id",next);
	$(".popup").css("background","url("+ arr[next] +") right center no-repeat");
	if(winw > 1000){
		$(".popup").css("width",(winw/4)*3);
		$(".popup").css("background","url("+ arr[next] +") right center no-repeat");
	}else{
		$(".popup").css("width",winw);
		$(".popup").css("background","url("+ arr[next] +") center center no-repeat");
	}
}
function popup(url,key){
	winw = $(window).width();
	winh = $(window).height();
	$(".popup").fadeOut();
	$(".popup").css("height",winh);
	$(".nav").css({height:winh,width:(winw/5)});
	$(".popup").attr("id",key);
	if(winw > 1000){
		$(".popup").css("width",(winw/4)*3);
		$(".popup").css("background","url("+url+") right center no-repeat");
	}else{
		$(".popup").css("width",winw);
		$(".popup").css("background","url("+url+") center center no-repeat");
	}
	$(".popup").attr("id",key);
	$(".popup").fadeIn();
	// for large screen, grey out the scrolling images so users know they cannot click them
	// else for mobile, make bottom thumbs access (autoscrolling)
}
$(window).resize(function() {resize(); });
function resize(){
	$(".popup").fadeOut();
	var winh = $(window).height();
	var winw = $(window).width();
	var infh = $(".info").height();
	var infp = (winh/2) - (infh/2) - (infh/12);
	
	$(".glow").css("width",winw);	
	$(".glow").css("height",winh);	
	
	if(infp > 0){ 
		if(winw < 500){ inforetop = 0; }else{ inforetop = infp; }
	} else {
		inforetop = 0;
	} 
	$(".info").animate({top:inforetop}, "slow","easeOutQuint");
}
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25982308-2']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
