//JavaScript
// dyanmically center navigation
function scaleNav(){
	var totalWidth = 0;
	jQuery('ul.nav-primary li').each(function(){
		totalWidth = totalWidth + jQuery(this).width();
	});
	if(totalWidth < 751){
		paddingleft = ((701 - totalWidth) / 2) + 50;
		jQuery('ul.nav-primary').css("padding-left", paddingleft+"px");
		//alert(totalWidth);
	}
}

/************** Scale homepage left column dynamically **************/

jQuery(document).ready(function(){
	scaleRightColumn();
});

jQuery(window).resize(function(){
	scaleRightColumn();
})

//var minWidth = 1280;
var minWidth = 1133;
function scaleRightColumn(){
	windowWidth = jQuery(window).width();
	if(windowWidth < minWidth){
		jQuery('div.column-right').css('width', '810px');
		jQuery('div.wrap-master').css('width', minWidth+'px');
	}else{
		newWidth = windowWidth - 323;
		jQuery('div.column-right').css('width', newWidth+'px');
		jQuery('div.wrap-master').css('width', windowWidth+'px');
		
		var offset = ((windowWidth - 608)/2) - 353;
		if(offset > 0){
			offset = offset/1.75
			jQuery('div.content').css('margin-left', offset+'px');
		}
		//jQuery('span.debug').html(offset);
	}
	jQuery('div.column-right').css('display', 'block');
}
/************** /Scale homepage left column dynamically **************/

/************** HOME HERO SLIDER **************/
var imageDelay = 3750 //length each image is displayed before rotation in milliseconds
var fadeDuration = 300 //length of fade in milliseconds 
var currentItem = 1;
var totalItems = jQuery('div.wrap-slider div').length;

function rotateImage(){
	nextItem = (currentItem == totalItems) ? 1: currentItem+1;
	jQuery('div.wrap-slider div.item'+nextItem).css('z-index', '-1');
	jQuery('div.wrap-slider div.item'+nextItem).css('display', 'block');
	jQuery('div.wrap-slider div.item'+currentItem).fadeOut(fadeDuration, function(){
		jQuery('div.wrap-slider div.item'+nextItem).css('z-index', '1');
		//highlight next hero nav item
		jQuery('ul.nav-hero-home li.item'+currentItem).removeClass('current');
		jQuery('ul.nav-hero-home li.item'+nextItem).addClass('current');		
		currentItem = nextItem;
	});

}
var rotation;
function rotation(){
	rotation = setInterval('rotateImage()', imageDelay);
}

jQuery('ul.nav-hero-home li').click(function(){
	nextItem = jQuery(this).attr('class').split(' ')[0].replace("item", "");
	rotation = window.clearInterval(rotation);
	jQuery('div.wrap-slider div.item'+nextItem).css('z-index', '-1');
	jQuery('div.wrap-slider div.item'+nextItem).css('display', 'block');
	jQuery('div.wrap-slider div.item'+currentItem).fadeOut(fadeDuration, function(){
		jQuery('div.wrap-slider div.item'+nextItem).css('z-index', '1');
		//highlight next hero nav item
		jQuery('ul.nav-hero-home li.item'+currentItem).removeClass('current');
		jQuery('ul.nav-hero-home li.item'+nextItem).addClass('current');		
		currentItem = nextItem;
	});
	
});

/************** HOME HERO SLIDER **************/
