/* ---------------------------------------------------------------------------
 * Client Object
 */
	
Client = new Object();
(function(){
	var ua = navigator.userAgent.toLowerCase();
	Client.win = ua.indexOf('win') != -1;
	Client.mac = ua.indexOf('mac') != -1;
	Client.ipod = ua.indexOf('ipod') != -1;
	Client.iphone = ua.indexOf('iphone') != -1;
	Client.ie = false;
	/*@cc_on
		Client.ie = true;
	@*/
})();

/* ---------------------------------------------------------------------------
 * Request Object
 */

Request = new Object();
Request.search = new Object();
Request.hasSearch = false;
(function(){
	var str = window.location.search;
	if (str.length > 1) {
		Request.hasSearch = true;
		var pairs = str.substr(1).split('&');
		for (var i = 0; i < pairs.length; i++) {
			var pair = pairs[i].split('=');
			var hasValue = typeof(pair[1]) != 'undefined' && pair[1].length > 0;
			Request.search[pair[0]] = hasValue ? unescape(pair[1]) : null;
		}
	}
})();

/* ---------------------------------------------------------------------------
 * Element Object
 */

Element = {
	$ : function (p_elem) {
		if (typeof(p_elem) == 'string') {
			p_elem = document.getElementById(p_elem);
		}
		return p_elem || null;
	},
	css : function (p_elem, p_name, p_value) {
		p_elem = this.$(p_elem);
		if (p_elem) p_elem.style[p_name] = p_value;
	},
	hide : function (p_elem) {
		this.css(p_elem, 'display', 'none');
	},
	show : function (p_elem) {
		this.css(p_elem, 'display', 'block');
	},
	setClassName : function (p_elem, p_className) {
		p_elem = this.$(p_elem);
		if (p_elem) p_elem.className = p_className;
	},
	insertInto : function (p_elem, p_content) {
		p_elem = this.$(p_elem);
		if (p_elem) p_elem.innerHTML = p_content;
	},
	appendTo : function (p_elem, p_content) {
		p_elem = this.$(p_elem);
		if (p_elem) {
			if (typeof(p_content) == 'string') {
				p_content = this.createTextElement(p_content);
			}
			p_elem.appendChild(p_content);
		}
	},
	createTextElement : function (p_content) {
		var div = document.createElement('div');
		div.innerHTML = p_content;
		return div.firstChild;
	}
};

/* ---------------------------------------------------------------------------
 * Flash Object
 */

Flash = {
	hasVersion : function (p_versionRequired) {
		var versionRequired = parseInt(p_versionRequired);
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash'] && navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
			var description = navigator.plugins['Shockwave Flash'].description;
			var version = parseInt(description.split(' ')[2].split('.')[0]);
			return version >= versionRequired;
		} else if (Client.win && window.execScript) {
			this.hasVersionResult = null;
			execScript('on error resume next: Flash.hasVersionResult=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + versionRequired + '"))','VBScript');
			return this.hasVersionResult;
		}
		return false;
	}
};

/* ---------------------------------------------------------------------------
 * FlashElement Class
 */

FlashElement = function (p_movie, p_options) {
	this.movie = p_movie;
	this.version = p_options.version || '8';
	this.vars = p_options.vars || new Object();
	this.alt = p_options.alt || null;
	this.options = new Object();
	this.options.id                = p_options.id                || null;
	this.options.width             = p_options.width             || '550';
	this.options.height            = p_options.height            || '400';
	this.options.align             = p_options.align             || null;
	this.options.allowFullScreen   = p_options.allowFullScreen   || null;
	this.options.allowNetworking   = p_options.allowNetworking   || null;
	this.options.allowScriptAccess = p_options.allowScriptAccess || null;
	this.options.base              = p_options.base              || null;
	this.options.bgcolor           = p_options.bgcolor           || null;
	this.options.menu              = p_options.menu              || null;
	this.options.quality           = p_options.quality           || null;
	this.options.salign            = p_options.salign            || null;
	this.options.scale             = p_options.scale             || null;
	this.options.wmode             = p_options.wmode             || null;
	this.attributeNames = ['id', 'width', 'height', 'align'];
	var flashvars = '';
	for (var n in this.vars) {
		var v = this.vars[n];
		if (v) flashvars += n + '=' + escape(v) + '&';
	}
	this.options.FlashVars = flashvars;
	this.movie += '?' + flashvars;
	var embed = (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length);
	if (embed) {
		this.options.src = this.movie;
		this.options.type = 'application/x-shockwave-flash';
		this.options.pluginspage = 'http://www.macromedia.com/go/getflashplayer';
		if (this.options.id != null) {
			this.options.name = this.options.id;
			delete this.options.id;
		}
		var html = '<embed';
		for (var n in this.options) {
			var v = this.options[n];
			if (v) html += ' ' + n + '="' + v + '"';
		}
		html += '></embed>';
	} else {
		this.options.movie = this.movie;
		var attrs = new Object();
		attrs.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
		attrs.codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.version + ',0,0,0';
		for (var i = 0; i < this.attributeNames.length; i++) {
			var a = this.attributeNames[i];
			attrs[a] = this.options[a];
			delete this.options[a];
		}
		var html = '<object';
		for (var n in attrs) {
			var v = attrs[n];
			if (v) html += ' ' + n + '="' + v + '"';
		}
		html += '>';
		for (var n in this.options) {
			var v = this.options[n];
			if (v) html += '<param name="' + n + '" value="' + v + '" />';
		}
		html += '</object>';
		if (attrs.id && Client.win && Client.ie && Flash.hasVersion(8)) {
			window.attachEvent('onunload', function(){
				var obj = getElementById(attrs.id);
				if (obj) {
					for (var i in obj) {
						if (typeof obj[i] == 'function') {
							obj[i] = function(){};
						}
					}
					obj.parentNode.removeChild(obj);
				}
			});
		}
	}
	this.html = html;
};
FlashElement.prototype.getHtml = function(){
	if (this.alt != null && ! Flash.hasVersion(this.version)) {
		return this.alt;
	} else {
		return this.html;
	}
};
FlashElement.prototype.write = function(){
	document.write(this.getHtml());
};
FlashElement.prototype.insertInto = function (p_elem) {
	Element.insertInto(p_elem, this.getHtml());
};
FlashElement.prototype.appendTo = function (p_elem) {
	Element.appendTo(p_elem, this.getHtml());
};

/* ---------------------------------------------------------------------------
 * Popup Object
 */

Popup = {
	open : function (url, width, height, name, toolbar, scroll, x, y) {
		if (name == null) {
			var name = new Date();
			name = name.getTime();
			name = name.toString();
		}
		toolbar = toolbar ? 'yes' : 'no';
		scroll = scroll ? 'yes' : 'no';
		var features = 'toolbar='+toolbar+',menubar='+toolbar+',location='+toolbar+',status='+toolbar+',scrollbars='+scroll+',resizable='+scroll;
		if (width) features += ',width='+width;
		if (height) features += ',height='+height;
		if (x) features += ',screenX='+x+',left='+x;
		if (y) features += ',screenY='+y+',top='+y;
		this.reference = window.open(url, name, features);
		if (this.reference != null && ! this.reference.closed) {
			this.reference.focus();
		}
	},
	openCenter : function (url, width, height, name, toolbar, scroll) {
		var x = (width && window.screen.availWidth) ? Math.round((window.screen.availWidth - parseInt(width)) / 2) : 0;
		var y = (height && window.screen.availHeight) ? Math.round((window.screen.availHeight - parseInt(height)) / 2) : 0;
		this.open(url, width, height, name, toolbar, scroll, x, y);
	},
	openCenterChrome : function (url, width, height, name) {
		this.openCenter(url, width, height, name, true, false);
	},
	openCenterScroll : function (url, width, height, name) {
		this.openCenter(url, width, height, name, false, true);
	},
	openCenterChromeScroll : function (url, width, height, name) {
		this.openCenter(url, width, height, name, true, true);
	},
	openFull : function (url) {
		this.open(url, null, null, null, true, true, null, null);
	}
};

