

jQuery.userIdle = false;
jQuery.imagesLoaded = false;


/*********************************************/
/*********************************************/
/*** All JavaScript/jQuery Functions Start ***/
/*********************************************/
/*********************************************/






// Submenu Mousehover

jQuery(document).ready(function(){
jQuery("#submenu").hover(
  function () {
		jQuery(this).stop(true, true);
    jQuery(this).animate({width: "500px"}, 500);
  }, 
  function () {
		jQuery("#nav_quicklinks_container").delay(5000).hide("normal");
    jQuery(this).delay(5500).animate({width: "0px"}, 500);
  }
);
});

// QUICKLINKS

jQuery(document).ready(function(){
		jQuery("#nav_quicklinks").mouseover(function () { 
				jQuery(this).addClass("qulicklink_button_over");
    });
		jQuery("#nav_quicklinks").mouseout(function () { 
				jQuery(this).removeClass("qulicklink_button_over");
    });
		jQuery("#nav_quicklinks").mousedown(function () { 
				jQuery(this).removeClass("qulicklink_button_over");
				jQuery("#nav_quicklinks_container").slideToggle();
		});
		jQuery("#nav_quicklinks").mouseup(function () { 
				jQuery(this).addClass("qulicklink_button_over");
    });
});

// SEARCH

jQuery(document).ready(function(){
	jQuery("#searchform_field").mousedown(function () {
			jQuery("#nav_quicklinks_container").hide("normal");
	});
});






/**********************************************************************************************/






jQuery(document).ready(function(){
	jQuery("#mainmenuBorder").toggle(
		function () {
			jQuery("#mainmenuContent").animate({left: "-300px"}, 400);
			jQuery("#designAwards").fadeOut(800);
			jQuery("body").css({cursor: 'auto'});
		},
		
		function () {
			jQuery("#mainmenuContent").animate({left: "12px"}, 400);
			jQuery("#designAwards").fadeIn(800);
			jQuery("body").css({cursor: 'auto'});
		}
	);
});


jQuery(document).ready(function(){
	jQuery("#latestNewsBorder").toggle(
		function () {
			jQuery("#latestNews").animate({left: "-500px"}, 400);
		},
		
		function () {
			jQuery("#latestNews").animate({left: "12px"}, 400);
		}
	);
});






/**********************************************************************************************/






// Tooltips

jQuery(document).ready(function(){
	jQuery(".tooltip").delay(1000).fadeTo("normal", 0.9);
	jQuery(".tooltip").delay(5000).fadeTo("normal", 0);
});






/**********************************************************************************************/






// Preload Slideshow Images

	var PreloadFadeIn = (function () {
			jQuery("#preloadSlideshowImages").fadeTo("fast", 1);
	}); 
	var PreloadFadeOut = (function () {
			jQuery("#preloadSlideshowImages").stop();
			jQuery("#preloadSlideshowImages").fadeTo("normal", 0);
	});






/**********************************************************************************************/






// Background Image Resize

(function(jQuery) {
	// plugin definition
	jQuery.fn.ezBgResize = function(options) {
		// First position object
		this.css("position","fixed");
		this.css("top","0px");
		this.css("left","0px");
		this.css("z-index","-1");
		this.css("overflow","hidden");
		this.css("margin","0");
		
		// Set obj to the width and height of window
		this.css("width",getWindowWidth() + "px");
		this.css("height",getWindowHeight() + "px");
		
		// Resize the img object to the proper ratio of the window.
		var iw = this.children('img').width();
		var ih = this.children('img').height();
		if (getWindowWidth() > getWindowHeight()) {
			if (iw > ih) {
				var fRatio = iw/ih;
				this.children('img').css("width",getWindowWidth() + "px");
				this.children('img').css("height",Math.round(getWindowWidth() * (1/fRatio)));
				
				var newIh = Math.round(getWindowWidth() * (1/fRatio));
				
				if(newIh < getWindowHeight()) {
					var fRatio = ih/iw;
					this.children('img').css("height",getWindowHeight());
					this.children('img').css("width",Math.round(getWindowHeight() * (1/fRatio)));
				}
			} else {
				var fRatio = ih/iw;
				this.children('img').css("height",getWindowHeight());
				this.children('img').css("width",Math.round(getWindowHeight() * (1/fRatio)));
			}
		} else {
			var fRatio = ih/iw;
			this.children('img').css("height",getWindowHeight());
			this.children('img').css("width",Math.round(getWindowHeight() * (1/fRatio)));
		}
	};
	
	// private function for debugging
	function debug(jQueryobj) {
		if (window.console && window.console.log) {
			window.console.log('Window Width: ' + jQuery(window).width());
			window.console.log('Window Height: ' + jQuery(window).height());
		}
	};
	
	// Dependable function to get Window Height
	function getWindowHeight() {
		var windowHeight = 0;
		if (typeof(window.innerHeight) == 'number') {
			windowHeight = window.innerHeight;
		}
		else {
			if (document.documentElement && document.documentElement.clientHeight) {
				windowHeight = document.documentElement.clientHeight;
			}
			else {
				if (document.body && document.body.clientHeight) {
					windowHeight = document.body.clientHeight;
				}
			}
		}
		return windowHeight;
	};
	
	// Dependable function to get Window Width
	function getWindowWidth() {
		var windowWidth = 0;
		if (typeof(window.innerWidth) == 'number') {
			windowWidth = window.innerWidth;
		}
		else {
			if (document.documentElement && document.documentElement.clientWidth) {
				windowWidth = document.documentElement.clientWidth;
			}
			else {
				if (document.body && document.body.clientWidth) {
					windowWidth = document.body.clientWidth;
				}
			}
		}
		return windowWidth;
	};
})(jQuery);



// Background Resize Action

jQuery(window).load(function() {
		jQuery("#backgroundImage").ezBgResize();
});
jQuery(window).bind("resize", function(){
		jQuery("#backgroundImage").ezBgResize();
});






/**********************************************************************************************/






// Site Preloader

var QueryLoader = {
	/*
	 * QueryLoader		Preload your site before displaying it!
	 * Author:			Gaya Kessler
	 * Date:			23-09-09
	 * URL:				http://www.gayadesign.com
	 * Version:			1.0
	 * 
	 * A simple jQuery powered preloader to load every image on the page and in the CSS
	 * before displaying the page to the user.
	 */
	
	overlay: "",
	loadBar: "",
	preloader: "",
	items: new Array(),
	doneStatus: 0,
	doneNow: 1,
	selectorPreload: "body",
	ieLoadFixTime: 2000,
	ieTimeout: "",
		
	init: function() {
		if (navigator.userAgent.match(/MSIE (\d+(?:\.\d+)+(?:b\d*)?)/) == "MSIE 6.0,6.0") {
			//break if IE6			
			return false;
		}
		if (QueryLoader.selectorPreload == "body") {
			QueryLoader.spawnLoader();
			QueryLoader.getImages(QueryLoader.selectorPreload);
			QueryLoader.createPreloading();
		} else {
			jQuery(document).ready(function() {
				QueryLoader.spawnLoader();
				QueryLoader.getImages(QueryLoader.selectorPreload);
				QueryLoader.createPreloading();
			});
		}
		
		//help IE drown if it is trying to die :)
		QueryLoader.ieTimeout = setTimeout("QueryLoader.ieLoadFix()", QueryLoader.ieLoadFixTime);
	},
	
	ieLoadFix: function() {
		var ie = navigator.userAgent.match(/MSIE (\d+(?:\.\d+)+(?:b\d*)?)/);
		if (ie[0].match("MSIE")) {
			while ((100 / QueryLoader.doneStatus) * QueryLoader.doneNow < 100) {
				QueryLoader.imgCallback();
			}
		}
	},
	
	imgCallback: function() {
		QueryLoader.doneNow ++;
		QueryLoader.animateLoader();
	},
	
	getImages: function(selector) {
		var everything = jQuery(selector).find("*:not(script)").each(function() {
			var url = "";
			
			if (jQuery(this).css("background-image") != "none") {
				var url = jQuery(this).css("background-image");
			} else if (typeof(jQuery(this).attr("src")) != "undefined" && jQuery(this).attr("tagName").toLowerCase() == "img") {
				var url = jQuery(this).attr("src");
			}
			
			url = url.replace("url(\"", "");
			url = url.replace("url(", "");
			url = url.replace("\")", "");
			url = url.replace(")", "");
			
			if (url.length > 0) {
				QueryLoader.items.push(url);
			}
		});
	},
	
	createPreloading: function() {
		QueryLoader.preloader = jQuery("<div></div>").appendTo(QueryLoader.selectorPreload);
		jQuery(QueryLoader.preloader).css({
			height: 	"0px",
			width:		"0px",
			overflow:	"hidden"
		});
		
		var length = QueryLoader.items.length; 
		QueryLoader.doneStatus = length;
		
		for (var i = 0; i < length; i++) {
			var imgLoad = jQuery("<img></img>");
			jQuery(imgLoad).attr("src", QueryLoader.items[i]);
			jQuery(imgLoad).unbind("load");
			jQuery(imgLoad).bind("load", function() {
				QueryLoader.imgCallback();
			});
			jQuery(imgLoad).appendTo(jQuery(QueryLoader.preloader));
		}
	},

	spawnLoader: function() {
		if (QueryLoader.selectorPreload == "body") {
			var height = jQuery(window).height();
			var width = jQuery(window).width();
			var position = "fixed";
		} else {
			var height = jQuery(QueryLoader.selectorPreload).outerHeight();
			var width = jQuery(QueryLoader.selectorPreload).outerWidth();
			var position = "absolute";
		}
		var left = jQuery(QueryLoader.selectorPreload).offset()['left'];
		var top = jQuery(QueryLoader.selectorPreload).offset()['top'];
		
		QueryLoader.overlay = jQuery("<div></div>").appendTo(jQuery(QueryLoader.selectorPreload));
		jQuery(QueryLoader.overlay).addClass("QOverlay");
		jQuery(QueryLoader.overlay).css({
			position: position,
			top: top,
			left: left,
			width: 100 + "%",
			height: height + "px"
		});
		
		QueryLoader.loadBar = jQuery("<div></div>").appendTo(jQuery(QueryLoader.overlay));
		jQuery(QueryLoader.loadBar).addClass("QLoader");
		
		jQuery(QueryLoader.loadBar).css({
			position: "relative",
			top: "50%",
			width: "0%"
		});
	},
	
	animateLoader: function() {
		var perc = (100 / QueryLoader.doneStatus) * QueryLoader.doneNow;
		if (perc > 99) {
			jQuery(QueryLoader.loadBar).stop().animate({
				width: perc + "%"
			}, 500, "linear", function() { 
				QueryLoader.doneLoad();
			});
		} else {
			jQuery(QueryLoader.loadBar).stop().animate({
				width: perc + "%"
			}, 500, "linear", function() { });
		}
	},
	
	doneLoad: function() {
		//prevent IE from calling the fix
		clearTimeout(QueryLoader.ieTimeout);
		
		//determine the height of the preloader for the effect
		if (QueryLoader.selectorPreload == "body") {
			var height = jQuery(window).height();
		} else {
			var height = jQuery(QueryLoader.selectorPreload).outerHeight();
		}
		
		//The end animation, adjust to your likings
		jQuery(QueryLoader.loadBar).animate({
			height: "3px",
			top: "50%"
		}, 0,  function() {
			jQuery(QueryLoader.overlay).fadeOut(800, function () {
					jQuery.preLoadImages(slideImages);
			});
			jQuery(QueryLoader.preloader).remove();
		});
	}
}






/**********************************************************************************************/






