/*
 * jQuery Global Functions
 * By Layered Pixels
 * Version 1.0
 */

var j = jQuery.noConflict();

(function($) { 
  $(function() {
	(function ($) {

	$.topZIndex = function (selector) {
		/// <summary>
		/// 	Returns the highest (top-most) zIndex in the document
		/// 	(minimum value returned: 0).
		/// </summary>	
		/// <param name="selector" type="String" optional="true">
		/// 	(optional, default = "body *") jQuery selector specifying
		/// 	the elements to use for calculating the highest zIndex.
		/// </param>
		/// <returns type="Number">
		/// 	The minimum number returned is 0 (zero).
		/// </returns>

		return Math.max(0, Math.max.apply(null, $.map($(selector || "body *"), 
			function (v) {
				return parseInt($(v).css("z-index")) || null;
			}
		)));
	};

	$.fn.topZIndex = function (opt) {
		/// <summary>
		/// 	Increments the CSS z-index of each element in the matched set
		/// 	to a value larger than the highest current zIndex in the document.
		/// 	(i.e., brings all elements in the matched set to the top of the
		/// 	z-index order.)
		/// </summary>	
		/// <param name="opt" type="Object" optional="true">
		/// 	(optional) Options, with the following possible values:
		/// 	increment: (Number, default = 1) increment value added to the
		/// 		highest z-index number to bring an element to the top.
		/// 	selector: (String, default = "body *") jQuery selector specifying
		/// 		the elements to use for calculating the highest zIndex.
		/// </param>
		/// <returns type="jQuery" />

		// Do nothing if matched set is empty
		if (this.length === 0) {
			return this;
		}

		opt = $.extend({increment: 1, selector: "body *"}, opt);

		// Get the highest current z-index value
		var zmax = $.topZIndex(opt.selector), inc = opt.increment;

		// Increment the z-index of each element in the matched set to the next highest number
		return this.each(function () {
			$(this).css("z-index", zmax += inc);
		});
	};

	})(jQuery);
  });
})(jQuery);

 
j(document).ready(function() {

	/* Homepage - Full Screen Display */
	j("a.fullsize").click(
		function(){
			j("div.header").slideToggle("slow","easeInOutBack");
			j(this).toggleClass("active");
			return false;
	});
		
	/* Global - Dropdown Navigation */
	j('div.menu ul li ul').hide();
	j('div.menu ul li').hover(function(){
		j(this).topZIndex();
		j(this).find('ul').show();
	},
	function(){
		j(this).find('ul').hide("fast","easeOutSine");
	;})

	LoadFadeImage();
	LoadImageLoading();
	
})

/* Image Loading Effect */
var i = 0; 
var int=0; 

function ImageLoading() {
	var images = j('.load').length;
	if (i >= images) {
		clearInterval(int);
		delete int;
	}
	j('.load:hidden').eq(0).fadeIn(200);
	i++;
}

function LoadImageLoading() {
	j('.load').hide()
	setInterval("ImageLoading(i)",500);
}

/* Image Fade Effect */
function LoadFadeImage() {
	j(".fade").fadeTo(125, 0.9); 
	
	j(".fade").hover(function(){
		j(this).fadeTo(75, 1.0); 
	},
	
	function(){
		j(this).fadeTo(125, 0.9);
	});
}

