/********************************************************************************\
	On Load Events, initiate jQuery apps on selected items
\********************************************************************************/
$(function() {
	$('#gw-nav .wrapper > ul').gwMenu();
	$().gwReload({ seconds:60 });
	$('.gw-carousel').gwCarousel({show: 3, showPageControls:true});
	$('.gwtabs').each(function(){ 
		$(this).gwTabs() 
	});
	$('.sf-showcase').gwSectionFront();
});



/********************************************************************************\
	Doubleclick variables 
\********************************************************************************/
var axel = Math.random() + "";
var ord = axel * 1000000000000000000;
var sgi_ord = Math.random()*10000000000000000;
var sgi_tile = 1;



/********************************************************************************\
	Tabbed Content
		- content should have one ul with list of links
		- grabs these links and associates them with <div>s of same class
\********************************************************************************/
jQuery.fn.gwTabs = function() {
	var content = this;
	//first div is visible content
	var visible = $('div:first', content)[0];
	
	//grab list's links and cycle through each
	$('>ul>li>a', content).each(function(){
		//grab window with same class
		var link_class = $(this).attr('class');
		//careful, must make class pair unique and not a substring of another
		var selector = 'div[class*="' + link_class + '"]';
		var window = $(selector, content)[0];
		if(!window) return true; //link does not have window pair
		
		//activate link
		$(this).click(function(e){
			e.preventDefault();
			// remove all active, add to current
			$('>ul>li>a', content).removeClass('active');
			$(this).addClass('active');
			$(window).toggleClass('hide');
			$(visible).toggleClass('hide');
			visible = window;
		});
		
		//add active class to link
		if($(visible).hasClass($(this).attr('class')))
			$(this).addClass('active');		
	});	
};


/********************************************************************************\ 
	Section Front Showcase
\********************************************************************************/
jQuery.fn.gwSectionFront = function(sfDefaults) {
	var sfDefaults = jQuery.extend({		
	}, sfDefaults);
	
	var thumbs = $(this).find('> ul > li');
	var visible = $(this).find('.item')[0];
	
	// Add click events to each sub story thumb
	thumbs.each(function(){
		if(this.id){
			var item = $('#show-' + this.id);
			if(item.length){
				$(this).click(function(e){
					e.preventDefault();
					$(visible).css({display: 'none' });
					$(item).css({display: 'block' });
					visible = item;
				});
			}	
		}
	});
}


/********************************************************************************\
	Ad Refresh app
\********************************************************************************/
jQuery.fn.gwReload = function(reloadDefaults){
	var adCount = 1; //used for position and tiling
	var num=1;
}


