var rotator_curr = "";

var rotator_time = 5000;
var mouse_wait = 5000;
var do_mouse_wait = false;
var do_rotation = false;


	jQuery.preloadImages = function()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
	    jQuery("<img>").attr("src", arguments[i]);
	  }
	}

function set_up_rotator(time, mouseOverWait, rotate)
{
	rotator_time = time;
	mouse_wait = mouseOverWait;
	do_rotation = rotate;	
}


function change_rotator( sp, changeTo )
{
	$("#article-blank").show();	
	$("#article-image").hide();
	
	//Change class out...
	$(".big").removeClass("big");
	changeTo.addClass("big");


	$("#article-image").css("background", "url("+model[sp][2]+")");
	$("#article-title").html(model[sp][0]);
	$("#article-intro").html(model[sp][1]);
	$("#icontab").html(model[sp][8]);
	
			
	$("#article-href_text").html(model[sp][5]);
			
	Cufon.replace('.cufon_font');
	if(model[sp][6] == "video")
	{
	    document.getElementById('article-href_link').href = model[sp][3];
	    document.getElementById('article-href_link').target = "_self";	     
	}else{
	    document.getElementById('article-href_link').href = model[sp][3];
	    document.getElementById( "article-href_link" ).onclick = function() {};
	    document.getElementById('article-href_link').target = "_blank";
	}
	$("#article-blank").fadeOut("slow");	
	$("#article-image").fadeIn("slow");
}
var statMessage = "";


$().ready( function() {
	
	if(do_rotation)
	{
		$().everyTime(rotator_time, function(i) {
  			
  			if(!do_mouse_wait)
  			{
  				//GET CURRENT BIG and go to the next small..
  				var currRotator = $(".big");
  				var nextRotator = $(".big").next(".rotator");
  				
  				var name = nextRotator.children().attr("id");
  				if(name == "undefined" || name == "null" || name == null || name == undefined)
  				{
  					name = "a1";  				
  				}
  				
				var sp = stringFilter(name, 'a');
  				
  				//window.status=name+" ";
  				change_rotator( sp, $("#art"+sp));
  			}
  			
		}, 0);
	}
	
	$("#rotator_obj").mouseover( function() {
		do_mouse_wait = true;
	});
	
	$("#rotator_obj").mouseout( function() {
		do_mouse_wait = false;
	});
	
/* 5/27/10 - TWL - Commenting out this code because it's pushing down the article in the BigRotator. Not sure why this code is here in the first place.
	$(".plan, .shop").mouseover( function() { 
		$("#article-title").hide();		
	});
	
	$(".plan, .shop").mouseout( function() {
		$("#article-title").show();		
	});
*/
	

	$(".rotator").mouseover( function() {

		if($(this).hasClass("big")){
			//Do nothing..
		}else{
		
			var name = $(this).children().attr("id");
			var sp = stringFilter(name, 'a');
			
			change_rotator(sp, $(this));
		}
	});	
});


function stringFilter (input, strip) {
	s = input;
	filteredValues = strip; //"1234567890";     // Characters stripped out
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
	var c = s.charAt(i);
	if (filteredValues.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}
