// JavaScript Document
var banner_top_pos = 0;

function fixBannerPos()
{
	var rotating_banners = $(".rotating_banner");
	
	//var banner_pos = $(rotating_banners[0]).offset();
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	//
	//	JUL 2010:	Changed 'position' : 'absolute', to 'position' : 'static',
	//			because the rotating_container was in the middle of the page 
	//			instead of where it should be
	//
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	var cssObj = {
		'position' : 'static',
		'z-index' : "20"
	}
	
	$(rotating_banners).css(cssObj);
	
	$("#rcc").css("z-index","30");
}

$(document).ready(function()
{
	banner_top_pos = $("#rotating_container").offset().top;
	
	var hidden_banners = $(".b_image");
	for (h=0; h<hidden_banners.length; h++)
	{
		$(hidden_banners[h]).css("background", "url('/components/rotating-container/images/rotating_banners/"+$(hidden_banners[h]).attr("id").substr(2)+".jpg')");
	}
	
	var bnum = 0;
	var rotating_banners = $(".rotating_banner");
	
	//don't have to worry about all the fancy stuff if there's only 1 banner
	if (rotating_banners.length == 1)
	{
		return;
	}
	
	var banner_pos = $(rotating_banners[0]).offset();
	
	fixBannerPos();
	
	if (!jQuery.support.boxModel)
	{
		var cssObj2 = {
			'background-image' : 'none',
			'background-color' : '#E5E5E5'
		}
		$(".b_text").css(cssObj2);
	}
	
	var iid = window.setInterval(function()
	{
		$(rotating_banners[bnum]).fadeOut(1500);
		if (bnum+1 == rotating_banners.length)
			bnum = 0;
		else
			bnum++;
		$(rotating_banners[bnum]).fadeIn(1500);
		$("#home_content #rotating_container #rcc ul li.selected").removeClass("selected");
		$("#home_content #rotating_container #rcc ul li:nth-child("+(bnum+1)+")").addClass("selected");
	}, 7500);
	
	$(".b_text").click(function()
	{
		top.location.href = $(this).parent().children("a").attr("href");	
	});
	
	//setup the 1-5 buttons for banner navigation
	var rc_control = "<ul>";
	for (var r=1; r<=rotating_banners.length; r++)
	{
		rc_control += "<li class='";
		if (r==1)
			rc_control += "rcc_left selected";
		else if (r==rotating_banners.length)
			rc_control += "rcc_right";
		else
			rc_control += "rcc_middle";
		rc_control += "'>"+r+"</li>";
	}
	rc_control += "</ul>";
	
	$("#home_content #rotating_container #rcc").html(rc_control);
	
	//position the 1-5 buttons to the correct place
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	//
	//	JUL 2010:	Changed 'position' : 'absolute', to 'position' : 'static',
	//			because the rotating_container was in the middle of the page 
	//			instead of where it should be
	//
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 	
	var cssObj3 = {
		'display' : 'block',
		'position' : 'absolute',
		'top' : (banner_pos.top-235)+"px",
		'left' : (banner_pos.left+270)+"px"
	}
	$("#home_content #rotating_container #rcc").css(cssObj3);
	
	$("#home_content #rotating_container #rcc ul li").click(function()
	{
		var banner_id = $(this).html();
		clearInterval(iid);
		$("#home_content #rotating_container #rcc ul li.selected").removeClass("selected");
		$("#home_content #rotating_container #rcc ul li:nth-child("+(banner_id)+")").addClass("selected");
		
		$(rotating_banners[bnum]).hide();
		bnum = banner_id-1;
		$(rotating_banners[bnum]).show();
	});
	
});

window.onresize = fixBannerPos;
