/*
*	Simple Image Rotator
*	By Jason Boyer
*	Feel free to use at will!
*/
/*var current = $('#msg1');		
var delay = 7000;//9000 orig
$('#msg2').hide();
$('#msg3').hide();		
var number=3;
var isgoing = true;
var timer;

$(document).ready(function() {
	timer = setTimeout("nextItem("+number+")",delay);
});

function togglePlay() {
	if (isgoing) {
		clearTimeout(timer);
		$('#toggle').css('background-position', '-39px -22px');	
		isgoing = false; 
	} else {
		nextItem();
		isgoing = true; 
		timer = setTimeout("nextItem("+number+")",delay);
		$('#toggle').css('background-position', '-26px -22px');	
	}
}

function nextItem(num) {
	if(num==null){
		num = number;	
	}
	clearTimeout(timer);
	if(current.attr('id').replace('msg', '') != num) {		
		
		$('.control').css('background-position', '0 -22px');
		$('#item'+num).css('background-position', '-13px -22px');
		
		current.fadeOut(2000, function(){		
			current.hide();
		});
		
		$('#msg'+num).fadeIn(2000, function() {
			current = $("#msg"+num)
		});
	}
	if (number == 3) { 
		number = 1;
	} else {
		number += 1;
	}
	timer = setTimeout("nextItem("+number+")",delay);
	
	if (!isgoing) {
		isgoing = true; 
		$('#toggle').css('background-position', '-26px -22px');
	}
}
*/

var $tony;
jQuery.fn.exists = function(){return jQuery(this).length>0;}


$(function(){
    var $browserName = navigator.appName;
     if($("#rotation").exists()){ 
        $('#rotation img:first').show();
        $('#rotation img:last').addClass('last'); 
        if($browserName == 'Microsoft Internet Explorer'){
            $tony = setInterval("rotateIE()",6000);
		
        }else{
            $tony = setInterval("rotate()",6000);
		 
        }
        var $i = 0;
        $("#rotation img").each(function(){
            $(this).attr('rel',$i);
            $("#mastRot").append('<a rel="'+$i+'"></a>');
            $i++;
        });
        
        $("#mastRot a:first").addClass('active');
        
        $("#mastRot a").live('click',function(){
            $("#rotation img").each(function(){
                $(this).hide();
            });
            $("#rotation img[rel="+$(this).attr('rel')+"]").show();
            $("#mastRot a.active").removeClass('active');
            $(this).addClass('active');
            clearInterval($tony);
            if($browserName == 'Microsoft Internet Explorer'){
                $tony = setInterval("rotateIE()",6000);
            }else{
                $tony = setInterval("rotate()",6000);
            }    
        });
    }
})
function rotateIE(){
    if($('#rotation img:visible').hasClass('last')){
        $('#rotation img:visible').hide(); 
        $('#mastRot a.active').removeClass('active');
        $('#mastRot a[rel=0]').addClass('active');
        $('#rotation img:first').show();            
    }else{
        $('#mastRot a.active').removeClass('active'); 
        $('#rotation img:visible').hide().parent().next('a').children().show(); 
        $('#mastRot a[rel='+$('#rotation img:visible').attr('rel')+']').addClass('active');  
    }    
}
function rotate(){
    if($('#rotation img:visible').hasClass('last')){
        $('#rotation img:visible').fadeOut(2000);  
        $('#rotation img:first').fadeIn(2000); 
        $('#mastRot a.active').removeClass('active');
        $('#mastRot a[rel=0]').addClass('active');           
    }else{
        $('#mastRot a.active').removeClass('active');
        $('#rotation img:visible').fadeOut(2000).parent().next('a').children().fadeIn(2000); 
        $('#mastRot a[rel='+$('#rotation img:visible').parent().next('a').children().attr('rel')+']').addClass('active');  
    }    
}

