function popup_pdf(file) {
	window.open(file,'','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600');
}

function popup_contact() {
	window.open('contact.php','','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=686');
}

function popup_web(file) {
	var height = 600;
	
	if (file == "privacy.html") {
		height = 585;
	} else if (file == "copyright.html") {
		height = 235;
	}
	
	window.open(file,'','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=' + height);
}

//////////////////////////////////////
////////////////Lee's Section//////////
//////////////////////////////////////

var whichSweep = 0;
var lastSweep = 0;
var notMoving = true;

//gets input from arrows on the page. they send the values "next" or "prev"
function arrows(which) {
	if (which == "next") {
		//if the end of the array is reached, return to 0
		if (whichSweep == dataObject.data.length-1) {
			whichSweep = 0;
		}
		//if not yet reached the end of the array, add one
		else {
			whichSweep ++;
		}
	}
	else if (which == "prev") {
		//if the beginning of the array is reached, go to the end
		if (whichSweep == 0) {
			whichSweep = dataObject.data.length-1;
		}
		//if not yet reached the beginning of the array, subtract one
		else {
			whichSweep --;
		}
	}
	else {
		whichSweep = which;
	}
	/*/eliminate the background color of all clients in the list
	//doesn't work in either IE or Safari
	var clientList = document.getElementById('client-list-ul');
	for (var i=0; i<clientList.childNodes.length; i++) {
		alert(clientList.childNodes[i]);
		if (clientList.childNodes[i] == "[object HTMLLIElement]") {
			clientList.childNodes[i].style.backgroundColor = "transparent";
		}
	}*/
	//remove background color from the previous client in the list
	var lastClient = document.getElementById('client-'+lastSweep);
	lastClient.style.backgroundColor = "transparent";
	
	//change the background color of the chosen client in the list
	var whichClient = document.getElementById('client-'+whichSweep);
	whichClient.style.backgroundColor = "#CC6666";;
	
	//changes the last sweep to the currently chosen sweep
	lastSweep = whichSweep;
	
	listRoll("all", "null");
	
	function jumpScroll() {
		document.getElementById('client-list-inner').scroll(0,document.getElementById('client-'+whichSweep).offsetHeight); // horizontal and vertical scroll targets
	}
	
	//if the clicked item is out of view in the div, scroll the div to a point where item is viewable
	clientScroll(whichSweep);
	
	//load content based on whichSweep
	loadContent(whichSweep);
}

//num determines the position in the dataObject array to draw data from
function loadContent(num) {
	//input the ID for each field (p or img tags)
	var state = "promotion_state_text";
	var image = "promotion_image_image";
	var name  = "promotion_name_text";
	var date  = "promotion_date_text";
	var desc  = "promotion_desc_text";
	var url1  = "promotion_link-image";
	var url2  = "promotion_link-name";
	
	//instead of firstChild.nodeValue, can also use firstChild.nodeValue or childNodes[0].nodeValue
	//document.getElementById(state).firstChild.nodeValue = "STARTS "+dataObject.data[num]["start_time"];
	document.getElementById(state).firstChild.nodeValue = "PROMOTIONS";
	document.getElementById(image).src = "http://www.ussweeps.com/img/screenshots/" + dataObject.data[num]["screenshot"];
	document.getElementById(image).alt = dataObject.data[num]["name"];
	document.getElementById(name).firstChild.nodeValue = dataObject.data[num]["name"];
	document.getElementById(date).firstChild.nodeValue = "Run dates: " + dataObject.data[num]["start_time"] + " - " + dataObject.data[num]["end_time"];
	document.getElementById(url1).href = dataObject.data[num]["url"];
	document.getElementById(url1).title = "Click to open " + dataObject.data[num]["name"];
	document.getElementById(url2).href = dataObject.data[num]["url"];
	document.getElementById(url2).title = "Click to open " + dataObject.data[num]["name"];
	document.getElementById(desc).firstChild.nodeValue = dataObject.data[num]["description"];
}

//This function is used to show the description of the "tag cloud" words upon rollover
function describe(which) {
	var theDesc = document.getElementById(which.id+"-desc");
	var descBox = document.getElementById("tag-cloud-desc");
	//hide all of the previously viewable descriptions before showing the new one
	for (var i=0; i<descBox.childNodes.length; i++) {
		//alert(descBox.childNodes[i]);
		if (descBox.childNodes[i] == "[object HTMLParagraphElement]" || descBox.childNodes[i] == "[object]") {
			descBox.childNodes[i].style.display = "none";
		}
	}
	
	//Works with code in the onLoad function, if the onLoad function code worked.
	//for (var i=0; i<descList.length; i++) {
	//	descList[i].style.display = "none";
	//}
	
	//show the new description
	theDesc.style.display = "block";
}

/**
 * By default the arrows are hidden. This is a failsafe for people with JS
 * disabled. When the page loads it will display them using JS.
 */
function onLoad() {
	if (dataObject.data.length > 1) {
		document.getElementById("arrows").style.display = "block";
	}
	
	document.getElementById('client-0').style.backgroundColor = "#CC6666";
	
	/*
	//makes a list of all the descriptions and stores them in the array descList
	//This works except for the pushing to the array. For some reason, it comes out as "undefined"
	///////////////////////NEEDS FIXING///////////////////////////
	var descList = new Array();
	var descBox = document.getElementById("tag-cloud-desc");
	//hide all of the previously viewable descriptions before showing the new one
	for (var i=0; i<descBox.childNodes.length; i++) {
		//alert(descBox.childNodes[i]);
		if (descBox.childNodes[i] == "[object HTMLParagraphElement]") {
			descList.push(descBox.childNodes[i]);
			//descBox.childNodes[i].style.display = "none";
			alert(descBox.childNodes[i]);
			alert(descList[i]);
		}
	}
	*/
}

/*from http://www.faqts.com/knowledge_base/view.phtml/aid/2193/fid/128 */
function getElementsByStyleClass (className) {
  var all = document.all ? document.all :
	document.getElementsByTagName('*');
  var elements = new Array();
  for (var e = 0; e < all.length; e++)
	if (all[e].className == className)
	  elements[elements.length] = all[e];
  return elements;
}

//changes the display style from hidden to block and vice versa
function showHide(which) {
	if (which.style.display == "none") {
		which.style.display = "block";
	} else {
		which.style.display = "none";
	}
}


//key finding function from javascriptsearch.com/tutorials
//returns which arrow, or if enter was pressed
function pressArrows(oEvent) {

if(window.event) // IE 
   {
    switch(oEvent.keyCode) {
        case 38: //up arrow
			//alert("up");
			arrows("prev");
			break;
		case 37: //left arrow
			//alert("left");
			arrows("prev");
			break;
        case 40: //down arrow
			//alert("down");
			arrows("next");
			break;
		case 39: //right arrow
			//alert("right");
			arrows("next");
			break;
        case 13: //enter
			//alert("enter");
			break;
	}
}
else if(oEvent.which) // Netscape/Firefox/Opera
  {
	switch(oEvent.which) {
        case 38: //up arrow
			//alert("up");
			arrows("prev");
			break;
		case 37: //left arrow
			//alert("left");
			arrows("prev");
			break;
        case 40: //down arrow
			//alert("down");
			arrows("next");
			break;
		case 39: //right arrow
			//alert("right");
			arrows("next");
			break;
        case 13: //enter
			//alert("enter");
			break;
	}
  }
}

/*
*   clientScroll scrolls the client list window to the desired height (so the selected promo is still viewable in the list)
*
*   @num		-> which item is selected
*
*   theDiv 		-> which div to be scrolled
*   itemHeight	-> height of the items in the list
*   numToLead	-> number of "buffer" items to show between chosen item and the top or bottom of the div when scrolling
*   
*   everything else is automatic.
*/
function clientScroll(num) {
	var theDiv = document.getElementById('client-list-inner');
	var itemHeight =  17;
	var numToLead = 2;
	var divHeight = theDiv.clientHeight;
	var scrollHeight = theDiv.scrollHeight;
	var where = (parseInt(num)+1)*itemHeight;
	//alert("num +1: "+(parseInt(num)+1)+" where: "+where+" divHeight+theScroll: "+(divHeight+theDiv.scrollTop));
	if ( where > (divHeight+theDiv.scrollTop-(itemHeight*numToLead) ) ) {
		var scrollTo = where-divHeight+(itemHeight*numToLead);
		if (scrollTo > (scrollHeight-divHeight) ) {scrollTo = (scrollHeight-divHeight);}
		theDiv.scrollTop = scrollTo;
		//moveTo (theDiv, scrollTo);
	} else if (where < (theDiv.scrollTop+itemHeight+(itemHeight*numToLead) ) ) {
		var scrollTo = where-itemHeight-(itemHeight*numToLead);
		if (scrollTo < 0) {scrollTo = 0;}
		theDiv.scrollTop = scrollTo;
		//moveTo (theDiv, scrollTo);
	}
	else {
		//alert("no need to move.");
	}
}

function moveTo(elm,dist) {
	notMoving = false;
	var x=parseInt(elm.scrollTop);
	//alert("x = "+x);
	var distance=dist-x;
	//alert("distance = "+distance);
	var tot=x+Math.floor((distance/2));
	//alert("tot = "+tot);
	elm.scrollTop=tot+'px';
	function c() {
		moveTo(elm,dist);
	}
	if(distance==0) {
		clearTimeout(timer);
		notMoving = true;
		return;
	}
	timer=setTimeout(c,50);
}


//listRoll takes an object (or the string "all") and a string ("on" or "off" to differentiate rollovers) and changes the background color accordingly.
function listRoll(which, what) {
	//have to have hex for IE as well as rgb for FireFox & others
	var bgcolorSelIE = "#cc6666";
	var bgcolorSelFF = "rgb(204, 102, 102)";
	var bgcolorRollIE = "#694747";//"#ee8888";
	var bgcolorRollFF = "rgb(105, 71, 71)";//"rgb(238, 136, 136)";
	if (which != "all") {
		if (which.style.backgroundColor != bgcolorSelIE && which.style.backgroundColor != bgcolorSelFF) {
			if(what == "on") {
				which.style.backgroundColor = bgcolorRollIE;
			}
			if(what == "off") {
				which.style.backgroundColor = "transparent";
			}
		}
	} else if (which == "all") {
		var theClients = getElementsByStyleClass("client-li");
		//alert (theClients.length);
		//alert(theClients[0].style.backgroundColor);
		for (var i=0; i<theClients.length; i++) {
			if (theClients[i].style.backgroundColor == bgcolorRollIE || theClients[i].style.backgroundColor == bgcolorRollFF) {
			//if (theClients[i].style.backgroundColor != bgcolorSelIE && theClients[i].style.backgroundColor != bgcolorSelFF) {
				theClients[i].style.backgroundColor = "transparent";
			}
		}
	} else {
		alert("error: roll["+which+"]["+what+"]");
	}
}