var whichSweep = 0, d = document;

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_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);
}

//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 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--;
		}
	}
	//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
	//d.getElementById(state).firstChild.nodeValue = "STARTS "+dataObject.data[num]["start_time"];
	d.getElementById(state).firstChild.nodeValue = "PROMOTIONS";
	d.getElementById(image).src = "img/screenshots/" + dataObject.data[num]["screenshot"];
	d.getElementById(image).alt = dataObject.data[num]["name"];
	d.getElementById(name).firstChild.nodeValue = dataObject.data[num]["name"];
	d.getElementById(date).firstChild.nodeValue = "Run dates: " + dataObject.data[num]["start_time"] + " - " + dataObject.data[num]["end_time"];
	d.getElementById(url1).href = dataObject.data[num]["url"];
	d.getElementById(url1).title = "Click to open " + dataObject.data[num]["name"];
	d.getElementById(url2).href = dataObject.data[num]["url"];
	d.getElementById(url2).title = "Click to open " + dataObject.data[num]["name"];
	d.getElementById(desc).firstChild.nodeValue = dataObject.data[num]["description"];
}

/**
 * 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) {
		d.getElementById("arrows").style.display = "block";
	}
}