
// SWFOBJECT

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

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

  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/MF_demo.swf", "about-flash-replace", "326", "416", "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 ($('ellen-flash-replace')) { 
    swfobject.embedSWF("flash/ellen_vid.swf", "ellen-flash-replace", "750", "407", "9.0.0", false, {}, {}, { 'id' : 'flash-feature'});
  }

  if ($('tv-martha-replace')) { 
    swfobject.embedSWF("flash/martha_vid_goodbye.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'});
  }

  if ($('find-focus-flash-replace')) { 
    swfobject.embedSWF("flash/find_focus.swf", "find-focus-flash-replace", "750", "580", "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
	var certificate_wrap = $('certificate-wrap');
	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 });
	}
	
	var browse_photo_wrapper = $("browse-photos-wrapper");
	var photo = $("photo");
	if (browse_photo_wrapper && photo) {
		var fakeFileUpload = new Element("div", { "class" : "fakefile" });
		fakeFileUpload.appendChild(new Element("img", { "src" : "/img/btn.browse-photos.gif", "style" : "float:right" }));
		fakeFileUpload.appendChild(new Element("input", { "type" : "text", "id" : "file-input-display", "disabled" : "disabled" } ));
		photo.className = "overlaid-file-input";
		var clone = fakeFileUpload.cloneNode(true);
		browse_photo_wrapper.appendChild(clone);
		photo.relatedElement = $(clone).down("input");
		photo.onchange = photo.onmouseout = function(){
			this.relatedElement.value = this.value;
		};
	}
	
});


var Popup = {
  open: function(options)
  {
    this.options = {
      url: '#',
      width: 580,
      height: 355
    }
    Object.extend(this.options, options || {});   
	this.window_ref = window.open(this.options.url, '', 'width='+this.options.width+',height='+this.options.height+'scrollbars=yes,resizable=yes');
	this.window_ref.focus();
	return false;
  }
}



