
//javascript code by Kevin Cook for rotating sidebar functionality. 3 Separate functions needed for different stylings
//theRotator/rotate() for standard, right floated sidebars
//theRotator_dyk/rotate_dyk() for left floated, "did you know" sidebars
//theRotator_home/rotate_home() for left floated, homepage sidebars
function theRotator(interval) {
		//$('div#rotator').show();
		
		$('div#rotator').height($('div#rotator ul li.show').height());
        //Set the opacity of all images to 0
        $('div#rotator > ul > li').css({ opacity: 0.0 });
		
        //Get the first image and display it (gets set to full opacity)
        $('div#rotator > ul > li:first').css({ opacity: 1.0 });

        //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
        window["theRotator_interval"] = setInterval('rotate()', interval);
		 
    }
function rotate() {
	//Get the first image
	var current = ($('div#rotator ul li.show') ? $('div#rotator ul li.show') : $('div#rotator ul li:first'));
//	alert(current.height());

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') : current.next()) : $('div#rotator ul li:first'));
	if(current.height() > next.height()){ $('div#contactSideBar').hide(); $('div#rotator').height(next.height() + 15); $('div#contactSideBar').delay(500).fadeIn(); }
	else $('div#rotator').height(next.height() + 15);
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 500);

	//Hide the current image
	current.animate({ opacity: 0.0 }, 500)
	.removeClass('show');

};
function theRotator_dyk(interval) {
		//$('div#rotator').show();
		
		$('div#rotator_dyk').height($('div#rotator_dyk ul li.show').height());
        //Set the opacity of all images to 0
        $('div#rotator_dyk ul li').css({ opacity: 0.0 });
		
        //Get the first image and display it (gets set to full opacity)
        $('div#rotator_dyk ul li:first').css({ opacity: 1.0 });

        //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
        setInterval('rotate_dyk()', interval);
		 
    }
function rotate_dyk() {
	//Get the first image
	var current = ($('div#rotator_dyk ul li.show') ? $('div#rotator_dyk ul li.show') : $('div#rotator_dyk ul li:first'));
//	alert(current.height());

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator_dyk ul li:first') : current.next()) : $('div#rotator_dyk ul li:first'));
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 500);

	//Hide the current image
	current.animate({ opacity: 0.0 }, 500)
	.removeClass('show');

};
function theRotator_home(interval) {
		//$('div#rotator').show();
		
		$('div#rotator_home').height($('div#rotator_home ul li.show').height());
        //Set the opacity of all images to 0
        $('div#rotator_home ul li').css({ opacity: 0.0 });
		
        //Get the first image and display it (gets set to full opacity)
        $('div#rotator_home ul li:first').css({ opacity: 1.0 });

        //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
        setInterval('rotate_home()', interval);
		 
    }
function rotate_home() {
	//Get the first image
	var current = ($('div#rotator_home ul li.show') ? $('div#rotator_home ul li.show') : $('div#rotator_home ul li:first'));
//	alert(current.height());

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator_home ul li:first') : current.next()) : $('div#rotator_home ul li:first'));
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 500);

	//Hide the current image
	current.animate({ opacity: 0.0 }, 500)
	.removeClass('show');

};
$(window).load(
	function() { 
		$('div#rotator_home').show();
		$('div#rotator').show(); 
		$('div#rotator').height($('div#rotator ul li.show').height() + 15); 
		$('div#rotator_dyk').show(); 
		$('div#rotator_dyk').height($('div#rotator_dyk ul li.show').height() + 15); 
		$('div.contactSideBar').show(); 
	}
)
