



jQuery.fn.extend({
	everyTime: function(interval, label, fn, times, belay) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, times, belay);
		});
	},
	oneTime: function(interval, label, fn) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, 1);
		});
	},
	stopTime: function(label, fn) {
		return this.each(function() {
			jQuery.timer.remove(this, label, fn);
		});
	}
});

jQuery.extend({
	timer: {
		guid: 1,
		global: {},
		regex: /^([0-9]+)\s*(.*s)?$/,
		powers: {
			// Yeah this is major overkill...
			'ms': 1,
			'cs': 10,
			'ds': 100,
			's': 1000,
			'das': 10000,
			'hs': 100000,
			'ks': 1000000
		},
		timeParse: function(value) {
			if (value == undefined || value == null)
				return null;
			var result = this.regex.exec(jQuery.trim(value.toString()));
			if (result[2]) {
				var num = parseInt(result[1], 10);
				var mult = this.powers[result[2]] || 1;
				return num * mult;
			} else {
				return value;
			}
		},
		add: function(element, interval, label, fn, times, belay) {
			var counter = 0;
			
			if (jQuery.isFunction(label)) {
				if (!times) 
					times = fn;
				fn = label;
				label = interval;
			}
			
			interval = jQuery.timer.timeParse(interval);

			if (typeof interval != 'number' || isNaN(interval) || interval <= 0)
				return;

			if (times && times.constructor != Number) {
				belay = !!times;
				times = 0;
			}
			
			times = times || 0;
			belay = belay || false;
			
			if (!element.$timers) 
				element.$timers = {};
			
			if (!element.$timers[label])
				element.$timers[label] = {};
			
			fn.$timerID = fn.$timerID || this.guid++;
			
			var handler = function() {
				if (belay && this.inProgress) 
					return;
				this.inProgress = true;
				if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
					jQuery.timer.remove(element, label, fn);
				this.inProgress = false;
			};
			
			handler.$timerID = fn.$timerID;
			
			if (!element.$timers[label][fn.$timerID]) 
				element.$timers[label][fn.$timerID] = window.setInterval(handler,interval);
			
			if ( !this.global[label] )
				this.global[label] = [];
			this.global[label].push( element );
			
		},
		remove: function(element, label, fn) {
			var timers = element.$timers, ret;
			
			if ( timers ) {
				
				if (!label) {
					for ( label in timers )
						this.remove(element, label, fn);
				} else if ( timers[label] ) {
					if ( fn ) {
						if ( fn.$timerID ) {
							window.clearInterval(timers[label][fn.$timerID]);
							delete timers[label][fn.$timerID];
						}
					} else {
						for ( var fn in timers[label] ) {
							window.clearInterval(timers[label][fn]);
							delete timers[label][fn];
						}
					}
					
					for ( ret in timers[label] ) break;
					if ( !ret ) {
						ret = null;
						delete timers[label];
					}
				}
				
				for ( ret in timers ) break;
				if ( !ret ) 
					element.$timers = null;
			}
		}
	}
});

if (jQuery.browser.msie)
	jQuery(window).one("unload", function() {
		var global = jQuery.timer.global;
		for ( var label in global ) {
			var els = global[label], i = els.length;
			while ( --i )
				jQuery.timer.remove(els[i], label);
		}
	});










$(document).ready(function() {
	//On Hover Over
	function megaHoverOver(){
		$(this).find(".sub").css('z-index', 9999);
	    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
	    (function($) {
	        //Function to calculate total width of all ul's
	        jQuery.fn.calcSubWidth = function() {
	            rowWidth = 0;
	            //Calculate row
	            $(this).find("ul ul").each(function() { //for each ul...
	                rowWidth += $(this).width() +2; //Add each ul's width together
	                if(rowWidth > 900) {rowWidth = 900;}
	            });
	        };
	    })(jQuery); 
	
	    if ( $(this).find(".row").length > 0 ) { //If row exists...
	
	        var biggestRow = 0;	
	
	        $(this).find(".row").each(function() {	//for each row...
	            $(this).calcSubWidth(); //Call function to calculate width of all ul's
	            //Find biggest row
	            if(rowWidth > biggestRow) {
	                biggestRow = rowWidth;
	            }
	           
	        });
	
	        $(this).find(".sub").css({'width' :biggestRow}); //Set width
	        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin
	
	    } else { //If row does not exist...
	
	        $(this).calcSubWidth();  //Call function to calculate width of all ul's
	        //$(this).find(".sub").css({'width' : rowWidth}); //Set Width
	
	    }
	}
	//On Hover Out
	function megaHoverOut(){
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
	      $(this).hide();  //after fading, hide it
	  });
	}



	//Set custom configurations
	var config = {
	     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
	     interval: 100, // number = milliseconds for onMouseOver polling interval
	     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
	     timeout: 500, // number = milliseconds delay before onMouseOut
	     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};
	
	$("ul#topnav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
	$("ul#topnav li").hoverIntent(config); //Trigger Hover intent with custom configurations


	
	
	
	//When page loads...
	$(".inner_tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".inner_tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".inner_tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		
		return false;
	});
	
	
	
	
	
	
	
	
	$(".inner_tab_contentB").hide(); //Hide all content
	$("ul.tabsB li:first").addClass("active").show(); //Activate first tab
	$(".inner_tab_contentB:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabsB li").click(function() {

		$("ul.tabsB li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".inner_tab_contentB").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		
		return false;
	});
		
	

	// copyright 2010 - luminosity-group.com ribbon banner
	
	//fix IE7 Z-Index Bug
		$(function() {
			var zIndexNumber = 1000;
			$('div').each(function() {
				$(this).css('zIndex', zIndexNumber);
				zIndexNumber -= 10;
			});
		});
	
	// rearrange z-index because of ie7 --- thanks microsoft
	$('#luminosityGroupBanner #BannerContent a').css('z-index', '100');	
	$('#luminosityGroupBanner #BannerContent a img').css('z-index', '90');
	$('#luminosityGroupBanner #BannerContent a').hide();
	$('#luminosityGroupBanner #BannerContent a:first').show();
	
	var bannerItemCount = 0;
	var lastItem;
	var currentItem;
	var myTarget;

	$("#luminosityGroupBanner").find("#BannerContent img").each(function() {	//for each row...
	            bannerItemCount += 1;
	           
	            
	            if(bannerItemCount == 1){
	            $('<a href="#target'+bannerItemCount+'" class="active">'+bannerItemCount+'</a>').appendTo('#middle');
	            } else {
	            $('<a href="#target'+bannerItemCount+'"">'+bannerItemCount+'</a>').appendTo('#middle');
	            }
	            
	            $(this).parent().attr('id', 'target'+bannerItemCount+'');
    
	 });
	 
	
	 
		 
	 $('#middle a').click(function(){
	 	myTarget = $(this).attr("href");
	 	$('#luminosityGroupBanner #BannerContent a').fadeTo(200,0); 	
	 	$(myTarget).fadeTo(800, 1);
	 	$('#middle a').removeClass('active');
	 	$(this).addClass('active');	
	 	
	 	return false;
			 
	 });
	            
	    
	 $( "#luminosityGroupBanner") .everyTime ( '15s', function (){
	 		var myTarget;
	 		$('#middle a').last().addClass('last')
	 		currentItem = $('#middle').find('.active');
	 		
	 		if($(currentItem).hasClass('last')){
	 			//if last, go to start
	 		 	$(currentItem).removeClass('active');
	 		 	$('#middle a').first().addClass('active')
	 		 	myTarget = $('#middle a').first().attr("href");
	 		 	$('#luminosityGroupBanner #BannerContent a').fadeTo(200,0);	
	 			$(myTarget).fadeTo(1000, 1);
	 		 		
	 		} else {
	 			// go to next
	 			$(currentItem).removeClass('active').next().addClass('active');
	 			myTarget = $(currentItem).next().attr("href");
	 		 	$('#luminosityGroupBanner #BannerContent a').fadeTo(200,0);	
	 			$(myTarget).fadeTo(1000, 1);
	 		};
			
			 
		}, 99);   
	    
	            

		
	            
	            	
	
	
});//END OF DOCUMENT READY
