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






// Submenu Mousehover

jQuery(document).ready(function(){
jQuery("#submenuBottom").hover(
  function () {
		jQuery(this).stop(true, true);
    jQuery(this).animate({width: "500px"}, 500);
  }, 
  function () {
		jQuery("#nav_quicklinks_container").delay(4500).hide("normal");
    jQuery(this).delay(5000).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");
	});
});





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






// 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();
});
