var expanded = Array();
var slider_top;
var contDiv;
var icontDiv;
var defaultNode;
var contactNode;

// image selector class
function Pselect(arr) {
	try {
		this.name = arr["name"];
		this.year = arr["year"];
		this.is_artist = arr["is_artist"];
	}
	catch(i) {
		this.name = "";
		this.year = "";
		this.is_artist = 1;
	}
}

Pselect.prototype.setByValue = function(name, year, is_artist) {
	this.name = name;
	this.year = year;
	this.is_artist = is_artist;
}

function page_init() {
	var selector = new Pselect()
	selector.setByValue("", "", 1)
	xajax_get_artist_list(selector);
	menu_lists_init();
	
	// Reposition red line under TL menu items
	var tlht = document.getElementById("kff_tlm").scrollHeight;
	var tltp = document.getElementById("kff_tlm").offsetTop;	
	document.getElementById("long_red_bar").style.top = (tlht + tltp + 10) + "px";
	slider_top = tlht + tltp + 5;

	// Set up the contact info iframe
/*
	contDiv = document.createElement("div");
	contDiv.style.position = "absolute"
	contDiv.style.left = "200px";
	contDiv.style.top = "200px";
	var contIframe = document.createElement("iframe");
	contIframe.setAttribute("src", "contact.html");
	contIframe.setAttribute("scrolling", "no");
	contIframe.frameBorder = 0;
	contIframe.setAttribute("width", "500");
	contIframe.setAttribute("height", "500");
	contDiv.appendChild(contIframe);
*/

	// Set up contact info div, take 2 (inline, not an iframe)
	icontDiv = document.createElement("div");
	icontDiv.style.position = "absolute";
	icontDiv.style.left = "200px";
	icontDiv.style.top = "200px";
	icontDiv.style.width = "500px";
	var icontSpan = document.createElement("span");
	icontSpan.style.fontSize = "20px";
	icontSpan.style.lineHeight = "24px";
	icontSpan.setAttribute("class", "menu");
	icontSpan.setAttribute("className", "menu");  // For IE6
	icontSpan.innerHTML = "If you like Susan's photographs, you may purchase them from her.   Contact her for details.";
	icontDiv.appendChild(icontSpan);
	var icontDiv2 = document.createElement("div");
	icontDiv2.style.position = "relative";
	icontDiv2.style.left = "20px";
	icontDiv2.style.top = "20px";
	var icontImg1 = document.createElement("img");
	icontImg1.setAttribute("src", "images/contact_info.gif");
	icontImg1.setAttribute("width", "216");
	icontImg1.setAttribute("height", "38");
	icontImg1.setAttribute("alt", "");
	icontDiv2.appendChild(icontImg1);
	var icontDiv3 = document.createElement("div");
	icontDiv3.style.position = "relative";
	icontDiv3.style.top = "40px";
	icontDiv3.style.left = "0px";
	icontDiv3.setAttribute("class", "menu");
	icontDiv3.setAttribute("className", "menu");  // For IE6
	icontDiv3.innerHTML = "(Click on <a href='javascript:displayHome()' class='menu'><u><b>Home</u></b></a> to return to picture view)";
	icontDiv.appendChild(icontDiv2);
	icontDiv.appendChild(icontDiv3);
	
	// Initialize drop-down menus
	menu_init();
}

function menu_lists_init() {
	document.getElementById("kerrville_fest_list").innerHTML = xajax.call('get_festival_list', {mode:'synchronous', parameters:["festival_name like 'Kerrville %' and is_artist = TRUE", 1]});
	document.getElementById("other_fest_list").innerHTML = xajax.call('get_festival_list', {mode:'synchronous', parameters:["festival_name not like 'Kerrville %' and festival_name != '' and is_artist = TRUE", 1]});
	document.getElementById("other_photos_list").innerHTML = xajax.call('get_festival_list', {mode:'synchronous', parameters:["is_artist=FALSE", 0]});
}

function getArtistsByFestival(fest, year, is_artist) {
	for (var i = 0; i < imax; i++) {
		expanded[i] = do_shrink(i);
	}
	var selector = new Pselect();
	selector.setByValue(fest, year, is_artist);
	xajax_get_artist_list(selector);
}

function thumbnail_win(subj, fest, year, is_artist) {
	th_win_han = window.open("thumbnails.php?subj=" + subj + "&fest=" + fest + "&year=" + year + "&is_artist=" + is_artist, "th_win", "height=" + (screen.height - 100) + ",width=" + (screen.width - 200) + ",scrollbars,resizable");
	th_win_han.focus();
}

function festival_pulldown(listId, index) {
	document.getElementById(listId).style.visibility = "visible";
	if (typeof(expanded[index]) == "undefined") expanded[index] = false;
	if (!expanded[index]) {
		for (var i = 0; i < imax; i++) {
			expanded[i] = do_shrink(i);
		}
		expanded[index] = do_expand(index);
	}
	else expanded[index] = do_shrink(index);
	return true;
}

function displayContactInfo() {
	var indexPix = document.getElementById("index_pix");
	defaultNode = document.getElementById("content").removeChild(indexPix);
	document.getElementById("content").appendChild(icontDiv);
}

function displayHome() {
	try {
		document.getElementById("content").removeChild(icontDiv);
		document.getElementById("content").appendChild(defaultNode);
	}
	catch(e) {
		void(0);
	}
}

function testing() {
	var data = {name:"Kerrville FF", year:"1994", is_artist:0};
	var sel = new Pselect(data);
	var retsel = xajax.call("test_class_in", {mode:'synchronous', parameters:[sel]});
	var nsel = new Pselect();
	nsel.setByValue("Old Settler's", "2007", 1);
	var retsel2 = xajax.call("test_class_in", {mode:'synchronous', parameters:[nsel]});
	void(0);
}
