// JQuery Based Panel Rotator Application // gFly_Rotr V2.2009.12.02
// Grendelfly - A Division of SC&G Technology Solutions
// Requires JQuery: jquery-1.3.2.min.js or higher

// Updated 2010.02.16 - cleaned up sentax and documentation
// 2010.03.28 - Altered for Acorn Construction


$(function(){
$(document).ready(function() {


// Set Rotator Styles
$('#gFly_Rotr').css({
	'width':'720px',
	'height':'423px',
	'position':'relative',
	'overflow':'hidden'
	});	
$('#gFly_Rotr div').css({
	'position':'absolute',
	'display':'none'
	});	

$('div.vwr_thm img').css({'cursor':'pointer'});


// start up info
$('#gFly_Rotr div#frt_1').fadeIn(500);
$('#tm_1').css({'background-image':'url(/img/vwr_thm_bck_on.png)'});

var fTimer = ""; // Declears Variable fTime


// Rotator and Time Function
fTimer = setInterval(function(){fRotate()}, 5000); // timed at 5 seconds per rotation
							
function fRotate(){
	var nDiv = $('#gFly_Rotr div').length; nDiv = nDiv - 1; // Get number of divs in set
	var nPnl = $('#gFly_Rotr_Stats').html(); nPnl = parseInt(nPnl) + 1; // Get what div (panel) number we're currently on and moves one forward
	if (nPnl>nDiv) { nPnl=0;}; // if we've seen all panels let's start from the beginning
	
	$('div.vwr_thm').css({'background-image':'url(/img/vwr_thm_bck.png)'});
	$('#gFly_Rotr div').fadeOut(1800); // hide all divs
	$('#gFly_Rotr div').each(function (index, domEle) { // index is 'number count' / domEle is 'this'

		if (index==nPnl){			
			$('#tm_' + (nPnl+1)).css({'background-image':'url(/img/vwr_thm_bck_on.png)'});
			$(domEle).fadeIn(1800); // Change 'Show' effect here - show,fadeIn,slideDown
			$('#gFly_Rotr_Stats').html(parseInt(nPnl));
			return false; // stops process			
		}; // if (index==nPnl)
	}); // $('#gFly_Rotr div').each

}; // function fRotate()


// Select Function
$('div.vwr_thm').click(function() {
clearInterval(fTimer); // Stops Auto Rotate
$('#gFly_Rotr div').fadeOut(1200); // hide all divs

$('div.vwr_thm').css({'background-image':'url(/img/vwr_thm_bck.png)'});
$(this).css({'background-image':'url(/img/vwr_thm_bck_on.png)'});

	var get_num = this.id.replace("tm_",""); get_div = "frt_" + get_num;
	
	$('#' + get_div).fadeIn(1200); // Change 'Show' effect here - show,fadeIn,slideDown
	$('#gFly_Rotr_Stats').html(get_num-1);

}); // $('#wk_thm img').click


// Close Button ' Start Auto Rotate Through Panels
$('div.vwr_cls').css({'cursor':'pointer'});
$('div.vwr_cls').click(function() {
	$('div.vwr_cls').hide();
	$('div.vwr_thm').hide();
	$('div.vwr_bar').css({'height':'12px','margin-top':'-12px'});
	
	$('div.vwr_trgr').show();

clearInterval(fTimer); // Stops Auto Rotate
fTimer = setInterval(function(){fRotate()}, 5000); // timed at 5 seconds per rotation
	
}); // $('#srt').click


// Show Control Bar
$('div.vwr_trgr').mouseenter(function(){
	$('div.vwr_cls').show();
	$('div.vwr_thm').show();
	$('div.vwr_bar').animate({'height':'74px','margin-top':'-74px'},500);
	$('div.vwr_trgr').hide();
});



}); // $(document).ready
}); // $(function()
