﻿/*
	Base, version 1.1
	Copyright 2006, Dean Edwards
	License: http://creativecommons.org/licenses/LGPL/2.1/
*/

/* end Base */
var Base=function(){};Base.prototype={extend:function(c){if(arguments.length>1){var d=this[c];var e=arguments[1];if(typeof e=="function"&&d&&/\bbase\b/.test(e)){var f=e;e=function(){var a=this.base;this.base=d;var b=f.apply(this,arguments);this.base=a;return b};e.method=f;e.ancestor=d}this[c]=e}else if(c){var g=Base.prototype.extend;if(Base._prototyping){var h,i=0,members=["constructor","toString","valueOf"];while(h=members[i++])if(c[h]!=Object.prototype[h]){g.call(this,h,c[h])}}else if(typeof this!="function"){g=this.extend||g}for(h in c)if(!Object.prototype[h]){g.call(this,h,c[h])}}return this},base:Base};Base.extend=function(b,c){var d=Base.prototype.extend;Base._prototyping=true;var e=new this;d.call(e,b);delete Base._prototyping;var constructor=e.constructor;var f=e.constructor=function(){if(!Base._prototyping){if(this._constructing||this.constructor==f){this._constructing=true;constructor.apply(this,arguments);delete this._constructing}else{var a=arguments[0];if(a!=null){(a.extend||d).call(a,e)}return a}}};for(var i in Base)f[i]=this[i];f.ancestor=this;f.base=Base.base;f.prototype=e;f.toString=this.toString;d.call(f,c);if(typeof f.init=="function")f.init();if(typeof f.pageReady=="function"&&Aris.Event)$AE.pageReady?f.pageReady():$AE.onDOMReady.add(f.pageReady,f);return f};Base=Base.extend({constructor:function(){this.extend(arguments[0])}},{ancestor:Object,base:Base,implement:function(a){if(typeof a=="function"){a(this.prototype)}else{this.prototype.extend(a)}return this}});
// Object
Object.extend = Object.merge = function (dest, src, bOverride) {
	dest = dest || {};
	if ( src ) {
		for (var prop in src) {
			if( dest[prop] && bOverride===false );
			else dest[prop] = src[prop];
		}	
	}
	return dest;
};
Object.extract = function(obj,name) {
	var rv = {};
	if (arguments.length ==2) { return obj[name]; }
	for(var i=1,l=arguments.length;i<l; i++) {
		var a = obj[arguments[i]];
		if ( a ) {rv[arguments[i]] = a;}
	}
	return rv;
};
Object.remove = function(obj, name){
	var rv = {};
	if ( arguments.length == 2) {
		var x = obj[name];
		delete obj[name];
		return x;
	}
	for(var i=1,l=arguments.length;i<l; i++) {
		var a = obj[arguments[i]];
		if ( a ) {
			rv[arguments[i]] = a;
			delete obj[arguments[i]];
		}
	}
	return rv;
};
Object.getType = function(obj){
	var t = typeof obj;
	if (obj===null){ t = 'null'; }
	else if (obj && obj.constructor == Array) { t = 'array'; }
	return t;
};
var Fp = Function.prototype;
Fp.bind = function(thisObj) {
	var __method = this, args = $A(arguments), obj = args.shift();
	return function() { return __method.apply(obj, args); };
};
Fp.delay = function(ms, thisObj) {
	var args = $A(arguments), ms = args.shift();
	return setTimeout(this.bind.apply(this, args),ms);
};

var Aris = Base.extend(null,{
	
	extend: function (obj) {
		return this.base(null,obj);
	},
	_guid: 0,
	
	version: "1.0.0",
	
	guid: function () { 
		return (typeof arguments[0] == 'string' ? arguments[0] + ++this._guid : ++this._guid);
	},
	
	popWin: function (url, name, width, height, center) {
		var win, opt = [];
		if (width || height) {
			height = height || 570;
			width = width || 770;
			opt.push('height='+ height,'width='+ width);
			if (center===false) { 
				opt.push('top=' + ( (screen.width) ? (screen.width-width)/2 : 0 )); 
				opt.push('left=' + ( (screen.height) ? (screen.height-height)/2 : 0 ));
			}
			opt.push('scrollbars=yes','resizable','menubar=1');
		}
		win = window.open(url,name,opt.join(',') );
		if (win) win.focus();
		return win;
	}
});

var Observer = function() {
	this.fns = [];
	this.locked = false;
};
Observer.prototype = {
	add: function(f,thisObj) {
		if (!f) return;
		if ( !this.fns.some( function (obj) { return obj.fn === f; }) )
			this.fns.push({fn:f, context:thisObj});
	},
	remove: function(fn) {
		this.fns = this.fns.filter( function(el) {
			if ( typeof fn == 'undefined' || (el.fn && el.fn !== fn) ) {
				delete el;
				return false;
			}
			return true;
		});
	},
	fire: function(sender, args) {
		if ( this.locked ) this.fire.delay(this, 10);
		var i = this.fns.length, el;
		if ( i == 0 ) return;
		this.locked = true;
		while(el = this.fns[--i]) {
			if ( el.fn.call(el.context, sender, args) === false ) break;
		}
		this.locked = false;
		return args;
	}
};

var $AE = Aris.Event = Event = Base.extend(null,{

	all: [],
	onDOMReady: new Observer,
	onPageUnloading: new Observer,
	onPageLoad: new Observer,
	pageReady: false,
	_timer: null,

	_getCacheIndex: function(el, eType, fn) {
		for (var i=0,len=this.all.length; i<len; i++) {
			var li = this.all[i];
			if ( li && li[2] == fn && li[0] == el && li[1] == eType ) return i;
		}
		return -1;
	},
	
	_on: function() {
		var addEvent;
		if (document.addEventListener) {
			addEvent = function(element, type, handler) {
				element.addEventListener(type, handler, false);
			};
		} else if (document.attachEvent) {
			addEvent = function(element, type, handler) {
				element.attachEvent("on" + type, handler);
			};
		} else {
			addEvent = function(){}; // not supported
		}
		return addEvent;
	}(),
	
	_rem: function () {
		var removeEvent;
		if (document.removeEventListener) {
			removeEvent = function(element, type, handler) {
				element.removeEventListener(type, handler, false);
			};
		} else if (document.detachEvent) {
			removeEvent = function(element, type, handler) {
				element.detachEvent("on"+type, handler);
			};
		} else {
			removeEvent = function(){};
		}
		return removeEvent;
	}(),

	_ready: function() {
		if (!this.pageReady) {
			this.pageReady = true;
			this.onDOMReady.fire(this);
			this.onDOMReady.remove();
		}
	},

	
	add: function(el, eType, fn, scope) {
		if ( !el || !fn || !fn.call ) return this;
		
		if ( typeof el == "string" ) { 
			if ( this.pageReady ) { this.add( document.getElementById(el), eType, fn, scope ); }
			else { this.onDOMReady.add( function() { $AE.add(el, eType, fn, scope); } ); }
		}
		else {
			var wFn = (scope) ? this.bind(fn, scope, el) : this.bind(fn,el);
			var li = [el,eType,fn,wFn,scope];
			this.all.push(li);
			this._on(el,eType,wFn);
		}
		return true;
		
	}, //end add
	
	bind: function(fn, obj, orig) {
		var __method = fn;
		return function(e) {
			return __method.call(obj,e||window.event,orig);
		};
	},
	
	init: function() {
		// for Mozilla/Opera 9
		if (document.addEventListener) {
		    document.addEventListener("DOMContentLoaded", this.bind(this._ready,this), false);
		}

		// for Internet Explorer (using conditional comments)
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		document.write("<script id=__ie_onload defer src=//0><\/script>");
		var script = document.getElementById("__ie_onload");
		var _this = this;
		script.onreadystatechange = function() {
		    if (this.readyState == "complete") {
		    	_this._ready(); // call the onload handler
		    }
		};
		/*@end @*/

		//for Safari/KTHML based browsers
		if (/KHTML/i.test(navigator.userAgent)) { // sniff
		    this._timer = setInterval(function() {
		        if (/loaded|complete/.test(document.readyState)) {
		           this._ready(); // call the onload handler
	        	}
		    }, 100);
		}		
		
		this.add(window, 'unload', this.unLoad, this);
		this.add(window, 'load', this.load, this);
	},

	load: function() {
		if ( !this.pageReady ) {
			this._ready();
		}	
		this.onPageLoad.fire(this);
	},
	
	preventDefault: function(ev) {
		if ( ev.preventDefault) { ev.preventDefault(); }
		else {ev.returnValue = false;}
	},
	
	remove: function(el,eType,fn,idx) {
		if (!el || !el.nodeName || !fn || !fn.call) return false;

		var cacheItem = null;
		if (typeof idx == "undefined") idx = this._getCacheIndex(el, eType, fn);
		if (idx >= 0) cacheItem = this.all[idx];
		if (!cacheItem) return false;
		
		this._rem(el, eType, cacheItem[3]);

		delete cacheItem[3];
		delete cacheItem[2];
		delete cacheItem;
		return true;
	},

	stopEvent: function(ev) {
		this.stopPropagation(ev);
		this.preventDefault(ev);
	},
	
	stopPropagation: function(ev) {
		if (ev.stopPropagation)
			ev.stopPropagation();
		else
			ev.cancelBubble = true;
	},
	
	unLoad: function(e) {
		this.onPageUnloading.fire(Aris.Event);
		this.all.forEach( function(l,idx) {
			this.remove(l[0],l[1],l[2],idx);
		},this);
	}
});

var DOM = {

	addClass: function(o, c1) {
		if(!this.hasClass(o, c1)) {
			o.className += o.className ?' ' + c1 : c1;
		}
	},

	hasClass: function(o, c1) {
		return new RegExp('\\b'+c1+'\\b').test(o.className)
	},

	clear: function(el) {
		while(el && el.hasChildNodes()) {
			el.removeChild(el.firstChild);
		}
	},

	create: function(elName, attr) {
		if (BOM.is('ie') && attr) {
			var el = [elName];
			['name','type'].forEach(function(val) {
				if (attr[val]){ el.push(val+'="'+attr[val]+'"'); delete attr[val]; }
			});
			if ( el.length > 1 ){ elName = '<'+el.join(' ')+'>'; }
		}
		var el = document.createElement(elName);
		if ( attr ) {
			var children = Object.remove(attr, 'children');
			forEach(attr, function(val, a) {
				if (a=='style'){ DOM.setStyle(el,val); }
				else{el[a] = val;}
			});
			if (typeof children =='string') children = [children];
			if ( children ) Array.from(children).forEach(function(c) {
				if ( typeof c == 'string' ) { el.appendChild(document.createTextNode(c)); }
				else if ( c.nodeType == 3 ) { el.appendChild(document.createTextNode(c.nodeValue)); }
				else if ( c.nodeType == 1 ) { el.appendChild(c); }
				else { el.appendChild( DOM.create(c.tag, c.attr) ); }
			});
		}
		return el;
	},

	get: function(el) {
		if (typeof el == 'string')
			el = document.getElementById(el);
		return el;
	},
	
	getElementsByTagName: function(root, tag) {
		var node = root||document;
		tag = tag || '*';
		var els = node.getElementsByTagName(tag);
		if( !els.length && (tag == '*' && node.all) ) els = node.all;
		return els;
	},
	
	getElementsByClass: function (searchClass,node,tag) {
		var cEls = [];
		var els = this.getElementsByTagName(node, tag);
		var elsLen = els.length;
		var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
		for (var i=0,j=0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) { cEls[j++] = els[i]; }
		}
		return cEls;
	},
	
	getStyle: function() {
		if (document.defaultView && document.defaultView.getComputedStyle) {
			return function(o,prop) {
				if (!o) return;
				prop = prop == 'float' ? 'cssFloat' : prop;
				var s = document.defaultView.getComputedStyle(o,'');
				return o.style[prop] || s ? s[prop] : null;
			};
		}
		else if (document.all) {
			return  function(o, prop) {
				if (!o) return;
				prop = prop == 'float' ? 'styleFloat' : prop;
				
				if ( prop == 'opacity' && window.ActiveXObject) {
					var val = 100;
                    try { // will error if no DXImageTransform
                        val = o.filters['DXImageTransform.Microsoft.Alpha'].opacity;
                    } catch(e) {
                        try { // make sure its in the document
                            val = o.filters('alpha').opacity;
                        } catch(e) { }
                    }
                    return val / 100;
				}
				else {
					return o.style[prop] || o.currentStyle[prop];
				}
			};
		}
		else {
			return function(o, prop) { if(!o) return; return o.style[prop] };
		}
	}(),
	
	removeClass: function(o, c1) {
		var rep = o.className.match(' '+c1) ? ' ' + c1 : c1;
		o.className=o.className.replace(rep,'');
	},
	
	setOpacity: function() {
		if (window.ActiveXObject) {
			return function(o, val) {
				o.style.filter = "alpha(opacity:"+val*100+")";
				if (!o.hasLayout) o.style.zoom = 1; 
			}
		}
		else {
			return function(o,val) {
				o.style.opacity = val<1 ? val : .999;
			};
		}
	}(),
	
	setStyle: function(el, style, val) {
		if ( !el ) return;
		if (arguments.length ==3)
			style == "opacity" ?  DOM.setOpacity(el, val) :  el.style[style] = val;
		else {
			for( var s in style) {
				s == "opacity" ? DOM.setOpacity(el, style[s]) :  el.style[s] = style[s];
			}
		}
	},

	swapClass: function(o,c1,c2) {
		o.className=!this.hasClass(o,c1) ? o.className.replace(c2,c1) : o.className.replace(c1,c2);
	},
	
	getPos: function(tEl, asArray) {
		var el = DOM.get(tEl);
		var pos = { top: 0, left: 0 };
		do {
			pos.top += el.offsetTop;
			pos.left += el.offsetLeft;
		} while( el = el.offsetParent );
		return asArray? [pos.top, pos.left] : pos;
	},
	
	getDim: function(tEl,asArray) {
		var tEl = DOM.get(tEl);
		var dim = {};
		dim.width = tEl.offsetWidth;
		dim.height = tEl.offsetHeight;
		return asArray ? [dim.width,dim.height] : dim;
	},
	
	getLayout: function(el) { return Object.extend( this.getPos(el), this.getDim(el) ); }
	
};
if ( window.Ext && window.Ext.query ) {
	DOM.match = Ext.query;
	DOM.matchOne = Ext.DomQuery.selectNode;
}

var BOM = function(){
	var ua = navigator.userAgent.toLowerCase();
	this.xpath = !!(document.evaluate);
	if (window.ActiveXObject) { this.ie = this[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true; }
	else if (document.childNodes && !document.all && !navigator.taintEnabled){ this.khtml = this.webkit = this[this.xpath ? 'webkit420' : 'webkit419'] = true; }
	else if (document.getBoxObjectFor !== null){ this.gecko = true; }
	this.mac = /mac/.test(ua);
	this.winCE = /windows ce/.test(ua);
	this.opera = /opera/.test(ua);
	return this;
}();

BOM.is = function() {
	return [].every.call(arguments, function(condition) {
			return this[condition] === true;
	},this);
};

Object.serialize = function(obj, s1, s2) {
	s1 = s1 || ':';
	s2 = s2 || ',';
	var rv = [];
	forEach(obj, function(val,name) {
		rv.push(name+s1+val);
	});
	return rv.join(s2);
};

var IConfigurable = Base.extend({
	config: null,
	setConfig: function(config) {
		if (!this.config ) this.config = {};
		forEach(config,function(opt,name) {
			this.config[name] = opt;
		},this);
		return this.config;
	}
});


Object.merge(Array.prototype,{
	//javascript 1.6 array functions forEach, every, some, filter
	forEach: function(fn,context) {
		for(var i=0,len=this.length;i < len; i++) {
			if(i in this)
				fn.call(context, this[i], i, this );
		}
	},

	filter: function(fn,context) {
		var rv = [];
		for (var i=0,len=this.length;i < len; i++) {
			if (i in this){
				if ( fn.call(context,this[i],i,this) )
					rv.push( this[i] );
			}
		}
		return rv;
	},

	every: function(fn,context) {
		var rv = true;
		for (var i=0,len=this.length;i < len; i++) {
			
			if (i in this && !fn.call(context,this[i],i,this) )
				return false;
		}
		return true;
	},

	some: function(fn,context) {
		for (var i=0,len=this.length;i < len; i++) {
			
			if( i in this && fn.call(context,this[i],i,this) )
				return true;
		}
		return false;
	},

	map: function(fn,context) {
		var len = this.length;
		var rv = new Array(len);
		for (var i=0; i < len; i++) {
			if(i in this)
				rv[i] = fn.call(context,this[i],i,this);
		}
		return rv;
	},

	indexOf: function(obj,start) {
		var len = this.length;
		var i = start || 0;
		if (i < 0) i += len;
		for (;start < len; i++) {
			if (i in this && this[i]===obj) 
				return i;
		}
		return -1;
	}
},false);

var $A = Array.from = function(iterable) {
	if (!(iterable && iterable.length) ) return iterable = [].concat(iterable);
	return [].map.call(iterable,function(v) { return v; });
};

// array-like enumeration
if (!Array.forEach) { // mozilla already supports this
    Array.forEach = function(object, fn, context) {
        for (var i=0,len=object.length; i < len; i++) {
            fn.call(context, object[i], i, object);
        }
    };
}
var $forEach = Array.forEach;

// generic enumeration
Function.prototype.forEach = function(object, fn, context) {
    for (var key in object) {
        if (typeof this.prototype[key] == "undefined") {
            fn.call(context, object[key], key, object);
        }
    }
};

// globally resolve forEach enumeration
var forEach = function(object, fn, context) {
    if (object) {
        var resolve = Object; // default
        if (object instanceof Function) {
            // functions have a "length" property
            resolve = Function;
        } else if (object.forEach instanceof Function) {
            // the object implements a custom forEach method so use that
            object.forEach(fn, context);
            return;
        } else if (typeof object.length == "number") {
            // the object is array-like
            resolve = Array;
        }
        resolve.forEach(object, fn, context);
    }
};

String.prototype.normalize = function(){
	return this.replace(/\s+/g, " ");
};

var sIFR = Aris.extend((function(){

	function matchNodeNames(el, nn) { return (el.nodeName.toLowerCase() == nn); };

	function fetchContent(node, nodeNew, sCase, nLinkCount, sLinkVars){
		var sContent = "";
		var oSearch = node.firstChild;
		var oRemove, nodeRemoved, oResult, sValue;

		if(nLinkCount == null){ nLinkCount = 0; }
		if(sLinkVars == null){ sLinkVars = {}; }
		
		while(oSearch){
			if(oSearch.nodeType == 3){
				sValue = oSearch.nodeValue.replace("<", "&lt;");
				switch(sCase){
					case "lower":
						sContent += sValue.toLowerCase();
						break;
					case "upper":
						sContent += sValue.toUpperCase();
						break;
					default:
						sContent += sValue;
				};
			} else if(oSearch.nodeType == 1){
				if(matchNodeNames(oSearch, "a") && !oSearch.getAttribute("href") == false){
					if(oSearch.getAttribute("target")){
						sLinkVars["sifr_url_" + nLinkCount + "_target"] = oSearch.getAttribute("target");
					};
					sLinkVars["sifr_url_" + nLinkCount] = escape(oSearch.getAttribute("href"));
					sContent += '<a href="asfunction:_root.launchURL,' + nLinkCount + '">';
					nLinkCount++;
				} else if(matchNodeNames(oSearch, "br")){
					sContent += "<br/>";
				};
				if(oSearch.hasChildNodes()){
					/*	The childNodes are already copied with this node, so nodeNew = null */
					oResult = fetchContent(oSearch, null, sCase, nLinkCount, sLinkVars);
					sContent += oResult.sContent;
					nLinkCount = oResult.nLinkCount;
					sLinkVars = oResult.sLinkVars;
				};
				if(matchNodeNames(oSearch, "a")){
					sContent += "</a>";
				};
			};
			oRemove = oSearch;
			oSearch = oSearch.nextSibling;
			if(nodeNew != null){
				nodeRemoved = oRemove.parentNode.removeChild(oRemove);
				nodeNew.appendChild(nodeRemoved);	
			};
		};
		
		return {"sContent" : sContent, "nLinkCount" : nLinkCount, "sLinkVars" : sLinkVars};
	};

	function doReplace(fo, args) {
		var p = args.pNode;
		args.cancel = DOM.hasClass(p, 'sIFR-replaced');
		if (args.cancel) return false;
		var dim = DOM.getDim(p);
		args.attr.width = dim.width;
		args.attr.height = dim.height;
		fo.addVariable('w', dim.width);
		fo.addVariable('h', dim.height);
		
		var alt = DOM.create('div');
		DOM.addClass(alt, 'sIFR-alternate');
		var rs = fetchContent(p, alt, fo.flashvars.sCase);
		fo.addVariable('txt', escape(rs.sContent.normalize()));
		Object.extend(fo.flashvars, rs.sLinkVars);
		DOM.addClass(p,'sIFR-replaced');
		fo.altContent = alt;
	};

	return {
		replaceElement: function(sifr) { /* {sSelector, sFlashSrc, sColor, sLinkColor, sHoverColor, sBgColor, nPaddingTop, nPaddingRight, nPaddingBottom, nPaddingLeft, sFlashVars, sCase, sWmode} */
			if ( !Flash ) return;
			var swf = Flash.create({
				selector: sifr.sSelector,
				movie: sifr.sFlashSrc,
				ver: "6",
				flashvars: {
					textcolor: sifr.sColor,
					linkcolor: sifr.sLinkColor || sifr.sColor,
					hovercolor: sifr.sHoverColor || sifr.sColor,
					sBgColor: sifr.sBgColor || '',
					nPaddingTop: sifr.nPaddingTop || 0,
					nPaddingRight: sifr.nPaddingRight || 0,
					nPaddingBottom: sifr.nPaddingBottom || 0,
					nPaddingLeft: sifr.nPaddingLeft || 0,
					sCase: sifr.sCase || ''
				},
				wmode: sifr.sWmode
			});
			swf.onWriting.add(doReplace);
			swf.write();
			
		}
	};
})());
var TagWriter = function(tag, allowContent) {
	var tag = tag;
	var sb = [];
	var ac = allowContent === false ? false: true;
	var endTag = ac === false ? '' : '</'+tag+'>';
	var open = false;
	var str = '';
	return {
		open: function(t) {
			str = '';
			sb = [];
			sb.push('<'+tag);
			open = true;
			return this;
		},
		close: function() {
			if (open) {
				open = false;
				sb = [sb.join(' ')];
				if (!ac) { sb.push(' />'); }
				else {  sb.push('>'); }
			}
		},
		writeAttribute: function(attrs) {
			forEach(attrs,function(v,n){ sb.push(n+'="'+(v||n)+'"'); });
			return this;
		},
		
		write: function(str) {
			if (ac) {
				this.close();
				sb.push(str);
			}
			return this;
		},
		getHTML: function() {
			if (str) return str;
			this.close();
			sb.push(endTag);
			return (str = sb.join(''));
		}
	};
};
DOM.createHTML = function(tag, attr) {
	var noContent = /hr|br|param|input|img|base|link/i;
	var tw = new TagWriter(tag, !noContent.test(tag) );
	tw.open();
	if ( attr ) {
		var children = Object.remove(attr,'children');
		tw.writeAttribute(attr);
		if (typeof children =='string') children = [children];
		if ( children ) Array.from(children).forEach(function(c){
			if (typeof c == 'string'){ tw.write(c); }
			else if (c.nodeType==3) { tw.write(c.nodeValue); }
			else if (c.nodeType==1) { tw.write(c.innerHTML); }
			else { tw.write(c.tag, c.attr); }
		});
	}
	return tw.getHTML();
};
var Flash = Base.extend({
	constructor: function(swf, id, w, h, ver, c, xiPath) {
		this.id = id || 'swf';
		this.ver = typeof ver == 'string' ? ver.split('.') : [].concat(ver);
		this.attr = {
			width: (w || '0').toString(),
			height: (h || '0').toString()
		};
		this.params = {};
		this.flashvars = {};
		this.onWriting = new Observer;
		if ( BOM.is('ie') ){ this.addParam('movie', swf); }
		else { this.addAttribute('data', swf); }
		this.addParam('bgcolor',c);
		this.addParam('quality','high');
		return this;
	},
	addAttribute: function(att, val){
		this.attr[att] = val;
	},
	addParam: function(pname, val) {
		this.params[pname] = val;
	},
	addVariable: function(vname, val) {
		this.flashvars[vname] = val;
	},
	write: function(where) {
		if(where) this.domEl = where;
		Flash.writeSWF(this);
	},
	useExpressInstall: function(xiPath) {
		this.xi = xiPath;
		this.useXI = true;
	},
	setupXI: function() {
		if ( BOM.is('ie') ){ this.addParam('movie', this.xi); }
		else { this.addAttribute('data', this.xi); }
		this.id = Flash.XI.id;
		this.isXI = true;
		this.flashvars =  Flash.XI.flashvars;
		document.title = document.title.slice(0, 47) + " - Flash Player Installation";
		this.addVariable("MMdoctitle", document.title);
		if (this.attr.width.indexOf('%')<0){this.attr.width = Math.max(parseInt(this.attr.width,10), Flash.XI.width);}
		if (this.attr.height.indexOf('%')<0){this.attr.height = Math.max(parseInt(this.attr.height,10), Flash.XI.height);}
	}
},{ // Flash static methods.
	SWFs: [],
	wait: true,
	writeSWF: function(fo) {
		this.SWFs.push(fo);
		if ( !this.wait ){ this.writeAll(); }
	},
	
	writeAll: function() {
		this.SWFs.forEach(function(fo,idx) {
			if(fo.selector && DOM.match) {
				this.write(fo, DOM.match(fo.selector));
			}
			else if ( fo.domEl ) {
				this.write(fo, [DOM.get(fo.domEl)]);
			}
		},this);
	},
	
	create: function(o, nodes) {
		var nocopy = /movie|ver|width|height|id/i;
		var attrs  = /name|align|style/i;
		var params = /play|loop|menu|quality|scale|salign|wmode|bgcolor|base|devicefont|allowscriptaccess|seamlesstabbing|allowfullscreen|allownetworking|swliveconnect/i;
		var f = new Flash(o.movie, o.id, o.width, o.height, (o.ver));
		forEach(o, function(v,n){
			if (attrs.test(n)) { f.addAttribute(n, v); }
			else if(params.test(n)){ f.addParam(n, v); }
			else if(n=='flashvars'){
				forEach(v, function(fv, fn) { f.addVariable(fn, fv); });
			 }
			 else if (!nocopy.test(n)) {
				f[n] = v;
			 }
		});
		if (nodes) f.write(nodes);
		return f;
	},

	write: function(FO, nodes) {
		if ( nodes && !nodes.length ){ nodes = [].push(nodes); }
		if ( !nodes || !nodes[0] ) return;
		if ( !this.test(FO.ver) ) {
			if (FO.useXI && this.test(this.XI.ver) ) { FO.setupXI(); }
			else return;
		}
		var _ie = BOM.is('ie');
		var attr = Object.merge(this.defaultAttr, FO.attr);
		var _create = DOM.create;
		if ( this.PlayerInfo.axo === true||(BOM.is('opera')&&FO.FSCommand) ) {
			_create = DOM.createHTML;
		}

		$forEach(nodes, function(node,idx) {
			attr.id = FO.id + (nodes.length > 1 ? Aris.guid() : '');
			if ( FO.FSCommand ) {
				FO.addParam('swliveconnect','true');
				attr.name = attr.id;
				window[attr.id+'_DoFSCommand'] = FO.FSCommand;
			}
			var args = {pNode: node, attr: attr, cancel: false};
			FO.onWriting.fire(FO, args);
			if ( args.cancel === true ) return;
			attr.children = [];
			if ( FO.flashvars ){ FO.addParam('flashvars', Object.serialize(FO.flashvars,'=','&')); }
			forEach(FO.params, function(val, param){
				if ( val ) {attr.children.push(_create('param', {name: param, value: val }))};
			});
			if( FO.altContent ) {
				attr.children.push(FO.altContent);
			}
			var obj = _create('object', attr);
			DOM.clear(node);
			_create === DOM.createHTML ? node.innerHTML = obj : node.appendChild(obj);
		});
	},
	
	PlayerInfo: function() {
		var p = {};
		p.version = [0,0,0];
		p.axo = false;
		p.type = '';
		var axo = null;
		if(navigator.plugins && navigator.mimeTypes.length){
			var x = navigator.plugins["Shockwave Flash"];
			if(x && x.description) {
				p.version = x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".");
				p.type = 'PlugIn';
			}
		}else if (BOM.is('winCE')){ // if Windows CE
			p.axo = true;
			axo = 1;
			var counter = 3;
			while(axo) {
				try {
					counter++;
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
					p.version = [counter,0,0];
					p.mobile = true;
					p.type = 'ActiveX';
				} catch (e) {
					axo = null;
				}
			}
		} else { // Win IE (non mobile)
			// do minor version lookup in IE, but avoid fp6 crashing issues
			// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
			var badversion = false;
			try{
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			}catch(e){
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
					p.version = [6,0,21];
					axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
				} catch(e) {
					badversion = p.version[0] == 6; // cant use $version below!
				}
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				} catch(e) {}
			}
			if (axo !== null) {
				if (!badversion) p.version = axo.GetVariable("$version").split(" ")[1].split(",");
				p.type = 'ActiveX';
				p.axo = true;
			}
		}
		
		['major','minor','rev'].forEach( function(o,idx){
			p.version[idx] = p.version[o] = (p.version[idx] ? parseInt(p.version[idx],10) : 0);
		});
		return p;		
	}(),
	
	test: function(reqd) {
		reqd = (typeof reqd == 'string') ? reqd.split('.') : [].concat(reqd);
		if ( reqd.length < 3 ) { reqd[1] = reqd[1] || 0; reqd[2] = reqd[2] || 0; }
		var have = this.PlayerInfo.version;
		return reqd[0] < have[0] || (reqd[0] == have[0] && ( reqd[1] < have[1] || (reqd[1] == have[1]  && reqd[2] <= have[2]) ) );
	},
	init: function () {
		this.defaultAttr = { type: 'application/x-shockwave-flash'};
		if (this.PlayerInfo.axo===true) {
			this.defaultAttr.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
			this.defaultAttr.codebase = location.protocol||'http:'+ '//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab';
		}
		this.XI = {
			id: 'xiSWF',
			ver: [6,0,25],
			width: 215,
			height: 138,
			flashvars: {
				MMredirectURL: escape(location.href),
				MMpluginType: this.PlayerInfo.type
			}	
		};
		if (this.test(7)) { DOM.addClass(document.getElementsByTagName('html')[0],'hasFlash'); }
		if (BOM.is('ie')) { $AE.onPageUnloading.add(this.cleanupSWFs, this); }
	},
	cleanupSWFs: function() {
		$forEach(document.getElementsByTagName("OBJECT"), function(obj) {
			obj.style.display = 'none';
			for (var x in obj) {
				if (typeof obj[x] == 'function') {
					obj[x] = function(){};
				}
			}
		});
	}, 
	pageReady: function() {
		this.wait = false;
		this.writeAll();
	}
});
var FlashObject = Flash, SWFObject = Flash;
