


/******************************************************************************************
         swfobject2.js
 ******************************************************************************************/

/* SWFObject v2.1 <http://code.google.com/p/swfobject/>
	Copyright (c) 2007-2008 Geoff Stearns, Michael Williams, and Bobby van der Sluis
	This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
var swfobject=function(){var b="undefined",Q="object",n="Shockwave Flash",p="ShockwaveFlash.ShockwaveFlash",P="application/x-shockwave-flash",m="SWFObjectExprInst",j=window,K=document,T=navigator,o=[],N=[],i=[],d=[],J,Z=null,M=null,l=null,e=false,A=false;var h=function(){var v=typeof K.getElementById!=b&&typeof K.getElementsByTagName!=b&&typeof K.createElement!=b,AC=[0,0,0],x=null;if(typeof T.plugins!=b&&typeof T.plugins[n]==Q){x=T.plugins[n].description;if(x&&!(typeof T.mimeTypes!=b&&T.mimeTypes[P]&&!T.mimeTypes[P].enabledPlugin)){x=x.replace(/^.*\s+(\S+\s+\S+$)/,"$1");AC[0]=parseInt(x.replace(/^(.*)\..*$/,"$1"),10);AC[1]=parseInt(x.replace(/^.*\.(.*)\s.*$/,"$1"),10);AC[2]=/r/.test(x)?parseInt(x.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof j.ActiveXObject!=b){var y=null,AB=false;try{y=new ActiveXObject(p+".7")}catch(t){try{y=new ActiveXObject(p+".6");AC=[6,0,21];y.AllowScriptAccess="always"}catch(t){if(AC[0]==6){AB=true}}if(!AB){try{y=new ActiveXObject(p)}catch(t){}}}if(!AB&&y){try{x=y.GetVariable("$version");if(x){x=x.split(" ")[1].split(",");AC=[parseInt(x[0],10),parseInt(x[1],10),parseInt(x[2],10)]}}catch(t){}}}}var AD=T.userAgent.toLowerCase(),r=T.platform.toLowerCase(),AA=/webkit/.test(AD)?parseFloat(AD.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,q=false,z=r?/win/.test(r):/win/.test(AD),w=r?/mac/.test(r):/mac/.test(AD);/*@cc_on q=true;@if(@_win32)z=true;@elif(@_mac)w=true;@end@*/return{w3cdom:v,pv:AC,webkit:AA,ie:q,win:z,mac:w}}();var L=function(){if(!h.w3cdom){return }f(H);if(h.ie&&h.win){try{K.write("<script id=__ie_ondomload defer=true src=//:><\/script>");J=C("__ie_ondomload");if(J){I(J,"onreadystatechange",S)}}catch(q){}}if(h.webkit&&typeof K.readyState!=b){Z=setInterval(function(){if(/loaded|complete/.test(K.readyState)){E()}},10)}if(typeof K.addEventListener!=b){K.addEventListener("DOMContentLoaded",E,null)}R(E)}();function S(){if(J.readyState=="complete"){J.parentNode.removeChild(J);E()}}function E(){if(e){return }if(h.ie&&h.win){var v=a("span");try{var u=K.getElementsByTagName("body")[0].appendChild(v);u.parentNode.removeChild(u)}catch(w){return }}e=true;if(Z){clearInterval(Z);Z=null}var q=o.length;for(var r=0;r<q;r++){o[r]()}}function f(q){if(e){q()}else{o[o.length]=q}}function R(r){if(typeof j.addEventListener!=b){j.addEventListener("load",r,false)}else{if(typeof K.addEventListener!=b){K.addEventListener("load",r,false)}else{if(typeof j.attachEvent!=b){I(j,"onload",r)}else{if(typeof j.onload=="function"){var q=j.onload;j.onload=function(){q();r()}}else{j.onload=r}}}}}function H(){var t=N.length;for(var q=0;q<t;q++){var u=N[q].id;if(h.pv[0]>0){var r=C(u);if(r){N[q].width=r.getAttribute("width")?r.getAttribute("width"):"0";N[q].height=r.getAttribute("height")?r.getAttribute("height"):"0";if(c(N[q].swfVersion)){if(h.webkit&&h.webkit<312){Y(r)}W(u,true)}else{if(N[q].expressInstall&&!A&&c("6.0.65")&&(h.win||h.mac)){k(N[q])}else{O(r)}}}}else{W(u,true)}}}function Y(t){var q=t.getElementsByTagName(Q)[0];if(q){var w=a("embed"),y=q.attributes;if(y){var v=y.length;for(var u=0;u<v;u++){if(y[u].nodeName=="DATA"){w.setAttribute("src",y[u].nodeValue)}else{w.setAttribute(y[u].nodeName,y[u].nodeValue)}}}var x=q.childNodes;if(x){var z=x.length;for(var r=0;r<z;r++){if(x[r].nodeType==1&&x[r].nodeName=="PARAM"){w.setAttribute(x[r].getAttribute("name"),x[r].getAttribute("value"))}}}t.parentNode.replaceChild(w,t)}}function k(w){A=true;var u=C(w.id);if(u){if(w.altContentId){var y=C(w.altContentId);if(y){M=y;l=w.altContentId}}else{M=G(u)}if(!(/%$/.test(w.width))&&parseInt(w.width,10)<310){w.width="310"}if(!(/%$/.test(w.height))&&parseInt(w.height,10)<137){w.height="137"}K.title=K.title.slice(0,47)+" - Flash Player Installation";var z=h.ie&&h.win?"ActiveX":"PlugIn",q=K.title,r="MMredirectURL="+j.location+"&MMplayerType="+z+"&MMdoctitle="+q,x=w.id;if(h.ie&&h.win&&u.readyState!=4){var t=a("div");x+="SWFObjectNew";t.setAttribute("id",x);u.parentNode.insertBefore(t,u);u.style.display="none";var v=function(){u.parentNode.removeChild(u)};I(j,"onload",v)}U({data:w.expressInstall,id:m,width:w.width,height:w.height},{flashvars:r},x)}}function O(t){if(h.ie&&h.win&&t.readyState!=4){var r=a("div");t.parentNode.insertBefore(r,t);r.parentNode.replaceChild(G(t),r);t.style.display="none";var q=function(){t.parentNode.removeChild(t)};I(j,"onload",q)}else{t.parentNode.replaceChild(G(t),t)}}function G(v){var u=a("div");if(h.win&&h.ie){u.innerHTML=v.innerHTML}else{var r=v.getElementsByTagName(Q)[0];if(r){var w=r.childNodes;if(w){var q=w.length;for(var t=0;t<q;t++){if(!(w[t].nodeType==1&&w[t].nodeName=="PARAM")&&!(w[t].nodeType==8)){u.appendChild(w[t].cloneNode(true))}}}}}return u}function U(AG,AE,t){var q,v=C(t);if(v){if(typeof AG.id==b){AG.id=t}if(h.ie&&h.win){var AF="";for(var AB in AG){if(AG[AB]!=Object.prototype[AB]){if(AB.toLowerCase()=="data"){AE.movie=AG[AB]}else{if(AB.toLowerCase()=="styleclass"){AF+=' class="'+AG[AB]+'"'}else{if(AB.toLowerCase()!="classid"){AF+=" "+AB+'="'+AG[AB]+'"'}}}}}var AD="";for(var AA in AE){if(AE[AA]!=Object.prototype[AA]){AD+='<param name="'+AA+'" value="'+AE[AA]+'" />'}}v.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AF+">"+AD+"</object>";i[i.length]=AG.id;q=C(AG.id)}else{if(h.webkit&&h.webkit<312){var AC=a("embed");AC.setAttribute("type",P);for(var z in AG){if(AG[z]!=Object.prototype[z]){if(z.toLowerCase()=="data"){AC.setAttribute("src",AG[z])}else{if(z.toLowerCase()=="styleclass"){AC.setAttribute("class",AG[z])}else{if(z.toLowerCase()!="classid"){AC.setAttribute(z,AG[z])}}}}}for(var y in AE){if(AE[y]!=Object.prototype[y]){if(y.toLowerCase()!="movie"){AC.setAttribute(y,AE[y])}}}v.parentNode.replaceChild(AC,v);q=AC}else{var u=a(Q);u.setAttribute("type",P);for(var x in AG){if(AG[x]!=Object.prototype[x]){if(x.toLowerCase()=="styleclass"){u.setAttribute("class",AG[x])}else{if(x.toLowerCase()!="classid"){u.setAttribute(x,AG[x])}}}}for(var w in AE){if(AE[w]!=Object.prototype[w]&&w.toLowerCase()!="movie"){F(u,w,AE[w])}}v.parentNode.replaceChild(u,v);q=u}}}return q}function F(t,q,r){var u=a("param");u.setAttribute("name",q);u.setAttribute("value",r);t.appendChild(u)}function X(r){var q=C(r);if(q&&(q.nodeName=="OBJECT"||q.nodeName=="EMBED")){if(h.ie&&h.win){if(q.readyState==4){B(r)}else{j.attachEvent("onload",function(){B(r)})}}else{q.parentNode.removeChild(q)}}}function B(t){var r=C(t);if(r){for(var q in r){if(typeof r[q]=="function"){r[q]=null}}r.parentNode.removeChild(r)}}function C(t){var q=null;try{q=K.getElementById(t)}catch(r){}return q}function a(q){return K.createElement(q)}function I(t,q,r){t.attachEvent(q,r);d[d.length]=[t,q,r]}function c(t){var r=h.pv,q=t.split(".");q[0]=parseInt(q[0],10);q[1]=parseInt(q[1],10)||0;q[2]=parseInt(q[2],10)||0;return(r[0]>q[0]||(r[0]==q[0]&&r[1]>q[1])||(r[0]==q[0]&&r[1]==q[1]&&r[2]>=q[2]))?true:false}function V(v,r){if(h.ie&&h.mac){return }var u=K.getElementsByTagName("head")[0],t=a("style");t.setAttribute("type","text/css");t.setAttribute("media","screen");if(!(h.ie&&h.win)&&typeof K.createTextNode!=b){t.appendChild(K.createTextNode(v+" {"+r+"}"))}u.appendChild(t);if(h.ie&&h.win&&typeof K.styleSheets!=b&&K.styleSheets.length>0){var q=K.styleSheets[K.styleSheets.length-1];if(typeof q.addRule==Q){q.addRule(v,r)}}}function W(t,q){var r=q?"visible":"hidden";if(e&&C(t)){C(t).style.visibility=r}else{V("#"+t,"visibility:"+r)}}function g(s){var r=/[\\\"<>\.;]/;var q=r.exec(s)!=null;return q?encodeURIComponent(s):s}var D=function(){if(h.ie&&h.win){window.attachEvent("onunload",function(){var w=d.length;for(var v=0;v<w;v++){d[v][0].detachEvent(d[v][1],d[v][2])}var t=i.length;for(var u=0;u<t;u++){X(i[u])}for(var r in h){h[r]=null}h=null;for(var q in swfobject){swfobject[q]=null}swfobject=null})}}();return{registerObject:function(u,q,t){if(!h.w3cdom||!u||!q){return }var r={};r.id=u;r.swfVersion=q;r.expressInstall=t?t:false;N[N.length]=r;W(u,false)},getObjectById:function(v){var q=null;if(h.w3cdom){var t=C(v);if(t){var u=t.getElementsByTagName(Q)[0];if(!u||(u&&typeof t.SetVariable!=b)){q=t}else{if(typeof u.SetVariable!=b){q=u}}}}return q},embedSWF:function(x,AE,AB,AD,q,w,r,z,AC){if(!h.w3cdom||!x||!AE||!AB||!AD||!q){return }AB+="";AD+="";if(c(q)){W(AE,false);var AA={};if(AC&&typeof AC===Q){for(var v in AC){if(AC[v]!=Object.prototype[v]){AA[v]=AC[v]}}}AA.data=x;AA.width=AB;AA.height=AD;var y={};if(z&&typeof z===Q){for(var u in z){if(z[u]!=Object.prototype[u]){y[u]=z[u]}}}if(r&&typeof r===Q){for(var t in r){if(r[t]!=Object.prototype[t]){if(typeof y.flashvars!=b){y.flashvars+="&"+t+"="+r[t]}else{y.flashvars=t+"="+r[t]}}}}f(function(){U(AA,y,AE);if(AA.id==AE){W(AE,true)}})}else{if(w&&!A&&c("6.0.65")&&(h.win||h.mac)){A=true;W(AE,false);f(function(){var AF={};AF.id=AF.altContentId=AE;AF.width=AB;AF.height=AD;AF.expressInstall=w;k(AF)})}}},getFlashPlayerVersion:function(){return{major:h.pv[0],minor:h.pv[1],release:h.pv[2]}},hasFlashPlayerVersion:c,createSWF:function(t,r,q){if(h.w3cdom){return U(t,r,q)}else{return undefined}},removeSWF:function(q){if(h.w3cdom){X(q)}},createCSS:function(r,q){if(h.w3cdom){V(r,q)}},addDomLoadEvent:f,addLoadEvent:R,getQueryParamValue:function(v){var u=K.location.search||K.location.hash;if(v==null){return g(u)}if(u){var t=u.substring(1).split("&");for(var r=0;r<t.length;r++){if(t[r].substring(0,t[r].indexOf("="))==v){return g(t[r].substring((t[r].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(A&&M){var q=C(m);if(q){q.parentNode.replaceChild(M,q);if(l){W(l,true);if(h.ie&&h.win){M.style.display="block"}}M=null;l=null;A=false}}}}}();


/******************************************************************************************
         swfaddress.js
 ******************************************************************************************/

/**
 * SWFAddress 2.1: Deep linking for Flash and Ajax - http://www.asual.com/swfaddress/
 *
 * SWFAddress is (c) 2006-2007 Rostislav Hristov and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * This file has been modified by vyew in various places. Search for "vyew" to find where...
 */

if (typeof com == "undefined") var com = {};
if (typeof com.asual == "undefined") com.asual = {};
if (typeof com.asual.util == "undefined") com.asual.util = {};
   
/**
 * @class Utility class that provides detailed browser information.
 * @static
 * @ignore
 */
com.asual.util.Browser = new function() {

    var _version = -1;
    var _agent = navigator.userAgent;
    var _ie = false, _camino = false, _safari = false, _opera = false, 
        _firefox = false, _netscape = false, _mozilla = false;

    var _getVersion = function(s, i) {
        return parseFloat(_agent.substr(_agent.indexOf(s) + i));
    }
    
    if (_ie = /MSIE/.test(_agent))
        _version = _getVersion('MSIE', 4);
        
    if (_safari = /AppleWebKit/.test(_agent))
        _version = _getVersion('Safari', 7);
        
    if (_opera = /Opera/.test(_agent))
        _version = parseFloat(navigator.appVersion);
        
    if (_camino = /Camino/.test(_agent))
        _version = _getVersion('Camino', 7);
        
    if (_firefox = /Firefox/.test(_agent))
        _version = _getVersion('Firefox', 8);
        
    if (_netscape = /Netscape/.test(_agent))
        _version = _getVersion('Netscape', 9);
        
    if (_mozilla = /Mozilla/.test(_agent) && /rv:/.test(_agent))
        _version = _getVersion('rv:', 3);


    /**
     * Detects the version of the browser.
     * @return {Number}
     * @static
     */
    this.getVersion = function() {
        return _version;
    }

    /**
     * Detects if the browser is Internet Explorer.
     * @return {Boolean}
     * @static
     */
    this.isIE = function() {
        return _ie;
    }

    /**
     * Detects if the browser is Safari.
     * @return {Boolean}
     * @static
     */
    this.isSafari = function() {
        return _safari;
    }

    /**
     * Detects if the browser is Opera.
     * @return {Boolean}
     * @static
     */
    this.isOpera = function() {
        return _opera;
    }

    /**
     * Detects if the browser is Camino.
     * @return {Boolean}
     * @static
     */
    this.isCamino = function() {
        return _camino;
    }

    /**
     * Detects if the browser is Firefox.
     * @return {Boolean}
     * @static
     */
    this.isFirefox = function() {
        return _firefox;
    }

    /**
     * Detects if the browser is Netscape.
     * @return {Boolean}
     * @static
     */
    this.isNetscape = function() {
        return _netscape;
    }
        
    /**
     * Detects if the browser is Mozilla.
     * @return {Boolean}
     * @static
     */
    this.isMozilla = function() {
        return _mozilla;
    }
}

/**
 * @class Utility class that provides event helpers.
 * @static
 * @ignore
 */
com.asual.util.Events = new function() {

    var _cache = [];
    var _browser = com.asual.util.Browser;
    var _dcl = 'DOMContentLoaded';

    if (_browser.isIE() || _browser.isSafari()) {
        (function (){
            try {
                if (_browser.isIE() || !/loaded|complete/.test(document.readyState))
                    document.documentElement.doScroll('left');
            } catch(e) {
                return setTimeout(arguments.callee, 0);
            }
            for (var i = 0, e; e = _cache[i]; i++)
                if (e.t == _dcl) e.l.call(null);
        })();
    }

    /**
     * Adds an event listener to an object.
     * @param {Object} obj The object that provides events.
     * @param {String} type The type of the event.
     * @param {Function} listener The event listener function.
     * @return {void}
     * @static
     */
    this.addListener = function(obj, type, listener) {
        _cache.push({o: obj, t: type, l: listener});
        if (!(type == _dcl && (_browser.isIE() || _browser.isSafari()))) {
            if (obj.addEventListener)
                obj.addEventListener(type, listener, false);
            else if (obj.attachEvent)
                obj.attachEvent('on' + type, listener);
        }
    }

    /**
     * Removes an event listener from an object.
     * @param {Object} obj The object that provides events.
     * @param {String} type The type of the event.
     * @param {Function} listener The event listener function.
     * @return {void}     
     * @static
     */
    this.removeListener = function(obj, type, listener) {
        for (var i = 0, e; e = _cache[i]; i++) {
            if (e.o == obj && e.t == type && e.l == listener) {
                _cache.splice(i, 1);
                break;
            }
        }
        if (!(type == _dcl && (_browser.isIE() || _browser.isSafari()))) {
            if (obj.removeEventListener)
                obj.removeEventListener(type, listener, false);
            else if (obj.detachEvent)
                obj.detachEvent('on' + type, listener);
        }
    }

    var _unload = function() {
        for (var i = 0, evt; evt = _cache[i]; i++) {
            if (evt.t != _dcl)
                com.asual.util.Events.removeListener(evt.o, evt.t, evt.l);
        }
    }

    this.addListener(window, 'unload', _unload);
}

/**
 * Creates a new SWFAddress event.
 * @class Event class for SWFAddress.
 * @param {String} type Type of the event.
 */
SWFAddressEvent = function(type) {
    
    /**
     * String representation of this object.
     * @ignore
     */
    this.toString = function() {
        return '[object SWFAddressEvent]';
    }

    /**
     * The type of this event.
     * @type String
     */
    this.type = type;

    /**
     * The target of this event.
     * @type Function
     */
    this.target = [SWFAddress][0];

    /**
     * The value of this event.
     * @type String
     */
    this.value = SWFAddress.getValue();

    /**
     * The path of this event.
     * @type String
     */
    this.path = SWFAddress.getPath();
    
    /**
     * The folders in the deep linking path of this event.
     * @type Array
     */
    this.pathNames = SWFAddress.getPathNames();

    /**
     * The parameters of this event.
     * @type Object
     */
    this.parameters = {};

    var _parametersNames = SWFAddress.getParameterNames();
    for (var i = 0, l = _parametersNames.length; i < l; i++)
        this.parameters[_parametersNames[i]] = SWFAddress.getParameter(_parametersNames[i]);
    
    /**
     * The parameters names of this event.
     * @type Array     
     */
     this.parametersNames = _parametersNames;
}

/**
 * Init event.
 * @type String
 * @memberOf SWFAddressEvent
 * @static
 */
SWFAddressEvent.INIT = 'init';

/**
 * Change event.
 * @type String
 * @memberOf SWFAddressEvent
 * @static 
 */
SWFAddressEvent.CHANGE = 'change';

/**
 * @class The SWFAddress class can be configured with query parameters using the following format:
 * swfaddress.js?html=false&history=1&tracker=pageTracker._trackPageview&strict=1.<br /> 
 * The list of supported options include:<br /><br />
 * <code>history:Boolean</code> - Enables or disables the creation of history entries.<br />
 * <code>html:Boolean</code> - Enables or disables the usage of swfaddress.html.<br />
 * <code>strict:Boolean</code> - Enables or disables the strict mode.<br />
 * <code>tracker:String</code> - Sets a function for page view tracking.<br />
 * @static 
 */ 
SWFAddress = new function() {

    var _browser = com.asual.util.Browser;
    var _events = com.asual.util.Events;
    var _version = _browser.getVersion();
    var _supported = false;

    if (_browser.isIE()) 
        _supported = _version >= 6;
        
    if (_browser.isSafari())
        _supported = _version >= 312;
        
    if (_browser.isOpera())
        _supported = _version >= 9.02;
        
    if (_browser.isCamino()) 
        _supported = _version >= 1;
        
    if (_browser.isFirefox())
        _supported = _version >= 1;
        
    if (_browser.isNetscape())
        _supported = _version >= 8;
        
    if (_browser.isMozilla())
        _supported = _version >= 1.8;
	
	//--- Added by vyew - try/catch statement
	//--- this was breaking iframe load accross domains
	try {
		var __test=top.document.title
    	var _t = top;
	}catch(e){ 
		var _t=window; 
	}
    var _d = _t.document;
    var _h = _t.history;
    var _l = _t.location;
    var _st = setTimeout;
    
    var FUNCTION = 'function';
    var UNDEFINED = 'undefined';
    var SWFADDRESS = 'swfaddress';

    var _iframe, _form, _url;
    var _title = _d.title;
    var _length = _h.length;
    var _silent = false;
    var _listeners = {};
    var _stack = [];
    var _ids = [];
    
    var _opts = {};
    _opts.history = true;
    _opts.html = false;
    _opts.strict = true;
    _opts.tracker = '_trackDefault';
    
    /*// commented out by vyew
      if ((!_supported && _l.href.indexOf('#') != -1) || 
        (_browser.isSafari() && _version < 412 && _l.href.indexOf('#') != -1 && _l.search != '')){
        _d.open();
        _d.write('<html><head><meta http-equiv="refresh" content="0;url=' + 
            _l.href.substr(0, _l.href.indexOf('#')) + '" /></head></html>');
        _d.close();
    }*/

    var _getHash = function() {
        var index = _l.href.indexOf('#');
        if (index != -1) {
            var hash = unescape(_l.href.substr(index + 1));
// 3 lines commented by vyew
//            if (/^[a-z0-9 ,=_&\-\.\?\+\/]*$/i.test(hash))
                return hash;
//            else
//                _l.replace(_l.href.substr(0, index));
        }
        return '';
    }

    var _value = _getHash();

    var _strictCheck = function(value, force) {
        if (_opts.strict)
            value = force ? (value.substr(0, 1) != '/' ? '/' + value : value) : (value == '' ? '/' : value);
        return value;
    }

    var _ieLocal = function(value) {
        return (_browser.isIE() && _l.protocol == 'file:') ? _value.replace(/\?/, '%3F') : value;    
    }

    var _searchScript = function(el) {
        if (el.src && /swfaddress\.js(\?.*)?$/.test(el.src)) return el;
        for (var i = 0, l = el.childNodes.length, s; i < l; i++)
            if (s = _searchScript(el.childNodes[i])) return s;
    }
    
    var _titleCheck = function() {
        if (_browser.isIE() && _d.title != _title)
            SWFAddress.setTitle(_title);
    }

    var _listen = function() {
        if (!_silent) {
            var hash = _getHash();
            if (_browser.isIE()) {
                if (_value != hash) {
					//alert("_listen: \nold:"+_value+"\nnew:"+hash);
                    if (_version < 7)
                        _l.reload();
                    else
                        SWFAddress.setValue(hash);
                }
            } else if (_browser.isSafari() && _version < 523) {
                if (_length != _h.length) {
                    _length = _h.length;
                    if (typeof _stack[_length - 1] != UNDEFINED)
                        _value = _stack[_length - 1];
                    _update();
                }
            } else if (_value != hash) {
				//alert("_listen: \nold:"+_value+"\nnew:"+hash);
                _value = hash;
                _update();
            }
            _titleCheck();
        }
    }

    var _jsDispatch = function(type) {
        if (SWFAddress.hasEventListener(type))
            SWFAddress.dispatchEvent(new SWFAddressEvent(type));
        type = type.substr(0, 1).toUpperCase() + type.substr(1);
        if(typeof SWFAddress['on' + type] == FUNCTION)
            SWFAddress['on' + type]();
    }

    var _jsInit = function() {
        _jsDispatch('init');
    }

    var _jsChange = function() {
        _jsDispatch('change');
    }

    var _swfChange = function() {
		//alert("swfChange: "+SWFAddress.getValue());
        for (var i = 0, id, value = SWFAddress.getValue(), setter = 'setSWFAddressValue'; id = _ids[i]; i++) {
            var obj = document.getElementById(id);
            if (obj) {
                if (obj.parentNode && typeof obj.parentNode.so != UNDEFINED) {
                    obj.parentNode.so.call(setter, value);
                } else {
                    if (!(obj && typeof obj[setter] != UNDEFINED)) {
                        var objects = obj.getElementsByTagName('object');
                        var embeds = obj.getElementsByTagName('embed');
                        obj = ((objects[0] && typeof objects[0][setter] != UNDEFINED) ? 
                            objects : ((embeds[0] && typeof embeds[0][setter] != UNDEFINED) ? 
                                embeds[0] : null));
                    }
                    if (obj)
                        obj[setter](value);
                } 
            } else if (obj = document[id]) {
                if (typeof obj[setter] != UNDEFINED)
                    obj[setter](value);
            }
        }
    }

    var _update = function() {
//this only works with firebug
//console.debug('_update func called');
        _swfChange();
        _jsChange();
        _st(_track, 10);
    }

    var _trackDefault = function(value) {
        if (typeof urchinTracker == FUNCTION) 
            urchinTracker(value);
        if (typeof pageTracker != UNDEFINED && typeof pageTracker._trackPageview == FUNCTION)
            pageTracker._trackPageview(value);
    }
    
    eval('var _trackDefault = ' + _trackDefault + ';');
    
    var _track = function() {
        if (typeof _opts.tracker != UNDEFINED && eval('typeof ' + _opts.tracker + ' != "' + UNDEFINED + '"')) {
            var fn = eval(_opts.tracker);
            if (typeof fn == FUNCTION)
                fn((_l.pathname + (/\/$/.test(_l.pathname) ? '' : '/') + SWFAddress.getValue()).replace(/\/\//, '/').replace(/^\/$/, ''));
        }
    }
    
    var _htmlWrite = function() {
        var doc = _iframe.contentWindow.document;
        doc.open();
        doc.write('<script>var ' + SWFADDRESS + ' = "' + _getHash() + '";</script>');
        doc.close();
    }

    var _htmlLoad = function() {
        var win = _iframe.contentWindow;
        if (_opts.html) {
            var src = win.location.href;
            _value = (src.indexOf('?') > -1) ? src.substr(src.indexOf('?') + 1) : '';
        } else {
            _value = (typeof win[SWFADDRESS] != UNDEFINED) ? win[SWFADDRESS] : '';
        }
        win.document.title = _d.title;
        if (_value != _getHash()) {
            _update();
            _l.hash = _ieLocal(_value);
        }
    }

    var _load = function() {
//only works with firebug
//console.debug('_load func called');
        var attr = 'id="' + SWFADDRESS + '" style="position:absolute;top:-9999px;"';
        if (_browser.isIE()) {
            document.body.appendChild(document.createElement('div')).innerHTML = '<iframe ' + attr + ' src="' + 
                (_opts.html ? _url.replace(/\.js(\?.*)?$/, '.html') + '?' + _getHash() : 'javascript:false;') + 
                '" width="0" height="0"></iframe>';
            _iframe = document.getElementById(SWFADDRESS);
            _st(function() {
                _events.addListener(_iframe, 'load', _htmlLoad);            
                if (!_opts.html && typeof _iframe.contentWindow[SWFADDRESS] == UNDEFINED) 
                    _htmlWrite();
            }, 10);
        } else if (_browser.isSafari()) {
            if (_version < 412) {
                document.body.innerHTML += '<form ' + attr + ' method="get"></form>';
                _form = document.getElementById(SWFADDRESS);
            }
            if (typeof _l[SWFADDRESS] == UNDEFINED) _l[SWFADDRESS] = {};
            if (typeof _l[SWFADDRESS][_l.pathname] != UNDEFINED) _stack = _l[SWFADDRESS][_l.pathname].split(',');
        } else if (_browser.isOpera() && _ids.length == 0 && typeof navigator.plugins['Shockwave Flash'] == 'object') {
            document.body.innerHTML += '<embed ' + attr + ' src="' + _url.replace(/\.js(\?.*)?$/, '.swf') + 
                '" type="application/x-shockwave-flash" />';
        }
        _st(_jsInit, 1);
        _st(_jsChange, 2);
        _st(_track, 10);
        setInterval(_listen, 1000);
    }

    /**
     * Init event.
     * @type Function
     * @event
     * @static
     */
    this.onInit = null;
    
    /**
     * Change event.
     * @type Function
     * @event
     * @static
     */
    this.onChange = null;
    
    /**
     * String representation of this class.
     * @ignore
     */
    this.toString = function() {
        return '[class SWFAddress]';
    }

    /**
     * Loads the previous URL in the history list.
     * @return {void}
     * @static
     */
    this.back = function() {
        _h.back();
    }

    /**
     * Loads the next URL in the history list.
     * @return {void}
     * @static
     */
    this.forward = function() {
        _h.forward();
    }

    /**
     * Loads a URL from the history list.
     * @param {Number} delta An integer representing a relative position in the history list.
     * @return {void}
     * @static
     */
    this.go = function(delta) {
        _h.go(delta);
    }

    /**
     * Opens a new URL in the browser. 
     * @param {String} url The resource to be opened.
     * @param {String} target Target window.
     * @return {void}
     * @static
     */
    this.href = function(url, target) {
        target = (typeof target != UNDEFINED) ? target : '_self';     
        if (target == '_self')
            self.location.href = url; 
        if (target == '_top')
            _l.href = url; 
        if (target == '_blank')
            window.open(url); 
        else
            _t.frames[target].location.href = url; 
    }

    /**
     * Opens a browser popup window. 
     * @param {String} url Resource location.
     * @param {String} name Name of the popup window.
     * @param {String} options Options which get evaluted and passed to the window.open() method.
     * @param {String} handler Optional JavaScript code for popup handling.    
     * @return {void}
     * @static
     */
    this.popup = function(url, name, options, handler) {
        var popup = window.open(url, name, eval(options));
        eval(handler);
    }

    /**
     * Registers an event listener.
     * @param {String} type Event type.
     * @param {Function} listener Event listener.
     * @return {void}
     * @static
     */
    this.addEventListener = function(type, listener) {
        if (typeof _listeners[type] == UNDEFINED)
            _listeners[type] = [];
        _listeners[type].push(listener);
    }

    /**
     * Removes an event listener.
     * @param {String} type Event type.
     * @param {Function} listener Event listener.
     * @return {void}
     * @static     
     */
    this.removeEventListener = function(type, listener) {
        if (typeof _listeners[type] != UNDEFINED) {
            for (var i = 0, l; l = _listeners[type][i]; i++)
                if (l == listener) break;
            _listeners[type].splice(i, 1);
        }
    }

    /**
     * Dispatches an event to all the registered listeners. 
     * @param {Object} event Event object.
     * @return {Boolean}
     * @static
     */
    this.dispatchEvent = function(event) {
        if (typeof _listeners[event.type] != UNDEFINED && _listeners[event.type].length) {
            event.target = this;
            for (var i = 0, l; l = _listeners[event.type][i]; i++)
                l(event);
            return true;           
        }
        return false;
    }

    /**
     * Checks the existance of any listeners registered for a specific type of event. 
     * @param {String} event Event type.
     * @return {Boolean}
     * @static
     */
    this.hasEventListener = function(type) {
        return (typeof _listeners[type] != UNDEFINED && _listeners[type].length > 0);
    }
    
    /**
     * Provides the base address of the document. 
     * @return {String}
     * @static
     */
    this.getBaseURL = function() {
        var url = _l.href;
        if (url.indexOf('#') != -1)
            url = url.substr(0, url.indexOf('#'));
        if (url.substr(url.length - 1) == '/')
            url = url.substr(0, url.length - 1);
        return url;
    }

    /**
     * Provides the state of the strict mode setting. 
     * @return {Boolean}
     * @static
     */
    this.getStrict = function() {
        return _opts.strict;
    }

    /**
     * Enables or disables the strict mode.
     * @param {Boolean} strict Strict mode state.
     * @return {void}
     * @static
     */
    this.setStrict = function(strict) {
        _opts.strict = strict;
    }

    /**
     * Provides the state of the history setting. 
     * @return {Boolean}
     * @static
     */
    this.getHistory = function() {
        return _opts.history;
    }

    /**
     * Enables or disables the creation of history entries.
     * @param {Boolean} history History state.
     * @return {void}
     * @static
     */
    this.setHistory = function(history) {
        _opts.history = history;
    }

    /**
     * Provides the tracker function.
     * @return {String}
     * @static
     */
    this.getTracker = function() {
        return _opts.tracker;
    }

    /**
     * Sets a function for page view tracking. The default value is 'urchinTracker'.
     * @param {String} tracker Tracker function.
     * @return {void}
     * @static
     */
    this.setTracker = function(tracker) {
        _opts.tracker = tracker;
    }

    /**
     * Provides a list of all the Flash objects registered. 
     * @return {Array}
     * @static
     */
    this.getIds = function() {
        return _ids;
    }

    /**
     * Provides the id the first and probably the only Flash object registered. 
     * @return {String}
     * @static
     */
    this.getId = function(index) {
        return _ids[0];
    }

    /**
     * Sets the id of a single Flash object which will be registered for deep linking.
     * @param {String} id ID of the object.
     * @return {void}
     * @static
     */
    this.setId = function(id) {
        _ids[0] = id;
    }

    /**
     * Adds an id to the list of Flash object registered for deep linking.
     * @param {String} id ID of the object.
     * @return {void}
     * @static
     */
    this.addId = function(id) {
        this.removeId(id);
        _ids.push(id);
    }

    /**
     * Removes an id from the list of Flash object registered for deep linking.
     * @param {String} id ID of the object.
     * @return {void}
     * @static
     */
    this.removeId = function(id) {
        for (var i = 0; i < _ids.length; i++) {
            if (id == _ids[i]) {
                _ids.splice(i, 1);
                break;
            }
        }
    }

    /**
     * Provides the title of the HTML document.
     * @return {String}
     * @static
     */
    this.getTitle = function() {
        return _d.title;
    }

    /**
     * Sets the title of the HTML document.
     * @param {String} title Title value.
     * @return {void}
     * @static
     */
    this.setTitle = function(title) {
        if (!_supported) return null;
        if (typeof title == UNDEFINED) return;
        if (title == 'null') title = '';
        _title = _d.title = title;
        _st(function() {
            if (_iframe && _iframe.contentWindow && _iframe.contentWindow.document && _iframe.contentWindow.title)
                _iframe.contentWindow.document.title = _title;
         }, 1000);
    }

    /**
     * Provides the status of the browser window.
     * @return {String}
     * @static
     */
    this.getStatus = function() {
        return _t.status;
    }

    /**
     * Sets the status of the browser window.
     * @param {String} status Status value.
     * @return {void}
     * @static
     */
    this.setStatus = function(status) {
        if (!_supported) return null;
        if (typeof status == UNDEFINED) return;
        if (!_browser.isSafari()) {
            status = _strictCheck((status != 'null') ? status : '', true);
            if (status == '/') status = '';
            if (!(/http(s)?:\/\//.test(status))) {
                var index = _l.href.indexOf('#');
                status = (index == -1 ? _l.href : _l.href.substr(0, index)) + '#' + status;
            }
            _t.status = status;
        }
    }

    /**
     * Resets the status of the browser window.
     * @return {void}
     * @static
     */
    this.resetStatus = function() {
        _t.status = '';
    }

    /**
     * Provides the current deep linking value.
     * @return {String}
     * @static
     */
    this.getValue = function() {
        if (!_supported) return null;
        return _strictCheck(_value, false);
    }

    /**
     * Sets the current deep linking value.
     * @param {String} value A value which will be appended to the base link of the HTML document.
     * @return {void}
     * @static
     */
    this.setValue = function(value) {
        if (!_supported) return null;
        if (typeof value == UNDEFINED) return;
		//vyew add:
		if(value.match(/\/undefined\//)){
			try{
				dbg("CAUGHT UNDEFINED ERROR:"+value);
			}catch(e){}
			return;
		}
        if (value == 'null') value = ''
        value = _strictCheck(value, true);
        if (value == '/') value = '';
        if (_value == value) return;
		//alert("setValue: "+value);
        _value = value;
        _silent = true;
        _update();
        _stack[_h.length] = _value;
        if (_browser.isSafari()) {
            if (_opts.history) {
                _l[SWFADDRESS][_l.pathname] = _stack.toString();
                _length = _h.length + 1;
                if (_version < 412) {
                    if (_l.search == '') {
                        _form.action = '#' + _value;
                        _form.submit();
                    }
                } else if (_version < 523){
                    var evt = document.createEvent('MouseEvents');
                    evt.initEvent('click', true, true);
                    var anchor = document.createElement('a');
                    anchor.href = '#' + _value;
                    anchor.dispatchEvent(evt);                
                } else {
                    _l.hash = '#' + _value;
                }
            } else {
                _l.replace('#' + _value);
            }
        } else if (_value != _getHash()) {
            if (_opts.history)
                _l.hash = '#' + _ieLocal(_value);
            else
                _l.replace('#' + _value);
        }
        if (_browser.isIE() && _opts.history) {
            if (_opts.html) {
                var loc = _iframe.contentWindow.location;
                loc.assign(loc.pathname + '?' + _getHash());
            } else {
                _htmlWrite();
            }
        }
        if (_browser.isSafari())
            _st(function(){ _silent = false; }, 1);
        else
            _silent = false;
    }

    /**
     * Provides the deep linking value without the query string.
     * @return {String}
     * @static
     */
    this.getPath = function() {
        var value = this.getValue();
        return (value.indexOf('?') != -1) ? value.split('?')[0] : value;
    }

    /**
     * Provides a list of all the folders in the deep linking path.
     * @return {Array}
     * @static
     */
    this.getPathNames = function() {
        var path = SWFAddress.getPath();
        var names = path.split('/');
        if (path.substr(0, 1) == '/')
            names.splice(0, 1);
        if (path.substr(path.length - 1, 1) == '/')
            names.splice(names.length - 1, 1);
        return names;
    }

    /**
     * Provides the query string part of the deep linking value.
     * @return {String}
     * @static
     */
    this.getQueryString = function() {
        var value = this.getValue();
        var index = value.indexOf('?');
        return (index != -1 && index < value.length) ? value.substr(index + 1) : '';
    }

    /**
     * Provides the value of a specific query parameter.
     * @param {String} param Parameter name.
     * @return {String}
     * @static
     */
    this.getParameter = function(param) {
        var value = this.getValue();
        var index = value.indexOf('?');
        if (index != -1) {
            value = value.substr(index + 1);
            var params = value.split('&');
            var p, i = params.length;
            while(i--) {
                p = params[i].split('=');
                if (p[0] == param)
                    return p[1];
            }
        }
        return '';
    }

    /**
     * Provides a list of all the query parameter names.
     * @return {Array}
     * @static
     */
    this.getParameterNames = function() {
        var value = this.getValue();
        var index = value.indexOf('?');
        var names = [];
        if (index != -1) {
            value = value.substr(index + 1);
            if (value != '' && value.indexOf('=') != -1) {
                var params = value.split('&');
                var i = 0;
                while(i < params.length) {
                    names.push(params[i].split('=')[0]);
                    i++;
                }
            }
        }
        return names;
    }

    if (_supported) {
    
        for (var i = 1; i < _length; i++)
            _stack.push('');
            
        _stack.push(_getHash());
    
        if (_browser.isIE() && _l.hash != _getHash())
            _l.hash = '#' + _ieLocal(_getHash());
    
        try {
            _url = String(_searchScript(document).src);
            var qi = _url.indexOf('?');
            if (_url && qi > -1) {
                var param, params = _url.substr(qi + 1).split('&');
                for (var i = 0, p; p = params[i]; i++) {
                    param = p.split('=');
                    if (/^(history|html|strict)$/.test(param[0]))
                        _opts[param[0]] = (isNaN(param[1]) ? eval(param[1]) : (parseFloat(param[1]) > 0));
                    if (/^tracker$/.test(param[0]))
                        _opts[param[0]] = param[1];
                }
            }
        } catch(e) {}
        if (/file:\/\//.test(_l.href)) _opts.html = false;
    
        _titleCheck();
        _events.addListener(document, 'DOMContentLoaded', _load);
    
    } else {
        _track();
    }
}

/**
 * SWFAddress embed hooks.
 * @ignore
 */
new function() {

    var _func, _args;
    var UNDEFINED = 'undefined';

    if (typeof swfobject != UNDEFINED) SWFObject = swfobject;
    if (typeof FlashObject != UNDEFINED) SWFObject = FlashObject;
    
    if (typeof SWFObject != UNDEFINED) {
        if (SWFObject.prototype && SWFObject.prototype.write) {
            _func = SWFObject.prototype.write;
            SWFObject.prototype.write = function() {
                _args = arguments;
                if (this.getAttribute('version').major < 8) {
                    this.addVariable('$swfaddress', SWFAddress.getValue());
                    ((typeof _args[0] == 'string') ? 
                        document.getElementById(_args[0]) : _args[0]).so = this;
                }
                var success;
                if (success = _func.apply(this, _args))
                    SWFAddress.addId(this.getAttribute('id'));
                return success;
            }
        } else {
            _func = SWFObject.registerObject;
            SWFObject.registerObject = function() {
                _args = arguments;
                _func.apply(this, _args);
                SWFAddress.addId(_args[0]);            
            }
            _func = SWFObject.createSWF;
            SWFObject.createSWF = function() {
                _args = arguments;
                _func.apply(this, _args);
                SWFAddress.addId(_args[0].id);            
            }
            _func = SWFObject.embedSWF;
            SWFObject.embedSWF = function() {
                _args = arguments;
                _func.apply(this, _args);
                SWFAddress.addId(_args[8].id);            
            }
        }
    }
    
    if (typeof UFO != UNDEFINED) {
        _func = UFO.create;
        UFO.create = function() {
            _args = arguments;
            _func.apply(this, _args);
            SWFAddress.addId(_args[0].id);        
        }
    }
    
    if (typeof AC_FL_RunContent != UNDEFINED) {
        _func = AC_FL_RunContent;
        AC_FL_RunContent = function() {
            _args = arguments;        
            _func.apply(this, _args);
            for (var i = 0, l = _args.length; i < l; i++)
                if (_args[i]== 'id') SWFAddress.addId(_args[i+1]);
        }
    }
}




/******************************************************************************************
         vyewLib.js
 ******************************************************************************************/

/**
 * vyewLib.js 
 * Vyew Javascript Library 
 * Copyright (c)2007-2008 Vyew, Simulat, Inc.
 *
 * @author timh@vyew dot com
 *
 * DEPENDANCIES:
 * -------------
 * 		jquery.js
 *		vyew.phpobject.js
 *
 * INCLUDES:
 * ---------
 *		- cookie lib functions
 * 		- login checks
 *
 * CHANGES:
 *		8/29/08 - changed to depend on vyew.phpobject.js for calling json gateway instead of siteajax.php
 *
 * TODO:
 *		- handle multiple ajax calls ?? is this still relevant?
 */


//--- Setup package
if(typeof vyew=="undefined") vyew=new Object();
if(!vyew.ud) vyew.ud=new Object();
if(!vyew.od) vyew.od=new Object();
vyew.whoami="vyew object";

//make sure vyew.phpobject is loaded
if(!vyew.php || vyew.php == undefined){
	try{ var auto_vers=document.location.href.match(/(\/v[0-9]+\.[0-9]+[^/]*)\//)[1];
    }catch(e){}
	if(empty(auto_vers)) dbg("No detection: vyewLib-auto_vers");
	try{ $.getScript(auto_vers+"/js/vyew.phpobject.js"); }catch(e){}
}


/**
 * Checks users logged in status by examining session/loginID cookies
 * then retreives missing user data. Follows this logic:
 * 		if- sid cookie exists, and vyew.ud.em exists, then assume its good
 *		elseif- sid or lid exists, 
 *
 *
 * @param callback - a function to be called back with results object
 * @param scope - an optional scope object for which the callback is applied to (callback.apply(scope,args))
 * @param options - options Object: {translateMid:'string'} will translate a customID to its numeric MID
 *					and return it in result Object as :{translatedMid:NNNN}, else {translatedMid:false}
 * @return void
 */
vyew.checkLogin=function(callback,scope,options)
{
	//TODO: there is a bug here commented out.
 	// login, check tree, logout inside vyew, login as someone else, and the tree is someone elses
	// TOFIX: try tracing out all cookies and vyew.ud/vyew.od data and compare them...
	scope=(!scope) ? this : scope;
	//c_ud=getCookie('ud');
	//try{ vyew.ud=eval(c_ud); }
	//catch(e) { vyew.ud={} }
	//if(getCookie('sid') && vyew.ud && vyew.ud.em && vyew.ud.em.length > 3){
	//	dbg("check login 1");
	//	if(callback) callback.apply(scope,[vyew.ud]);
	//}else 
	if(typeof(callback)!="function") callback=new Function();
	//alert('sid:'+getCookie('sid')+"  lid:"+getCookie('lID'));
	if(getCookie('sid') || getCookie('lID')){
		vyew.getUserInfo(callback,scope,options);
	}else{ 
		if(callback) callback.apply(scope,[false]);
	}
}

	

/**
 * Gets user data based on sid or lid
 * calls callback with result object
 * @param callback - function
 * @param scope - object to apply callback to
 * @param options - options Object: {translateMid:'string'} will translate a customID to its numeric MID
 *                  and return it in result Object as :{translatedMid:NNNN}, else {translatedMid:false}
 */
vyew.getUserInfo=function(callback,scope,options)
{
	if(!vyew.php) return;
	if(typeof(callback)!="function") callback=new Function();
    var lID=getCookie('lID');
	var sid=getCookie('sid');
	//todod.... 
	//if sid, check if good, return em
	//else if lid, check, return em and sid
	if(lID){
        var ref=fs_getCookie('ref');
        var adRef=fs_getCookie('adRef');
        if(!ref)ref="none";
        if(!adRef)adRef="none";
		vyew.php.call("Login.checkLID", [lID, ref, adRef, options], 
			function(res)
			{
				if(res && res.em && res.em.length>2){
                    setCookie('em',vyew.ud.em, cookieexp);
                    setCookie('ud', res, 'session');
                    vyew.ud=res;
                    var cookieexp=(getCookie('keepLoggedIn')=="1")?'never':'session'
                    if( !(getCookie('sid').length>5) ) setCookie('sid',vyew.ud.sid,'session');
                    callback.apply(scope, [res]);
				}else{
					vyew.clearCookies();
					callback.apply(scope, [false]);
				}
			},this)

	}else if(sid){
		vyew.php.call("Login.checkSID", [options], 
            function(res)
			{
				if(res && res.em && res.em.length>2){
					setCookie('em',res.em,'session');
					setCookie('ud', res, 'session');
					vyew.ud=res;
					if(callback) callback.apply(scope, [res]);
				}else{
					callback.apply(scope, [false]);
				}
			});
    }else{
		callback.apply(this,[false]);
    }
}
vyew.getUserEmail=vyew.getUserInfo;



/**
 * Validates an email address
 * @param em - the email address
 * @return boolean
 */
vyew.isEmailAddress=function(em)
{
    if (typeof em == "undefined") return false;
    if (typeof em == "object") em = em[0];
    em=''+em;
	if(em.match(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9_.-]+\.[a-zA-Z0-9]+$/)) return true;
    else return false;
}


/**
 * Simple JSON Decoder - decodes with eval(), but includes try/catch for error handling
 * If the eval fails or Json is invalid, returns an empty obj:{}
 * @param str - Json String must start and end with ( and ).
 * @return {object}
 */
vyew.jsonDecode=function(str)
{
    if(!str || typeof(str)!="string" || str.length<3) return {x:99};
    str=str.match(/^.*[}\)]/)[0]
    var obj={};
    try{ obj=eval(str); }
    catch(e){throw 'Error in JSON decode of:'+str}
    return obj; 
}

/**
 * Adds variables from sourceObj to targObj (not sure if cloned or not? todo: check it)
 * @param targObj 
 * @param sourceObj
 */
vyew.updateObj=function(targObj, sourceObj)
{
	if(typeof targObj != "object" || typeof sourceObj != "object") return;
	for(var v in sourceObj){
		targObj[v]=sourceObj[v];
	}
}

/**
 * Clears all relevant Vyew login cookies
 */
vyew.clearCookies=function()
{
    clearCookie('em'); clearCookie('lID'); clearCookie('sid'); clearCookie("keepLoggedIn"); 
	clearCookie('userdata');
	clearCookie('ud');
    clearCookie('exp_uniqueid'); clearCookie('exp_userhash');
}
vyew.logout=vyew.clearCookies;






/**
 * ------------------------------------------------------------------
 * 	MISCELLANEOUS 
 * ------------------------------------------------------------------
 */

function empty(v){
  if(typeof v == "undefined" || v==null || v==undefined) return true;
  else return false;
}
function isDefined(obj){
	return !empty(obj);
}

function getFirebugConsole()
{
	try{
	//if top frame, use that console
	if(top!=window) var win=top;
	else win=this.window;
	if(typeof win.console == "undefined"){ 
		if(!win.loadFirebugConsole) return false;
		else win.loadFirebugConsole();
	}
	if(typeof win.console != "undefined" && win.console.debug) return win.console;
	return false;
	}catch(e){ return false; }
}

function dbg()
{
	var console=getFirebugConsole();
	if (!console) return;
   	var out="";
   	for(var i=0;i<arguments.length;i++){ out+=arguments[i]+", "; }
   	out=out.substr(0,out.length-2);
 	console.debug(out);
}

function dbd(x,txt)
{
	var console=getFirebugConsole();
	if(!console) return;
	if(txt) console.debug('---------------- '+txt);
	else console.debug('----------------');
    console.dir(x);
}

//alert
function ale()
{
	var out="";
	for(var i=0;i<arguments.length;i++){ out+=arguments[i]+", "; }
	out=out.substr(0,out.length-2);
	alert(out);
}

function isNumeric(n){
	return !isNaN(n);
}

/**
 * Searches through an object array for specified key/value within an object. 
 * Usage: a=[{id:1,name'bob'},{id:2,name:'joe'}]; 
 *        a.findObj('name','joe') //returns object:{id:2,name:'joe'}
 *        a.findObj('name','joe',true) //returns 1
 * @param key - String: the text of the variable name to search through
 * @param value - the value you are searching for
 * @param returnIndex - Bool: if true, return index, else return the object itself
 * @return: The found object, or its index
 */
Array.prototype.findObj = function(key, value, returnIndex ){
  for(var i in this){
     if (this[i][key] == value){ 
		if(returnIndex==true) return i
		else return this[i]
	 }
  }
  return false;
}


/**
 * getVersDir - tries to auto detect the version of the app based on dir name
 */
vyew.getVers = function()
{
 	try{
        var default_vers=top.vers;
		if(default_vers.match(/^v[0-9][0-9]?\.[0-9]/)) return default_vers;
    }catch(e){}
	try{
		var auto_vers=document.location.href.match(/\/(v[0-9]+\.[0-9]+[^/]*)\//)[1];
		if(auto_vers.match(/^v[0-9][0-9]?\.[0-9]/)) return auto_vers;
	}catch(e){}
	return "latest";
}

/**
 * Given a url: http://domain.com/content/product/uses?a=1&b=2#hello
 * Examples:
 * 		urlSegment(0) = "content"
 *   	urlSegment(1) = "product"
 *   	urlSegment("#") = "hello"
 * 	 	urlSegment("?") = "a=1&b=2#hello"
 *   	urlSegment("?a") = "1"
 *   	urlSegment("?b") = "2"
 *		urlSegment("domain") = "domain.com"
 *		urlSegment("base") = "http://domain.com/content/product/uses"
 *		urlSegment("baserel") = /content/product/uses"
 *
 * TO SET THE URL HASH:
 *		top.location.hash = "abc"
 */
function urlSegment(num, win)
{
	if(!win) win=this;
	try{
    var loc=win.location.href.match(/\/\/(.*)/)[1];
	}catch(e){ return ""; }
    if (!loc) return "";
    if(!isNaN(num)){
		segs=loc.split("/");
        return segs[num+1];
    }else if(num=="#"){
        pl=loc.indexOf("#");
        if(pl==-1)return "";
        else {
            loc=loc.substr(pl+1);
            pl=loc.indexOf("?");
            if(pl==-1) return loc;
            else return loc.substr(0,loc.indexOf("?"));
        }
    }else if(num=="?"){
        pl=loc.indexOf("?");
        if(pl==-1)return "";
        else return loc.substr(pl+1);
    //check if "?variable"
    }else if(num.substr(0,1)=="?"){
        var getv=num.substr(1);
        if(loc.indexOf(getv)==-1) return '';
        pl=loc.indexOf("?");
        if(pl==-1) return "";
        var q=''+loc.substr(pl+1);
        if(q.indexOf(getv)==-1 || typeof q != "string") return '';
        var regx=new RegExp(getv+"=([^&#]*)");
        var res=q.match(regx)[1];
        return res;
    }else if(num=="domain"){
		return loc.match(/(.*?)\//)[1]
	}else if(num=="base"){
		var loc=win.location.href;
		pl=loc.indexOf("?");
		if(pl>=0) loc=loc.substr(0,pl);
		pl=loc.indexOf("#");
		if(pl>=0) loc=loc.substr(0,pl);
		return loc;
	}else if(num=="baserel"){
        var loc=win.location.href.match(/^.*?\/\/.*?(\/.*)/)[1];
        pl=loc.indexOf("?");
        if(pl>=0) loc=loc.substr(0,pl);
        pl=loc.indexOf("#");
        if(pl>=0) loc=loc.substr(0,pl);
        return loc;
    }

    return "";
}


/**
 * Returns specified segment after the hash (#) in url
 * A segment is text between "/" slashes
 * If no segNum passed, return whole hash string
 * Examples with url : domain.com/room#/abc/def/ghi
 *      hashUrlSegment(0) : "abc"  (leading slashes are removed)
 *      hashUrlSegment(1) : "def"
 *      hashUrlSegment()  : "/abc/def/ghi"
 * Note: To set the hash use: document.hash=""
 * @param segNum - segment number
 * @return mixed - the segment specified or false
 */
function hashUrlSegment(segNum,win)
{
    if(!win)win=this;
    var loc=win.location.href;
    pl=loc.indexOf("#");
    if(pl==-1) return false;
    if(!pl) return false;
    loc=loc.substr(pl+1)
	//todo: add browser switch thing..
    //loc=unescape(loc);            //if ie
    //loc=decodeURIComponent(loc);  //if ff
    if(segNum==null) return loc;
    segs=loc.split("/");
    if(!segs[0]) segs.shift()
    return segs[segNum];
}


/**
 * ---------------------------------------------------------------------------
 * COOKIE LIBRARY: (also provides support for flash cookie setter/getter)
 *		getCookie(cookieName, isJson)
 *		setCookie(cookieName, value)
 *
 * FLASH INSTRUCTIONS:
 *       1. copy cookieLib.js (or vyewLib) to the same place as your .html file which references your .swf
 *       2. put this lines in your .html file :
 *       ---------------------------------------------------------------------------
 *           <script src="cookieLib.js" type="text/javascript"></script>
 *       ---------------------------------------------------------------------------
 * SET A COOKIE FROM FLASH:
 *            import flash.external.*;
 *            ExternalInterface.call("fs_setCookie", "cookieName", "cookieValue", "EXPIRATION");
 *
 *            (expiration can be: "never", or "session" or a "number" representing minutes)
 *            (default expiration is "never")
 *            (session expires when the browser is closed)
 *           (minutes= "60" for 1 hour, "1440" for 1 day, etc...)
 *
 * RETRIEVE A COOKIE FROM FLASH:
 *           import flash.external.*;
 *          var cookievalue = ExternalInterface.call("fs_getCookie", "cookieName");
 *
 * ------------------------------------------------------------------
 */

function fs_getAllCookies(){
	return document.cookie;		
}

/**
 * Retrieves a cookie, converts to json if passed
 * @param a {string} - cookie name
 * @param isJson {bool} - if true, object will be converted from JSON string to object
 * @return {mixed} - cookie data, or false if cookie not found
 */
function getCookie(a,isJson){
	var e, m=" "+document.cookie+";"
	var N=" "+a+"=",s=m.indexOf(N),r="";
	if(s!=-1){
		s+=N.length;
		e=m.indexOf(";",s);
		r=unescape(m.substring(s,e))
	}
	if(typeof(r)=="undefined" || r=="") return false;
	if(r.match(/ckjson.:1/) || r.match(/ckjson:1/) || isJson==true){ 
		try {
			r=r.match(/^[ (]*(.*?)[) ]*$/)[1];		//trip and strip outer parenthesis
			r=JSON.decode(r);
			delete r.ckjson;
		}catch(e){ dbg('Err394x:Converting JSON') }
	}
	if(r=="false") r=false;
	return r
}

function clearCookie(n){
    var e=new Date();
	e.setTime(e.getTime()-20000000);
	document.cookie=n+"=0; path=/; expires="+e.toGMTString() + "; domain="+fs_getHostname();
	document.cookie=n+"=0; path=/; expires="+e.toGMTString();
}

/**
 * Set a cookie (alias fore setCookie())
 * NEW: if value is a complex object/array, it will be json'd and unjson'd automatically on getCookie()
 * @param varName - cookie name
 * @param varVal - value to be set
 * @param exp - expiration in minutes, or set to "session", or "never"
 * @param allSubDomains - boolean: set true if you want to set to ".domain.com"
 *						which will make cookie available to all subdomains
 */
function setCookie(varName,varVal,exp,allSubDomains){
    varVal=(varVal==null)?'0':varVal
	if(typeof(varVal)!="string" && typeof(varVal)!="number"){
		varVal.ckjson=1;
		varVal=JSON.encode(varVal);
	}
	//escape semicolons
	try{ varVal=varVal.replace(/;/g,"%3B"); }catch(e){}
	var e=new Date();
	if(typeof(exp)=="undefined" || exp=="null" || exp==null || exp=="" || exp=="session"){
		exp=";";
    }else if (exp=="never"||exp=="forever")
	{
		e.setFullYear(e.getFullYear() + 10);
		exp="; expires=" + e.toGMTString();
    }else{
        e.setTime(e.getTime()+(60000*exp))
		exp="; expires=" + e.toGMTString();
    }
    var ck = varName+"=" + escape(varVal) + "; path=/;" + exp;
	if(allSubDomains==true) ck += " domain="+fs_getHostname()+";";
    document.cookie = ck;
	return "1";
}

/**
 * Returns the hostname of current url:
 * ie. if url is www.domain.com/abc/dev, returns: domain.com
 */
function getHostname()
{
    var h=document.location.host;
    var p=h.lastIndexOf('.');
    p=h.lastIndexOf('.',p-1);
    if (p>-1) h=h.substr(p+1);
    return h;         
}
var fs_clearCookie=clearCookie;
var fs_getHostname=getHostname;
var fs_setCookie=setCookie;
var fs_getCookie=getCookie;



/**
 * Tecords all vyew cookies, clears them, then re-sets them
 * this is to clear out the global subdomain cookies (.domain.com)
 */
function resetVyewCookies(){
	var sid=getCookie("sid");
	var lID=getCookie("lID");
	var kli=getCookie("keepLoggedIn");
	clearCookie("sid"); clearCookie("lID"); clearCookie("keepLoggedIn");
	setCookie("sid",sid);
	if(lID && kli) setCookie("lID", lID, "forever");
	if(kli) setCookie("keepLoggedIn", kli, "forever");
}






/**
 * JSON Library
 * JSON.decode( {string} )   @returns javascript object
 * JSON.encode( {object} )   @return {string} javascript encoded object into string
 */
JSON=new function(){this.decode=function(){var filter,result,self,tmp;if($$("toString")){switch(arguments.length){case 2:self=arguments[0];filter=arguments[1];break;case 1:if($[typeof arguments[0]](arguments[0])===Function){self=this;filter=arguments[0];}
else
self=arguments[0];break;default:self=this;break;};if(rc.test(self)){try{result=e("(".concat(self,")"));if(filter&&result!==null&&(tmp=$[typeof result](result))&&(tmp===Array||tmp===Object)){for(self in result)
result[self]=v(self,result)?filter(self,result[self]):result[self];}}
catch(z){}}
else{throw new JSONError("bad data");}};return result;};this.encode=function(){var self=arguments.length?arguments[0]:this,result,tmp;if(self===null)
result="null";else if(self!==undefined&&(tmp=$[typeof self](self))){switch(tmp){case Array:result=[];for(var i=0,j=0,k=self.length;j<k;j++){if(self[j]!==undefined&&(tmp=JSON.encode(self[j])))
result[i++]=tmp;};result="[".concat(result.join(","),"]");break;case Boolean:result=String(self);break;case Date:result='"'.concat(self.getFullYear(),'-',d(self.getMonth()+1),'-',d(self.getDate()),'T',d(self.getHours()),':',d(self.getMinutes()),':',d(self.getSeconds()),'"');break;case Function:break;case Number:result=isFinite(self)?String(self):"null";break;case String:result='"'.concat(self.replace(rs,s).replace(ru,u),'"');break;default:var i=0,key;result=[];for(key in self){if(self[key]!==undefined&&(tmp=JSON.encode(self[key])))
result[i++]='"'.concat(key.replace(rs,s).replace(ru,u),'":',tmp);};result="{".concat(result.join(","),"}");break;}};return result;};this.toDate=function(){var self=arguments.length?arguments[0]:this,result;if(rd.test(self)){result=new Date;result.setHours(i(self,11,2));result.setMinutes(i(self,14,2));result.setSeconds(i(self,17,2));result.setMonth(i(self,5,2)-1);result.setDate(i(self,8,2));result.setFullYear(i(self,0,4));}
else if(rt.test(self))
result=new Date(self*1000);return result;};var c={"\b":"b","\t":"t","\n":"n","\f":"f","\r":"r",'"':'"',"\\":"\\","/":"/"},d=function(n){return n<10?"0".concat(n):n},e=function(c,f,e){e=eval;delete eval;if(typeof eval==="undefined")eval=e;f=eval(""+c);eval=e;return f},i=function(e,p,l){return 1*e.substr(p,l)},p=["","000","00","0",""],rc=null,rd=/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/,rs=/(\x5c|\x2F|\x22|[\x0c-\x0d]|[\x08-\x0a])/g,rt=/^([0-9]+|[0-9]+[,\.][0-9]{1,3})$/,ru=/([\x00-\x07]|\x0b|[\x0e-\x1f])/g,s=function(i,d){return"\\".concat(c[d])},u=function(i,d){var n=d.charCodeAt(0).toString(16);return"\\u".concat(p[n.length],n)},v=function(k,v){return $[typeof result](result)!==Function&&(v.hasOwnProperty?v.hasOwnProperty(k):v.constructor.prototype[k]!==v[k])},$={"boolean":function(){return Boolean},"function":function(){return Function},"number":function(){return Number},"object":function(o){return o instanceof o.constructor?o.constructor:null},"string":function(){return String},"undefined":function(){return null}},$$=function(m){function $(c,t){t=c[m];delete c[m];try{e(c)}catch(z){c[m]=t;return 1}};return $(Array)&&$(Object)};try{rc=new RegExp('^("(\\\\.|[^"\\\\\\n\\r])*?"|[,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t])+?$')}
catch(z){rc=/^(true|false|null|\[.*\]|\{.*\}|".*"|\d+|\d+\.\d+)$/}};function JSONError(message){this.message=message||"";this.name="JSONError";};JSONError.prototype=new Error;

