window.onload = initPage;

function initPage() {
  
  externalLinks();
  
  if(document.getElementById('flash_object')) {
    InsertFlashObject("flash_object", "flash/site_1/banner.swf", 978, 275, "KVM cycling images"); 
  }
  
}

function externalLinks() { 
  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 openfloatmenu(tmenu){
  var omenu = document.getElementById(tmenu);
  if(omenu != null){
    omenu.className = 'floatmenu_open';
  } 
}

function closefloatmenu(tmenu){
  var cmenu = document.getElementById(tmenu);
  if(cmenu != null){
    cmenu.className = 'floatmenu'; 
  }
}

function openedmenu(tmenu){
  var omenu = document.getElementById(tmenu);
  if(omenu != null){
    omenu.className = 'top_menu_cont_a_selected';
  } 
}

function closedmenu(tmenu){
  var omenu = document.getElementById(tmenu);
  if(omenu != null){
    omenu.className = 'top_menu_cont_a';
  } 
}

// make global variables.
var map;
var point;
var marker;
var html;

function mapload() {
  if (GBrowserIsCompatible()) {
    // get the HTML which we need to use to create the new info box
    var html = document.getElementById('shop').innerHTML;
    // replace the linkname tag for a different one, so our toggle function doesnt get confused.
    html = html.replace('linkname','linkname2');
    // replace the getDirToggle tag for a different one, so our toggle function doesnt get confused.
    html = html.replace('getDirToggle','getDirToggle2');  
    
    map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(51.452275, -0.965263), 15);
    point = new GLatLng(51.452275, -0.965263);
    marker = new GMarker(point);
    map.addOverlay(marker)
    // open the info window with the modified HTML. no duplicate ID's for us!
    map.openInfoWindowHtml(map.getCenter(), html);
    
    // add an onclict event, too!
    GEvent.addListener(marker, "click", function() {  
      // open the info window with the modified HTML. no duplicate ID's for us!    
      map.openInfoWindowHtml(point, html);
    });
  }
}

function prepareForm(form, cid){
  if (GBrowserIsCompatible()) {
    gApplication.prepareForm(form, cid);
  }
}

function displayDir(){    
  if (GBrowserIsCompatible()) {  
    var toggle = document.getElementById("getDirToggle").style.display;
    if(toggle == 'none'){      
      document.getElementById("getDirToggle").style.display='block';
      document.getElementById("linkname").innerHTML = "Don't get directions";      
    }else{
        document.getElementById("getDirToggle").style.display='none';
        document.getElementById("linkname").innerHTML = "Get directions";
  }
    
    // get the HTML which we need to use to create the new info box
    var html = document.getElementById('shop').innerHTML;
    // replace the linkname tag for a different one, so our toggle function doesnt get confused.
    html = html.replace('linkname','linkname2');
    // replace the getDirToggle tag for a different one, so our toggle function doesnt get confused.
    html = html.replace('getDirToggle','getDirToggle2');      
    // open the info window with the modified HTML. no duplicate ID's for us!
    map.openInfoWindowHtml(point, html);
  }
}

function InsertFlashObject(objID, flashLocation, width, height, title) {
  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 + "' title='" + title + "'>";
  flashObject = flashObject + "<param name='wmode' value='transparent'>";
  flashObject = flashObject + "<param name='movie' value='" + flashLocation + "' />";
  flashObject = flashObject + "<param name='quality' value='high' />";
  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 + "></embed></object>";
  document.getElementById(objID).innerHTML = flashObject;
}