var scrollSpeed = 1; // number of pixels to change every frame
var scrollHeight = 0; // this will hold the height of your content
var scrollDelay = 60; // delay between movements.
var scrollInitialDelay = 1000; // Initial scroll delay
var scrollMove = scrollSpeed; // for stop & start of scroll

window.onload = initPage;
function initPage() {
  InsertFlashObject("quadra_flash_banner", "flash/quadra_banner.swf",585,268);
  InsertFlashObject("flash_bottom", "flash/banner.swf",580,207);
  InsertFlashObject("gallery", "flash/gallery.swf",585,590);
  if(document.getElementById('qc_name')) {
    document.getElementById('qc_name').onfocus = clearfield;
    document.getElementById('qc_company').onfocus = clearfield;
    document.getElementById('qc_telephone').onfocus = clearfield;
    document.getElementById('qc_email').onfocus = clearfield;
    document.getElementById('qc_enquiry').onfocus = clearfield;
    document.getElementById('qc_name').onblur = resetfield;
    document.getElementById('qc_company').onblur = resetfield;
    document.getElementById('qc_telephone').onblur = resetfield;
    document.getElementById('qc_email').onblur = resetfield;
    document.getElementById('qc_enquiry').onblur = resetfield;
  }
  if(document.getElementById('scrollTxt') && document.getElementById('scrollBox')) {
    getHeight();
    document.getElementById('scrollTxt2').style.top = (scrollHeight) + 'px';
    setTimeout('scrollBox();', scrollInitialDelay);
    document.getElementById('scrollBox').onmouseover = scrollStop;
    document.getElementById('scrollBox').onmouseout = scrollResume;
  }
  if(document.getElementById('homepage_intro_middle_main')) {
    setInterval(moveleft, 20);
  }
  external_links();
}
function scrollBox() {
  var currentPosition = document.getElementById('scrollTxt').style.top.substring(0, document.getElementById('scrollTxt').style.top.length - 2);
  var currentPosition2 = document.getElementById('scrollTxt2').style.top.substring(0, document.getElementById('scrollTxt2').style.top.length - 2);
  if(currentPosition == "") {
    currentPosition = 0;
  }
  if(currentPosition2 == "") {
    currentPosition2 = 0;
  }
  if(currentPosition < (0 - scrollHeight)) {
    currentPosition = scrollHeight;
  }
  if(currentPosition2 < (0 - scrollHeight)) {
    currentPosition2 = scrollHeight;
  }
  document.getElementById('scrollTxt').style.top = (currentPosition - scrollMove) + 'px';
  document.getElementById('scrollTxt2').style.top = (currentPosition2 - scrollMove) + 'px';
  setTimeout('scrollBox();', scrollDelay);
}
function getHeight() {
  scrollHeight = document.getElementById('scrollTxt').offsetHeight;
}
function scrollResume() {
  scrollMove = scrollSpeed;
}
function scrollStop() {
  scrollMove = 0;
}
function clearfield() {
  if(this.id == 'qc_name') {
    if(this.value == 'Name :') {
      this.value = '';
    }
  }
  if(this.id == 'qc_company') {
    if(this.value == 'Company :') {
      this.value = '';
    }
  }
  if(this.id == 'qc_telephone') {
    if(this.value == 'Tel :') {
      this.value = '';
    }
  }
  if(this.id == 'qc_email') {
    if(this.value == 'E-mail :') {
      this.value = '';
    }
  }
  if(this.id == 'qc_enquiry') {
    if(this.value == 'Enquiry :') {
      this.value = '';
    }
  }
}

function resetfield() {
  if(this.id == 'qc_name') {
    if(this.value == '') {
      this.value = 'Name :';
    }
  }
  if(this.id == 'qc_company') {
    if(this.value == '') {
      this.value = 'Company :';
    }
  }
  if(this.id == 'qc_telephone') {
    if(this.value == '') {
      this.value = 'Tel :';
    }
  }
  if(this.id == 'qc_email') {
    if(this.value == '') {
      this.value = 'E-mail :';
    }
  }
  if(this.id == 'qc_enquiry') {
    if(this.value == '') {
      this.value = 'Enquiry :';
    }
  }
}

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 image_popup(image) {
  var image = image;
  var newLink = image.replace("main", "large");
  window.open(newLink,"","width=1024,height=768,location,menubar");
}
function display_flash() {
  document.write('<object type="application/x-shockwave-flash" data="flash/slide.swf" width="756" height="205"><param name="movie" value="flash/slide.swf" /></object>');
}
function InsertFlashObject(objID, flashLocation, width, height, flashString) {
  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(flashString) == "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='" + flashString + "'";
    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='" + flashString + "'";
  }
  flashObject = flashObject + "></embed></object>";
  if(document.getElementById(objID)) {
    document.getElementById(objID).innerHTML = flashObject;
  }
}
function rollOverMenu(evt) {
  div = evt.currentTarget;
  for(var x = 0; div.childNodes[x]; x++) {
    if(div.childNodes[x].tagName == 'DIV') {
      div.childNodes[x].style.display = 'block';
    } else if(div.childNodes[x].tagName == 'A') {
      div.childNodes[x].style.fontWeight = 'bold';
    } else if(div.childNodes[x].tagName == 'SPAN') {
      for(var y = 0; div.childNodes[x].childNodes[y]; y++) {
        if(div.childNodes[x].childNodes[y].tagName == 'A') {
          div.childNodes[x].childNodes[y].style.fontWeight = 'bold';
        }
      }
    }
  }
}
function rollOffMenu(evt) {
  div = evt.currentTarget;
  for(var x = 0; div.childNodes[x]; x++) {
    if(div.childNodes[x].tagName == 'DIV') {
      div.childNodes[x].style.display = 'none';
    } else if(div.childNodes[x].tagName == 'A') {
      div.childNodes[x].style.fontWeight = 'normal';
    } else if(div.childNodes[x].tagName == 'SPAN') {
      for(var y = 0; div.childNodes[x].childNodes[y]; y++) {
        if(div.childNodes[x].childNodes[y].tagName == 'A') {
          div.childNodes[x].childNodes[y].style.fontWeight = 'normal';
        }
      }
    }
  }
}

var $custmod = 1;

function moveleft(){
  if(document.getElementById('homepage_intro_middle_main_overlay')){
    pos = document.getElementById('homepage_intro_middle_main_overlay').style.backgroundPosition;
    posArray = pos.split(' ');
    posx = posArray[0].replace('px', '');
    newposx = posx -5;
    document.getElementById('homepage_intro_middle_main_overlay').style.backgroundPosition = newposx + "px 0px";

    if(newposx == -10){
      //if((document.getElementById('homepage_intro_middle_main'). style. backgroundImage == 'url(images/content/hislide_custom_stands.jpg)') || (document.getElementById('homepage_intro_middle_main'). style. backgroundImage == 'url(http://preview5.woh.co.uk/dev/dimension/images/content/hislide_custom_stands.jpg)') || (document.getElementById('homepage_intro_middle_main'). style. backgroundImage == 'url("http://preview5.woh.co.uk/dev/dimension/images/content/hislide_custom_stands.jpg")')){
      if($custmod == 1){
        document.getElementById('homepage_intro_middle_desc_left').innerHTML = '<a href="index.php?view=system-build-modular-exhibition-stand" id="homepage_intro_desc_link">View Modular System Stands</a>';
        document.getElementById('homepage_intro_middle_desc_right').innerHTML = '<a href="index.php?view=system-build-exhibition-stand-gallery" id="homepage_intro_more_button"><img src="images/content/home_intro_more.gif" alt="More" title="Find out more" height="17" width="47"></a>';
        document.getElementById('homepage_intro_middle_main'). style. backgroundImage = 'url(images/content/hislide_modular_stands.jpg)';
      //}else if((document.getElementById('homepage_intro_middle_main'). style. backgroundImage == 'url(images/content/hislide_modular_stands.jpg)') || (document.getElementById('homepage_intro_middle_main'). style. backgroundImage == 'url(http://preview5.woh.co.uk/dev/dimension/images/content/hislide_modular_stands.jpg)') || (document.getElementById('homepage_intro_middle_main'). style. backgroundImage == 'url("http://preview5.woh.co.uk/dev/dimension/images/content/hislide_modular_stands.jpg")')){
      }else{
        document.getElementById('homepage_intro_middle_desc_left').innerHTML = '<a href="index.php?view=custom-build-exhibition-stand" id="homepage_intro_desc_link">View Custom Build Stands</a>';
        document.getElementById('homepage_intro_middle_desc_right').innerHTML = '<a href="index.php?view=custom-build-exhibition-stand" id="homepage_intro_more_button"><img src="images/content/home_intro_more.gif" alt="More" title="Find out more" height="17" width="47"></a>';
        document.getElementById('homepage_intro_middle_main'). style. backgroundImage = 'url(images/content/hislide_custom_stands.jpg)';
      }
    }

    if(newposx <= -2370){
      //if((document.getElementById('homepage_intro_middle_main_overlay'). style. backgroundImage == 'url(images/content/home_banner_modular_word.gif)') || (document.getElementById('homepage_intro_middle_main_overlay'). style. backgroundImage == 'url(http://preview5.woh.co.uk/dev/dimension/images/content/home_banner_modular_word.gif)') || (document.getElementById('homepage_intro_middle_main_overlay'). style. backgroundImage == 'url("http://preview5.woh.co.uk/dev/dimension/images/content/home_banner_modular_word.gif")')){
      if($custmod == 1){
        document.getElementById('homepage_intro_middle_main_overlay'). style. backgroundImage = 'url(images/content/home_banner_custom_word.gif)';
        document.getElementById('homepage_intro_middle_main_overlay').style.backgroundPosition = "580px 0px";
        $custmod = 2;
      //}else if((document.getElementById('homepage_intro_middle_main_overlay'). style. backgroundImage == 'url(images/content/home_banner_custom_word.gif)') || (document.getElementById('homepage_intro_middle_main_overlay'). style. backgroundImage == 'url(http://preview5.woh.co.uk/dev/dimension/images/content/home_banner_custom_word.gif)') || (document.getElementById('homepage_intro_middle_main_overlay'). style. backgroundImage == 'url("http://preview5.woh.co.uk/dev/dimension/images/content/home_banner_custom_word.gif")')){
      }else{
        document.getElementById('homepage_intro_middle_main_overlay'). style. backgroundImage = 'url(images/content/home_banner_modular_word.gif)';
        document.getElementById('homepage_intro_middle_main_overlay').style.backgroundPosition = "580px 0px";
        $custmod = 1;
      }
    }
  }
}
