google.load("swfobject", "2.1");

var Home = new Class({
	initialize:function() {
		//new InputFocusClear($$("#content #touts li.newsletter input")[0], "Email address");
		
		var flashvars = {
		};
		var params = {
			align:"lt",
			scale:"noScale",
			allowfullscreen:"true",
			wmode:"transparent"
		};
		var attributes = {};
		
		swfobject.embedSWF("swf/homepage-animation.swf", "flashcontent", "100%", "100%", "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes);	
	}
});

var InputFocusClear = new Class({
	inputElement:null,
	inputString:null,
	initialize:function(a, b) {
		this.inputElement = a;
		this.inputString = b;
		a.addEvent("focus", this.clear.bind(this));
	},
	clear:function() {
		if (this.inputElement.value == this.inputString) this.inputElement.value = "";
	}
});

var PageOverlay = new Class({
	overlayElement:null,
	overlayBox:null,
	overlayBg:null,
	initialize:function() {
		// create element, create background element, set bg alpha to 54%, add interface
		this.overlayBox = new Element( 'div', { 'id':'overlay' }).injectInside($$('body')[0]);
		this.overlayBg = new Element('div', {'class':'bg'}).injectInside(this.overlayBox);
		var d = detectMacXFF2();
		if (d) {
			this.overlayBg.style.background = "Transparent url(../img/bg-overlay.png) repeat";
		} else {
			this.overlayBg.set('opacity', 0.54);
		}
		this.overlayBg.addEvent("click",this.dismissOverlay.bind(this));
		this.overlayContent = new Element('div', {'class':'content'}).injectInside(this.overlayBox);
		if (d) {
			this.overlayIFrame = new Element('iframe').injectInside(this.overlayContent);
		}
		this.overlayClose = new Element('div', {'class':'close'}).injectInside(this.overlayContent);
		this.overlayClose.addEvent("click",this.dismissOverlay.bind(this));
		this.overlayVideo = new Element('div', {'class':'video'}).injectInside(this.overlayContent);
		this.overlayVideoPlayer = new Element('div', {'id':'qrs-demo'}).injectInside(this.overlayVideo);
		window.addEvent("resize", this.repositionOverlay.bind(this));
		this.overlayContent.style.left = parseInt((Window.getWidth() - this.overlayContent.offsetWidth + 30) / 2) + "px";
		var otPosition = parseInt(($$('#content')[0].getHeight() - this.overlayContent.offsetHeight) / 2);
		otPosition = (otPosition < -65) ? -65 : otPosition;
		this.overlayContent.style.top = otPosition + "px";
		
		var flashvars = {};
		var params = {
			align:"lt",
			scale:"noScale",
			allowfullscreen:"true",
			wmode:"opaque",
			bgcolor:"#ffffff"
		};
		var attributes = {};
		
		swfobject.embedSWF("swf/QRSVideo.swf", "qrs-demo", "692", "442", "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes);	
	},
	dismissOverlay:function() {
		$("overlay").parentNode.removeChild($("overlay"));
	},
	repositionOverlay:function() {
		this.overlayContent.style.left = parseInt((Window.getWidth() - this.overlayContent.offsetWidth + 30) / 2) + "px";
		var otPosition = parseInt(($$('#content')[0].getHeight() - this.overlayContent.offsetHeight) / 2);
		otPosition = (otPosition < -65) ? -65 : otPosition;
		this.overlayContent.style.top = otPosition + "px";
	}
});

function detectMacXFF2() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
    var ffversion = new Number(RegExp.$1);
    if (ffversion < 3 && userAgent.indexOf('mac') != -1) {
      return true;
    }
  }
}

function popVideo() {
	new PageOverlay();
}

function initHome() {
	new Home();
}

window.addEvent("domready", initHome);