//
//  these javascript functions   
//  pertain to all things Western Front
//


// on DOM ready

var pageLoaded = 0;
window.onload = function() {pageLoaded = 1;}
function loaded(i,f) {
if (document.getElementById &&
  document.getElementById(i) != null) f();
  else if (!pageLoaded) setTimeout('loaded(\''+i+'\','+f+')',1000);
}


// SIFR settings 

var bembo = {
  src: '/resources/scripts/sifr_fonts/bembo-8.swf'
};

var bembosc = {
  src: '/resources/scripts/sifr_fonts/bembosc-8.swf'
};

sIFR.debugMode = false;
//sIFR.domains = ['front.bc.ca'] // Don't check for domains in this demo
sIFR.prefetch(bembo, bembosc);
sIFR.activate();

sIFR.replace(bembo, {
  selector: '#searchform h3'
  ,css: {
    '.sIFR-root' : { 'color': '#8B8181', 'background-color': '#FFFFFF', 'letter-spacing': '-.2' }
  }
});


sIFR.replace(bembo, {
  selector: 'h3'
  ,css: {
    '.sIFR-root' : { 'color': '#000000', 'background-color': '#FFFFFF', 'letter-spacing': '-.2' }
  }
});

sIFR.replace(bembosc, {
  selector: '#content li.title'
  ,css: {
    '.sIFR-root' : { 'color' : '#E653A1' },
    'a' : { 'color': '#000000', 'text-decoration': 'none' },
    'a:hover' : { 'color': '#000000' }
  }
});

sIFR.replace(bembosc, {
  selector: '.event-artists'
});



// safe and valid popups

function popUps() {
  var popup_array = Array;
  popup_array[0] = new Array(
                         document.getElementById('switched-content').getElementsByTagName('a'),
                         "",
                         ""
                       );

  for (i=0; i<popup_array.length; i++) {
    popuplinks = popup_array[i][0];
    for (f=0; f<popuplinks.length; f++) {
      popuplinks[f].target = popup_array[i][1];
      popuplinks[f].settings = popup_array[i][2];
      popuplinks[f].onclick = function() {
        newWin = window.open(this.href, this.target, this.settings);
        newWin.focus();
        return false;
      }
    }
  }
} 


// opens search form in header

function opensearch() {
    searchdiv = document.getElementById("search");
    searchdiv.getElementsByTagName("a").item(0).href = '#';
    searchdiv.getElementsByTagName("a").item(0).onclick = function() {
      searchtext = searchdiv.getElementsByTagName("p").item(0);
      searchwidth = new fx.Width(searchtext, {
        duration: 600, onComplete: function() {
          searchinput = searchdiv.getElementsByTagName("input").item(0);
          searchinput.style.display = "inline";
      }});
      searchwidth.open();
    };
}



// Content Switcher

function hide_switched_content() {
  var results = document.getElementsByClassName('content');
  for (j=0; j<results.length; j++) {
      results[j].style.display="none";
  }
}

function switch_content(first) {
  var switchers=document.getElementById('switchers').getElementsByTagName('a');
  for (i=0; i<switchers.length; i++) {
    switchers[i].onclick=function() {
      hide_switched_content();
      var result=(this.href).split("#",2)[1];
      document.getElementById(result).style.display="block";
      return false;
    }
  }
  if (first) {
    var firstone=document.getElementById('switched-content').firstChild;
    if (firstone.nodeType != 1) {firstone = firstone.nextSibling;}
    firstone.style.display="block";
  }
}



// initialize all needed functions

loaded('search', function() {
  opensearch();
  if (document.getElementById('switched-content')) {
    popUps();
    hide_switched_content(); 
    switch_content(1); 
  }
});