////////////////////
//// set speeds ////
////////////////////
var wait_to_load = 500;
var change_speed = 1000;
var rotation_speed = 6000;

////////////////
////  paths ////
////////////////
var site_path = "http://www.southernpoliceequipment.com"
var img_path = site_path + "/images/contact/"

///////////////////////////////////////
//// array of promo images to show ////
///////////////////////////////////////
var promo_image_Array = new Array();
promo_image_Array.push(img_path + "RSign.jpg");
promo_image_Array.push(img_path + "StoreIntRight.jpg");
promo_image_Array.push(img_path + "StoreIntLeft.jpg");


//////////////////////////////
//// array of promo links ////
//////////////////////////////
var promo_link_Array = new Array();
promo_link_Array.push("");
promo_link_Array.push("");
promo_link_Array.push("");


////////////////////////////////////////////
//// array holding position of rotation ////
////////////////////////////////////////////
var pos_rotation_Array = new Array();
pos_rotation_Array[0] = "0";




////////////////////////////////////////////////////////////
//// start the homepage promos 1 second after page load ////
////////////////////////////////////////////////////////////
function retail_promos()
{
	var howmany = promo_image_Array.length - 1
	var randomMenu = Math.floor(Math.random() * howmany)
	pos_rotation_Array.splice(0,1,randomMenu);
	var show_content = setTimeout("start_promos("+parseInt(randomMenu)+")",wait_to_load);
}


//////////////////////////////////////////////////
//// call functions to load and rotate promos ////
//////////////////////////////////////////////////
function start_promos(randomMenu)
{
	show_hide_promo_divs();
	set_blenddiv_start_background(parseInt(randomMenu));
	build_promo_scroll_links(parseInt(randomMenu));
	set_blenddiv_anchors(parseInt(randomMenu));
	start_rotation(parseInt(randomMenu));
}

//////////////////////////////////////////////
//// start animation / rotation of promos ////
//////////////////////////////////////////////
function start_rotation(randomMenu)
{
	menuInterval = setInterval("rotate_promo_image("+parseInt(randomMenu)+");", rotation_speed);
}

///////////////////////
//// stop rotation ////
///////////////////////
function stop_rotate()
{
	clearInterval(menuInterval);
}



///////////////////////////////////////////
//// rotate the promo images and links ////
///////////////////////////////////////////
function rotate_promo_image(randomMenu)
{
	try
	{
		var max_count = promo_image_Array.length - 1
		var next_id = parseInt(pos_rotation_Array[0])
		if(next_id < max_count)
		{
			next_id = next_id + 1
		}
		else
		{
			next_id = 0
		}
		pos_rotation_Array.splice(0,1,next_id); 
		swap_promo_image(next_id)
	}
	catch(err)
	{
		txt="There was an error on this page.\n\n";
		txt+="Error description: " + err.description + "\n\n";
		txt+="Click OK to continue.\n\n";
		alert(txt);
		stop_rotate();
	}
}

///////////////////////////////////////////////////////////////
//// swap out the promo image and update active promo link ////
///////////////////////////////////////////////////////////////
function swap_promo_image(id)
{
	// change image
	blendimage("retail_blenddiv","retail_blendimage",""+ promo_image_Array[id] +"",""+ change_speed +"");
	
	// change link
	set_blenddiv_anchors(id)
	
	// change promo scroll menu
	build_promo_scroll_links(id);
}

////////////////////////
//// set promo link ////
////////////////////////
function set_blenddiv_anchors(id)
{

	var getlink = promo_link_Array[id]
	var blenddiv_anchors = document.getElementById("retail_blenddiv_anchors");
	
	//alert("getlink = " + getlink)
	
	if(getlink != "")
	{
		blenddiv_anchors.style.display = "block";
		document.getElementById("retail_blenddiv_anchors").href = getlink;
	}
	else
	{
		//alert("hide anchor")
		blenddiv_anchors.style.display = "none";
		document.getElementById("retail_blenddiv_anchors").href = "";
	}
	
	
}


///////////////////////////////////////////////////////
//// build scroll links to navigate between promos ////
///////////////////////////////////////////////////////
function build_promo_scroll_links(id)
{
	var i = 0;
	var max_count = promo_image_Array.length - 1;
	var str = ""
	for(i = 0; i <= max_count; i++)
	{
		str += "<div id=\"link"+ i +"\" class=\"retail_blend_div_links\">"
		str += "<a href=\"javascript:void(0);\""
		str += " onclick=\"javascript:swap_promo_image(" + i + ");\""
		str += " onmouseover=\"javascript:stop_rotate();\""
		str += " onmouseout=\"javascript:start_rotation();\""
		if(i == id)
		{
			str += " class=\"retail_blend_active_link\""
		}
		str += ">"
		str += i + 1
		str += "</a>"
		str += "</div>"
	}
	document.getElementById("retail_blenddiv_links").innerHTML = str;
}

//////////////////////////////////////////////////////////////////
//// set the background image to the first image in the array ////
//////////////////////////////////////////////////////////////////
function set_blenddiv_start_background(randomMenu)
{
	document.getElementById('retail_blenddiv').style.backgroundImage = 'url('+ promo_image_Array[parseInt(randomMenu)] +')';
	document.getElementById('retail_blenddiv').innerHTML = "<img src=\""+ img_path + promo_link_Array[parseInt(randomMenu)] + "\" id=\"retail_blendimage\" alt=\"\" />";
}

//////////////////////////////
//// show hide promo divs ////
//////////////////////////////
function show_hide_promo_divs()
{
	var hp_loading = document.getElementById("retail_loading");
	var blenddiv = document.getElementById("retail_blenddiv");
	var blenddiv_links = document.getElementById("retail_blenddiv_links");
	hp_loading.style.display = "none";
	blenddiv.style.display = "block";
	blenddiv_links.style.display = "block";
}