window.addEvent('domready', function() {

  /* external links */
  var objs = $$('a');
  objs.each(function(obj, i) {
    if (obj.get('href') && ((obj.get('rel') == 'external') || (obj.get('target') == '_blank'))){
      obj.set('target', '_blank');
      if (obj.get('href').indexOf('http://') != -1){
        obj.addEvent("click", function(event) {
          if(confirm("You are about to be directed away from the VSNMT website.")) {
            return true;
          }
          return false;
        });
      }
    }
  });

  /* drop downs */
  if (Browser.Engine.trident || Browser.Engine.webkit){
    var nav = $$('#left ul li');
    nav.each(function(navs, i) {
      navs.addEvent("mouseenter", function(event) {
        this.addClass('hover');
      });
    	navs.addEvent("mouseleave", function(event) {
        this.removeClass('hover');
      });
    });
  }

  /* IE hovers */
  if (Browser.Engine.trident){
    var objs = $$('button');
    objs.each(function(obj, i) {
      obj.addEvent("mouseover", function(event) {
        this.addClass('hover');
      });
    	obj.addEvent("mouseout", function(event) {
        this.removeClass('hover');
      });
    });
    var objs = $$('input').extend($$('textarea'));
    objs.each(function(obj, i) {
      obj.addEvent("focus", function(event) {
        this.addClass('focus');
    	});
    	obj.addEvent("blur", function(event) {
        this.removeClass('focus');
    	});
    });
  }

  if ($chk($('exam-submit'))) {
    $('exam-submit').addEvent('click', function(event) {
      if(confirm("Are you sure you want to submit this exam? Please ensure you have answered all the questions.")) {
        return true;
      }
      return false;
    });
  }

  if ($chk($('exam-timer'))) {
    baseTime = parseInt($('exam-timer').get('title'));
    myTimer = updateTime.delay(1000);
  }

});

function updateTime(){
  $clear(myTimer);
  baseTime--;
  var remainder = baseTime;
  var hours = Math.floor(remainder / (60 * 60));
  remainder = remainder % (60 * 60);
  var minutes = Math.floor(remainder / 60);
  var seconds = remainder % 60;
  if (hours > 0){
    if (hours.toString().length == 1) { hours = '0'+hours }
  } else {
    hours += '0';
  }
  if (minutes > 0){
    if (minutes.toString().length == 1) { minutes = '0'+minutes }
  } else {
    minutes += '0';
  }
  if (seconds > 0){
    if (seconds.toString().length == 1) { seconds = '0'+seconds }
  } else {
    seconds += '0';
  }
  var time = hours+':'+minutes+':'+seconds;
  $('exam-timer').set('html', time);
  if (baseTime <= 0){
    $('exam').submit();
  } else {
    myTimer = updateTime.delay(1000);
  }
}

var dax={src:"_swf/sifr.swf"};
sIFR.compatMode=true;
sIFR.activate(dax);
sIFR.replace(dax,{
  selector:"h2",
  wmode: 'transparent',
  fixhover:true,
  css:[
    ".sIFR-root { font-size: 21px; color: #8E258D; font-weight: bold; line-height: 24px; float: left; }"
  ]
});

sIFR.replace(dax,{
  selector:"span.item",
  wmode: 'transparent',
  fixhover:true,
  css:[
    ".sIFR-root { font-size: 18px; color: #8E258D; font-weight: bold; line-height: 24px; }",
    ".sIFR-root a:link {color: #8E258D; text-decoration: none;}",
    ".sIFR-root a:hover {color: #4C4C4C; text-decoration: underline;}"
  ]
});

sIFR.replace(dax,{
  selector:"h4",
  wmode: 'transparent',
  fixhover:true,
  css:[
    ".sIFR-root { font-size: 18px; color: #ffffff; font-weight: bold;}"
  ]
});

sIFR.replace(dax,{
  selector:"h6",
  wmode: 'transparent',
  fixhover:true,
  css:[
    ".sIFR-root { font-size: 18px; color: #8E258D; font-weight: bold; line-height: 24px; }",
    ".sIFR-root a:link {color: #8E258D; text-decoration: none;}",
    ".sIFR-root a:hover {color: #4C4C4C; text-decoration: underline;}"
  ]
});