var id=0;
var rotate = true;
var clearRotate = true;

//function to rotate randomly through the ads
function autoRotate() {
	if (rotate != false) {
		switchImg(document.getElementById(id));
		switchAd(id);
		id = (id == 4) ? 0 : id + 1;
		if (rotate == true) {
			setTimeout("autoRotate()", 5000);
		}
	}
}

function switchMenuImg(obj){
	var sub_menu_id = obj.id + "-sub";
	var class_name = "nav-sub";
	if (obj.id == "store") {
		class_name = "nav-sub-green";
	}
	if (obj.src.match("_over") != null) {
		obj.src = obj.src.replace("_over", "");
		document.getElementById(sub_menu_id).className = 'off';
	}
	else {
		document.getElementById(sub_menu_id).className = class_name;
		if (obj.src.match(".jpg") != null) {
			obj.src = obj.src.replace(".jpg", "_over.jpg");
		}
		else {
			if (obj.src.match(".gif") != null) {
				obj.src = obj.src.replace(".gif", "_over.gif");
			}
			else {
				obj.src = obj.src.replace(".png", "_over.png");
			}
		}
	}
}


//function that switches images based on previous images.
function switchImg(obj) {
	if (obj.src.match("_over") != null) {
		obj.src = obj.src.replace("_over", "");
	} else {
		if (obj.src.match(".jpg") != null) {
			obj.src = obj.src.replace(".jpg", "_over.jpg");
		} else if (obj.src.match(".gif") != null) {
			obj.src = obj.src.replace(".gif", "_over.gif");
		} else {
			obj.src = obj.src.replace(".png", "_over.png");
		}
		if (clearRotate) {
			//alert(clearRotate);
			prev_id = (id == 0) ? 4 : id + -1;
			prev_obj = document.getElementById(prev_id);
			prev_obj.src = prev_obj.src.replace("_over", "");
			if (rotate != true) {
				clearRotate = false;
			}
		}			
	}
}

function switchAd(adId) {
	for (i=0; i<5; i++) {
		if (i == adId) {
			document.getElementById("ad_" + i).className="on";
		} else {
			document.getElementById("ad_" + i).className="off";
		}
	}	
}

function switchAdOverride(obj) {
	rotate = false;
	switchImg(obj);
	adId = obj.id * 1;
	for (i=0; i<5; i++) {
		if (i == adId) {
			document.getElementById("ad_" + i).className="on";
		} else {
			document.getElementById("ad_" + i).className="off";
		}
	}

}

function startShow(status) {
	rotate = status;
	clearRotate = status;
}

function switchClass(obj, newClass) {
	obj.className = newClass;
}
