var FLICKS_EVENT = null;
var FLICKS_EV = new Array();
var FLICKS_arg = {};
var FLICKS_orgH = {};
var FLICKS_ww = -1;
var FLICKS_wh = -1;
var FLICKS_fw = 0;

function FLICKS_UA()
{
	var b = navigator.userAgent.toLowerCase();

	this.webkit = b.indexOf("applewebkit") > -1;
	this.webkitV = (this.webkit && b.match(/.*applewebkit\/(\d+).*/))? (new Number(b.match(/.*applewebkit\/(\d+).*/)[1])) : 0.0;
	this.safari = b.indexOf("safari") > -1;
	this.konq = navigator.product && navigator.product.toLowerCase().indexOf("konqueror") > -1;
	this.opera = b.indexOf("opera") > -1;
	this.operaV = this.opera? (new Number(b.match(/.*opera(\s|\/)(\d+\.\d+)/)[2])) : 0.0;
	this.xml = document.contentType && document.contentType.indexOf("xml") > -1;
	this.khtml = this.webkit || this.konq;
	this.gecko = !this.webkit && navigator.product && navigator.product.toLowerCase() == "gecko";
	this.ie = b.indexOf("msie") > -1 && !this.opera && !this.khtml && !this.gecko;
	this.iemac = this.ie && b.match(/.*mac.*/);
	this.dom = !(this.ie || (this.opera && this.operaV < 7.6));
	this.ns = "http://www.w3.org/1999/xhtml";

	if (!this.iemac && !this.gecko && document.createElementNS)
	{
		try
		{
			document.createElementNS(this.ns, "i").innerHTML = "";
		}
		catch(e)
		{
			this.xml = true;
		}
	}
	
	this.ihack = this.konq || (this.webkit && this.webkitV < 312);
	this.bTitle = this.ie && window.location.hash != '';
	this.title = document.title;
}

function FLICKS_CE(ua, t)
{
	if (document.createElementNS && ua.dom)
		return document.createElementNS(ua.ns, t);	
	else
		return document.createElement(t);
}

function FLICKS_CP(ua, p, n, v)
{
	var c = FLICKS_CE(ua, "param");
	c.setAttribute("name", n);
	c.setAttribute("value", v);
	p.appendChild(c);
}

function FLICKS_GS(e,s)
{
	var s1 = s.split('-');

	for (var i=1; i<s1.length; i++)
	{
		s1[i] = s1[i].substr(0,1).toUpperCase() + s1[i].substr(1);
	}

	if (e.currentStyle)
	{
		return e.currentStyle[s1.join('')];
	}
	else
	if (window.getComputedStyle)
	{
		return document.defaultView.getComputedStyle(e, null).getPropertyValue(s);
	}

	return '';
}

function FLICKS_GP(e)
{
	var p = {};

	//var a = new Array('font-size', 'font-style', 'font-weight', 'color', 'text-align', 'text-decoration', 'padding-left', 'padding-right', 'padding-top', 'padding-bottom', 'border-left-width', 'border-right-width', 'border-top-width', 'border-bottom-width', 'border-left-color', 'border-right-color', 'border-top-color', 'border-bottom-color', 'float', 'cssFloat', 'styleFloat', 'clear', 'background-image', 'background-position', 'background-repeat', 'display', 'letter-spacing');
	var a = new Array('font-size', 'font-style', 'font-weight', 'color', 'text-align', 'text-decoration', 'letter-spacing');

	for (var i=0; i<a.length; i++)
	{
		p[a[i]] = FLICKS_GS(e, a[i]);
	}

	return p;
}

function FLICKS_TS(e, s)
{
	var ff = e.style[s];

	if (!ff)
	{
		var m = 0;

		for (var i=document.styleSheets.length-1; i>=0; i--)
		{
			var ss = document.styleSheets.item(i);

			var rules = (ss.rules? ss.rules : (ss.cssRules? ss.cssRules:null));

			for (var j=rules.length-1; j>=0; j--)
			{
				var ru = rules.item(j);

				if (ru.style[s])
				{
					var _m = FLICKS_CS(e, ru.selectorText);
					{
						if (_m > m)
						{
							m = _m;

							ff = ru.style[s];
						}
					}
				}
			}
		}
	}

	return ff;
}

function FLICKS_CSe(e, r)
{
	var t = e.nodeName.toLowerCase();
	var re = r[r.length - 1];

	var a = re.indexOf('>') > -1;
	re = re.replace('>', '');

	var m = 0;

	if (re == '*')
	{
		m = 1;
	}
	else
	if (re.indexOf('#') > -1)
	{
		var d = re.split('#');

		if (!d[0] || d[0].toLowerCase() == t)
		{
			if (!d[1])
			{
				m = 3;
			}
			else
			{
				m = (e.id.toLowerCase() == d[1].toLowerCase()? 7:0);
			}
		}
	}
	else
	{
		var d = re.split('.');

		if (!d[0] || d[0].toLowerCase() == t)
		{
			if (!d[1])
			{
				m = 3;
			}
			else
			{
				var c = e.className.split(' ');

				for (var i=0; i<c.length; i++)
				{
					if (c[i].toLowerCase() == d[1].toLowerCase())
					{
						m = 5;
					}
				}
			}
		}
	}

	if (m)
	{
		r.pop();

		if (!r.length)
			return m;
	}
	else
	if (a)
		return 0;

	if (t == 'body')
		return 0;

	return (FLICKS_CSe(e.parentNode, r)? (m+1):0);
}

function FLICKS_CS(e, s)
{
	var _s = s.split(',');

	var m = 0;

	for (var i=0; i<_s.length; i++)
	{
		var r = _s[i].replace(/^ +/, "").replace(/ +$/, "").replace(/>/g, ' > ').replace(/ +/g, ' ').replace(/ > /g, '> ').concat('>').split(' ');

		var _m = FLICKS_CSe(e, r);

		if (_m > m)
		{
			m = _m;
		}
	}

	return m;
}

function FLICKS_GF(e)
{
	var ff = FLICKS_TS(e, 'fontFamily');

	if (ff)
		return ff;

	var p = e.parentNode;

	if (p && e.nodeName.toLowerCase() != 'body')
		return FLICKS_GF(p);

	ff = FLICKS_GS(e, 'font-family');

	if (ff == 'serif')
		ff = 'Times New Roman';

	return ff;
}

function FLICKS_Bk(e)
{
	var bk = FLICKS_GS(e, 'background-color');

	if (bk != 'transparent' && bk != 'inherit')
	{
		var a = bk.match(/rgba? *\((.*)\) */);

		if (a)
		{
			var a1 = a[1].replace(/ /g, '').split(',');

			if (a1.length < 4 || a1[3] != 0)
			{
				var r = Number(a1[0] * 256 * 256 + a1[1] * 256 + Number(a1[2])).toString(16);

				while (r.length < 6)
					r = '0' + r;

				return "#" + r;
			}
		}
		else
		{
			//return bk.substr(1);

			return bk;
		}
	}

	var p = e.parentNode;

	if (p && e.nodeName.toLowerCase() != 'body')
		return FLICKS_Bk(p);

	return '#ffffff';
}

function FLICKS_iw(e)
{
	var r = e.offsetWidth - FLICKS_num(FLICKS_GS(e, 'padding-left').replace('px', '')) - FLICKS_num(FLICKS_GS(e, 'padding-right').replace('px', '')) - FLICKS_num(FLICKS_GS(e, 'border-left-width').replace('px', '')) - FLICKS_num(FLICKS_GS(e, 'border-right-width').replace('px', ''));

	return isNaN(r)? e.offsetWidth:r;
}

function FLICKS_ih(e)
{
	var r = e.offsetHeight - FLICKS_num(FLICKS_GS(e, 'padding-top').replace('px', '')) - FLICKS_num(FLICKS_GS(e, 'padding-bottom').replace('px', '')) - FLICKS_num(FLICKS_GS(e, 'border-top-width').replace('px', '')) - FLICKS_num(FLICKS_GS(e, 'border-bottom-width').replace('px', ''));

	return isNaN(r)? e.offsetHeight:r;
}

function FLICKS_enc(s)
{
	return escape(s).replace('+', '%2B').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}

function FLICKS_encH(s)
{
	return s.replace(/\&/g, '&amp;').replace(/\</g, '&lt;').replace(/\>/g, '&gt;').replace(/\"/g, '&quot;').replace(/\'/g, '&#39;')
}

function FLICKS_num(s)
{
	return (isNaN(s)? 0:Number(s));
}

function FLICKS_Se(e, TL)
{
	var t = e.nodeName.toLowerCase();
	var fa = (t == 'div' || t == 'span' || t == 'p' || t.match(/h[1-6]/) || t == 'img')? FLICKS_GF(e) : '';

	if (TL)
	{
		var p = FLICKS_GP(e);
		p['font-family'] = fa;
		p['line-height'] = FLICKS_TS(e, 'lineHeight');

		/*
		p['background-color'] = FLICKS_Bk(e);
		p['width'] = FLICKS_TS(e, 'width');
		p['height'] = FLICKS_TS(e, 'height');
		p['background-position'] = FLICKS_TS(e, 'backgroundPosition');
		p['background-repeat'] = FLICKS_TS(e, 'backgroundRepeat');
		p['position'] = FLICKS_TS(e, 'position');
		p['z-index'] = FLICKS_TS(e, 'zIndex');
		p['left'] = FLICKS_TS(e, 'left');
		p['top'] = FLICKS_TS(e, 'top');
		p['right'] = FLICKS_TS(e, 'right');
		p['bottom'] = FLICKS_TS(e, 'bottom');
		p['margin-left'] = FLICKS_TS(e, 'marginLeft');
		p['margin-right'] = FLICKS_TS(e, 'marginRight');
		p['margin-top'] = FLICKS_TS(e, 'marginTop');
		p['margin-bottom'] = FLICKS_TS(e, 'marginBottom');
		p['margin'] = FLICKS_TS(e, 'margin');
		p['visibility'] = FLICKS_TS(e, 'visibility');
		*/

		var p1 = new Array();

		for (var k in p)
		{
			p1.push(k + ":" + FLICKS_enc(p[k]));
		}

		e.setAttribute('flicks:css-style', p1.join(';'));
	}

	for (var i=0; i<e.childNodes.length; i++)
	{
		fa = fa.concat(',', FLICKS_Se(e.childNodes.item(i), 0));
	}

	return fa;
}

function FLICKS_AE(ua, e, id)
{
	var fa = FLICKS_Se(e, 1);

	var s1 = e.getAttribute('flicks:css-style');
	var s2 = e.getAttribute('flicks:style');
	var s3 = e.getAttribute('onload');
	var s4 = e.getAttribute('onclick');
	var ctt = '<' + e.nodeName + ' id="' + e.id + '" class="' + e.className + '" xmlns:flicks="http://www.fusionwebtechnologies.com/2010/flicks" flicks:css-style="'+ (s1? s1.replace(/\"/g, '&quot;'):'') + '" flicks:style="' + (s2? s2.replace(/\"/g, '&quot;'):'') + '" onload="' + (s3? s3:'') + '" onclick="' + (s4? s4:'') + '">' + e.innerHTML + '</' + e.nodeName + '>';

	var _id = "FLICKS" + id;
	var bk = FLICKS_Bk(e);

	var ss = '';
	var st = document.getElementsByTagName('style');

	for (var i=0; i<st.length; i++)
	{
		ss += st.item(i).innerHTML;
	}

	var lk = '';
	var lt = document.getElementsByTagName('link');

	for (i=0; i<lt.length; i++)
	{
		var li = lt.item(i);

		if (li.rel == 'stylesheet')
			lk += (lk? '|':'') + li.getAttribute('href');
			//lk += (lk? '|':'') + li.href;
	}

	var dir = (typeof FLICKS_DIR != 'undefined') && FLICKS_DIR.length > 0? (FLICKS_DIR + '/') : '';

	FLICKS_orgH[_id] = e.innerHTML;

	var w = FLICKS_iw(e);
	var h = FLICKS_ih(e);

	e.innerHTML = "";

	if (FLICKS_fw)
	{
		var r = FLICKS_sz2();
		w = r.ww;
		h = r.wh;
	}

	FLICKS_arg[_id] = 'ctt=' + FLICKS_enc(ctt) + '&w=' + w + '&h=' + h + '&bk=' + FLICKS_enc(bk) + '&d=' + FLICKS_enc(dir) + '&fa=' + FLICKS_enc(fa) + '&ss=' + FLICKS_enc(ss) + '&lk=' + FLICKS_enc(lk) + '&fw=' + FLICKS_fw;

	if (ua.dom)
	{
		var c;

		if (ua.opera)
		{
			c = FLICKS_CE(ua, "object");
			c.setAttribute("data", dir + "Flicks.swf");
			FLICKS_CP(ua, c, "quality", "best");
			FLICKS_CP(ua, c, "bgcolor", bk);
		}
		else
		{
			c = FLICKS_CE(ua, "embed");
			c.setAttribute("src", dir + "Flicks.swf");
			c.setAttribute("quality", "best");
			c.setAttribute("bgcolor", bk);
			c.setAttribute("pluginspace", "http://www.macromedia.com/go/getflashplayer");
			c.setAttribute("scale", "noscale");
		}

		c.setAttribute("id", _id);
		c.setAttribute("name", _id);
		c.setAttribute("type", "application/x-shockwave-flash");
		c.setAttribute("width", w);
		c.setAttribute("height", h);
		c.style.width = w + "px";
		c.style.height = h + "px";

		//e.innerHTML = "";
		e.appendChild(c);

		c = FLICKS_CE(ua, "form");
		c.setAttribute("id", "FLICKSFORM" + id);
		e.appendChild(c);

		c = FLICKS_CE(ua, 'div');
		c.setAttribute('id', 'FLICKS_CONTENT_NODE');
		c.setAttribute('style', 'display: none;');
		e.appendChild(c);
	}
	else
	{
		if (ua.ie)
		{
			e.innerHTML = ['<object id="', _id, '" name="', _id, '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="', w, '" height="', h, '">',
								'<param name="movie" value="', dir, 'Flicks.swf"></param>',
								'<param name="quality" value="best"></param>',
								'<param name="bgcolor" value="', bk, '"></param>',
							  '</object>'].join('');
		}
		else
		{
			e.innerHTML = ['<embed id="', _id, '" name="', _id, '" type="application/x-shockwave-flash" src="', dir, 'Flicks.swf" quality="best" bgcolor="', bk, '" width="', w, '" height="', h, '"></embed>'].join("");
		}

		e.innerHTML += "<form id='FLICKSFORM" + id + "' style='display:none'></form><div id='FLICKS_CONTENT_NODE' style='display:none'></div>";
	}

	if (ua.ihack)
	{
		e.innerHTML += "";
	}
}

function FLICKS_ar(id, a)
{
	return FLICKS_arg[id];
}

function FLICKS_h(id, h)
{
	var o = document.getElementById(id);
	o.height = Number(h);
	o.style.height = h + "px";
	o.parentNode.height = Number(h);
	o.parentNode.style.height = h + "px";
}

function FLICKS_ld(id)
{
	if (window.parent && window.parent.editor)
	{
		var e = window.parent.editor;

		if (typeof e.onFlicksLoaded == "function")
		{
			e.onFlicksLoaded();
		}
	}
}

function FLICKS_fal(id)
{
	setTimeout("FLICKS_faL('" + id + "');", 1);
}

function FLICKS_faL(id)
{
	document.getElementById(id).parentNode.innerHTML = FLICKS_orgH[id];
}

function FLICKS_CSf(id, r)
{
	return FLICKS_CSe(document.getElementById(id).parentNode.parentNode, r);
}

function FLICKS_sz2()
{
	var r = new Object();

	r.ww = Number(window.innerWidth);
	r.wh = Number(window.innerHeight);

	if (isNaN(r.ww))
	{
		var de = document.documentElement;

		if (de)
		{
			r.ww = Number(de.clientWidth);
			r.wh = Number(de.clientHeight);
		}

		if (isNaN(r.ww) || r.ww == 0 && r.wh == 0)
		{
			r.ww = Number(document.body.clientWidth);
			r.wh = Number(document.body.clientHeight);
		}
	}

	return r;
}

function FLICKS_sz()
{
	var r = FLICKS_sz2();

	if (r.ww != FLICKS_ww || r.wh != FLICKS_wh)
	{
		for (var id in FLICKS_arg)
		{
			var o = document.getElementById(id);

			if (o)
			{
				var p = o.parentNode;

				if (FLICKS_fw)
				{
					p.width = r.ww;
					p.style.width = String(r.ww) + "px";
				}

				o.width = 5;
				o.style.width = "5px";

				var w = FLICKS_fw? r.ww : FLICKS_iw(p);
				o.width = Number(w>5?w:5);
				o.style.width = String(w>5?w:5) + "px";

				if (typeof o.onsize == "function")
				{
					o.onsize(w);
				}
			}
		}

		FLICKS_ww = r.ww;
		FLICKS_wh = r.wh;
	}
}

function FLICKS_gwh()
{
	return FLICKS_sz2().wh;
}

function FLICKS_pg(objID)
{
	return (typeof FLICKS_PLUGINS != 'undefined'? FLICKS_PLUGINS:null);
}

function FLICKS_ev(fid, c, id)
{
	var e = new Object();
	e.flicksObject = document.getElementById(fid);
	e.id = id;
	e.code = c;
	FLICKS_EV.push(e);
	setTimeout("FLICKS_eV();", 0);
}

function FLICKS_eV()
{
	FLICKS_EVENT = FLICKS_EV.shift();
	eval(FLICKS_EVENT.code);
}

function FLICKS_fc(id)
{
	document.getElementById(id).focus();
}

function FLICKS_cf(id, a, m)
{
	var f = document.getElementById("FLICKSFORM" + id.replace('FLICKS', ''));
	f.innerHTML = '';
	f.action = a;
	f.method = m;
}

function FLICKS_pf(id, n, v)
{
	var ua = new FLICKS_UA();
	var f = document.getElementById("FLICKSFORM" + id.replace('FLICKS', ''));

	if (ua.dom)
	{
		c = FLICKS_CE(ua, "input");
		c.setAttribute('type', 'hidden');
		c.setAttribute('name', n);
		c.setAttribute('value', v);
		f.appendChild(c);
	}
	else
	{
		f.innerHTML += "<input type='hidden' name='" + FLICKS_encH(n) + "' value='" + FLICKS_encH(v) + "' />";
	}
}

function FLICKS_sf(id)
{
	document.getElementById("FLICKSFORM" + id.replace('FLICKS', '')).submit();
}

function FLICKS_os(r, id)
{
	if (window.parent && window.parent.editor)
	{
		var e = window.parent.editor;

		if (typeof e.onFlicksOS == "function")
		{
			e.onFlicksOS(r, id);
		}
	}
}

function FLICKS_FULL_WINDOW(css)
{
	FLICKS_fw = 1;
	FLICKS(css);
}

function FLICKS_LONG_PAGE(css)
{
	FLICKS_fw = 2;
	FLICKS(css);
}

function FLICKS(css)
{
	if (typeof(css) == 'undefined')
		css = '.FLICKS';

	//try
	//{
		var f = true;

		if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") > -1)
		{
			try
			{
				var o = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			}
			catch (e)
			{
				f = false;
			}
		}
		else
		if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
		{
			var b = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;

			f = (parseInt(b.substr(b.indexOf(".") - 2, 2), 10) >= 6);
		}
		else
		{
			f = false;
		}

		//if(!f)
		//	return;

		var ua = new FLICKS_UA();

		if (!document.createElement || !document.getElementById || (ua.xml && (ua.ihack || ua.ie)))
			return;

		FLICKS_sz();
		setInterval("FLICKS_sz()", 100);

		var a = new Array('div','h1','h2','h3','h4','h5','h6');

		var id = 0;

		for(var i=0; i<a.length; i++)
		{
			var es = document.getElementsByTagName(a[i]);

			for (var j=0; j<es.length; j++)
			{
				var e = es.item(j);

				if (FLICKS_CS(e, css))
				{
					e.style.visibility = 'visible';

					if (f)
						FLICKS_AE(ua, e, id++);

					if (FLICKS_fw)
					{
						e.style.position = 'fixed';
						e.style.left = '0px';
						e.style.top = '0px';
					}
				}
			}
		}

		if (ua.ie && ua.bTitle)
		{
			setTimeout(function(){document.title = ua.title}, 0);
		}

	//}
	//catch(e)
	//{
	//}
}

