/*************************************************
*** 
*** This file is used to create the rollover
***   effect for various sections in each page.
***
*** See comments below to determine what code
***   controls what rollovers
*** 
*************************************************/

// Used by each rollover section to determine if browser can parse Javascript
var W3CDOM = (document.createElement && document.getElementsByTagName);

// On the load of window, call appropriate funcitons
/*
window.onload = function () {
  includeFlash (section);
  breadcrumbRollovers ();
  localRollovers ();
  globalRollovers ();
  // replaceFlashWithImage ();
  legalRollovers ();
}
*/

// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~
// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~

/*************************************************
*** 
*** This section is used to create the rollover
***   effect for breadcrumb elements
*** 
*************************************************/

var breadcrumbOvers = new Array();
var breadcrumbOuts = new Array();

function breadcrumbRollovers () {

  // If the W3C dom isn't supported, rollovers aren't supported
  if (!W3CDOM) return;
  
  // All the navigation images are in p#breadcrumbs
  var nav = document.getElementById ('breadcrumbs');
  
  // img.breadcrumbs is in p#breadcrumbs
  var imgs = nav.getElementsByTagName('img');
  
  // For every image in p#breadcrumbs, we want rollovers
  for (var i = 0; i < imgs.length; i++) {
  
    imgs[i].onmouseover = breadcrumbOver;
    imgs[i].onmouseout = breadcrumbOut;
    
    // Get the file extension
    var suffix = imgs[i].src.substring (imgs[i].src.lastIndexOf('.'));
    breadcrumbOuts[i] = new Image ();
    breadcrumbOuts[i].src = imgs[i].src;
    breadcrumbOvers[i] = new Image ();
    breadcrumbOvers[i].src = imgs[i].src.substring (0, imgs[i].src.lastIndexOf ('.')) + "_hover" + suffix;
    imgs[i].number = i;
  } 
}

function breadcrumbOver () {
  this.src = breadcrumbOvers [this.number].src;
}

function breadcrumbOut () {
  this.src = breadcrumbOuts [this.number].src;
}

// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~
// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~

/*************************************************
*** 
*** This section is used to create the rollover
***   effect for local navbar elements
*** 
*************************************************/

var localOvers = new Array();
var localOuts = new Array();

function localRollovers () {

  // If the W3C dom isn't supported, rollovers aren't supported
  if (!W3CDOM) return;
  
  // All the navigation images are in table#sidebar
  var sideTable = document.getElementById ('sidebar');
  
  // Get all the images in the above table
  var imgs = sideTable.getElementsByTagName ('img');
  
  // For every image in p#locals, we want rollovers
  for (var i = 0; i < imgs.length; i++) {
  
    // If classname not equal to "sidebar", skip iteration
    if (imgs[i].className != "sidebar")
      continue;
  
    imgs[i].onmouseover = localOver;
    imgs[i].onmouseout = localOut;
    
    // Get the file extension
    var suffix = imgs[i].src.substring (imgs[i].src.lastIndexOf('.'));
    localOuts[i] = new Image ();
    localOuts[i].src = imgs[i].src;
    localOvers[i] = new Image ();
    localOvers[i].src = imgs[i].src.substring (0, imgs[i].src.lastIndexOf ('.')) + "_hover" + suffix;
    imgs[i].number = i;
  }  
}

function localOver () {
  this.src = localOvers [this.number].src;
}

function localOut () {
  this.src = localOuts [this.number].src;
}

// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~
// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~

/*************************************************
*** 
*** This section is used to create the rollover
***   effect for global navbar elements
*** 
*************************************************/

var globalOvers = new Array();
var globalOuts = new Array();

function globalRollovers () {

  // If the W3C dom isn't supported, rollovers aren't supported
  if (!W3CDOM) return;
  
  // All the navigation images are in table#sidebar
  var globalTable = document.getElementById ('navbar');
  
  // Get all the images in the above table
  var imgs = globalTable.getElementsByTagName ('img');
  
  // For every image in p#locals, we want rollovers
  for (var i = 0; i < imgs.length; i++) {
  
    // If classname not equal to "sidebar", skip iteration
    if (imgs[i].className != "navbar")
      continue;
  
    imgs[i].onmouseover = globalOver;
    imgs[i].onmouseout = globalOut;
    
    // Get the file extension
    var suffix = imgs[i].src.substring (imgs[i].src.lastIndexOf('.'));
    globalOuts[i] = new Image ();
    globalOuts[i].src = imgs[i].src;
    globalOvers[i] = new Image ();
    globalOvers[i].src = imgs[i].src.substring (0, imgs[i].src.lastIndexOf ('.')) + "_hover" + suffix;
    imgs[i].number = i;
  }  
}

function globalOver () {
  this.src = globalOvers [this.number].src;
}

function globalOut () {
  this.src = globalOuts [this.number].src;
}

// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~
// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~

/*************************************************
*** 
*** This section is used to create the rollover
***   effect for legal disclaimer
*** 
*************************************************/

var legalOvers = new Image ();
var legalOuts = new Image ();

function legalRollovers () {

  // If the W3C dom isn't supported, rollovers aren't supported
  if (!W3CDOM) return; 
 
  // The "disclaimer" image!
  var disclaimer_img = document.getElementById ('disclaimer');
 
  // The rollover effect
  disclaimer_img.onmouseover = legalOver;
  disclaimer_img.onmouseout = legalOut;
  
  // Get the file extension
  var suffix = disclaimer_img.src.substring (disclaimer_img.src.lastIndexOf('.'));
  
  // Set legalOut and legalOver
  legalOuts.src = disclaimer_img.src;
  legalOvers.src = disclaimer_img.src.substring (0, disclaimer_img.src.lastIndexOf ('.')) + "_hover" + suffix;
  
}

function legalOver () {
  this.src = legalOvers.src;
}

function legalOut () {
  this.src = legalOuts.src;
}

// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~
// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~

/*************************************************
*** 
*** If W3C standards followed abut Flash  is not 
***   installed, or if installation is not known,
***   replace Flash file with banner image
***
*************************************************/

// W3C DOM is supported
function replaceFlashWithImage () {

  // If the W3C dom isn't supported, rollovers aren't supported
  if (!W3CDOM) return;
  
  //alert(flashinstalled);
  // Flash is not detected
  if (flashinstalled == 0 || flashinstalled == 1) {
  
    // Remove Flash file
    var flashContainer = document.getElementById ('forFlashMovie');
    removeChildrenFromNode (flashContainer);
    
    // Add image
    var bannerImage = document.createElement('img');
    bannerImage.setAttribute('src', '../images/masthead.jpg');
    bannerImage.setAttribute('id', 'banner');
    flashContainer.appendChild(bannerImage);
  }
}

function removeChildrenFromNode (node) {
   
   var len = node.childNodes.length;
   
   while (node.hasChildNodes()) {
      node.removeChild(node.firstChild);
   }
   
}

// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~

// Include Flash banners
function includeFlash (section) {

  var flash = '';

  if(section == 'company') {
    flash = '<object type="application/x-shockwave-flash" data="/flash/company.swf" width="800" height="180" id="banner" bgcolor="#393c29"><param name="movie" value="/flash/company.swf" id="banner" bgcolor="#393c29" /></object>';
  }
  
  else if (section == 'festival') {
    flash = '<object type="application/x-shockwave-flash" data="/flash/projects.swf" width="800" height="180" id="banner" bgcolor="#393c29"><param name="movie" value="/flash/projects.swf" id="banner" bgcolor="#393c29" /></object>';
  }
  
  else if (section == 'home') {
    flash = '<object type="application/x-shockwave-flash" data="/flash/home.swf" width="800" height="180" id="banner" bgcolor="#393c29"><param name="movie" value="/flash/home.swf" id="banner" bgcolor="#393c29" /></object>';
  }
  
    else if (section == 'test') {
    flash = '<object type="application/x-shockwave-flash" data="/flash/test.swf" width="800" height="180" id="banner" bgcolor="#393c29"><param name="movie" value="/flash/test.swf" id="banner" bgcolor="#393c29" /></object>';
  }
  
  else if (section == 'investors') {
    flash = '<object type="application/x-shockwave-flash" data="/flash/investors.swf" width="800" height="180" id="banner" bgcolor="#393c29"><param name="movie" value="/flash/investors.swf" id="banner" bgcolor="#393c29" /></object>';
  }
  
  else if (section == 'projects') {
    flash = '<object type="application/x-shockwave-flash" data="/flash/projects.swf" width="800" height="180" id="banner" bgcolor="#393c29"><param name="movie" value="/flash/projects.swf" id="banner" bgcolor="#393c29" /></object>';
  }
  
  document.getElementById('forFlashMovie').innerHTML = flash;
  
  
}

// +-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~+-+~

// Source: http://www.quirksmode.org/js/popup.html

function popup (url)
{
	newwindow = window.open (url, 'name', 'height=600,width=500');
	if (window.focus) { newwindow.focus() }
	return false;
}


