/* ----------------------------------------------------------------------------
	
	JavaScript Public Document
	Castanet Flash Media Player
	/media/support/mediasystem.js
	
	Written October 2006 - Todd Cytra <tcytra@gmail.com>
	
	Usage:
	Called from /media/player.php
	
---------------------------------------------------------------------------- */


/** Global Variable Definitions
-------------------------------
---------------------------------------------------------------------------- */
var mediaadkey		= "";
var mediaadsrc		= "";
var mediaadtype		= "";
var currentclip		= 0;
var currentcat		= "default";
var mediacat		= "all";
var screenmode		= "default";
var playerx		= 480;
var playery		= 327;
var searched		= false;
var keywords		= "";



/** Primary Operation Functionality
-----------------------------------
The following functions encompass the primary functionality of the window
---------------------------------------------------------------------------- */

// The initial call to the window from onload
// ------------------------------------------
var timer1;
function initWindow(ignoread) {
  // let's do some important initial setup
  self.focus();
  screenmode = "default";
  if (browser.ie7) defaultheight = defaultheight + 25;
  window.resizeTo(defaultwidth,defaultheight);
  window.moveTo(50,50);
  
  // Right about here we need to re-sort the menuItem array (little bit of a hack, moments before live lol)
  remember = mediaItem[currentclip].newsid;
  remember2 = mediaItem[currentclip].orderby;
  mediaItem.sort(sortbydate);
  for (i=0; i<mediaItem.length; i++) {
  	if (mediaItem[i].newsid == remember && mediaItem[i].orderby == remember2) {
  	  currentclip = i;
  	  break;
  	}
  }
  
  // now we'll generate the menu (sorted by date, mixed media, newest first)
  // determine and store the active item
  // script options for video only/audio only/reverse order?
  generateMediaMenu(1);
  
  // set the visibility to the default setup
  setVisibility('allfull',0);
  setVisibility('alldefault',1);
  
  // at this point the document is set up so now we run the ad
  if (!ignoread) {
    echo("nowplaying","Advertisement");
    c = "";
    c += "<a href=\"http://www.castanet.net/cgi-bin2/stats/clickcounter.cgi?id=" + mediaadkey + "&region=491\" target=\"_blank\">\n";
    c += "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"\n";
    c += "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\"\n";
    c += "width=\"" + playerx + "\" height=\"" + playery + "\"\n";
    c += "id=\"adtimer\" align=\"middle\">\n";
    c += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />\n";
    c += "<param name=\"movie\" value=\"" + mediaadsrc + "\" />\n";
    c += "<param name=\"quality\" value=\"high\" />\n";
    c += "<param name=\"bgcolor\" value=\"#FFFFFF\" />\n";
    c += "<embed src=\"" + mediaadsrc + "\"\n";
    c += "quality=\"high\" bgcolor=\"#FFFFFF\"\n";
    c += "width=\"" + playerx + "\" height=\"" + playery + "\"\n";
    c += "name=\"adtimer\" align=\"middle\" allowScriptAccess=\"sameDomain\"\n";
    c += "type=\"application/x-shockwave-flash\"\n";
    c += "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n";
    c += "</object>\n";
    c += "</a>\n";
    echo("mediaplayer",c);
    
    timer1 = setTimeout("adtimer(15)",1000);
    //setTimeout("makeMediaObj(currentclip,playerx,playery,'mediaplayer')",15000);
  } else {
    makeMediaObj(currentclip,playerx,playery,'mediaplayer');
  }
}
function adtimer(sec) {
  message = "";
  sec--;
  if (sec > 10) {
  	timer1 = setTimeout("adtimer(" + sec + ")",1000);
  } else if (sec > 0) {
  	message = "Advertisement - Your selection will play in " + sec + " seconds...";
  	echo("nowplaying",message);
  	timer1 = setTimeout("adtimer(" + sec + ")",1000);
  } else makeMediaObj(currentclip,playerx,playery,'mediaplayer');
}

// Redescribes the window to the user's screen dimensions
// ------------------------------------------------------
function initFullscreen() {
  self.focus();
  screenmode = "full";
  
  // turn all the primary layers off
  setVisibility('alldefault',0);
  
  // clear the content
  c = "";
  echo("mediaplayer",c);
  
  // set the window dimensions
  window.moveTo(5,5);
  window.resizeTo(screen.width-20,screen.height-50);
  
  // enable the necessary layers
  setVisibility('allfull',1)
  
  // set the dimensions
  setwidth	= screen.width - 60;
  setheight	= setwidth * .625;
  // adjust for widescreens if necessary
  if (setheight/screen.height > .75) {
  	setheight = screen.height - 200;
  	setwidth  = setheight / .625;
  }
  
  makeMediaObj(currentclip,setwidth,setheight,'fullplayer');
}


// Generate and write all document menus
// -------------------------------------
function generateMediaMenu(nolinks) {
  document.searchForm.searchfor.value = "";
  
  // Build and display the category menu in the menucats bar (top of window)
  c  = "";

  // This should all seriously be done from an array and a method...
  if (mediacat == "all") { c += "<span class=\"catstext\" style=\"background-color:#4761A4;color:white;\">ALL</span> \n"; }
  else {
  	if (nolinks) c+= "<span class=\"catstext\">ALL</span> \n";
  	else c += "<a class=\"menucat\" href=\"javascript:void(0);\" onclick=\"mediacat='all';generateMediaMenu();\"><span class=\"catstext\">ALL</span></a> \n";
  }
  
  if (mediacat == "news") { c += "<span class=\"catstext\" style=\"background-color:#4761A4;color:white;\">NEWS</span> \n"; }
  else {
  	if (nolinks)  c += "<span class=\"catstext\">NEWS</span>\n";
  	else c += "<a class=\"menucat\" href=\"javascript:void(0);\" onclick=\"mediacat='news';generateMediaMenu();\"><span class=\"catstext\">NEWS</span></a> \n";
  }
  
  if (mediacat == "sports") { c += "<span class=\"catstext\" style=\"background-color:#4761A4;color:white;\">SPORTS</span> \n"; }
  else {
  	if (nolinks)  c += "<span class=\"catstext\">SPORTS</span>\n";
  	else c += "<a class=\"menucat\" href=\"javascript:void(0);\" onclick=\"mediacat='sports';generateMediaMenu();\"><span class=\"catstext\">SPORTS</span></a> \n";
  }
  
  if (mediacat == "entertainment") { c += "<span class=\"catstext\" style=\"background-color:#4761A4;color:white;\">ENTERTAINMENT</span> \n"; }
  else {
  	if (nolinks)  c += "<span class=\"catstext\">ENTERTAINMENT</span>\n";
  	else c += "<a class=\"menucat\" href=\"javascript:void(0);\" onclick=\"mediacat='entertainment';generateMediaMenu();\"><span class=\"catstext\">ENTERTAINMENT</span></a> \n";
  }
  
  // newscast
  if (mediacat == "newscast") { c += "<span class=\"catstext\" style=\"background-color:#4761A4;color:white;\">NEWSCASTS</span> \n"; }
  else {
  	if (nolinks) c += "<span class=\"catstext\">NEWSCASTS</span>\n"; 
  	else c += "<a class=\"menucat\" href=\"javascript:void(0);\" onclick=\"mediacat='newscast';generateMediaMenu();\"><span class=\"catstext\">NEWSCASTS</span></a> \n";
  }
  
  // citycouncil
  if (mediacat == "citycouncil") { c += "<span class=\"catstext\" style=\"background-color:#4761A4;color:white;\">KELOWNA COUNCIL</span> \n"; }
  else {
  	if (nolinks) c += "<span class=\"catstext\">KELOWNA COUNCIL</span>\n";
  	else c += "<a class=\"menucat\" href=\"javascript:void(0);\" onclick=\"mediacat='citycouncil';generateMediaMenu();\"><span class=\"catstext\">KELOWNA COUNCIL</span></a> \n";
  }
  
  // searchresult
  if (mediacat == "searchresult") { c += "<span class=\"catstext\" style=\"background-color:#4761A4;color:white;\">SEARCH</span>\n"; }
  else {
  	if (nolinks) c += "<span class=\"catstext\">SEARCH</span>\n";
  	else c += "<a class=\"menucat\" href=\"javascript:void(0);\" onclick=\"mediacat='searchresult';generateMediaMenu();\"><span class=\"catstext\">SEARCH</span></a>\n";
  }
  
  echo("mediacats",c);
  
  // Build and display the mediaclip menu in the mediamenu area (right side of window)
  c  = ""
  
  // Here we have the Search display when a search has been performed, we either have...
  if ((mediacat == 'searchresult') && (searched)) {
  	// ... Results
  	if (searchItems.length > 0) {
  	  for (i=0; i<searchItems.length; i++) {
  	  	if ((i == currentclip) && (currentcat == "search")) c += "<div class=\"currentmenuitem\" onclick=\"currentcat='search';makeMediaObj(" + i + "," + playerx + "," + playery + ",'mediaplayer');\">\n";
  	  	else  c += "<div class=\"menuitem\" onmouseover=\"this.style.backgroundColor='#4761A4';this.style.color='white';\" onmouseout=\"this.style.backgroundColor='#4A597F';this.style.color='white';\" onclick=\"currentcat='search';makeMediaObj(" + i + "," + playerx + "," + playery + ",'mediaplayer')\">\n";
  	  	c += "<span class=\"menutitle\">" + searchItems[i].newstitle + "</span><br />\n";
  	  	c += "<span class=\"menudescription\">&nbsp;&nbsp;" + searchItems[i].mediatype + " - " + searchItems[i].postdate + "</span>\n";
  	  	c += "</div>\n";
  	  }
  	  
  	// ... Or no results
  	} else {
  	  c += "<div class=\"menuitem\">";
  	  c += "We're sorry, there were no results available for <span class=\"menutitle\">" + keywords + "</span>";
  	  c += "</div>\n";
  	}
  	
  // Here we have the standard Search message which is displayed until a search is made
  } else if (mediacat == 'searchresult') {
  	c += "<div class=\"menuitem\">\n";
  	c += "<p>To perform a search, enter any number of keywords into the text-field above, seperated by spaces, then press <span class=\"menutitle\">Go</span>.</p>\n"
  	c += "<p>Note: Common words such as 'and' or 'the' will be ignored.</p>\n";
  	c += "</div>\n";
  	
  } else {
  	for (i=0; i<mediaItem.length; i++) {
  	  if ( ((mediacat == 'all') && ( (mediaItem[i].storytype != 'newscast') || (mediaItem[i].storytype != 'citycouncil') )) || ((mediacat != 'all') && (mediacat == mediaItem[i].storytype)) ) {
  	  	if ((i == currentclip) && (currentcat != "search")) c += "<div class=\"currentmenuitem\" onclick=\"currentcat='default';makeMediaObj(" + i + "," + playerx + "," + playery + ",'mediaplayer');\">\n";
  	  	else if (nolinks) c += "<div class=\"menuitemnolink\">\n";
  	  	else  c += "<div class=\"menuitem\" onmouseover=\"this.style.backgroundColor='#4761A4';this.style.color='white';\" onmouseout=\"this.style.backgroundColor='#4A597F';this.style.color='white';\" onclick=\"currentcat='default';makeMediaObj(" + i + "," + playerx + "," + playery + ",'mediaplayer')\">\n";
  	  	c += "<span class=\"menutitle\">" + mediaItem[i].newstitle + "</span><br />\n";
  	  	c += "<span class=\"menudescription\">&nbsp;&nbsp;" + mediaItem[i].mediatype + " - " + mediaItem[i].postdate + "</span>\n";
  	  	c += "</div>\n";
  	  }
  	}
  }
  echo("mediamenu",c);
}


// Writes the flash media player to the document
// ---------------------------------------------
function makeMediaObj(ix,setw,seth,targ) {
  // first let's set the currentclip and regenerate the menu
tclip = currentclip;
  currentclip = ix;
  generateMediaMenu();
  
  // decide if we're playing back a search result
  if (mediacat == 'searchresult') PlayBack = searchItems;
  else PlayBack = mediaItem;
  
  // and decide which audio backdrop we would like
  switch (mediacat) {
  	case "newscast":
  	  backvisual	= "AudioNewscast";
  	  break;
  	  
  	case "citycouncil":
  	  backvisual	= "CouncilAudio";
  	  break;
  	
  	default:
  	  backvisual	= "AudioOnly";
  }
  
  // then let's clear any previous content
  c = "";
  echo("mediaplayer",c);
  echo("fullplayer",c);
  
  // write it up to the hit counter (if it's a newsclip-based item)
  if (!PlayBack[ix].userhit) {
    //if ((PlayBack[ix].storytype == 'news') || (PlayBack[ix].storytype == 'sports') || (PlayBack[ix].storytype == 'entertainment')) registerUserhit(PlayBack[ix].mediatype,PlayBack[ix].newsid);
    //if ((PlayBack[ix].storytype == 'news') || (PlayBack[ix].storytype == 'newscast') || (PlayBack[ix].storytype == 'sports') || (PlayBack[ix].storytype == 'entertainment')) registerUserhit(PlayBack[ix].storytype,PlayBack[ix].mediatype,PlayBack[ix].newsid);
    registerUserhit(PlayBack[ix].storytype,PlayBack[ix].mediatype,PlayBack[ix].newsid);
    PlayBack[ix].userhit = 1;
  }
  
  // let's set the title of the current clip into the Now Playing bar...
  echo("mediatitle",PlayBack[ix].cutline);
  
  // make sure applicable functionality is enabled
  if (PlayBack[ix].mediatype == 'Video') {
    if (screenmode == "default") {
      mplayer = "VideoPlayer.swf";
      document.windowControl.stopPlayback.disabled = false;
      document.windowControl.fullScreen.disabled = false;
    } else if (screenmode == "full") {
      mplayer = "VideoPlayerFullScreen.swf";
    }
  
  } else if (PlayBack[ix].mediatype == 'Audio') {
    mplayer = "AudioPlayer.swf";
    document.windowControl.stopPlayback.disabled = false;
    document.windowControl.fullScreen.disabled = true;
  } else {
    document.windowControl.stopPlayback.disabled = true;
    document.windowControl.fullScreen.disabled = true;
  }
  
  if (targ == "fullplayer") c += "<p>&nbsp;</p>\n";
  
  // now we can generate and run the new media item
  c += "<div style=\"text-align:center;\"> <!-- ix=" + ix + " currentclip=" + tclip + " -->\n";
  c += "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"\n";
  c += "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\"\n";
  c += "width=\"" + setw + "\" height=\"" + seth + "\"\n";
  c += "id=\"player\" align=\"middle\">\n";
  c += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />\n";
  c += "<param name=\"FlashVars\" value=\"mediaclip=" + PlayBack[ix].mediasrc;
  
  if (PlayBack[ix].mediatype == 'Audio') c += "&backvisual=" + backvisual + ".swf";
  
  c += "\" />\n";
  c += "<param name=\"movie\" value=\"" + mplayer + "\" />\n";
  c += "<param name=\"quality\" value=\"high\" />\n";
  c += "<param name=\"bgcolor\" value=\"#000000\" />\n";
  c += "<embed src=\"" + mplayer + "\" FlashVars=\"mediaclip=" + PlayBack[ix].mediasrc
  
  if (PlayBack[ix].mediatype == 'Audio') c += "&backvisual=" + backvisual + ".swf";
  
  c+= "\"\n";
  c += "quality=\"high\" bgcolor=\"#000000\"\n";
  c += "width=\"" + setw + "\" height=\"" + seth + "\"\n";
  c += "name=\"player\" align=\"middle\" allowScriptAccess=\"sameDomain\"\n";
  c += "type=\"application/x-shockwave-flash\"\n";
  c += "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n";
  c += "</object>\n";
  c += "</div>\n";
  
  if (targ == "fullplayer") c += "<p>&nbsp;</p>\n";
  echo(targ,c);
}





/** XMLResponse Functionality
-----------------------------
The following functions are used to update the environment 'on the fly'
---------------------------------------------------------------------------- */

// Build menu items for search results
// ------------------------------------
var responsedata	= new Array(0);
var searchItems		= new Array(0);
var searchindex		= 0;
function processSearchResults(returnstring) {
  // let's make sure we reset the data arrays
  responsedata.length	= 0;
  searchItems.length	= 0;
  searchindex		= 0;
  
  // We've performed a search now and this must be set to true for generateMediaMenu to follow through
  //  By getting this far the backend has reported some kind of response... if even an empty one
  //  In generateMediaMenu, if searchItems has no length then we have no results to show the user
  searched		= true;
  
  // if we have a response we will need to split the data
  if (returnstring != "noresults") {
  	responsedata = returnstring.split("::");
  	for(i=0; i<responsedata.length; i++) {
  	  var dataarray = new Array(0);
  	  dataarray = responsedata[i].split("|");
  	  searchItems[searchindex] = new menudef(
  	  	dataarray[0],
  	  	dataarray[1],
  	  	dataarray[2],
  	  	dataarray[3],
  	  	dataarray[4],
  	  	dataarray[5],
  	  	dataarray[6]
  	  );searchindex++;
  	}
  	// prepare menu for results
  	mediacat = 'searchresult';
  	generateMediaMenu();
  	
  // otherwise we just tell the user there are no results
  } else {
  	// prepare menu for no results
  	mediacat = 'searchresult';
  	generateMediaMenu();
  }
}

function processHitResult(returnstring) {
  // Basically, we'll do nothing.
  // But I want to confirm the hit..
  foo = 'foo';
  //alert(returnstring);
}

// AJAX functionality
// ------------------------------------
function registerUserhit(storytype,mediatype,newsid) {
  url = "/media/userhit.php?storytype=" + storytype + "&mediatype=" + mediatype + "&newsid=" + newsid + "&edition=" + edition;
  loadXMLDoc(url);
}
function getResults(loc,input) {
  keywords = input;
  input = input.toLowerCase();
  if (input.indexOf(" ") != -1) input = input.replace(/ /gi,"+");
  url = loc + input;
  loadXMLDoc(url);
}
var request;
function loadXMLDoc(url) {
  request = false;
  if (window.XMLHttpRequest) {
        try {
          request = new XMLHttpRequest();
        }
        catch(e) {
          request = false;
        }
  } else if (window.ActiveXObject) {
        try {
          request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e) {
          try {
                request = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e) { request = false; }
        }
  }
  if (request) {
        request.onreadystatechange = processRequestChange;
        request.open("GET", url, true);
        request.send(null);
  }
}
function processRequestChange() {
  if (request.readyState == 4) {
        if (request.status == 200) {
          response = request.responseXML.documentElement;
          method = response.getElementsByTagName('method')[0].firstChild.data;
          result = response.getElementsByTagName('result')[0].firstChild.data;
          eval(method + '(result)');
        } else {
          alert("There was an issue retrieving the data:\n" + request.statusText);
        }
  }
}





/** Document Object Definitions
-------------------------------
The following functions are used to build various objects used in the script
---------------------------------------------------------------------------- */

// Menu Item Object
// ------------------------------------
var clipindex = 0;	var mediaItem	= new Array();

function menudef(newsid,typeid,newstitle,cutline,postdate,mediatype,mediasrc,orderby) {
  this.newsid		= newsid;
  this.storytype	= (typeid==1000)?"searchresult":(typeid==2000)?"newscast":(typeid==3000)?"citycouncil":(typeid==8)?"entertainment":(typeid==7)?"sports":"news";
  this.newstitle	= newstitle;
  this.cutline		= cutline;
  this.postdate		= postdate;
  this.mediatype	= mediatype;
  this.mediasrc		= mediasrc;
  this.userhit		= 0;
  this.orderby		= orderby;
}

function sortbydate(a,b) {
  var x = a.orderby;
  var y = b.orderby;
  return ((x < y)?1:((x > y)?-1:0));
}

// Browser & Platform Objects
// ------------------------------------
function Browser() {
  this.agt		= navigator.userAgent.toLowerCase();
  this.app		= navigator.appName.toLowerCase();
  
  this.dom		= document.getElementById?1:0;
  this.ie		= (this.app.indexOf("microsoft") != -1)?1:0;
  this.nav		= (this.app.indexOf("netscape") != -1)?1:0;
  this.opera		= (this.agt.indexOf("opera") != -1)?1:0;
  
  this.ie4		= (this.ie && this.agt.indexOf("msie 4") > -1)?1:0;
  this.ie5		= (this.ie && this.agt.indexOf("msie 5") > -1 && !this.opera)?1:0;
  this.ie6		= (this.ie && this.agt.indexOf("msie 6") > -1 && !this.opera)?1:0;
  this.ie7		= (this.ie && this.agt.indexOf("msie 7") > -1 && !this.opera)?1:0;
  this.ie5up		= (this.ie5 || this.ie6 || this.ie7)?1:0;
  
  this.nav4		= (document.layers && !this.dom)?1:0;
  this.nav5up		= (this.nav && this.dom)?1:0;
  
  this.mozilla		= (this.nav && this.agt.indexOf("gecko") > -1)?1:0;
  this.firefox		= (this.nav && this.agt.indexOf("firefox") > -1)?1:0;
  
  this.opera5		= (this.opera && document.getElementById)?1:0
  
  this.compat		= ((this.nav5up) || (this.ie5up) || (this.opera5))?1:0;
}
var browser		= new Browser();
var defaultwidth	= ((browser.nav5up)||(browser.firefox))?665:670;
var defaultheight	= ((browser.nav5up)||(browser.firefox))?516:519;

function Platform() {
  this.agt		= navigator.userAgent.toLowerCase();
  
  this.win		= ((this.agt.indexOf("win") != -1) || (this.agt.indexOf("16bit") != -1))?1:0;
  this.mac		= (this.agt.indexOf("mac") != -1)?1:0;
  this.linux		= (this.agt.indexOf("inux") != -1)?1:0;
  this.other		= (!this.win && !this.mac && !this.linux)?1:0;
}
var platform		=  new Platform();





/** Utility Functionality
-------------------------
The following functions are used to streamline interaction with the DOM
---------------------------------------------------------------------------- */

// Element DOM References
// ------------------------------------
function getThisElement(o) {
  return (browser.dom)?document.getElementById(o):document.all.o;
}

function getParentElementID(o) {
  return (browser.dom)?getThisElement(o).parentNode.attributes["id"].value:0;
}

function makePix(i) {
  return eval("'" + i + "px'");
}

function echo(o,c) {
  getThisElement(o).innerHTML = c;
}

// set (o)bject (x) & (y) positions
function setElementPosition(o,x,y) {
  setLeft(o,x);
  setTop(o,y);
}

// set (o)bject (x) & (y) dimensions
function setElementGeometry(o,x,y) {
  setWidth(o,x);
  setHeight(o,y);
}

// set (o)object (l)eft in pixels
function setLeft(o,l) {
  getThisElement(o).style.left = makePix(l);
}

// set (o)object (t)op in pixels
function setTop(o,t) {
  getThisElement(o).style.top = makePix(t);
}

// set (o)bject (x) in pixels
function setWidth(o,x) {
  getThisElement(o).style.width = makePix(x);
}

// set (o)bject (y) in pixels
function setHeight(o,y) {
  getThisElement(o).style.height = makePix(y);
}

// set (o)bject (t)op, (r)ight, (b)ottom, and (l)eft clip
function setClip(o,t,r,b,l) {
  if (r == "byoffset") r = getOffsetWidth(o);
  if (b == "byoffset") b = getOffsetHeight(o);
  getThisElement(o).style.clip = "rect(" + t + "px " + r + "px " + b + "px " + l + "px)";
}

// set (o)bject background colour
function setBGColor(o,c) {
  getThisElement(o).style.backgroundColor = c;
}

// set (o)bject foreground colour
function setColor(o,c) {
  getThisElement(o).style.color = c;
}

// set (o)bject z-index
function setZindex(o,z) {
  getThisElement(o).style.zIndex = z;
}

// set (o)bject's visibility to (1) on or (0) off
function setVisibility(o,v) {
  if (o == "alldefault") {
    setVisibility('titlelogo',v);
    setVisibility('titlespot',v);
    setVisibility('mediacats',v);
    setVisibility('mediasearch',v);
    setVisibility('mediatitle',v);
    setVisibility('mediaplayer',v);
    setVisibility('wincontrols',v);
    setVisibility('mediamenu',v);
  } else if (o == "allfull") {
    setVisibility('fulltitlebar',v);
    setVisibility('fullplayer',v);
  } else {
    if (v) getThisElement(o).style.visibility = "visible";
    else getThisElement(o).style.visibility = "hidden";
  }
}

// Element Geometry Functionality
// ------------------------------------
function getOffsetWidth(o) {
  return (browser.dom)?getThisElement(o).offsetWidth:o.scrollWidth;
}

function getOffsetHeight(o) {
  return (browser.dom)?getThisElement(o).offsetHeight:o.scrollHeight;
}

function getTopPosition(o) {
  return (browser.dom)?parseInt(getThisElement(o).style.top):getThisElement(o).style.pixelTop;
}

function getLeftPosition(o) {
  return (browser.dom)?parseInt(getThisElement(o).style.left):getThisElement(o).style.pixelLeft;
}

function getRightPosition(o) {
  return getLeftPosition(o) + getOffsetWidth(o);
}

function getBottomPosition(o) {
  return getTopPosition(o) + getOffsetHeight(o);
}
