function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function addOverlay() {
	changeOpac(0,'headerOverlay');
	document.getElementById('headerOverlay').style.visibility='visible';
	opacity('headerOverlay',0,100,2000);
}

function visitWebsite(innId,extra) {
	window.open('/?action=viewWebsite&innId='+innId+extra);
}
function gotoPage(action,extra) {
	window.location='/?action='+action+extra;
}
function scUpdateLink(action,innId,scId) {
	// Set up the request
	var xmlhttp =  new XMLHttpRequest();
	xmlhttp.open('POST', '/application/cityTrackingFunctions.php', true);

	// The callback function
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			window.location='/?action='+action+'&innId='+innId;
		}
	}
	// Send the POST request
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send('fxn=scUpdate&innId='+innId+'&scId='+scId);
}
function iomUpdateLink(action,innId,iomCityId) {
	// Set up the request
	var xmlhttp =  new XMLHttpRequest();
	xmlhttp.open('POST', '/application/cityTrackingFunctions.php', true);

	// The callback function
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			window.location='/?action='+action+'&innId='+innId;
		}
	}
	// Send the POST request
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send('fxn=iomUpdate&innId='+innId+'&iomCityId='+iomCityId);
}
function scUpdateWebsite(innId,scId) {
	var action='viewWebsite';
	// Set up the request
	var xmlhttp =  new XMLHttpRequest();
	xmlhttp.open('POST', '/application/cityTrackingFunctions.php', true);

	// The callback function
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			window.open='/?action='+action+'&innId='+innId;
		}
	}
	// Send the POST request
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send('fxn=scUpdateWebsite&innId='+innId+'&scId='+scId);
}
function iomUpdateWebsite(innId,iomCityId) {
	var action='viewWebsite';
	// Set up the request
	var xmlhttp =  new XMLHttpRequest();
	xmlhttp.open('POST', '/application/cityTrackingFunctions.php', true);

	// The callback function
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			window.open='/?action='+action+'&innId='+innId;
		}
	}
	// Send the POST request
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send('fxn=iomUpdateWebsite&innId='+innId+'&iomCityId='+iomCityId);
}


/*
  NEW AS OF 08.27.09
*/
function highlightThis() {
  this.style.backgroundColor = "#d6e9f8";
}
function unhighlightThis() {
  this.style.backgroundColor = "#ffffff";
}

/*
	Image SlideShow
	Made into a Singleton Object by Samuel Roldan www.sam3k.com
	Original by Steve's "Image Cross Fade Redux" http://sonspring.com/journal/slideshow-alternative v.1, 02.15.2006
*/
var SlideShow = new function() {
	var $this = this; //fix scope issues
	this.timer=7000;
	this.doc = document;
	this.imgs = new Array(); 
	this.zInterval = null; 
	this.current=0; 
	this.pause=false;	
	this.color = "blue";
	//this.divContainer = this.doc.getElementById('SlideShow');
	//this.ul = $this.doc.getElementById('SlideShow').getElementsByTagName('ul');
	//this.ul.style.listStyleType = "square";
	
	this.init = function () {
		if(!this.doc.getElementById || !this.doc.createElement)return;
		this.imgs = this.doc.getElementById('SlideShow').getElementsByTagName('img');
		this.uls = this.doc.getElementById('SlideShow').getElementsByTagName('ul');
		for(i=0;i<this.uls.length;i++) {
			this.uls[i].style.listStyleType = "none";
		}
		for(i=0;i<this.imgs.length;i++) {
			this.imgs[i].style.display = "none";
			this.imgs[i].style.position = "absolute";
			this.imgs[i].style.top = 0;
			this.imgs[i].style.left = 0;
			this.imgs[i].style.border = "none";
		}
		for(i=1;i<this.imgs.length;i++) this.imgs[i].xOpacity = 0;
		this.imgs[0].style.display = 'block';
		this.imgs[0].xOpacity = .99;
		setTimeout(this.fade,$this.timer);
	}
	
	this.fade = function() {
		$this.cOpacity = $this.imgs[$this.current].xOpacity;
		$this.nIndex = $this.imgs[$this.current+1]?$this.current+1:0;
		$this.nOpacity = $this.imgs[$this.nIndex].xOpacity;

		$this.cOpacity-=.05;
		$this.nOpacity+=.05;

		$this.imgs[$this.nIndex].style.display = 'block';
		$this.imgs[$this.current].xOpacity = $this.cOpacity;
		$this.imgs[$this.nIndex].xOpacity = $this.nOpacity;

		$this.setOpacity($this.imgs[$this.current]);
		$this.setOpacity($this.imgs[$this.nIndex]);

		if($this.cOpacity<=0) {
			$this.imgs[$this.current].style.display = 'none';
			$this.current = $this.nIndex;
			setTimeout($this.fade,$this.timer);
		} else {
			setTimeout($this.fade,50);
		}

	}
	this.setOpacity = function(obj) {
			if(obj.xOpacity>.99) {
				obj.xOpacity = .99;
				return;
			}

			obj.style.opacity = obj.xOpacity;
			obj.style.MozOpacity = obj.xOpacity;
			obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
		}
}

function initSlideShow() {
	SlideShow.timer = 7000;
	SlideShow.init();
}



/* homepage functions:  taken from js/homepageFunctions.js to keep reduce http requests */
function showPost(counter) {
	var thebox = document.getElementById("visible_news");
	var nextbox = document.getElementById("next_news");

	if (counter < 0) {
		counter=postArray.length-1;
	}else if(counter == postArray.length) {
		counter=0;
	}

	thebox.innerHTML=nextbox.innerHTML;
	nextbox.style.height='1px';

	blogId=counter;
	yUp=0;
}

function move_up() {
	showPost(blogId+1);
}

function move_down() {
	showPost(blogId-1);
}

var speed = 50;
var ystep = 5;
var yUp=0;

function slide(io) {
	if (io == 'Up') {
		slider='slideUp()';
	}else {
		slider='slideDown()';
	}
	slidingUp=setTimeout(slider,speed);
	yUp=yUp+ystep;
	if (yUp >=125) {
		stopCount(io);
	}
	var thebox = document.getElementById("visible_news");
	var nextbox = document.getElementById("next_news");
	var boxHeight=125-yUp;
	var nextHeight=yUp+1;

	thebox.style.height=boxHeight+"px";
	nextbox.style.height=nextHeight+"px";

}

function slideUp() {
	var nextCounter;
	if(blogId+1 == postArray.length) {
		nextCounter=0;
	}else {
		nextCounter=blogId+1;
	}
	document.getElementById("next_news").innerHTML=postArray[nextCounter];
	slide('Up');
}
function slideDown() {
	var nextCounter;
	if(blogId-1 < 0) {
		nextCounter=postArray.length-1;
	}else {
		nextCounter=blogId-1;
	}
	document.getElementById("next_news").innerHTML=postArray[nextCounter];
	slide('Down');
}

function stopCount(io) {
	if (io == 'Up') {
		clearTimeout(slidingUp);
		move_up();
	}else {
		clearTimeout(slidingUp);
		move_down();
	}
}
function WorldMap() {
	document.getElementById('smallMapBackground').style.background='url(\'/images/smallWorldSearch.gif\')';
	document.getElementById('smallMapBackground').style.backgroundPosition='center center';
	document.getElementById('smallMapBackground').style.backgroundRepeat='no-repeat';
	document.getElementById('smallMap').style.width='200px';
	document.getElementById('smallMap').style.height='105px';
	document.getElementById('smallMap').src='/images/transparent.gif';
	document.getElementById('smallMap').useMap='#smallWorld_Map';
	document.getElementById('mapBack').style.visibility='hidden';

	if (event.preventDefault) { //cancels the mouse click. Some kind of bug with IE where it was auto clicking on the new image map.
		event.preventDefault();
	}else {
		event.returnValue= false;
	}
	return false;
}
function USMap() {
	document.getElementById('smallMapBackground').style.background='url(\'/images/smallMapSearch.gif\')';
	document.getElementById('smallMapBackground').style.backgroundPosition='center center';
	document.getElementById('smallMapBackground').style.backgroundRepeat='no-repeat';
	document.getElementById('smallMap').style.width='148px';
	document.getElementById('smallMap').style.height='95px';
	document.getElementById('smallMap').src='/images/transparent.gif';
	document.getElementById('smallMap').useMap='#smallMap_Map';
	document.getElementById('mapBack').style.visibility='visible';

	if (event.preventDefault) { //cancels the mouse click. Some kind of bug with IE where it was auto clicking on the new image map.
		event.preventDefault();
	}else {
		event.returnValue= false;
	}
	return false;
}
function CanadaMap() {
	document.getElementById('smallMapBackground').style.background='url(\'/images/smallCanadaMap.gif\')';
	document.getElementById('smallMapBackground').style.backgroundPosition='center center';
	document.getElementById('smallMapBackground').style.backgroundRepeat='no-repeat';
	document.getElementById('smallMap').style.width='150px';
	document.getElementById('smallMap').style.height='124px';
	document.getElementById('smallMap').src='/images/transparent.gif';
	document.getElementById('smallMap').useMap='#smallCanadaMap_Map';
	document.getElementById('mapBack').style.visibility='visible';

	if (event.preventDefault) { //cancels the mouse click. Some kind of bug with IE where it was auto clicking on the new image map.
		event.preventDefault();
	}else {
		event.returnValue= false;
	}
	return false;
}
function mapHighlight(directory,imageName) {
	document.getElementById('smallMap').style.cursor='pointer';
	document.getElementById('smallMap').src='/images/'+directory+'/'+imageName+'.gif';
}
function cleanMap() {
	document.getElementById('smallMap').style.cursor='default';
	document.getElementById('smallMap').src='/images/transparent.gif';
}