﻿var settings = {
		imgFadeThroughSpeed: 500,
		pageFadeOutSpeed: 250,
		pageFadeLoaderSpeed: 150,
		pageFadeInSpeed: 250
	},
	historyCount = 0;



$(function(){

	$("a").livequery("focus", function(){ this.blur(); });
	
	//Preload nav over images
	for(var i=1; i<=8; i++) $('<img src="includes/css/images/btn-nav'+i+'.gif" />');
	
	//Page Fade Through
	$("a:not([target])").livequery("click", function(){
		
			var $this = $(this),
				sethistory = $this.attr("loadinto") ? false : true,
				f = function($this){
			
					var loaded = false,
						//$this = $(this), 
						wrapper = $this.attr("loadinto") ? $this.attr("loadinto") : "#content-wrapper",
						$wrapper = $(wrapper),
						newContent = ""
						pageIn = function(){
							//$('html,body').animate({scrollTop: 0}, 1000);
							$wrapper.animate({opacity: 0}, settings.pageFadeLoaderSpeed, function(){
									$wrapper.removeClass("loading").html(newContent).animate({opacity: 1}, settings.pageFadeInSpeed);
								})
							};
					
					targetWrapper = wrapper;
					$wrapper.animate( { opacity: 0 }, settings.pageFadeOutSpeed, function(){
							if(!loaded) 
								$wrapper.html("&nbsp;").addClass("loading").animate({opacity: 1}, settings.pageFadeLoaderSpeed);
							else pageIn();
						});
						
					$.ajax({
							url: $this.attr("href"),
							success: function(html){
								loaded = true;
								newContent = $(wrapper, html).html();
								if($wrapper.hasClass("loading")) pageIn();
							}	
						});
				};
			
			if(sethistory){
				historyCount++;
				$.History.bind("h-" + historyCount, function(){ f($this); });
				$.History.setHash("h-" + historyCount, "_self");
			}
			else f($this);
			
			return false;
		});
	
	$("#home-content").livequery(function(){
			$(this).slideshow({
					width: 935,
					height: 625,
					type: "fade",
					interval: 4000,
					duration: 750,
					controls: false,
					backgroundImage: false
				});
		});
	$("#collection-detail-slides").livequery(function(){
			var gtOne = $(this).find("li").length > 1,
				slideshow = $(this).slideshow({
						width: 375,
						height: 564,
						type: "fade",
						interval: gtOne ? 5000 : false,
						duration: 750,
						controls: false
					});
					
			if(!gtOne) $(".portfolio-detail-prevNext").hide();
			else {
				$("#collection-detail-prev").click(function(){
						slideshow.slideshow("prev")
						return false;
					})
				$("#collection-detail-next").click(function(){
						slideshow.slideshow("next")
						return false;
					})
			}
		});
	$("#collection-mosaic-slides").livequery(function(){
			var gtOne = $(this).find("li").length > 1,
				slideshow = $(this).slideshow({
						width: 555,
						height: 564,
						type: "fade",
						interval: gtOne ? 5000 : false,
						duration: 750,
						controls: false
					});
					
			if(!gtOne) $(".portfolio-detail-prevNext").hide();
			else {
				$("#collection-detail-prev").click(function(){
						slideshow.slideshow("prev")
						return false;
					})
				$("#collection-detail-next").click(function(){
						slideshow.slideshow("next")
						return false;
					})
			}
		});
	$("#collection-installations-slides").livequery(function(){
			var gtOne = $(this).find("li").length > 1,
				slideshow = $(this).slideshow({
						width: 564,
						height: 564,
						type: "fade",
						interval: gtOne ? 5000 : false,
						duration: 750,
						controls: false/*,
						change: function(ui, e){
							$(".collection-installations-column-right").html( $(e).find(".collection-installation-info").html() );
						}*/
					});
					
			if(!gtOne) $(".portfolio-detail-prevNext").hide();
			else {
				$("#collection-detail-prev").click(function(){
						slideshow.slideshow("prev")
						return false;
					})
				$("#collection-detail-next").click(function(){
						slideshow.slideshow("next")
						return false;
					})
			}
		});
	$(".portfolio-detail-imgs").livequery(function(){
			$(".portfolio-detail-img:first").show();
			$(".portfolio-detail-thumb").click(function(){
				$(".portfolio-detail-img:visible").fadeOut(settings.imgFadeThroughSpeed);
				$(".portfolio-detail-img:eq("+$(".portfolio-detail-thumb").index(this)+")").fadeIn(settings.imgFadeThroughSpeed);
			})
		});
	$("#portfolio-detail-prev").livequery("click", function(){
			var $in = $(".portfolio-detail-img:visible").prev();
			if(!$in.length) $in = $(".portfolio-detail-img:last")
			$(".portfolio-detail-img:visible").fadeOut(settings.imgFadeThroughSpeed);
			$in.fadeIn(settings.imgFadeThroughSpeed);
			return false;
		});
	$("#portfolio-detail-next").livequery("click", function(){
			var $in = $(".portfolio-detail-img:visible").next();
			if(!$in.length) $in = $(".portfolio-detail-img:first")
			$(".portfolio-detail-img:visible").fadeOut(settings.imgFadeThroughSpeed);
			$in.fadeIn(settings.imgFadeThroughSpeed);
			return false;
		});
		
	/*SHOW/HIDE AWARDS BANNER BASED ON WINDOW WIDTH*/
	if ($(window).width() < 1220) {	
		$('#BADGEWRAP').hide();	
	};
	$(window).resize(function() {
		if ($(window).width() < 1220) {	
			$('#BADGEWRAP').hide();	
		} else {
			$('#BADGEWRAP').show();	
		}
	});	

});










