var bIE = document.all ? true : false;  
var bSafari = navigator.userAgent.toLowerCase().indexOf("safari") != -1;
var aNavOverImages = new Array("whytrashstinks", "facebooktrashtalk", "freekarmapoints", "theuntrashers");
var aSubNavOverMenu = new Array("whatsourdeal", "facebookapplication", "untrashohioandscoresomekarmicgoodness", "whowearewhatwedo");
var sCurrentRO = "base";
var sSection; //set in body on sub pages
var nInterval;
var nOpacity; 
var sCurrentFade;
var hide_delay = 200;
var sID;
var currentfile;

//add code nav initialize code to onload event
if (document.getElementById) {
	addEvent(window, "onload", navInit);
	preloadImages();	
}

/*********************************************
 * preload navigation off images used in rollover
 *********************************************/	  
function preloadImages() 
{  
	var iImage = new Image();
	for (var i=0; i < aNavOverImages.length; i++) {
		iImage.src = "nav_" + aNavOverImages[i] + "_on.gif";
	}  
}

/*********************************************
 * initialize the navigation
 *********************************************/	
function navInit() 
{	
	if (document.getElementById)
	{
		//add rollover functionality to each nav button
		for (var i=0; i < aNavOverImages.length; i++) 
		{
			var oLink = document.getElementById(aNavOverImages[i]);
			
			oLink.onmouseover = function() 
			{		
		    	
				var sID = this.id.substring(0, this.id.length);	
                sID = this.id.substring(0, this.id.length);	
                
				if (sCurrentRO != sID) 
				{					
					//update nav states
					this.firstChild.src = "images/nav/nav_" + sID + "_on.gif";
					ResetSubNavs();
					ShowAppropriateSubNav(sID)											
				}
			}
			
		    oLink.onmouseout = function() 
		    {			
			    var sID = this.id.substring(0, this.id.length);	
                sID = this.id.substring(0, this.id.length);	
                
			    if (sCurrentRO != sID) 
			{					
	    		//update nav states
				this.firstChild.src = "images/nav/nav_" + sID + "_off.gif";	
														
			}
		}
			
		}  	

	}	
}

function hideNav()
{
    for (var i=0; i < aNavOverImages.length; i++) 
	{
		var oLink = document.getElementById(aNavOverImages[i]);
			
		oLink.onmouseout = function() 
		{			
			var sID = this.id.substring(0, this.id.length);	
            sID = this.id.substring(0, this.id.length);	
                
			if (sCurrentRO != sID) 
			{					
	    		//update nav states
				this.firstChild.src = "images/nav/nav_" + sID + "_off.gif";	
														
			}
		}
	}
}

function ResetSubNavs()
{
    HideSubNav(whatsourdealimg);
    HideSubNav(facebookapplicationimg);
    HideSubNav(untrashohioandscoresomekarmicgoodnessimg);
    HideSubNav(whowearewhatwedoimg);
}

function ShowAppropriateSubNav(sendingID)
{
    if (sendingID == "whytrashstinks")
    {
        ShowSubNav(whatsourdealimg);
    }

    if (sendingID == "facebooktrashtalk")
    {
        ShowSubNav(facebookapplicationimg);
    }
    
    if (sendingID == "freekarmapoints")
    {
        ShowSubNav(untrashohioandscoresomekarmicgoodnessimg);
    }
    
    if (sendingID == "theuntrashers")
    {
        ShowSubNav(whowearewhatwedoimg);
    }
}

function ShowSubNav(SubNavimage) 
{	
    var showimage = SubNavimage;
    document.getElementById(showimage.id).style.visibility = "visible";
}

function HideSubNav(image) 
{	
    var showimage = image;
    document.getElementById(showimage.id).style.visibility = "hidden";
}

function HideContent(mainimage)
{
    document.getElementById(mainimage).style.display = "none";
}

function ShowContent(mainimage)
{
    document.getElementById(mainimage).style.display = "block";
}

function ShowLayer(LayerID) 
{	
    var layername = LayerID;
    document.getElementById(layername.id).style.visibility = "visible";
}

function ShowPopUp(ImageName)
{
    ResetPopUps()
    var image = ImageName
    document.getElementById(image.id).style.visibility = "visible";
}

function HidePopUp(ImageName)
{
    var image = ImageName
    document.getElementById(image.id).style.visibility = "hidden";
}

function ResetPopUps()
{
    document.getElementById("ThrowYourTrashAway").style.visibility = "hidden";
    document.getElementById("ThrowSomeoneElsesTrahAway").style.visibility = "hidden";
    document.getElementById("ShareThisSite").style.visibility = "hidden";
    document.getElementById("UntrashFacebook").style.visibility = "hidden";
    document.getElementById("JunktheJunkMail").style.visibility = "hidden";
    document.getElementById("SpreadSomeKnowledge").style.visibility = "hidden";
    document.getElementById("GetInvolved").style.visibility = "hidden";

}

 
/*********************************************
 * bind an event and method
 *********************************************/	
function addEvent(oTarget, sType, fpDest) 
{
	var oOldEvent = oTarget[sType];
	if (typeof oOldEvent != "function") 
	{
		oTarget[sType] = fpDest;
	}
	else
	{
		oTarget[sType] = function(e)
		{
			oOldEvent(e);
			fpDest(e);
		}
	}
}

/*********************************************
 * Handles rotating the main image on the home page
 *********************************************/	  
 var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem("images/homeFeature/car.gif");
image_list[image_index++] = new imageItem("images/homeFeature/fish.gif");
image_list[image_index++] = new imageItem("images/homeFeature/golf.gif");
var number_of_image = image_list.length;

function imageItem(image_location) {
this.image_item = new Image();
this.image_item.src = image_location;
}

function get_ImageItemLocation(imageObj) {
return(imageObj.image_item.src)
}

function generate(x, y) {
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}

function getNextImage()
{
image_index = generate(0, number_of_image-1);
var new_image = get_ImageItemLocation(image_list[image_index]);
return(new_image);
}

function rotateImage(place) {
var new_image = getNextImage();
document.getElementById(place.id).src = new_image;
}

