//
//  application.js
//  Mission of Hope
//

function add_link_hovers () {
  if (navigator.userAgent.indexOf("MSIE") < 0) return;
  $$("#links li").each(function (link) {
    link.originalClassName = link.className;
    
    link.onmouseover = function () {
      if (this.originalClassName.indexOf("active") < 0)
        this.addClassName("active");
    }
    link.onmouseout = function () {
      if (this.originalClassName.indexOf("active") < 0)
        this.removeClassName("active");
    }
  });
}

function add_animated_anchors () {
	$$("a").each(function (anchor) {
		if (anchor.href.match(/#(.+)/)) {
			anchor.scroll_target = anchor.href.split("#")[1];
			anchor.onclick = scroll_to_anchor;
			anchor.href = "javascript:void();";
		}
	});
}

function scroll_to_anchor () {
	var name = this.scroll_target;
	$$("a").each(function (anchor) {
		if (anchor.getAttribute("name") == name) {
			new Effect.ScrollTo(anchor, { offset: -12.0, duration: 0.75 });
		}
	});
}

function add_photos_flash () {
  var photos = $("photos");
  if (!photos)
    return;
  
  var flash = new SWFObject("/flash/photos.swf", 
    "photos", "328", "218", "7");
  flash.addParam("wmode", "transparent");
  flash.write(photos);
}

function add_video_flash () {
  var video = $("video");
  if (!video)
    return;
  
  var flash = new SWFObject("/flash/player.swf", 
    "video", "240", "180", "8");
  
  flash.addParam("wmode", "transparent");
  flash.addVariable("file", "/flash/" + video.className + ".flv");
  flash.addVariable("image", 
    "/images/videos/" + video.className + ".jpg");
  
  flash.write(video); 
}

function add_wimpy_flash () {
  var wimpys = $$("div.wimpy");
  if (!wimpys || wimpys.length == 0)
    return;
    
  wimpys.each(function (wimpy) {
    var anchor = $$("#" + wimpy.getAttribute("id") + " a")[0];
    var flash = new SWFObject("/flash/wimpy.swf", 
      wimpy.getAttribute("id"), "42", "42", "7");
    
    flash.addParam("wmode", "transparent");
    flash.addVariable("theFile", anchor.getAttribute("href"));
    
    flash.write(wimpy);
  });
}

function sync_started () {
  $$("#progress")[0].show();
  $$("#sync input")[0].disabled = true;
  $("progress").update("<p>Downloading Changes&hellip;</p>");
}

function sync_finished () {
  $$("#sync input")[0].disabled = false;
}

Event.observe(window, "load", add_link_hovers);
Event.observe(window, "load", add_animated_anchors);
Event.observe(window, "load", add_photos_flash);
Event.observe(window, "load", add_video_flash);
Event.observe(window, "load", add_wimpy_flash);
