window.onload = initPage;

function initPage() {
  preload_images('images/template/left-menu-over.jpg',
                 'images/template/home-over.jpg',
                 'images/template/print-over.jpg',
                 'images/template/access-over.jpg',
                 'images/template/training_curve.gif',
                 'images/template/training_curve_blank.gif');
  if(document.getElementById('flashcontent')) {
    InsertFlashObject("flashcontent", "batec.swf", 200, 308);
  }
  if(document.getElementById('enquiry')) {
    InsertFlashObject("enquiry", "test.swf", '100%', '100%');
  }
  if(document.getElementById('uxo_video')) {
    InsertFlashObject("uxo_video", "http://www.youtube.com/v/yGWwvOyQffo&hl=en&fs=1&rel=0", '518', '315');
  }
  left_menu_hover();
  top_menu_hover();
  add_onhover_menu();
  submit_casestudyForm();
  external_links();
}  

function close_tb_window(){
  tb_remove();
}
function preload_images() {
  
  var myimages=new Array()
  
  for (i=0;i<preload_images.arguments.length;i++) {
    myimages[i]=new Image()
    myimages[i].src=preload_images.arguments[i]
  } 
}

function external_links() { 
  if(!document.getElementsByTagName) return; 
  var anchors = document.getElementsByTagName("a"); 
  for(var i=0; i<anchors.length; i++) { 
    var anchor = anchors[i]; 
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "external nofollow" ) 
      anchor.target = "_blank"; 
  } 
}

function InsertFlashObject(objID, flashLocation, width, height, includeString) {
  var flashObject;
  flashObject = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+width+"' height='"+height+"'>";
  flashObject = flashObject + "<param name='wmode' value='transparent'>";
  flashObject = flashObject + "<param name='movie' value='"+flashLocation+"' />";
  flashObject = flashObject + "<param name='quality' value='high' />";
  if(typeof(includeString) == "undefined") {
    flashObject = flashObject + "<embed src='"+flashLocation+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+width+"' height='"+height+"' wmode='transparent'";
  } else {
    flashObject = flashObject + "<param name='FlashVars' value='" + includeString + "'";
    flashObject = flashObject + "<embed src='"+flashLocation+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+width+"' height='"+height+"' wmode='transparent' ";
    flashObject = flashObject + "FlashVars='" + includeString + "'";
  }
  flashObject = flashObject + "></embed></object>";
  if(document.getElementById(objID)) {
    document.getElementById(objID).innerHTML = flashObject;
  }
}

function redirect(url){  
  window.location = url;
}

function display_flash(id) {
  document.write('<object type="application/x-shockwave-flash" data="flash/Bactec_Globe.swf" width="200" height="308"><param name="movie" value="flash/Bactec_Globe.swf" /></object>');
}

function left_menu_hover() {
  
  var div;
  div = document.getElementById('left_menu');
  
  var menu_li
  menu_li = div.getElementsByTagName('li');
  
  for(i=0; i<menu_li.length; i++) {
    var li = menu_li[i];
    if(document.getElementById('left_menu_link_' + (i + 1))){
       li.onmouseover = change_menu_image;
       li.onmouseout = reset_menu_image;
    }
    if(document.getElementById('left_menu_link_66')) {
       document.getElementById('left_menu_66').onmouseover = change_menu_image;
       document.getElementById('left_menu_66').onmouseout = reset_menu_image;
    }
    
  }
}

function redirect(form) {
  window.location = form + '.htm';
}

function change_menu_image() {
  document.getElementById(this.id).style.cursor = 'pointer';
  document.getElementById(this.id).className = 'left_menu_over';
}

function reset_menu_image() {
  document.getElementById(this.id).style.cursor = 'pointer';
  document.getElementById(this.id).className = 'left_menu';
}

function top_menu_hover() {
  
  if(document.getElementById('home') && document.getElementById('home').className != 'home_over'){
      var div_home;
      div_home = document.getElementById('home');
      
       div_home.onmouseover = function() {
         document.getElementById(this.id).style.cursor = 'pointer';    
         document.getElementById(this.id).className ='home_over';
      }
      div_home.onmouseout = function() {
        document.getElementById(this.id).className = 'home';
      }
  }
 
   if(document.getElementById('print')){ 
       var div_print;
       div_print = document.getElementById('print');
       
        div_print.onmouseover = function() {
          document.getElementById(this.id).style.cursor = 'pointer';
          document.getElementById(this.id).className = 'print_over';
            
        }
        div_print.onmouseout = function() {
          document.getElementById(this.id).className = 'print';
        }
   }        
  
  if(document.getElementById('access') && document.getElementById('access').className != 'access_over'){ 
      var div_access;
      div_access = document.getElementById('access');
   
      div_access.onmouseover = function() {
        document.getElementById(this.id).style.cursor = 'pointer';
        document.getElementById(this.id).className = 'access_over';
      }
      div_access.onmouseout = function() {
        document.getElementById(this.id).className = 'access';
      } 
   }
}

function add_onhover_menu() {
  
  var menu;
  menu = document.getElementById('top_menu');
  
  var lis;
  lis = menu.getElementsByTagName('li');
  
  var totalItems = 0;
  
  for(i=0; i<lis.length; i++) {
    
    var li = lis[i];
    var bgColours = Array('#F3BF77', '#57A5AA', '#90B386', '#4DA8CD', '#C78E74', '#B7758B');
    
    
    if(li.id.substring(0,10) == 'parent_li_'){
      totalItems++;
      if(document.getElementById('parent_li_' + li.id.substring(10,11)).className == 'activemenu') {
        document.getElementById('item_inner_' + li.id.substring(10,11)).style.color = '#FFFFFF';
      }
      li.onmouseover = function() {      
        document.getElementById(this.id).style.cursor = 'pointer';
        var finalId = new Number(this.id.substring(10,11));
        if(finalId != totalItems) {
          document.getElementById('item_' + this.id.substring(10,11)).style.backgroundColor = bgColours[this.id.substring(10,11)-1];     
        } else {
          document.getElementById('final_item').style.backgroundImage = 'url(images/template/training_curve.gif)';
        }
        document.getElementById('item_inner_' + this.id.substring(10,11)).style.color = '#FFFFFF';
      }      
      li.onmouseout = function() {
        if(document.getElementById('parent_li_' + this.id.substring(10,11)).className != 'activemenu') {
          var finalId = new Number(this.id.substring(10,11));
          if(finalId != totalItems) {
            document.getElementById('item_' + this.id.substring(10,11)).style.backgroundColor = '';      
          } else {
            document.getElementById('final_item').style.backgroundImage = 'url(images/template/training_curve_blank.gif)';
          }
          document.getElementById('item_inner_' + this.id.substring(10,11)).style.color = '#6E7B84';
        }
      }
    }
  }
}

function submit_casestudyForm() {
  if(document.getElementById("area")) {
    document.getElementById("area").onchange = function() {
      var area = document.getElementById('area');
      var areaID = area.options[area.selectedIndex].value;
      if(areaID != '') {
        window.location = 'index.php?view=casestudy-area&area=' + areaID;
      }
    }
  }
  if(document.getElementById("service")) {
    document.getElementById("service").onchange = function() {
      var service = document.getElementById('service');
      var serviceID = service.options[service.selectedIndex].value;
      if(serviceID != '') {
        window.location = 'index.php?view=casestudy-service&service=' + serviceID;
      }
    }
  }
}
function loadNewsImage(id,img, alt) {
  var news_img = document.getElementById('news_img');
  var eventElement = document.getElementById(id);
  var img_overlay = document.getElementById('img_img_corner');
  eventElement.style.cursor = 'pointer';
  eventElement.style.backgroundColor = "#133B54";
  news_img.style.background = "url("+ img +") 0px -20px no-repeat";
  img_overlay.alt = alt;
  img_overlay.title = alt;
}

function resetStyle(id,color) {
  var eventElement = document.getElementById(id);
   eventElement.style.backgroundColor = color;
}

function printPage() {
  window.print();
  return true;
}