// home page specific JS

$(document).ready(function(){

	//insert images for text wrapping
	/*$(".homefeature h2, .homefeature h1").each(function () {

		var imagefloats = "\n\n"+
			'<div class="homepageInsert first" style="height:46px; width:32px;"></div>' + "\n" +
			'<div class="homepageInsert" style="height:22px; width:37px;"></div>' + "\n" +
			'<div class="homepageInsert" style="height:23px; width:50px;"></div>' + "\n" +
			'<div class="homepageInsert" style="height:18px; width:60px;"></div>' + "\n" +
			'<div class="homepageInsert" style="height:15px; width:67px;"></div>' + "\n" +
			'<div class="homepageInsert" style="height:22px; width:77px;"></div>' + "\n" +
			'<div class="homepageInsert" style="height:73px; width:82px; clear: left;"></div>' + "\n";
		$(this).before(imagefloats);
	});*/// /end image insert
			/*'<div class="" style=" float: left; height:19px; width:225px;" /></div>' + "\n" + forces top padding*/
			/*'<div style="float: right; margin-top: -166px; _margin-top: 0;  height:160px; width:288px; " /></div>' + "\n"; floats to the right.  forces a width */

	//home page hovers
	$('#selectionmenu').tabs({fxFade: true, fxSpeed: 'slow'});
	
	// setup for custom slideshow function (follows)
	$('.ui-tabs-panel:not(:hidden)').addClass('currentslide');
	
	// auto slide changes executed outside of tabs. stops when tab is clicked.
	var changeSlide = function() {
		if ($('.currentslide:not(:hidden)').length > 0) {
			var currentslide = $('.currentslide');
			var nextslide = (currentslide.next('.ui-tabs-panel').length > 0) ? currentslide.next('.ui-tabs-panel') : $('#maincontent .ui-tabs-panel:first');
			
			currentslide.removeClass('currentslide')
				.addClass('ui-tabs-hide')
				.fadeOut('slow', function(){
						nextslide.fadeIn('slow')
							.removeClass('ui-tabs-hide')
							.addClass('currentslide')
			});
			var nextbutton = ($('#selectionmenu .ui-tabs-selected').next('li').length > 0) ? $('#selectionmenu .ui-tabs-selected').next('li').addClass('ui-tabs-selected') : $('#selectionmenu li:first').addClass('ui-tabs-selected');
			$('#selectionmenu .ui-tabs-selected').removeClass('ui-tabs-selected');
			nextbutton.addClass('ui-tabs-selected');
		} else { 
			clearInterval(slideshow);
			$('.currentslide').removeClass('currentslide');
			return false;
		}
	}
	var slideshow = setInterval(changeSlide, 10000);
	
	$('#selectionmenu a').mousedown(function(){ $(this).addClass('mousedown');}).mouseup(function(){ $(this).removeClass('mousedown');});
	
	var timer;
	$('#headlines li').each(function(){
		var current = $(this);
		var triggernext = function(){ current.blur() }
		current.css('display', 'none').blur(function(){
				var nextone = (current.next('li').length>0) ? current.next('li') : $('#headlines li:first');
				current.fadeOut('700', function(){
					clearTimeout(timer);
					nextone.focus();
				});
				return false;
			}).focus(function(){
				current.fadeIn('500', function(){
					timer = setTimeout(triggernext, 4500);
				}).bind("mouseover",function(){ 
			clearTimeout(timer);
		}).bind("mouseout",function(){
			timer= setTimeout(triggernext, 4500);
		});
				return false;
			});
	});
	$('#headlines li:first').focus();

}); //doc.ready

