var t; // just our timeout variable that we set/clear throughout
var page = 1; // the current page of the banner scroll
var max; // max number of pages so we know the limit
var stopped = false; // whether or not someone has clicked on a number, pausing the slideshow
	
$(document).ready(function(){
	// if our user is using a mobile browser we display bigger buttons on the banner by adding this class
	if ( masterDetector() ){
		$('ul#pagination').addClass('phat');
	}
	
	// counts the number of banners on the page and sets the max
	max = $('div.slider').length;
	
	// to the buttons on the banner we apply click functions that will pause the auto-progression
	// get the number of the page and call the function to bring it up
	$('#pagination li').click(function(){
		if ( false == $('div.slider.animating').hasClass('animating') ) {
			window.clearTimeout(t);
			stopped = true;
			pagePrep = parseInt($(this).attr('id').substring(5));
			page = pagePrep;
			nextPage();
		}
	});
	
	// here we start off our auto-progression of banners, executes nextPage() after 10 seconds
	t=window.setTimeout(nextPage, 10000);
});
function nextPage()
{	
	// pauses the timer as we work
	window.clearTimeout(t);

	// we capture the number of the last active banner
	oldPage = $('div.slider.on').attr('id').substring(6);

	// if we've paused the auto-progression this means we don't want to advance the page variable
	// since we've already set page to the banner we want
	if ( !stopped ) {
		if ( page < max ) {
			page++;
		}
		else {
			page = 1;
		}
	}
	
	// our banner animation
	$('#banner'+page).css({'z-index':'3','opacity':'0','left':'0'}).addClass('animating').animate({opacity:'1'},1000,function(){
		$('#banner'+oldPage).css({'left':'980px','z-index:':'2'}).removeClass('on');
		$(this).css('z-index','2').removeClass('animating').addClass('on');
		$('#pagination li.on').removeClass('on');
		$('#pagination li#click'+page).addClass('on');
	});

	// if the auto-progression hasn't been haulted we set up to progress in the next 10 seconds
	if ( !stopped ) {
		t=window.setTimeout(nextPage, 10000);
	}
}



/*//////////////////////////////////////////////

MOBILE DETECTION SECTION
this code was modified from code which detected a myriad of browswers individually
I have updated it to simply detect one of many mobile browsers and then be done
since discovering the specific browser isn't important for our needs

//////////////////////////////////////////////*/

function masterDetector() {
	var mobile = false;
	var uagent = navigator.userAgent.toLowerCase();
	mobileList = new Array(
		"iphone",
		"ipod",
		"series60",
		"symbian",
		"android",
		"windows ce",
		"blackberry",
		"palm"
	);
	for ( i = 0; i < mobileList.length; i++){
		 if (uagent.search(mobileList[i]) > -1) {
			mobile = true;
		 }
	}
	return mobile;
}

