// JavaScript Document

if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}

var cancel;

var _hasImageTwo = true;
var _hasImageThree = true;

jQuery(document).ready(function() {
	
	//initial actions
	if(window.location.pathname != "/administration/scripts/editor.aspx" )
	{	

		if(window.location.pathname == "/index_single.html" )
		{
			var _one = jQuery('#one').text();

			var _Two = jQuery('#two');
			var _Three = jQuery('#three');
			
			if(_Two.length > 0 && _Three.length > 0)
			{
				_hasImageTwo = (_Two.text().trim().length > 0);
				_hasImageThree = (_Three.text().trim().length > 0);
			}
			
			if(!_hasImageTwo && !_hasImageThree)
			{
				jQuery('.rotatorButtons').hide();
				return;
			}
		}
		
		jQuery('.rotatorContent').hide();
		jQuery('#one').show();
		jQuery('.rotatorButtons a:first').addClass("active");

		jQuery('.tabContent').hide();
		jQuery('#tabOne').show();
		jQuery('.tabsContainer a:first').addClass("active");
		//initial actions
		
		//click actions
		jQuery('.rotatorButtons a').click(function() {
			jQuery(".rotatorButtons a").removeClass("active");
			jQuery(this).addClass("active");
			var activeBtn = jQuery(this).attr('href');
			jQuery('.rotatorContent').fadeOut();
			jQuery(activeBtn).fadeIn();
			cancel = "true";
			return false;
		});
		
		jQuery('.tabsContainer a').click(function() {
			jQuery(".tabsContainer a").removeClass("active");
			jQuery(this).addClass("active");
			var activeTab = jQuery(this).attr('href');
			jQuery('.tabContent').hide();
			jQuery(activeTab).show();
			return false;
		});
		//click actions
	
		setTimeout("One()", 7000);
}	

});
//end document ready

function One(){
	if(cancel != "true"){
		jQuery(".rotatorButtons a").removeClass("active");
		jQuery(".rotatorButtons a:nth-child(2)").addClass("active");
		jQuery('.rotatorContent').fadeOut();
		jQuery("#two").fadeIn();
		setTimeout("Two()", 7000);
	}
}
function Two(){
	if(cancel != "true"){
		jQuery(".rotatorButtons a").removeClass("active");
		jQuery(".rotatorButtons a:nth-child(3)").addClass("active");
		jQuery('.rotatorContent').fadeOut();
		jQuery("#three").fadeIn();
		setTimeout("Three()", 7000);
	}
}
function Three(){
	if(cancel != "true"){
		jQuery(".rotatorButtons a").removeClass("active");
		jQuery(".rotatorButtons a:nth-child(1)").addClass("active");
		jQuery('.rotatorContent').fadeOut();
		jQuery("#one").fadeIn();
		setTimeout("One()", 7000);
	}
}
