//------------------------  IMAGE PRELOAD
imageArray = new Array();
var imageNames = [
"images/widgets/thermometer.eeeeeeBG.59x240.png",
"images/sw/nasa.102x84.jpg",
"images/sw/sw.173x94.jpg",
"images/backgrounds/aluminum.jpg",
"images/backgrounds/background_only.gif"
];
/*
for (var i=0; i<imageNames.length; i++)
{
  imageArray[imageArray.length] = new Image();
  imageArray[imageArray.length-1].src = "<?php bloginfo('template_directory');?>/"+imageNames[i];
}
*/

//--------------------------- COOKIE CODE

function Cookie() {}

Cookie.getexpirydate = function(nodays)
{
  var UTCstring;
  Today = new Date();
  nomilli = Date.parse(Today);
  Today.setTime(nomilli + nodays*24*60*60*1000);
  UTCstring = Today.toUTCString();
  return UTCstring;
}

Cookie.set = function(name,value,duration)
{
  cookiestring = name + "=" + escape(value);
  if (duration != null)
    cookiestring += ";EXPIRES=" + Cookie.getexpirydate(duration);
  document.cookie = cookiestring;
}

Cookie.get = function(cookiename)
{
  var cookiestring = "" + document.cookie;
  var index1 = cookiestring.indexOf(cookiename);
  if ((index1 == -1) || (cookiename == ""))
    return ""; 
  var index2 = cookiestring.indexOf(';',index1);
  if (index2 == -1)
    index2 = cookiestring.length; 
  return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

//------------------------- DEBUG CODE
function swAlert(text)
{
  if (Cookie.get("debug")=="1")
    alert("DEBUG:\n" + text);
}

srcFind=0;
if (srcFind) swAlert(2)

//------------------------- X-BROWSER CODE
var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all
function getDocObj(id) {if (dom) return document.getElementById(id); if (iebrowser) return docuement.all[id]; return null;}

// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
// for Netscape 6/Mozilla by Thor Larholm me@jscript.dk
// Usage: include this code segment at the beginning of your document
// before any other Javascript contents.

if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement)
{
 	swAlert("redefining");
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
	{
		switch (where)
		{
			case 'beforeBegin':	this.parentNode.insertBefore(parsedNode,this); break;
			case 'afterBegin': this.insertBefore(parsedNode,this.firstChild); break;
			case 'beforeEnd': this.appendChild(parsedNode); break;
			case 'afterEnd': if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling); else this.parentNode.appendChild(parsedNode); break;
		}
	}
	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}
	HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
} //end of code splice

if (srcFind) swAlert(1)


//----------------------- EMAIL LINKS
function writeEmailLink(s1,s2,s3,s4,s5)
{
  s0 = s1 + "@" + s2 + "." + s3;
  if (!s4) s4 = s0;
  if (s5) s0 += "?" + s5
  document.write("<a class='expb' href='mailto:"+s0+"'>" + s4 + "</a>");
}

function writeSWEmailLink(s1,s4,s5) {writeEmailLink(s1,"spaceward","org",s4,s5);}

//------------------------  PAYMENTS
if (srcFind) swAlert(5)
	
function checkoutG()
{
  var form = getDocObj("googleForm");
  var price = getDocObj("donationAmount").value;
  if (isNaN(price))
  {
    alert ("please enter a number in the text field");
	return false;
  }
  var currency = "USD";
  if (document.getElementById("currencyEuro").checked)
    currency = "EUR";
  if (document.getElementById("currencyYen").checked)
    currency = "JPY";
  if (currency != "USD")
  {
    alert ("We're sorry, but Google Checkout currently does not support non-US currency.");
	return false;
  }
  document.getElementById("item_price_1").value = price;
 	  document.getElementById("item_currency_1").value = currency;
  document.getElementById("item_description_1").value = "Donation for Space Elevator Games";
  document.getElementById("item_name_1").value = "Donation for Space Elevator Games";
  form.submit();
}

function checkoutP()
{
  var form = getDocObj("paypalForm");
  var price = getDocObj("donationAmount").value;
  if (isNaN(price))
  {
    alert ("please enter a number in the text field");
	return false;
  }
  var currency = "USD";
  if (document.getElementById("currencyEuro").checked)
    currency = "EUR";
  if (document.getElementById("currencyYen").checked)
    currency = "JPY";
  document.getElementById("amount").value = price;
  document.getElementById("currency_code").value = currency;
  document.getElementById("item_name").value = "Donation for Space Elevator Games";
  document.getElementById("item_number").value = "Donation for Space Elevator Games";
  form.submit();
}


//=================== SECTION SPECIFIC

//-------------- CONSOLE WINDOW BUTTON
var consoleWin=null;
function openConsole()
{
  if (!consoleWin || consoleWin.closed)
    if (window.screen.availHeight >=850)
      consoleWin = window.open("http://live.SpaceElevatorGames.org","live","width=1186,height=850,toolbar=no,resizable=no,status=no");
    else
      consoleWin = window.open("http://live.SpaceElevatorGames.org","live","width=1186,height=850,toolbar=no,resizable=yes,scrollbars=yes,status=no");
  consoleWin.focus();
}

var consoleWinBtnColor = "";
function flipBtn()
{
  var o = getDocObj("openConsoleBtn");
  if (o && o.style)
  {
    var c = o.style.color;
	if (c != 'black')
	{
	  consoleWinBtnColor = c;
	  o.style.color = 'black';
	}
	else
	  o.style.color = consoleWinBtnColor;
  }
}
setInterval("flipBtn()",1000);

//-------------------- EXPAND STORY
function expandStory(id)
{
   getDocObj("box-"+id).style.height = getDocObj("post-"+id).style.height;
   getDocObj("moreButton-"+id).innerHTML = "";
}
	
if (srcFind) swAlert(3)

//--------------- SUB-HEADER

function SubHeader() {}

SubHeader.writeBtnHTML = function()
{
  var showSubHeader = (Cookie.get("showSubHeader") != "F");
     document.write("<div id='subHeaderBtn' style='position:absolute; right:20px; top:170px; display:"+(showSubHeader?'none':'block')+";'>");
     document.write("(<a style='font-weight:900' href='javascript:void(SubHeader.toggle())'>Show Galleries!</a>)</div>");
}

SubHeader.writeDivHTML = function()
{
  var showSubHeader = (Cookie.get("showSubHeader") != "F");
     document.write("<div id='subHeaderDiv' style='height:384px; display:"+(showSubHeader?'block':'none')+"; min-width:1050px; max-height:384px; text-align:center '>");

  if (true)
  {
//    document.write("<div class='storyBox' style='float:left; height:344px; font-weight:900; font-size:12pt; margin-right:20px;'>2009 Space Elevator Games Image Gallery<div id='fpSS' style='text-align:center; width:100%'><img style='margin-top:55px; width:400px' src='http://lh5.ggpht.com/_KbQiiiwpi74/SuPF2aqkaHI/AAAAAAAABFM/99aC2NMe9xY/s400/splitTeaser.617x306.jpg'><div style='margin-top:5px; margin-bottom:25px; text-align:left; font-size:10pt'>(loading...)</div></div><div style='text-align:right; font-size:9pt'>(<a href='javascript:void(SubHeader.toggle())'>Hide Galleries</a>)</div></div>");
//    document.write("<div class='storyBox' style='float:left; height:344px; font-weight:900; font-size:12pt; margin-right:20px;'>2009 Space Elevator Games Image Gallery<div id='fpSS' style='text-align:center; width:100%'><img style='margin-top:55px; width:400px' src='http://lh5.ggpht.com/_KbQiiiwpi74/SuPF2aqkaHI/AAAAAAAABFM/99aC2NMe9xY/s400/splitTeaser.617x306.jpg'><div style='margin-top:5px; margin-bottom:25px; text-align:left; font-size:10pt'>(loading...)</div></div><div id='showDescriptionsDiv' style='text-align:right; font-size:9pt; display:none'>(<a href='javascript:void(photoConsole.showDescriptions())'>Show Descriptions</a>)</div></div>");
    document.write("<div class='storyBox' style='float:left; height:344px; font-weight:900; font-size:12pt; margin-right:20px;'>2009 Space Elevator Games Image Gallery<div id='fpSS' style='text-align:center; width:100%'><img style='margin-top:55px; width:400px' src='http://lh5.ggpht.com/_KbQiiiwpi74/SuPF2aqkaHI/AAAAAAAABFM/99aC2NMe9xY/s400/splitTeaser.617x306.jpg'><div style='margin-top:5px; margin-bottom:25px; text-align:left; font-size:10pt'>(loading...)</div></div><div id='showDescriptionsDiv' style='text-align:right; font-size:9pt;'>(Mouse-over to pause and show descriptions)</div></div>");
//    document.write("<div class='storyBox' style='float:right; '><object width=425 height=344><param name='movie' value='http://www.youtube.com/v/zO1EV6A76ZE&hl=en&fs=1&rel=0'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/zO1EV6A76ZE&hl=en&fs=1&rel=0' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width=425 height=344></embed></object></div>");
    document.write("<div class='storyBox' style='float:right; '><object width=425 height=344><param name='movie' value='http://www.youtube.com/v/_7euZNGrsLs&hl=en&fs=1&rel=0'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/_7euZNGrsLs&hl=en&fs=1&rel=0' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width=425 height=344></embed></object></div>");

	/*
    document.write("<div style='height:344px; margin-left: 440px; margin-right:463px; padding-top:250px; min-width:250px'>");

    document.write("<div class='headerBox' style='height:20px; min-width:250px'>START HERE</div>");

    document.write("<div id='learnMore' class='storyBox' style='height:58px; text-align:center;  min-width:250px'>");
    document.write("<a class='shNav' target='infoWin' href='http://www.spaceward.org/elevator'>What’s a Space Elevator?</a><br>");
    document.write("<a class='shNav' target='infoWin' href='http://www.spaceward.org/elevator2010'>What are the SE Games?</a><br>");
    document.write("<a class='shNav' target='infoWin' href='http://www.spaceward.org'>The Spaceward Foundation</a>");
    document.write("</div>");
    document.write("</div>");
	*/

  }
  else
  {
    document.write("<div class='storyBox' style='float:left; height:344px; font-weight:900; font-size:12pt; margin-right:20px'>2009 Space Elevator Games Official Poster<br><img style='margin:4px 0; width:617px' src='http://lh5.ggpht.com/_KbQiiiwpi74/SuPF2aqkaHI/AAAAAAAABFM/99aC2NMe9xY/s800/splitTeaser.617x306.jpg'><div style='text-align:right; font-size:9pt'>(<a href='javascript:void(SubHeader.toggle())'>Hide Poster and Trailer</a>)</div></div>");
    document.write("<div class='storyBox' style='float:right; '><object width=425 height=344><param name='movie' value='http://www.youtube.com/v/zO1EV6A76ZE&hl=en&fs=1&rel=0'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/zO1EV6A76ZE&hl=en&fs=1&rel=0' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width=425 height=344></embed></object></div>");
  }
 
  document.write("</div>")
}

SubHeader.toggle = function()
{
  var showSubHeader = (Cookie.get("showSubHeader") != "F");
  showSubHeader = !showSubHeader
  Cookie.set("showSubHeader",showSubHeader?"T":"F",100);
  var div2 = getDocObj("subHeaderBtn");
  if (div2 && div2.style) div2.style.display = showSubHeader?'none':'block';
  var div1 = getDocObj("subHeaderDiv");
  if (div1 && div1.style) div1.style.display = showSubHeader?'block':'none';
}

SubHeader.writeTooMuchHTML = function()
{
  var showTooMuch = (Cookie.get("showTooMuch") != "F");
  var showTooMuch = false;

  document.write("<div id='tooMuchDiv' style='margin-bottom:20px; display:"+(showTooMuch?'block':'none')+";'>");
  document.write("<div class='headerBox'>TOO MUCH INFORMATION?</div>");
  document.write("<div class='storyBox'>");
//PICASA	  document.write("<div style='float:right; margin-left:10px'><img src='<?php bloginfo('template_directory');?>/images/widgets/dontPanic.200x150.jpg'></div>");
  document.write("<div style='float:right; margin-left:10px'><img src='http://lh3.ggpht.com/_KbQiiiwpi74/SuPJJa6W-_I/AAAAAAAABFk/RM2ClwBobqA/s800/dontPanic.200x150.eeeeee.jpg'></div>");
  document.write("<p>This site is updated often, and describes many aspects of the Space Elevator Games - ongoing activities, technical background, people involved, and more...  For a first-time visitor, it can be a bit overwhelming!  Here's a quick &quot;Start Here&quot; guide, to help you find your way:</p>");
  document.write("<p>The movie on the top right is a good introduction to the games. The right-hand-side column (below it) contains information that is mostly static - take your time and read through it first.</p>");
  document.write("<p>Next, turn your attention to the blog below - this is the portion of the site that updates often. Hint: You can limit the number of posts that you see by using the <a href='#siteNav'>SITE NAV</a> box on the right to focus on only a single category of posts at a time. Another Hint: Blogs arrange posts so that the newest ones display near the top of the page. To get your bearings, it might help to go to the earliest post and work your way back up the page.</p>");
  document.write("<p><a href='javascript:void(SubHeader.toggleTooMuch())'>OK, got it, now be gone!</a></p>");
  document.write("</div></div>");
}

SubHeader.toggleTooMuch = function()
{
  var showTooMuch = (Cookie.get("showTooMuch") != "F");
  showTooMuch = !showTooMuch
  Cookie.set("showTooMuch",showTooMuch?"T":"F",100);
  var div1 = getDocObj("tooMuchDiv");
  if (div1 && div1.style) div1.style.display = showTooMuch?'block':'none';
}

//-------------- THERMOMETER
if (srcFind) swAlert(4)

function Thermometer() {}

Thermometer.write = function(fraction)
{
  var topPx = 22 + Math.round((1-fraction)*160);
  var heightPx = 5 + Math.round(fraction*160);
  document.write("<div id='redThermometerDiv' style='position:absolute; left:16px; top:"+topPx+"px; height:"+heightPx+"px; width:14px; z-index:+1; background-color:#ff0000; '></div>");
}

Thermometer.set = function(fraction)
{
  var topPx = 32 + Math.round((1-fraction)*160);
  var heightPx = 5 + Math.round(fraction*160);
  var o = getDocObj("redThermometerDiv");
  if (o && o.style)
  {
    o.style.top = topPx;
    o.style.height = heightPx;
  }
}

Thermometer.creep = function(targetFraction)
{
  var targetTop = 32 + Math.round((1-targetFraction)*160);
  var o = getDocObj("redThermometerDiv");
  if (o && o.style)
  {
    var t = o.style.pixelTop;
	var h = o.style.pixelHeight;
	if (targetTop == t)
	  return;
	var s = (targetTop > t) ? 1 : -1
     o.style.pixelTop +=  s;
     o.style.pixelHeight -= s;
     window.setTimeout("Thermometer.creep("+targetFraction+")",100)
  }
}

	
if (srcFind) swAlert(6)

// -------------------------  VIDEO JUKEBOX
function VideoJukebox()	{}
	
VideoJukebox.movieList = [
["kjaflfwEuAs",0,"trailer 1"],
["6Ddl55DCh-c",0,"whiteboard 1"],
["_-XoafyJ9K4",0,"the \"WHAT\" movie"],
["jfKKy33rb0U",0,"the \"WHY\" movie"]
]

VideoJukebox.YOUTUBEHTML = function(clipId,beMute)
{
return "\
<object id='mediaPlayer' width='320' height='265'>\
<param name='movie' value='http://www.youtube.com/v/"+clipId+"&hl=en&fs=1&rel=0&enablejsapi=1'></param>\
<param name='allowFullScreen' value='true'></param>\
<param name='allowscriptaccess' value='always'></param>\
<embed src='http://www.youtube.com/v/"+clipId+"&hl=en&fs=1&rel=0&enablejsapi=1' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='320' height='265'></embed>\
</object>";
}
	
VideoJukebox.writeContentDivs = function()
{
	document.write("<div id='VJB' class='sliderwrapper' style='margin-bottom:10px; height:265px'>");
	for (var i = 0; i<VideoJukebox.movieList.length; i++)
	{
	  var movieHTML = "";
	  switch (VideoJukebox.movieList[i][1])
	  {
	    case 0: movieHTML = VideoJukebox.YOUTUBEHTML(VideoJukebox.movieList[i][0]); break;
	  }
	  document.write("<div class='contentdiv'>"+movieHTML+"</div>");
	}
	document.write("</div>");
}

VideoJukebox.writeSelectorDivs = function()
{
	document.write("<div id='paginate-VJB' class='pagination'>");
	for (var i = 0; i<VideoJukebox.movieList.length; i++)
	{
	  document.write("<a href='#' class='toc'>"+VideoJukebox.movieList[i][2]+"</a>");
	}
	document.write("</div>");
}


/********************** CODE FORM LIVE.JS ********************************/

//  JSON CODE
var scripts = new Array();

var jsReqMethod = 1;
function reqJSData(reqURL)
{
  var e = document.createElement('script');
  switch (jsReqMethod)
  {
  case 1:
    e.src = reqURL;
    e.type = "text/javascript";
    document.getElementsByTagName("head")[0].appendChild(e);
    break;
  case 2:
    e.setAttribute('src', reqURL);
    e.setAttribute('type', "text/javascript");
    document.body.appendChild(e);
    break;
  }
  scripts.push(e);
}

function killJSReq()
{
  var e = scripts.shift();
  switch (jsReqMethod)
  {
  case 1:
    document.getElementsByTagName("head")[0].removeChild(e)
	break;
  case 2:
    document.body.removeChild(e)
	break;
  }
}


//SLIDESHOW CODE

function slideshowProcessImages(obj)
{
  photoConsole.processImages(obj);
}


//SLIDESHOW OBJECT CODE
function SlideShow(cId,esdd)
{
  this.canvasId = cId;
  this.extShowDescrDiv = esdd;
  this.fadeShow = null;
}


//to be called when wanting to reload images from a picasaWeb album
SlideShow.prototype.initPicasaWeb = function(u,a)
{
  reqJSData("http://picasaweb.google.com/data/feed/base/user/"+u+"/album/"+a+"?imgmax=400&alt=json-in-script&callback=slideshowProcessImages");
}

SlideShow.prototype.showDescriptions = function(state)
{
  if (!this.fadeShow)
    return;
  this.fadeShow.showhidedescpanel("show");
  if (this.extShowDescrDiv)
    document.getElementById(this.extShowDescrDiv).style.display = "none";
}

//to be called back by JSON code
SlideShow.prototype.processImages = function(obj)
{
  var imageList = new Array();
  var entryList = obj.feed.entry;
//  alert(entryList.length);
  for (var i=0; i<entryList.length; i++)
  {
    var url = entryList[i].media$group.media$content[0].url;
	var descr = entryList[i].media$group.media$description.$t;
    var link = "";
	var target = "";
	var linkPos = descr.lastIndexOf("http://");
	if (linkPos != -1)
	{
	  link = descr.substr(linkPos);
	  descr = descr.substr(0,linkPos);
	  target = "_blank";
	}
	var title = entryList[i].media$group.media$title.$t;
	var height = entryList[i].media$group.media$content[0].height;
	var width = entryList[i].media$group.media$content[0].width;
	var ar = height/width;
	if (ar > 1)  //height>400
	  url = url.replace("s400","s288");
	else if (ar > 0.9375)  //width=400, height > 375 
	  url = url.replace("s400","s288");
	else if (ar > 0.75)  //width=400, height > 300
	  url = url.replace("s400","s320");
//	var src = entryList[i].content.src;
//    var text = (descr.charAt(0) == "_") ? descr.substr(1) : "<b>" + title + ":</b> " + descr;
    var text = (descr.charAt(0) == "_") ? descr.substr(1) : "<span title='"+title+"'>" + descr + "</span>";
	//text += ":"+height+"x"+width;
	//text += url;
    imageList.push([url,link,target,text]);
//	alert(url+"---"+src);
  }
  
  this.fadeShow = new fadeSlideShow({
  wrapperid: this.canvasId,
  dimensions: [400,300],
  imagearray: imageList,
/*	imagearray: [
		["http://i26.tinypic.com/11l7ls0.jpg", "", "", "Nothing beats relaxing next to the pool when the weather is hot."],
		["http://i29.tinypic.com/xp3hns.jpg", "http://en.wikipedia.org/wiki/Cave", "_new", "Some day I'd like to explore these caves!"],
		["http://i30.tinypic.com/531q3n.jpg"],
		["http://i31.tinypic.com/119w28m.jpg", "", "", "What a beautiful scene with everything changing colors."] //<--no trailing comma after very last image element!
	],*/
  displaymode: {type:'auto', pause:3500, cycles:0, wraparound:false},
  persist: false,
  fadeduration: 500,
  descreveal: "ondemand", //"always",
  togglerid: ""
  });

  if (this.extShowDescrDiv)
    document.getElementById(this.extShowDescrDiv).style.display = "inline";
}


//VIDEOSHOW CODE

function showYouTubeList(obj)
{
  var videoList = new Array();
  var entryList = obj.feed.entry;
//  alert(entryList.length);
videoList.push("<div style='font-weight:bold; text-decoration:underline'>Our Favorite Videos:</div>")
  for (var i=0; i<entryList.length; i++)
  {
    var ytIdURL = entryList[i].id.$t;
	var ytId = ytIdURL.substr(ytIdURL.lastIndexOf("/")+1);
	var ytTitle = entryList[i].title.$t;
	//alert(ytId+":"+ytTitle);
	videoList.push("<li style='margin-left:15px'><a class='greenMon' href='javascript: void ytShow(\""+ytId+"\")'>"+ytTitle+"</a></li>");
  }
  var getAllListCmd = 'javascript: void reqJSData("http://gdata.youtube.com/feeds/users/SpacewardFoundation/uploads?alt=json-in-script&format=5&callback=showYouTubeList");'
//  videoList.push("<a class='greenMon' style='text-decoration:underline' href='"+getAllListCmd+"'>show ALL of our video clips</a>");

  videoSelector.fillCanvas("<div class='greenMon' style='overflow-y:auto; width:100%; height:334px; text-align:left; padding:5px'><ul style='margin:0'>" + videoList.join("") + "</ul></div>");
}


function ytShow(clipId)
{
//  document.getElementById("videoDiv").style.borderWidth=0;
  videoSelector.fillCanvas(ytHTML(clipId));
}

function ytHTML(clipId)
{
  var width = 425; //320
  var height = 344; //265  also specified in showYouTubeHTML, 10 less (334)
  return "\
<object id='mediaPlayer' width='"+width+"' height='"+height+"'>\
<param name='movie' value='http://www.youtube.com/v/"+clipId+"&hl=en&fs=1&rel=0&enablejsapi=1'></param>\
<param name='allowFullScreen' value='true'></param>\
<param name='allowscriptaccess' value='always'></param>\
<embed src='http://www.youtube.com/v/"+clipId+"&hl=en&fs=1&rel=0&enablejsapi=1' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='"+width+"' height='"+height+"'></embed>\
</object>";
}


//-------------------------------------------------------------------------
//SELECTOR CODE
function Selector(pa,f,tw,bw,m)
{
  Selector.objList[Selector.objList.length] = this;  //self register
  this.objId = Selector.objList.length-1;
  this.pageArray = pa;
  this.clickFunction = f;
  this.tmpMsg = (m == null) ? "<br><br>LOADING MEDIA<br>Please Stand By" : m;
  this.totalWidth = tw;
  this.buttonWidth = bw;
  this.nominalGap = (this.totalWidth - (this.buttonWidth * this.pageArray.length)) / (this.pageArray.length - 1);
  this.integerGap = Math.floor(this.nominalGap);
  this.gapGap = this.totalWidth - (this.buttonWidth * this.pageArray.length) - (this.integerGap * (this.pageArray.length - 1))

  this.buttonOutBGC = "#CCCCCC";
  this.buttonOutC = "#000044";
  this.buttonOutStyle = 'width:'+this.buttonWidth+'px; padding:0; border: solid black 1px; background-color:'+this.buttonOutBGC+'; color:'+this.buttonOutC+'; font-family: "arial", "lucida console", sans-serif; font-size: 10pt; text-align:center; font-weight:700; cursor: pointer';
  this.buttonInBGC = "#DFDFF7";
  this.buttonInC = "#440000";
  this.buttonInStyle = 'width:'+this.buttonWidth+'px; padding:0; border: solid black 1px; background-color:'+this.buttonInBGC+'; color:'+this.buttonInC+'; font-family: "arial", "lucida console", sans-serif; font-size: 10pt; text-align:center; font-weight:700; cursor: pointer';
  this.buttonHiC = "#ff0066";

  this.currentButton = -1;
}
Selector.objList = new Array();  //list of all Selectors

Selector.prototype.writeCanvas = function()
{
  document.write("<div id='C_"+this.objId+"' style='margin:0; padding:0; text-align:center; width:100%'");
  document.write(this.tmpMsg);
  document.write("</div>");
}

Selector.prototype.fillCanvas = function (htmlStr)
{
  getDocObj("C_"+this.objId).innerHTML = htmlStr;
}

Selector.prototype.writeButtons = function(n)
{
  document.write("<table width="+this.totalWidth+" border=0 cellspacing=0 cellpadding=0 style='margin:0'><tr valign='bottom'>");
  for (i=0; i<this.pageArray.length; i++)
  {
    var mrg = (i == 0) ? "" : " style='padding-left:"+this.integerGap+"px'"
    document.write("<td nowrap"+mrg+">");
    this.writeButton(i,this.pageArray[i],(n==i));
    document.write("</td>");
  }
  document.write("</tr></table>");
}

Selector.prototype.writeButton = function(n,text,isOn)
{
  if (!isOn)
    document.write("<div id='S_"+this.objId+"_B_"+n+"' onClick='Selector.doClick("+this.objId+","+n+")' style='"+this.buttonOutStyle+"'>"+text+"</div>");
  else
  {
    document.write("<div id='S_"+this.objId+"_B_"+n+"' onClick='Selector.doClick("+this.objId+","+n+")' style='"+this.buttonInStyle+"'>"+text+"</div>");
	this.currentButton = n;
  }
}


Selector.prototype.highlightButton = function(n)
{
  var button = getDocObj("S_"+this.id+"_B_"+n);
  button.style.color = this.buttonHiC;
}


Selector.doClick = function(id,n)  //static function on s, can convert to normal member function
{
  var s = Selector.objList[id];
  getDocObj("C_"+id).innerHTML = s.tmpMsg;  //clear out window
  Selector.doClick2(id,n);
//  setTimeout("Selector.doClick2("+id+","+n+")",300);  //refresh, continue in a mSec
}

Selector.doClick2 = function(id,n,justButton)  //static function on s, can convert to normal member function
{
  var s = Selector.objList[id];
  if (s.currentButton != -1)
  {
    var oldButton = getDocObj("S_"+id+"_B_"+s.currentButton);
//	oldButton.style.borderStyle = "outset";
	oldButton.style.backgroundColor = s.buttonOutBGC;
	oldButton.style.borderColor = "black";
	oldButton.style.color = s.buttonOutC;
  }
  s.currentButton = n;
  var newButton = getDocObj("S_"+id+"_B_"+n);
//  newButton.style.borderStyle = "inset";
  newButton.style.backgroundColor = s.buttonInBGC;
  newButton.style.borderColor ="black";
  newButton.style.color = s.buttonInC;

  if (!justButton)
    s.clickFunction(n);
}



