
function theRotator() {
	//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
	
	setInterval('rotate()',4000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));

    if ( current.length == 0 ) current = $('div.rotator ul li:first');

	//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'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
        //var rndNum = Math.floor(Math.random() * sibs.length );
        //var next = $( sibs[ rndNum ] );
			

	//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}, 2000);

	//Hide the current image
	current.animate({opacity: 0.0}, 2000)
	.removeClass('show');
	
};



$(document).ready(function() {		
	//Load the slideshow
	theRotator();
	$('div.rotator').fadeIn(1000);
    $('div.rotator ul li').fadeIn(1000); // tweek for IE
});





/*demo6*/(function($){
    $.fn.collapser= function(options, beforeCallback, afterCallback) {
        
        var defaults = {
            target: 'next',
			targetOnly: null,
            effect: 'slide',
			changeText: true,
			expandHtml: 'Expand',
			collapseHtml: 'Collapse',
			expandClass: '',
			collapseClass:''
        };
        
        var options = $.extend(defaults, options);
		
		var expHtml,collHtml, effectShow, effectHide;
		
		if(options.effect == 'slide'){
			effectShow = 'slideDown';
			effectHide = 'slideUp';
		}else{
			effectShow = 'fadeIn';
			effectHide = 'fadeOut';
		}
		
		if(options.changeText == true){
			expHtml = options.expandHtml;
			collHtml = options.collapseHtml;
		}
		
		function callBeforeCallback(obj){
			if(beforeCallback !== undefined){
				beforeCallback.apply(obj);
			}
		}
		
		function callAfterCallback(obj){
			if(afterCallback !== undefined){
				afterCallback.apply(obj);
			}
		}
		
		function hideElement(obj, method){
			callBeforeCallback(obj);
			if(method == 1){
				obj[options.target](options.targetOnly)[effectHide]();
				obj.html(expHtml);
				obj.removeClass(options.collapseClass);
				obj.addClass(options.expandClass);
			}else{
				$(document).find(options.target)[effectHide]();
				obj.html(expHtml);
				obj.removeClass(options.collapseClass);
				obj.addClass(options.expandClass);
			}
			callAfterCallback(obj);
		}
		
		function showElement(obj, method){
			callBeforeCallback(obj)
			if(method == 1){
				obj[options.target](options.targetOnly)[effectShow]();
				obj.html(collHtml);
				obj.removeClass(options.expandClass);
				obj.addClass(options.collapseClass);
			}else{
				$(document).find(options.target)[effectShow]();
				obj.html(collHtml);
				obj.removeClass(options.expandClass);
				obj.addClass(options.collapseClass);
			}
			callAfterCallback(obj);
		}
		
		function toggleElement(obj, method){
			if(method == 1){
				if(obj[options.target](options.targetOnly).is(':visible')){
					hideElement(obj, 1);
				}else{
					showElement(obj, 1);
				}
			}else{
				if($(document).find(options.target).is(':visible')){
					hideElement(obj, 2);
				}else{
					showElement(obj, 2);
				}
			}
		}
		
		return this.each(function(){
		   
		   if($.fn[options.target] && $(this)[options.target]()){
				$(this).toggle(function(){		
					toggleElement($(this), 1);
				},function(){
					toggleElement($(this), 1);
				});	
				
		   }else{
			   
			   $(this).toggle(function(){
					toggleElement($(this), 2);
				},function(){
					toggleElement($(this), 2);
				});
		   }
		   
		   // Initialize  
		   if($.fn[options.target] && $(this)[options.target]()){
				if($(this)[options.target]().is(':hidden')){
					$(this).html(expHtml);
					$(this).removeClass(options.collapseClass);
					$(this).addClass(options.expandClass);
				}else{
					$(this).html(collHtml);
					$(this).removeClass(options.expandClass);
					$(this).addClass(options.collapseClass);
				}
			}else{
				if($(document).find(options.target).is(':hidden')){
					$(this).html(expHtml);
				}else{
					$(this).html(collHtml);
				}
			}
		   
        });
    };
    
})(jQuery);

/*demo6*/ $(document).ready(function(){$('.panel').hide();$('.demo6').collapser({target: 'next',effect: 'slide',changeText: 0, expandClass: 'expIco', collapseClass: 'collIco'}, function(){$('.panel').slideUp();	});});

