
var currpane, currhash;
var panes = [];

var hpanels = [];

var intervals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1];
var ratios = [0];
var slidetimer, issliding = false;



function entryclick(i) {
	if(issliding == false) {
		slidetimer = setInterval(doslide, 30);
		issliding = true;
	}
	if(hpanels[i].pos == 0) {
		hpanels[i].dir = 1;
	}
	else {
		hpanels[i].dir = -1;	
	}
}

function doslide(e) {
	var i, j, k = 0;

	for (i in hpanels) {
		j = hpanels[i];
		if(j.dir !== 0) {
			j.pos += j.dir;
			if(j.pos >= ratios.length - 1) {
				j.pos = ratios.length - 1;
				j.dir = 0;
			}
			else if(j.pos <= 0) {
				j.pos = 0;
				j.dir = 0;
			}
			else {
				k = 1;
			}
			j.obj.style.height = (j.height * ratios[j.pos]) + "px";
		}
	}
	if(k == 0) {
		//end timer
		clearInterval(slidetimer);
		issliding = false;
	}
}


function EntryObj(hpname) {
	this.hpanel = hpname;
	this.obj = document.getElementById(hpname);
	this.dir = 0;
	this.height = this.obj.clientHeight;
	this.pos = 0;
	this.obj.style.height = "0px";
}

function PaneObj(pname, phash) {
	this.name = pname;
	this.obj = document.getElementById(pname);
	this.hash = phash;
	this.show = showpane;
	this.hide = hidepane;
}

function showpane() {
	this.obj.style.display = "block";
}

function hidepane() {
	this.obj.style.display = "none";	
}


function init(pns, hps, defpane) {
	
	var j, k, o;

	k = 0;
	for(j = 0; j < intervals.length; j++) {
		k += intervals[j];
	}
	
	for(j = 0; j < intervals.length - 1; j++) {
		ratios[j + 1] = ratios[j] + (intervals[j] / k);
	}
	ratios[j + 1] = 1;
	
	for(j in hps) {
		hpanels[hps[j][0]] = new EntryObj(hps[j][1]);
	}

	k = "";
	for(j in pns) {
		o = pns[j];
		panes[o[0]] = new PaneObj(o[1], o[2]);
		if(document.location.hash == o[2]) k = o[0];
	}
	
	if(k == "") k = defpane;
	
	for(j in panes) {
		if(j == k) {
			currpane = j;
			panes[j].show();
		}
		else panes[j].hide();
	}
	
	//document.getElementById("results").innerHTML = "<p>" + document.location.hash + " " + k + "</p>";
	

	setInterval(checkhash, 300);
	
	
}

function checkhash(e) {
	if(document.location.hash !== currhash) {
		for(j in panes) {
			if(document.location.hash == panes[j].hash) {
				switchpanes(j);
				break;
			}
		}
	}
}


function switchpanes(i) {
	if(currpane !== i) {
		panes[currpane].hide();
		panes[i].show();
		currpane = i;
		document.location.hash = panes[i].hash;
	}	
}



function playercode(i, c, url, t,  al, ap, ot) {
	// id for divs and objs
	// url of mp3
	// t is title
	// al is autoload
	// ap is autoplay
	// ot is other vars; should begin with '&&'
	
	var title = (t == null) ? "" : t;
	var others = (ot == null) ? "" : ot;
	var pclass = (c == null) ? "" : c;
	var id = (i == null) ? "" : i;
	
	fv = "url=" + url + "&&title=" + title;
	if(al) fv += "&&autoload=true";
	if(ap) fv += "&&autoplay=true";
	fv += others;
	
	var args = [
			'FlashVars', fv,
			'id', 'flashobj_' + id,
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '300',
			'height', '40',
			'src', 'bensmp3player-skinny',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'transparent',
			'devicefont', 'false',
			'bgcolor', '#ffffff',
			'name', 'bensmp3player-skinny',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', 'bensmp3player-skinny',
			'salign', ''
			];
	
	//document.write(args);
	
	var str = genFlashHTML(args);
	
	str = "<div class='" + pclass + "' id='flashdiv_" + id + "'>" + str + "</div>";
	
	return str;
}

function youtubecode(i, c, url) {
	// id for divs and objs
	// class for divs
	// url of mp3
	
	var pclass = (c == null) ? "" : c;
	var id = (i == null) ? "" : i;
		
	var args = [
			'id', 'flashobj_' + id,
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '480',
			'height', '295',
			'src', url,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'opaque',
			'devicefont', 'false',
			'bgcolor', '#ffffff',
			'name', 'youtube_player',
			'menu', 'true',
			'allowFullScreen', 'true',
			'allowScriptAccess','always',
			'movie', url,
			'salign', ''
			];
	
	//document.write(args);
	
	var str = genFlashHTML(args);
	
	str = "<div class='" + pclass + "' id='flashdiv_" + id + "'>" + str + "</div>";
	
	return str;
}


function genFlashHTML(args) {
	var str = "";
	var ret = AC_GetArgs (args, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash");
 	var objAttrs = ret.objAttrs;
	var params = ret.params;
	var embedAttrs = ret.embedAttrs;

	if (isIE && isWin && !isOpera) {
		str += '<object ';
		for (var i in objAttrs)
		{
		  str += i + '="' + objAttrs[i] + '" ';
		}
		str += '>';
		for (var i in params)
		{
		  str += '<param name="' + i + '" value="' + params[i] + '" /> ';
		}
		str += '</object>';
	}
	else {
		str += '<embed ';
		for (var i in embedAttrs)
		{
		  str += i + '="' + embedAttrs[i] + '" ';
		}
		str += '> </embed>';
	}
	return str;
}
