//-- ############################################################### --
//-- # TIMESTAMP: <070506-1831 alan@turransky.com>                 # --
//-- #                                                             # --
//-- # COPYRIGHT: Copyright (C) 2004-present. Turransky, LLC.,     # --
//-- #            unless otherwise noted below.                    # --
//-- #                                                             # --
//-- # LICENSE:   This library is free software; you can           # --
//-- #            redistribute it and/or modify it under the terms # --
//-- #            of the GNU Lesser General Public License as      # --
//-- #            published by the Free Software Foundation;       # --
//-- #            either version 2.1 of the License, or (at your   # --
//-- #            option) any later version. This library is       # --
//-- #            distributed in the hope that it will be useful,  # -- 
//-- #            but WITHOUT ANY WARRANTY; without even the       # --
//-- #            implied warranty of MERCHANTABILITY or FITNESS   # --
//-- #            FOR A PARTICULAR PURPOSE. See the GNU Lesser     # --
//-- #            General Public License for more details. You     # --
//-- #            should have received a copy of the GNU Lesser    # --
//-- #            General Public License along with this library;  # -- 
//-- #            if not, write to the Free Software Foundation,   # --
//-- #            Inc., 51 Franklin Street, Fifth Floor, Boston,   # --
//-- #            MA 02110-1301 USA.                               # --
//-- #                                                             # --
//-- #            Turransky, LLC., hereby disclaims all copyright  # --
//-- #            interest in this library.                        # --
//-- #                                                             # --
//-- # HISTORY:   Place newest entries on top:                     # --
//-- #  041214    Created version 1.0 of this file.                # --
//-- #                                                             # --
//-- ############################################################### --

//-- ############################################################### --
//-- # STRING CLASS EXTENSIONS                                     # --
//-- ############################################################### --
String.prototype.contains = function(){
  var a=arguments[0]; a=((a.indexOf('|')>-1)?(a.split('|')):(new Array(a))); 
  for(var x=0; x<a.length; x++) return((this.indexOf(a[x])>-1)?(true):(false));
};

String.prototype.capitalizeWords = function(){
  // v1.0 Jonas Raoni Soares Silva, http://www.joninhas.ath.cx
  return(this.replace(/\w+/g,function(a){ return(a.charAt(0).toUpperCase()+a.substr(1).toLowerCase()); }));
};


//-- ############################################################### --
//-- # WINDOW EXTENSIONS                                           # --
//-- ############################################################### --
window.onunload = function(){ window.fixExplorer(false); };

window.onload   = function(){
  // SET PAGE TITLE AND RIBBON ALT TAG BASED ON THE URL
  var u=y=document.location+''; y=y.split('/'); 
  var x=y[4]; x=(x.replace(/-/g,' ')).capitalizeWords();
  document.title='Home Media: '+x;
  document.getElementById("mastRibbon").alt=x;

  // SELECT THE CURRENT PAGE'S SUBNAV LINK IF THERE IS ONE
  u=document.location+'';
  u=u.split('/'); u=u[u.length-2];
  u=u.split('.'); u=u[0];
  u=document.getElementById(u);
  if(u!==null){
     u.style.backgroundImage='url(/common/site-images/pointer.gif)';
     u.style.backgroundRepeat='no-repeat'; 
     u.style.backgroundPosition='2px '+((u.className=='double')?(' 15px'):(' 2px'));
     u.style.backgroundColor='#b2b2b2';
  };
  // FIX INTERNET EXPLORER BUGS
  window.fixExplorer(true);
};

window.fixExplorer = function (){
  // IF ITS IE 6 OR ABOVE
  if(navigator.userAgent.contains('MSIE 6|MSIE 7')){
    // FIX THE BACKGROUND-IMAGE FLICKER PROBLEM AND 
    // THE OBJECT "Click to Active" PROBLEM
    try{
      document.execCommand("BackgroundImageCache",false,arguments[0]);
      if(arguments[0]) for(var x=0,o=document.getElementsByTagName("object"); x<o.length; x++) o[x].outerHTML=o[x].outerHTML;
    } catch(x){ };
  };
};


//-- ############################################################### --
//-- # DOCUMENT EXTENSIONS                                         # --
//-- ############################################################### --
document.setInfo = function(){
  var d=document.getElementById('ribbon');
  if(d!=null){
    // SET THE PAGE RIBBON AND DOCUMENT TITLE
    d.src=arguments[0];
    document.title='Home Media: '+arguments[1];
  };
};

document.setFrame = function(){
  var prefix=arguments[0].substring(0,arguments[0].length-1);

  // HIDE ALL FRAMES
  for(var c=a=d=x=0; x<10; x++){
    d=document.getElementById(prefix+x+'');
    if(d!=null){ d.style.display='none'; d.style.visibility='hidden'; };
  };

  // DISPLAY THE CURRENT FRAME
  d=document.getElementById(arguments[0]);
  if(d!=null){ d.style.display='block'; d.style.visibility='visible'; };

  // SWAP BACKGROUND COLOR (OPTIONAL)
  if(arguments.length==3){
    d=document.getElementById('background');
    if(d!=null&&d.className!=null){ d.className=arguments[1]; };
    d=document.getElementById('columnB');
    for(x=0; x<d.childNodes.length; x++){
      if(d.childNodes[x].nodeName.toLowerCase()=='p'){
        c=d.childNodes[x];
        c.style.backgroundImage='none';
        c.style.backgroundColor='#d6ceb5';
      };
    };

    // SWAP COLUMN B IMAGES (OPTIONAL)
    if(arguments.length==3){
      x=(arguments[2]=='why'||arguments[2]=='what'||arguments[2]=='how');
      if(x){
        x ='<img src="../common/section-topper.jpg" width="319" height="55" border="0" alt="page-topper" align="left" style="padding-right:1px;"/>';
        x+='<img src="columnBtop.jpg" width="159" height="55" border="0" class="column-topper" alt="column-topper"/>';
        document.getElementById('topper').innerHTML=x;
        document.getElementById('columnBimg').src='columnB'+arguments[2]+'.jpg';
      };
    };

    // HIGHLIGHT THE CURRENT PAGE'S SUB-NAVIGATION LINK
    d=document.getElementById(arguments[2]);
    if(d!=null){ 
      d.style.backgroundImage='url(/common/site-images/pointer.gif)';
      d.style.backgroundRepeat='no-repeat'; 
      d.style.backgroundPosition='2px '+((d.className=='double')?(' 15px'):(' 2px'));
      d.style.backgroundColor='#ad9463';
    };
  };
};

document.setImage = function(){
  // SWAP A PROJECT-GALLERY'S IMAGES
  var clsClickedOnIcon = document.getElementById('pos'+arguments[0]).className;
  var clsOfCurrentIcon = document.getElementById('posA').className;
  var clsNewMainImage  = 'img'+clsClickedOnIcon.substring(3,4);
  document.getElementById('main').className=clsNewMainImage;
  document.getElementById('pos'+arguments[0]).className=clsOfCurrentIcon;
  document.getElementById('posA').className=clsClickedOnIcon;
  switch(clsClickedOnIcon.substring(3,4)){
  case 'A': gotoFrame('frame1'); document.getElementById('background').style.backgroundColor='#ffffff'; break;
  case 'B': gotoFrame('frame2'); document.getElementById('background').style.backgroundColor='#e7e7e7'; break;
  case 'C': gotoFrame('frame3'); document.getElementById('background').style.backgroundColor='#d6ceb5'; break;
  };
};


//-- ############################################################### --
//-- # PUBLIC API FUNCTIONS                                        # --
//-- ############################################################### --
function swapImages(){ document.setImage(arguments[0]); };
function gotoFrame(){ var a=arguments;
  if(a.length==1) document.setFrame(a[0]);
  else            document.setFrame(a[0],a[1],a[2]);
};
