var current_feature = 1;
var num_of_features = 0;
var oldNum = 0;
var newNum = 0;
var old_img = 0;
var first_time = true;

$(function(){
	
	num_of_features = $("#main_pano span").length;
	
	// make sure the pano is on the page
	if(num_of_features)
	{
		show_pano();
		
		// =========================================
		//	SET UP TIMER FOR FEATURES
		// =========================================
		/*$(document).everyTime(5000, function(){
			show_pano();
		});*/
	}
	
});

function show_pano()
{
	var show = "";
	
	// while the new number is the same as the old one
	while(oldNum == newNum)
		newNum = Math.floor(Math.random()*num_of_features);
	
	// store the old selection
	oldNum = newNum;
	
	// get new img
	var new_img = $("#img_"+newNum).html();
	
	// check to see which pano is going to show up next
	if(($("#pano_2").css("display") == "none") || first_time)
		show = '2';
	else
		show = '1';
	
	// setup hidden pic
	$("#pano_"+show).attr('src', new_img);
	
	// wait for the image to load into the DOM (no red X in IE)
	$("#pano_"+show).load(function(){
		// flip the two panos
		if(show == '2')
		{
			// PANO TWO
			$("#pano_2").fadeIn("slow", function(){
												   
				// if first time around, show the first pano so the next loops work
				if(first_time)
				{
					$("#pano_1").show();
					first_time = false;
				}
				
				setTimeout("show_pano()",5000);

			});
		}
		else
		{
			// PANO ONE
			$("#pano_2").fadeOut("slow", function(){
				// =========================================
				//	SET UP TIMER FOR FEATURES
				// =========================================
				setTimeout("show_pano()",5000);
			});
		}
	});
}
