
// SWFOBJECT

document.observe('dom:loaded', function(){

  if ($('homepage-flash-replace')) {
    swfobject.embedSWF("flash/homepage.swf", "homepage-flash-replace", "750", "407", "9.0.0", false, {}, {}, { 'id' : 'flash-feature'});
  }

  if ($('about-flash-replace')) {
  	swfobject.embedSWF("flash/demo3.swf", "about-flash-replace", "300", "290", "9.0.0", false, {}, {}, { 'id' : 'flash-feature'});
  }

  if ($('demo-flash-replace')) {
    swfobject.embedSWF("flash/focus7.swf", "demo-flash-replace", "750", "450", "9.0.0", false, {}, {}, { 'id' : 'flash-feature'});
  }

  if ($('tv-flash-replace')) { 
    swfobject.embedSWF("flash/tvspot.swf", "tv-flash-replace", "750", "407", "9.0.0", false, {}, {}, { 'id' : 'flash-feature'});
  }

  if ($('tv-martha-replace')) { 
    swfobject.embedSWF("flash/martha_vid.swf", "tv-martha-replace", "750", "407", "9.0.0", false, {}, {}, { 'id' : 'flash-feature'});
  }

  if ($('promo-flash-replace')) { 
    swfobject.embedSWF("flash/form.swf", "promo-flash-replace", "750", "407", "9.0.0", false, {}, {}, { 'id' : 'flash-feature'});
  }

  if ($('quiz-flash-replace')) { 
    swfobject.embedSWF("flash/quiz.swf", "quiz-flash-replace", "750", "407", "9.0.0", false, {}, {}, { 'id' : 'flash-feature'});
  }

  if ($('color-flash-replace')) { 
    swfobject.embedSWF("flash/color_tips.swf", "color-flash-replace", "750", "407", "9.0.0", false, {}, {}, { 'id' : 'flash-feature'});
  }

  if ($('visual-flash-replace')) { 
    swfobject.embedSWF("flash/visual_therapy.swf", "visual-flash-replace", "750", "407", "9.0.0", false, {}, {}, { 'id' : 'flash-feature'});
  }

});

// NAVIGATION ROLLOVERS

var NavRollover = Class.create({
	initialize : function(list_item){
	  this.node = list_item;
	  // don't rollover for active items or homepage
	  if (!list_item || list_item.id == 'nav_home') { return; }
	  // if it's active, give it frame 5 and stop animation
	  if (list_item.hasClassName('Active')) {
	    list_item.addClassName('Frame5');
	    return;
	  }
	  this.current_frame = 0;
	  this.currently_hovering = false;
	  this.node.observe('mouseover', this.mouseOverHandler.bindAsEventListener(this));
	  this.node.observe('mouseout', this.mouseOutHandler.bindAsEventListener(this));
	},
	mouseOverHandler : function(){
	  this.currently_hovering = true;
	  this.setAnimationTimeout(30);
	},
	mouseOutHandler : function(){
	  this.currently_hovering = false;
	  this.setAnimationTimeout(30);
	},
	setAnimationTimeout : function(timeout){
	  setTimeout(this.animationHandler.bind(this), timeout);
	},
	animationHandler : function(){
	  if (this.currently_hovering) {
	    if (this.current_frame != 5) {
	      this.current_frame += 1;
	      this.drawAnimationFrame();
	      this.setAnimationTimeout(30);
	    }
	  } else {
	    if (this.current_frame != 0) {
	      this.current_frame -= 1;
	      this.drawAnimationFrame();
        this.setAnimationTimeout(50);
	    }
	  }
	},
	drawAnimationFrame : function(){
	  this.node.className = 'Frame'+this.current_frame;
	}
});
document.observe('dom:loaded', function(){
	$$('#MainNav LI').each(function(li){ new NavRollover(li); });
});


// PRINT CERTIFICATE
document.observe('dom:loaded', function(){
	if ($('certificate-wrap')) {
		var newButton = new Element('img', {'src' : 'img/btn.print-certificate.gif', 'alt' : 'Print Certificate', 'class' : 'button'});
		newButton.observe("click", function() { window.print() });		
		$('certificate-wrap').insert({'top' : newButton});
	}

});
