var flickrImageArray = new Array();
var imgPreload;
var toniteImgPreload;
var featuredImgPreload;

function showFeaturedBlock(id) {
	featuredImgPreload = new Image();
	featuredImgPreload.onload = function() {
		Effect.Fade("featuredShowsWrapper", { afterFinish: function() { nextFeaturedFrame(id); } });
		Effect.Fade("featuredShowsButtons");
	}
	
	if (featuredShowsPhotosArray[id-1].length == 0) {
		featuredImgPreload.src = "images/interface/default-show-image.jpg";
	} else {
		featuredImgPreload.src = "images/mainPhotos/" + featuredShowsPhotosArray[id - 1];
	}
}

function nextFeaturedFrame(id) {
	var width = featuredImgPreload.width;
	var height = featuredImgPreload.height;
	var newWidth, newHeight;
	var tempLinkObject;
	
	if (height > width) {
		newHeight = 308;
		newWidth = width * (newHeight / height);
	} else if (height > 308) {
		newHeight = 308;
		newWidth = width * (newHeight / height);
	} else {
		newWidth = width;
		newHeight = height;
	}
	
	if (featuredShowsPhotosArray[id - 1].length == 0) {
		document.getElementById("featuredShowsImage").src = "images/interface/default-show-image.jpg";
	} else {
		document.getElementById("featuredShowsImage").src = "images/mainPhotos/" + featuredShowsPhotosArray[id - 1];
	}
	document.getElementById("featuredShowsDescription").innerHTML = "<p>" + featuredShowsDescriptionsArray[id - 1] + "</p>";
	document.getElementById("featuredShowsImage").style.width = newWidth + "px";
	document.getElementById("featuredShowsImage").style.height = newHeight + "px";
	
	document.getElementById("featuredShowsButtons").innerHTML = "";
	tempLinkObject = document.createElement("a");
	tempLinkObject.setAttribute("class","button");
	tempLinkObject.setAttribute("href","javascript:void(0);");
	tempLinkObject.setAttribute("onclick","window.open('view_show.php?showId=" + featuredShowsIdsArray[id - 1] + "','showwindow','status=0,toolbar=0,menubar=0,scrollbars=1,resizable=1,width=565');");
	tempLinkObject.appendChild(document.createTextNode("More Info"));
	document.getElementById("featuredShowsButtons").appendChild(tempLinkObject);
	
	if (featuredShowsTicketsArray[id - 1].length > 0) {
		tempLinkObject = document.createElement("a");
		tempLinkObject.setAttribute("class","button");
		tempLinkObject.setAttribute("href",featuredShowsTicketsArray[id - 1]);
		tempLinkObject.setAttribute("target","_blank");
		tempLinkObject.appendChild(document.createTextNode("Buy Tickets"));
		document.getElementById("featuredShowsButtons").appendChild(tempLinkObject);
	}
	
	if (id >= featuredShowsPhotosArray.length) {
		var newId = 1;
	} else {
		var newId = id + 1;
	}
	
	Effect.Appear("featuredShowsButtons");
	Effect.Appear("featuredShowsWrapper", { afterFinish: function() { setTimeout("showFeaturedBlock(" + newId + ")",5000); } });
}

function showToniteBlock(id) {
	toniteImgPreload = new Image();
	toniteImgPreload.onload = function() {
		Effect.Fade("tonightsShowWrapper", { afterFinish: function() { nextToniteFrame(id); } });
		Effect.Fade("tonightsShowButtons");
	}
	
	if (tonightsShowPhotosArray[id-1].length == 0) {
		toniteImgPreload.src = "images/interface/default-show-image.jpg";
	} else {
		toniteImgPreload.src = "images/mainPhotos/" + tonightsShowPhotosArray[id - 1];
	}
}

function nextToniteFrame(id) {
	var width = toniteImgPreload.width;
	var height = toniteImgPreload.height;
	var newWidth, newHeight;
	
	if (height > width) {
		newHeight = 308;
		newWidth = width * (newHeight / height);
	} else if (height > 308) {
		newHeight = 308;
		newWidth = width * (newHeight / height);
	} else {
		newWidth = width;
		newHeight = height;
	}
	
	if (tonightsShowPhotosArray[id - 1].length == 0) {
		document.getElementById("tonightsShowImage").src = "images/interface/default-show-image.jpg";
	} else {
		document.getElementById("tonightsShowImage").src = "images/mainPhotos/" + tonightsShowPhotosArray[id - 1];
	}
	document.getElementById("tonightsShowDescription").innerHTML = "<p>" + tonightsShowDescriptionsArray[id - 1] + "</p>";
	document.getElementById("tonightsShowImage").style.width = newWidth + "px";
	document.getElementById("tonightsShowImage").style.height = newHeight + "px";
	document.getElementById("tonightsShowWrapper").style.height = newHeight + "px";
	document.getElementById("tonightsShowMoreInfoButton").setAttribute("onclick","window.open('view_show.php?showId=" + tonightsShowIdsArray[id - 1] + "','showwindow','status=0,toolbar=0,menubar=0,scrollbars=1,resizable=1,width=565');");
	
	if (id >= tonightsShowPhotosArray.length) {
		var newId = 1;
	} else {
		var newId = id + 1;
	}
	
	Effect.Appear("tonightsShowButtons");
	Effect.Appear("tonightsShowWrapper", { afterFinish: function() { setTimeout("showToniteBlock(" + newId + ")",5000); } });
}

function showFlickrPhoto(id) {	
	imgPreload = new Image();
	imgPreload.onload = function() {
		
		Effect.Fade("flickrPhoto", { afterFinish: function() { nextFlickrFrame(id); } });
	}
	imgPreload.src = flickrImageArray[id - 1];
}

function nextFlickrFrame(id) {
	var width = imgPreload.width;
	var height = imgPreload.height;
	var newWidth, newHeight;
	
	if (width >= height) {
		newWidth = 270;
		newHeight = height * (newWidth / width);
	} else {
		newHeight = 180;
		newWidth = width * (newHeight / height);
	}
	
	document.getElementById("flickrPhoto").src = flickrImageArray[id - 1];
	document.getElementById("flickrPhotoWrapper").style.width = newWidth + "px";
	document.getElementById("flickrPhotoWrapper").style.height = newHeight + "px";
	document.getElementById("flickrPhoto").style.width = newWidth + "px";
	document.getElementById("flickrPhoto").style.height = newHeight + "px";
		
	if (id >= 20) {
		var newId = 1;
	} else {
		var newId = id + 1;
	}
	
	Effect.Appear("flickrPhoto", { afterFinish: function() { setTimeout("showFlickrPhoto(" + newId + ")",5000); } });
	
}