var App = {
  "#island":function(element) {
    var flash = new FlashTag(element,{height:209,src:"http://www.findadatacenter.com/images/intro.swf",width:687});
    element.setHTML(flash.getHTML());
  },
  "#map":function(element) {
    var flash = new FlashTag(element,{height:417,src:"/images/map/map.swf",width:685});
    element.setHTML(flash.getHTML());
  },
  '#main-search .submit::keypress':function(element,event){
    if (event.key == 'enter') $('main-search').submit();
  },
  // "body":function(){
  //   window.resizeTo(1024,768);
  // },
  ".hide":function(element) {
    element.setStyle("display","none");
  },
  ".show":function(element) {
    element.setStyle("display","");
  },
  "a.external::click":function(element,event) {
    event.stop();
    window.open(element.href + (element.href.contains('?') ? '&' : '?') + 'external=yes','_external','height=500,width=740,left=100,resizable=yes,scrollbars=yes');
  },
  "a.new":function(element) {
    element.target = "_new";
  },
  "a.toggle::click":function(element,event) {
    event.stop();
    var toggle = $(element.getAttribute("rel"));
    if (toggle) {
      if (element.hasClass("toggled")) {
        element.removeClass("toggled");
        toggle.setStyle("display","none");
      } else {
        element.addClass("toggled");
        toggle.setStyle("display","");
      }
    }
    element.blur();
  },
  "div.tabset":function(element) {
    var tabs = element.getElements("a.tab");
    var tabBodies = element.getElements("div.tab-body");
    tabs.forEach(function(tab){tab.addEvent("click",function(event){
      event = new Event(event).stop().target.blur();
      tabBodies.forEach(function(tabBody){
        var tabBodyIndex = tabBodies.indexOf(tabBody);
        if (tabs.indexOf(tab) == tabBodyIndex) {
          tabBody.addClass("active");
          tab.addClass("active");
        } else {
          tabBody.removeClass("active");
          tabs[tabBodyIndex].removeClass("active");
        }
      });
    });});
  },
  // "h1,h2,h3":function(element) {
  //   var size = element.getSize().size;
  //   var html = element.innerHTML.toUpperCase().replace(/HREF="[^"]+"/,function(original) { return original.toLowerCase(); });
  //   if (html.match(/^<IMG[^>]*>$/)) return;
  //   if (element.tagName == "H3") size.y = 18;
  //   var flash = new FlashTag(element,{height:size.y,src:"/images/fonts/franklin-gothic.swf",variables:{h:size.y,txt:html,textcolor:"#003366",w:size.x},width:size.x,wmode:"transparent"});
  //   element.setHTML(flash.getHTML()).addClass("sifr");
  // },
  "#featured-partners":function(element) {
    new FlashTag(element,{height:100,src:"/images/featured-partners.swf",width:219}).embed();
  },
  "#fiber-locator-demo":function(element) {
    new FlashTag(element,{height:450,src:"http://www.findadatacenter.com/images/fiber-locator-demo.swf",width:720,wmode:'transparent'}).embed();
  }
}

var FlashTag = new Class({
	options:{allowFullScreen:"true",bgcolor:"",height:0,id:"flash",name:"flash",quality:"high",src:"",style:"",variables:{},width:0,wmode:"window"},
	initialize:function(container,options) {
		this.setOptions(options);
		this.container = $(container);
	},
	embed:function() {
		this.container.setHTML(this.getHTML());
		if (window.ie) this.fixIE.delay(100,this);
	},
	fixIE:function() {
		this.container.outerHTML = this.container.outerHTML.replace(/<param name="FlashVars" value="">/ig,'<param name="FlashVars" value="'+this.getVariables()+'"');
	},
	getHTML:function() {
		if (window.ie) {
			var html = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" height=\""+this.options.height+"\" id=\""+this.options.id+"\" style=\""+this.options.style+"\" width=\""+this.options.width+"\">";
			var options = this.getIEOptions();
			for (key in options)
				html += "<param name=\""+key+"\" value=\""+options[key]+"\" />";
			html += "</object>";
		} else {
			var tmp = new Element("div");
			this.getObject().injectInside(tmp);
			var html = tmp.innerHTML;
		}
		return html;
	},
	getIEOptions:function() {
		return {allowFullScreen:this.options.allowFullScreen,movie:this.options.src,bgcolor:this.options.bgcolor,quality:this.options.quality,flashvars:this.getVariables(),wmode:this.options.wmode};
	},
	getObject:function() {
		if (window.ie) {
			return new Element("div").setHTML(this.getHTML()).getFirst();
		} else {
			return new Element("embed",{bgcolor:this.options.bgcolor,flashVars:this.getVariables(),height:this.options.height,id:this.options.id,name:this.options.name,quality:this.options.quality,src:this.options.src,style:this.options.style,"type":"application/x-shockwave-flash",width:this.options.width,wmode:this.options.wmode});
		}
	},
	getVariables:function() {
		var variables = [];
		for (key in this.options.variables) {
			if (key != "") variables.push(key + "=" + this.options.variables[key]);
		}
		return variables.join("&");
	}
});
FlashTag.implement(new Options);

