/**
 * Static Class for namespace and functions
 */
var Rome = {
	
	registrationUrl: {
		test: 	"http://eu.uatlive.csg.issolutions.co.uk/cgi-bin/ToshibaCSG/regForm.jsp",
		stage: 	"http://eu.uatlive.csg.issolutions.co.uk/cgi-bin/ToshibaCSG/regForm.jsp",
		live: 	"http://eu.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/regForm.jsp"
	},
	
	flashMovie: "/flash/rome_41.swf",
	
	flashVersion: 8,
	
	popupWidth: screen.width,
	
	popupHeight: screen.height,
	
	flashMovieWidth: 980,
	
	flashMovieHeight: 600,
	
	isExternalCall: function() {
		var external = (location.href.match(/vista/)) ? true : false;
		return external;	
	},
	
	/**
	 * Creates a pop an focus if popupblocker not working
	 */
	openPopup: function(link, options) {
		var options = options || {};
		var width = options.width || this.popupWidth;
		var height = options.height || this.popupHeight;
		var scrollbars = options.scrollbars || "no"
		
		var w = window.open(link, options.name || "rome", "width=" + width + ", height=" + height + ",locationbar=auto,menubar=no,status=no,resizable=no,scrollbars=" + options.scrollbars);
		
		if(w) w.focus();
	},
	
	getRegistrationUrl: function() {
		
		var state = true;
		var server = null;
		
		if (location.host.match(/10\.1\.42\.85/))
			server = "test";
		
		if (server == null)
			server = (location.host.match(/\.stage\./)) ? "stage" : "live";
		
		return this.registrationUrl[server];
	}
};

Rome.ClientInfo = Class.create();
Rome.ClientInfo.prototype = {
	
	_clientDefaultLanguage: "eu",
	
	_clientLanguage: null,
	
	initialize: function(language) {
		this._clientLanguage = language;
	},
	
	getClientLanguage: function() {
		return this._clientLanguage;
	},
	
	/**
	 * @return String default language
	 */
	getClientDefaultLanguage: function() {
		return this._clientDefaultLanguage;
	}
}

function changeBckGrndColor(color) {
	document.body.style.backgroundColor='#'+color;
}

// wrapper functions
function openTermsOfUse(language) {
	var language = language || ClientInfo.getClientDefaultLanguage();
	Rome.openPopup("/" + language + "/terms_of_use.asp", {width: 600, height: 400, scrollbars: "yes", name: "termsofuse"});
}

function openPrivacyPolicy(language) {
	var language = language || ClientInfo.getClientDefaultLanguage();
	Rome.openPopup("/" + language + "/privacy_policy.html", {width: 600, height: 400, scrollbars: "yes", name: "privacypolicy"});
}

Event.observe(window, "load", function() {
	
	// use this only on startpage
	if ($("navigation")) {
		
		var so = new SWFObject("swf/test.swf", "so", "1", "1", Rome.flashVersion, "#000000");
		var hasFlash = so.installedVer.versionIsValid(so.getAttribute("version"));
		if (hasFlash) {
			Element.show("content");
		} else {
			Element.show("errorFlash");
		}
		
		
		var language = ClientInfo.getClientLanguage();
		var li = $(language);
		if (li) {
			var img = li.getElementsByTagName("img").item(0);
			img.src = decodeURIComponent(img.src).replace(/\[off\]/, "[on]");
			img._clicked = true;
			var link = li.getElementsByTagName("a").item(0).href;
			if (hasFlash && link) {
				window.setTimeout("Rome.openPopup('" + link + "')", 100);
			}
		}
		
		var images = $("navigation").getElementsByTagName("img");
		
		$A(images).each(function(element) {
			
			Event.observe(element, "mouseover", function(e) {
				if (!element._clicked) {
					element.src = decodeURIComponent(element.src).replace(/\[off\]/, "[on]");
				}
			}, false);
						
			Event.observe(element, "mouseout", function(e) {
				if (!element._clicked)
					element.src = decodeURIComponent(element.src).replace(/\[on\]/, "[off]");
			}, false);
			
			Event.observe(element, "click", function(e) {
				Event.stop(e);
				
				$A(images).each(function(element) {
					element.src = decodeURIComponent(element.src).replace(/\[on\]/, "[off]");
					element._clicked = false;
				});
				
				element._clicked = true;
				element.src = decodeURIComponent(element.src).replace(/\[off\]/, "[on]");
				
				var link = element.parentNode.href;
				if (hasFlash && link) {
					Rome.openPopup(link);
				}
				return false;
			}.bind(element), false);
		});
	}
});