//jQuery(document).ready(function() {
// "$" is a shorthand for jQuery
// "$(function()" is a shorthand for "$(document).ready(function()"

$(function() {

	//Time Variables
	var t = "";
	var picNum = 0;
	
	$("td").hover(function() {
		$(this).addClass("hovered");		
	},function(){
		$(this).removeClass("hovered");
	});

	
	//Change the selected menu item
	$("#menuTable").find("a").click(function() {
		$("td[class=current]").removeClass("current");
		$(this).parent().parent().addClass("current");
					
		$("#bodyContent").find("div").not("[name=" + this.id + "]").hide('slow');
		$("#bodyContent").find("div[name=" + this.id + "]").show('slow');

		//This cycles the pictures on the page
		window.clearInterval(t); t="";
		picNum = 1;
		var img = $("#bodyContent").find("div[name=" + this.id + "]").find(".RotatingImg");
		var s = img.attr("src");
			if (s) {
				t = window.setInterval(function() {					
					picNum++
					if (!urlExists(s.replace(s.charAt(s.indexOf(".jpg")-1), picNum))) picNum = 1;
					img.attr("src", s.replace(s.charAt(s.indexOf(".jpg")-1), picNum));
				}, 5000);
			}
			
		if(this.id == "home") {
			$("#bodyContent").css("background", "#000 url('images/phono14.gif') no-repeat top right");
		} else {
			$("#bodyContent").css("background", "#000 url('images/phono14Still.gif') no-repeat top right");
		}
		
	});
	
	$(".RotatingImg").click(function() {
		window.clearInterval(t); t="";
		var img = $(this);
		var s = img.attr("src");
		//Set the initial change.
			picNum++;
			if (!urlExists(s.replace(s.charAt(s.indexOf(".jpg")-1), picNum))) picNum = 1;
			img.attr("src", s.replace(s.charAt(s.indexOf(".jpg")-1), picNum));
		
		//Future Changes
		t = window.setInterval(function() {					
			picNum++;
			if (!urlExists(s.replace(s.charAt(s.indexOf(".jpg")-1), picNum))) picNum = 1;
			img.attr("src", s.replace(s.charAt(s.indexOf(".jpg")-1), picNum));
		}, 5000);
	});
	
	//This is the code to enlarge and make smaller the DJ Profile Pictures
	$(".DJpix").toggle(function() {
		$(this).animate({"width": "+=435px", "height": "+=330px"}, 500);
	},function() {
		$(this).animate({"width": "-=435px", "height": "-=330px"}, 500);	
	});	
	
	
	//Hide all elements other than home on load
	$("#bodyContent").find("div").not("[name=home]").hide();
	
});


// Some Ajax Funtions
function urlExists(url) {
	var req = new AJ(); // XMLHttpRequest object
	try {
		req.open("HEAD", url, false);
		req.send(null);		
		return req.status == 200 ? true : false;
	}
	catch (er) {
		return false;
	}
}

function AJ() {
	var obj;
	if (window.XMLHttpRequest) obj= new XMLHttpRequest(); 
	else if (window.ActiveXObject){
		try{
			obj= new ActiveXObject('MSXML2.XMLHTTP.3.0');
		}
		catch(er){
			try{
				obj= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(er){
				obj= false;
			}
		}
	}
	return obj;
}