function goLink(linkhref,idofdiv) 
	{
    advAJAX.post({
		url: linkhref,		
		onLoading : function(obj) { document.getElementById(idofdiv).innerHTML = '<img src="images/loader.gif"> Loading...';},																		
		onSuccess : function(obj) { document.getElementById(idofdiv).innerHTML = obj.responseText;}		
							});
    }
		
function goLink2(linkhref,idofdiv,idpar) 
	{
	$(document).ready(function(){
			var newid = '#'+idpar;
			$(newid).replaceWith("Loading...");
			$(idofdiv).load(linkhref);
	});
	}

function sendRegform(idofdiv,idofform) 
	{
  advAJAX.submit(document.getElementById(idofform), 
			{
			disableForm : false,
			onLoading : function(obj) { 
							document.getElementById(idofdiv).innerHTML = '<img src="images/loader.gif"> Loading...<br><br>';
																},											
			onSuccess : function(obj) { 
							document.getElementById(idofdiv).innerHTML = obj.responseText;
																},

			onFinalization : 	function(obj) {resetform('regPass','regConf');}
			 }
			 );
  }

function sendContform(idofdiv,idofform) 
	{
  advAJAX.submit(document.getElementById(idofform), 
			{
			disableForm : false,
			onLoading : function(obj) { 
							document.getElementById(idofdiv).innerHTML = '<img src="images/loader.gif"> Loading...<br><br>';
																},											
			onSuccess : function(obj) { 
							document.getElementById(idofdiv).innerHTML = obj.responseText;
																},
			
			onFinalization : 	function(obj) {resetform('contactEmail','contactEmail');}
			 }
			 );
  }
	
function sendPassform(idofdiv,idofform) 
	{
  advAJAX.submit(document.getElementById(idofform), 
			{
			disableForm : false,
			onLoading : function(obj) { 
							document.getElementById(idofdiv).innerHTML = '<img src="images/loader.gif"> Loading...<br><br>';
																},											
			onSuccess : function(obj) { 
							document.getElementById(idofdiv).innerHTML = obj.responseText;
																},
			
			onFinalization : 	function(obj) {resetform('passEmail','passConf');}
			 }
			 );
  }
	
function sendUpdateform(idofdiv,idofform) 
	{
  advAJAX.submit(document.getElementById(idofform), 
			{
			disableForm : false,
			onLoading : function(obj) { 
							document.getElementById(idofdiv).innerHTML = '<img src="images/loader.gif"> Loading...<br><br>';
																},											
			onSuccess : function(obj) { 
							document.getElementById(idofdiv).innerHTML = obj.responseText;
																}
			 }
			 );
  }	

function resetform(iditem1,iditem2)
	{
	item1Id = document.getElementById(iditem1);
	item2Id = document.getElementById(iditem2);
	item1Id.value=''; item2Id.value='';
	}

function showBox(idoflink)
	{
	GB_showCenter('','http://caretovote.com/showB.php?go='+idoflink,400,500);	
	}

/* jQuery functions */

$(document).ready(function(){													 
	$('.slide1').slidePanel(
		{
		status:'open'
		});	

		$(".imgFade").hover(
      function () {
        $(this).fadeTo("fast", 0.77);
      }, 
      function () {
        $(this).fadeTo("fast", 1);
      }
    );
		
		$('#tabContainer').tabs({ fxFade: true, fxSpeed: 'fast' });
		
		$.NiceJForms.build();
		
		
});


function enforcechar(what,limit){
	if (what.value.length>=limit)
	return false
}

/*
 *  AdvancedAJAX 2.0 RC2
 *  (c) 2006 Łukasz Lach
 *  mail: anakin@php5.pl
 *  www:  http://advajax.anakin.us/
 *        http://anakin.us/
 * Licensed under Creative Commons GNU Lesser General Public License
 * http://creativecommons.org/licenses/LGPL/2.1/
 */
function advAJAX() {

    this.url = window.location.href;
    this.method = 'GET';
    this.parameters = new Object();
    this.headers = new Object();
    this.mimeType = null;
    this.username = null;
    this.password = null;

    this.useJSON = false;
    this.useCache = false;

    this.requestDone = false;
    this.requestAborted = false;
    this.requestTimedOut = false;

    this.queryString = '';
    this.responseText = null;
    this.responseXML = null;
    this.responseJSON = null;
    this.status = null;
    this.statusText = null;

    this.timeout = 0;
    this.retryCount = 0;
    this.retryDelay = 1000;
    this.retryNo = 0;

    this.repeat = false;
    this.repeatCount = 0;
    this.repeatNo = 0;
    this.repeatDelay = 1000;

    this.tag = null;
    this.group = null;
    this.form = null;
    this.disableForm = true;

    this.onInitialization = null;
    this.onFinalization = null;
    this.onAbort = null;
    this.onReadyStateChange = null;
    this.onLoading = null;
    this.onLoaded = null;
    this.onInteractive = null;
    this.onComplete = null;
    this.onSuccess = null;
    this.onFatalError = null;
    this.onInternalError = null;
    this.onError = null;
    this.onTimeout = null;
    this.onRetryDelay = null;
    this.onRetry = null;
    this.onRepeat = null;
    this.onRepeatDelay = null;
    this.onGroupEnter = null;
    this.onGroupLeave = null;

    this._xhr = null;
    this._eventHandled = [ false ];

    this._timerTimeout = null;
    this._timerRepeat = null;

    this.init = function() {

        (this._xhr !== null) && this.destroy();
        if ((this._xhr = this._createXHR()) === null)
            return false;
        if (typeof advAJAX._defaultParameters != 'undefined')
            this.handleArguments(advAJAX._defaultParameters);
        if (typeof this._xhr.overrideMimeType == 'function' && this.mimeType !== null)
            this._xhr.overrideMimeType(this.mimeType);
        this._eventHandled = [ this._eventHandled[0], false, false, false, false ];

        var _this = this;
        this._xhr.onreadystatechange = function() {

            if (_this.requestAborted)
                return;
            _this._raise('ReadyStateChange', _this._xhr.readyState);
            (!_this._eventHandled[_this._xhr.readyState]) && _this._handleReadyState(_this._xhr.readyState);
        };
        return true;
    };

    this.destroy = function(abort) {

        abort = abort || false;
        try {
            abort && this._xhr.abort();
            delete this._xhr['onreadystatechange'];
        } catch(e) {
        }
        ;
        this._xhr = null;
    };

    this._createXHR = function() {

        if (typeof XMLHttpRequest != 'undefined')
            return new XMLHttpRequest();
        var xhr = [ 'MSXML2.XMLHttp.6.0', 'MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0',
                'MSXML2.XMLHttp', 'Microsoft.XMLHttp' ];
        for (var i = 0; i < xhr.length; i++) {
            try {
                var xhrObj = new ActiveXObject(xhr[i]);
                return xhrObj;
            } catch (e) {
            }
            ;
        }
        this._raise('FatalError');
        return null;
    };

    this._handleReadyState = function(readyState) {

        if (this._eventHandled[readyState])
            return;
        this._eventHandled[readyState] = true;
        switch (readyState) {
            /* loading */
            case 1:
                if (this.retryNo == 0 && this.group !== null) {
                    if (typeof advAJAX._groupData[this.group] == 'undefined') {
                        advAJAX._groupData[this.group] = 0;
                        this._raise('GroupEnter', this.group);
                    }
                    advAJAX._groupData[this.group]++;
                }
                this._raise('Loading', this);
                break;
            /* loaded */
            case 2:
                this._raise('Loaded', this);
                break;
            /* interactive */
            case 3:
                this._raise('Interactive', this);
                break;
            /* complete */
            case 4:
                window.clearTimeout(this._timerTimeout);
                if (this.requestAborted)
                    return;
                this.requestDone = true;
                this.responseText = this._xhr.responseText;
                this.responseXML = this._xhr.responseXML;
                try {
                    this.status = this._xhr.status || null;
                    this.statusText = this._xhr.statusText || null;
                } catch (e) {
                    this.status = null;
                    this.statusText = null;
                }
                this._raise('Complete', this);
                if (this.status == 200) {
                    try {
                        var _contentType = this._xhr.getResponseHeader('Content-type');
                        if (_contentType.match(/^text\/javascript/i))
                            eval(this.responseText); else
                        if (_contentType.match(/^text\/x\-json/i))
                            this.responseJSON = eval('(' + this.responseText + ')');
                    } catch(e) {
                        this._raise('InternalError', advAJAX.ERROR_INVALID_EVAL_STRING);
                    };
                    this._raise('Success', this);  
                } else
                    this._raise('Error', this);
                if (this.repeat) {
                    if (++this.repeatNo != this.repeatCount - 1) {
                        this._raise('RepeatDelay', this);
                        var _this = this;
                        this._timerRepeat = window.setTimeout(function() {
                            _this._raise('Repeat', this);
                            _this.init();
                            _this.run();
                        }, this.repeatDelay);
                        return;
                    }
                }
                this.destroy();
                (this.disableForm) && this._switchForm(true);
                this._handleGroup();
                this._raise('Finalization', this);
        }
    };

    this._handleGroup = function() {

        if (this.group === null) return;
        (--advAJAX._groupData[this.group] == 0) && this._raise('GroupLeave', this);
    }

    this._onTimeout = function() {

        if (this._xhr == null || this._eventHandled[4])
            return;
        this.requestAborted = this.requestTimedOut = true;
        this._xhr.abort();
        this._raise('Timeout');
        if (this.retryNo++ < this.retryCount) {
            this.init();
            this._raise('RetryDelay', this);
            var _this = this;
            this._timerTimeout = window.setTimeout(function() {
                _this._raise('Retry', _this);
                _this.run();
            }, this.retryDelay);
        } else {
            this.destroy();
            (this.disableForm) && this._switchForm(true);
            this._handleGroup();
            this._raise('Finalization', this);
        }
    };

    this.run = function() {

        if (this.init() == false)
            return false;
        this.requestAborted = this.requestTimedOut = false;
        (!this._eventHandled[0]) && (this._raise('Initialization', this)) && (this._eventHandled[0] = true);
        if (this.retryNo == 0 && this.repeatNo == 0) {
            if (this.useJSON) {
                if (typeof [].toJSONString != 'function') {
                    this._raise('InternalError', advAJAX.ERROR_NO_JSON);
                    return;
                }
                for (var p in this.parameters) {
                    var useJson = typeof [].toJSONString == 'function';
                    (this.queryString.length > 0) && (this.queryString += '&');
                    this.queryString += encodeURIComponent(p) + '=' +
                                        encodeURIComponent(this.parameters[p].toJSONString());
                }
            } else {
                for (var p in this.parameters) {
                    (this.queryString.length > 0) && (this.queryString += '&');
                    if (typeof this.parameters[p] != "object")
                        this.queryString += encodeURIComponent(p) + '=' + encodeURIComponent(this.parameters[p]); else {
                        if (!(this.parameters[p] instanceof Array)) continue;
                        for (var i = 0, cnt = this.parameters[p].length; i < cnt; i++)
                            this.queryString += encodeURIComponent(p) + '=' + encodeURIComponent(this.parameters[p][i]) + '&';
                        this.queryString = this.queryString.slice(0, -1);
                    }
                }
            }
            (this.method == 'GET') && (this.queryString.length > 0) && (this.url += (this.url.indexOf('?') != -1 ? '&' : '?') + this.queryString);
        }
        (this.disableForm) && this._switchForm(false);
        try {
            this._xhr.open(this.method, this.url, true, this.username || '', this.password || '');
        } catch(e) {
            this._raise('FatalError', this);
            return false;
        }
        var _this = this;
        (this.timeout > 0) && (this._timerTimeout = window.setTimeout(function() {
            _this._onTimeout();
        }, this.timeout));
        if (typeof this._xhr.setRequestHeader == 'function') {
            if (this.method == 'GET' && !this.useCache)
                this._xhr.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
            for (var p in this.headers)
                this._xhr.setRequestHeader(encodeURIComponent(p), encodeURIComponent(this.headers[p]));
        }
        if (this.method == 'POST') {
            try {
                this._xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            } catch(e) {
            };
            this._xhr.send(this.queryString);
        } else if (this.method == 'GET') {
            this._xhr.send('');
        }
    };

    this.getResponseHeader = function(name) {

        return this._xhr.getResponseHeader(name) || null;
    };

    this.getAllResponseHeaders = function() {

        return this._xhr.getAllResponseHeaders() || null;
    };

    this.abort = function() {

        this.requestAborted = true;
        window.clearTimeout(this._timerTimeout);
        window.clearTimeout(this._timerRepeat);
        this._handleGroup();
        this._raise('Abort', this);
        this.destroy();
        this._raise('Finalization', this);
    },

    this._extendObject = function(target, source) {

        for (var p in source)
            target[p] = source[p];
    };

    this.handleArguments = function(args) {

        (typeof args['form'] == 'string') && (args['form'] = document.getElementById(args['form']));
        for (var p in args) {
            if (typeof this[p] == 'undefined') {
                this.parameters[p] = args[p];
            } else {
                if (p != 'parameters' && p != 'headers') {
                    this[p] = args[p];
                } else
                    this._extendObject(this[p], args[p]);
            }
        }
        this.method = this.method.toUpperCase();
        (typeof this.form == 'object') && (this.form !== null) && this._appendForm();
        (args.repeat) && (this.repeatCount++);
    };

    this._switchForm = function(enable) {

        if (typeof this.form != 'object' || this.form === null)
            return;
        var _f = this.form;
        for (var i = 0; i < _f.elements.length; i++)
            if (!enable) {
                if (_f.elements[i]['disabled'])
                    _f.elements[i]['_disabled'] = true; else
                    _f.elements[i]['disabled'] = 'disabled';
            } else {
                if (typeof _f.elements[i]['_disabled'] == 'undefined' || _f.elements[i]['_disabled'] === null)
                    _f.elements[i]['disabled'] = '';
                try {
                    delete _f.elements[i]['_disabled'];
                } catch(e) {
                    _f.elements[i]['_disabled'] = null;
                };
            }
    };

    this._appendForm = function() {

        var _f = this.form;
        this.method = _f.getAttribute('method').toUpperCase();
        this.url = _f.getAttribute('action');
        for (var i = 0; i < _f.elements.length; i++) {
            var _e = _f.elements[i];
            if (_e.disabled)
                continue;
            switch (_e.type) {
                case 'text':
                case 'password':
                case 'hidden':
                case 'textarea':
                    this._addParameter(_e.name, _e.value);
                    break;
                case 'select-one':
                    if (_e.selectedIndex >= 0)
                        this._addParameter(_e.name, _e.options[_e.selectedIndex].value);
                    break;
                case 'select-multiple':
                    var _r = [];
                    for (var j = 0; j < _e.options.length; j++)
                        if (_e.options[j].selected)
                            _r[_r.length] = _e.options[j].value;
                    (_r.length > 0) && (this._addParameter(_e.name, _r));
                    break;
                case 'checkbox':
                case 'radio':
                    (_e.checked) && (this._addParameter(_e.name, _e.value));
                    break;
            }
        }
    };

    this._addParameter = function(name, value) {

        if (typeof this.parameters[name] == 'undefined') {
            this.parameters[name] = value;
        } else {
            if (typeof this.parameters[name] != 'object')
                this.parameters[name] = [ this.parameters[name], value ]; else
                this.parameters[name][this.parameters[name].length] = value;
        }
    };

    this._delParameter = function(name) {

        delete this.parameters[name];
    };

    this._raise = function(name) {

        for (var i = 1, args = []; i < arguments.length; args[args.length] = arguments[i++]);
        (typeof this['on' + name] == 'function') && (this['on' + name].apply(null, args));
        (name == 'FatalError') && this._raise('Finalization', this);
    }

}

advAJAX._groupData = new Object();
advAJAX._defaultParameters = new Object();

advAJAX.get = function(args) {

    return advAJAX._handleRequest('GET', args);
}
advAJAX.post = function(args) {

    return advAJAX._handleRequest('POST', args);
}
advAJAX.head = function(args) {

    return advAJAX._handleRequest('HEAD', args);
}
advAJAX._handleRequest = function(requestType, args) {

    args = args || { };
    var _a = new advAJAX();
    _a.method = requestType;
    _a.handleArguments(args);
    setTimeout(function() {
        _a.run()
    }, 0);
    return _a;
};
advAJAX.submit = function(form, args) {

    args = args || {};
    if (typeof form == 'undefined' || form === null)
        return false;
    var _a = new advAJAX();
    args['form'] = form;
    _a.handleArguments(args);
    setTimeout(function() {
        _a.run()
    }, 0);
    return _a;
};
advAJAX.assign = function(form, args) {

    args = args || {};
    (typeof form == 'string') && (form = document.getElementById(form));
    if (typeof form == 'undefined' || form === null)
        return false;
    form['_advajax_args'] = args;
    var _onsubmit = function(event) {
        event = event || window.event;
        if (event.preventDefault) {
            event.preventDefault();
            event.stopPropagation();
        } else {
            event.returnValue = false;
            event.cancelBubble = true;
        }
        var _e = event.target || event.srcElement;
        return !advAJAX.submit(_e, _e['_advajax_args']);
    }
    if (form.addEventListener) {
        form.addEventListener('submit', _onsubmit, false);
    } else if (form.attachEvent) {
        form.attachEvent('onsubmit', _onsubmit);
    }
    return true;
};
advAJAX.download = function(target, url) {

    (typeof target == 'string') && (target = document.getElementById(target));
    if (typeof target == 'undefined' || target === null)
        return false;
    advAJAX.get({
        'url': url,
        'onSuccess' : function(o) {
            target.innerHTML = o.responseText;
        }
    });
};
advAJAX.setDefaultParameters = function(args) {

    advAJAX._defaultParameters = new Object();
    for (var a in args)
        advAJAX._defaultParameters[a] = args[a];
};

advAJAX.ERROR_INVALID_EVAL_STRING = -1;
advAJAX.ERROR_NO_JSON = -2;



/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} 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/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObjectUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
		}
		window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;



// A few configuration settings
var CROSSHAIRS_LOCATION = '/colorselector/crosshairs.png';
var HUE_SLIDER_LOCATION = '/colorselector/h.png';
var HUE_SLIDER_ARROWS_LOCATION = '/colorselector/position.png';
var SAT_VAL_SQUARE_LOCATION = '/colorselector/sv.png';

// Here are some boring utility functions. The real code comes later.

function hexToRgb(hex_string, default_)
{
    if (default_ == undefined)
    {
        default_ = null;
    }

    if (hex_string.substr(0, 1) == '#')
    {
        hex_string = hex_string.substr(1);
    }
    
    var r;
    var g;
    var b;
    if (hex_string.length == 3)
    {
        r = hex_string.substr(0, 1);
        r += r;
        g = hex_string.substr(1, 1);
        g += g;
        b = hex_string.substr(2, 1);
        b += b;
    }
    else if (hex_string.length == 6)
    {
        r = hex_string.substr(0, 2);
        g = hex_string.substr(2, 2);
        b = hex_string.substr(4, 2);
    }
    else
    {
        return default_;
    }
    
    r = parseInt(r, 16);
    g = parseInt(g, 16);
    b = parseInt(b, 16);
    if (isNaN(r) || isNaN(g) || isNaN(b))
    {
        return default_;
    }
    else
    {
        return {r: r / 255, g: g / 255, b: b / 255};
    }
}

function rgbToHex(r, g, b, includeHash)
{
    r = Math.round(r * 255);
    g = Math.round(g * 255);
    b = Math.round(b * 255);
    if (includeHash == undefined)
    {
        includeHash = true;
    }
    
    r = r.toString(16);
    if (r.length == 1)
    {
        r = '0' + r;
    }
    g = g.toString(16);
    if (g.length == 1)
    {
        g = '0' + g;
    }
    b = b.toString(16);
    if (b.length == 1)
    {
        b = '0' + b;
    }
    return ((includeHash ? '#' : '') + r + g + b).toUpperCase();
}

var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);

function fixPNG(myImage)
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
        var node = document.createElement('span');
        node.id = myImage.id;
        node.className = myImage.className;
        node.title = myImage.title;
        node.style.cssText = myImage.style.cssText;
        node.style.setAttribute('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader"
                                        + "(src=\'" + myImage.src + "\', sizingMethod='scale')");
        node.style.fontSize = '0';
        node.style.width = myImage.width.toString() + 'px';
        node.style.height = myImage.height.toString() + 'px';
        node.style.display = 'inline-block';
        return node;
    }
    else
    {
        return myImage.cloneNode(false);
    }
}

function trackDrag(node, handler)
{
    function fixCoords(x, y)
    {
        var nodePageCoords = pageCoords(node);
        x = (x - nodePageCoords.x) + document.documentElement.scrollLeft;
        y = (y - nodePageCoords.y) + document.documentElement.scrollTop;
        if (x < 0) x = 0;
        if (y < 0) y = 0;
        if (x > node.offsetWidth - 1) x = node.offsetWidth - 1;
        if (y > node.offsetHeight - 1) y = node.offsetHeight - 1;
        return {x: x, y: y};
    }
    function mouseDown(ev)
    {
        var coords = fixCoords(ev.clientX, ev.clientY);
        var lastX = coords.x;
        var lastY = coords.y;
        handler(coords.x, coords.y);

        function moveHandler(ev)
        {
            var coords = fixCoords(ev.clientX, ev.clientY);
            if (coords.x != lastX || coords.y != lastY)
            {
                lastX = coords.x;
                lastY = coords.y;
                handler(coords.x, coords.y);
            }
        }
        function upHandler(ev)
        {
            myRemoveEventListener(document, 'mouseup', upHandler);
            myRemoveEventListener(document, 'mousemove', moveHandler);
            myAddEventListener(node, 'mousedown', mouseDown);
        }
        myAddEventListener(document, 'mouseup', upHandler);
        myAddEventListener(document, 'mousemove', moveHandler);
        myRemoveEventListener(node, 'mousedown', mouseDown);
        if (ev.preventDefault) ev.preventDefault();
    }
    myAddEventListener(node, 'mousedown', mouseDown);
    node.onmousedown = function(e) { return false; };
    node.onselectstart = function(e) { return false; };
    node.ondragstart = function(e) { return false; };
}

var eventListeners = [];

function findEventListener(node, event, handler)
{
    var i;
    for (i in eventListeners)
    {
        if (eventListeners[i].node == node && eventListeners[i].event == event
         && eventListeners[i].handler == handler)
        {
            return i;
        }
    }
    return null;
}
function myAddEventListener(node, event, handler)
{
    if (findEventListener(node, event, handler) != null)
    {
        return;
    }

    if (!node.addEventListener)
    {
        node.attachEvent('on' + event, handler);
    }
    else
    {
        node.addEventListener(event, handler, false);
    }

    eventListeners.push({node: node, event: event, handler: handler});
}

function removeEventListenerIndex(index)
{
    var eventListener = eventListeners[index];
    delete eventListeners[index];
    
    if (!eventListener.node.removeEventListener)
    {
        eventListener.node.detachEvent('on' + eventListener.event,
                                       eventListener.handler);
    }
    else
    {
        eventListener.node.removeEventListener(eventListener.event,
                                               eventListener.handler, false);
    }
}

function myRemoveEventListener(node, event, handler)
{
    removeEventListenerIndex(findEventListener(node, event, handler));
}

function cleanupEventListeners()
{
    var i;
    for (i = eventListeners.length; i > 0; i--)
    {
        if (eventListeners[i] != undefined)
        {
            removeEventListenerIndex(i);
        }
    }
}
myAddEventListener(window, 'unload', cleanupEventListeners);

// This copyright statement applies to the following two functions,
// which are taken from MochiKit.
//
// Copyright 2005 Bob Ippolito <bob@redivi.com>
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject
// to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

function hsvToRgb(hue, saturation, value)
{
    var red;
    var green;
    var blue;
    if (value == 0.0)
    {
        red = 0;
        green = 0;
        blue = 0;
    }
    else
    {
        var i = Math.floor(hue * 6);
        var f = (hue * 6) - i;
        var p = value * (1 - saturation);
        var q = value * (1 - (saturation * f));
        var t = value * (1 - (saturation * (1 - f)));
        switch (i)
        {
            case 1: red = q; green = value; blue = p; break;
            case 2: red = p; green = value; blue = t; break;
            case 3: red = p; green = q; blue = value; break;
            case 4: red = t; green = p; blue = value; break;
            case 5: red = value; green = p; blue = q; break;
            case 6: // fall through
            case 0: red = value; green = t; blue = p; break;
        }
    }
    return {r: red, g: green, b: blue};
}

function rgbToHsv(red, green, blue)
{
    var max = Math.max(Math.max(red, green), blue);
    var min = Math.min(Math.min(red, green), blue);
    var hue;
    var saturation;
    var value = max;
    if (min == max)
    {
        hue = 0;
        saturation = 0;
    }
    else
    {
        var delta = (max - min);
        saturation = delta / max;
        if (red == max)
        {
            hue = (green - blue) / delta;
        }
        else if (green == max)
        {
            hue = 2 + ((blue - red) / delta);
        }
        else
        {
            hue = 4 + ((red - green) / delta);
        }
        hue /= 6;
        if (hue < 0)
        {
            hue += 1;
        }
        if (hue > 1)
        {
            hue -= 1;
        }
    }
    return {
        h: hue,
        s: saturation,
        v: value
    };
}

function pageCoords(node)
{
    var x = node.offsetLeft;
    var y = node.offsetTop;
    var parent = node.offsetParent;
    while (parent != null)
    {
        x += parent.offsetLeft;
        y += parent.offsetTop;
        parent = parent.offsetParent;
    }
    return {x: x, y: y};
}

// The real code begins here.
var huePositionImg = document.createElement('img');
huePositionImg.galleryImg = false;
huePositionImg.width = 35;
huePositionImg.height = 11;
huePositionImg.src = HUE_SLIDER_ARROWS_LOCATION;
huePositionImg.style.position = 'absolute';

var hueSelectorImg = document.createElement('img');
hueSelectorImg.galleryImg = false;
hueSelectorImg.width = 35;
hueSelectorImg.height = 200;
hueSelectorImg.src = HUE_SLIDER_LOCATION;
hueSelectorImg.style.display = 'block';

var satValImg = document.createElement('img');
satValImg.galleryImg = false;
satValImg.width = 200;
satValImg.height = 200;
satValImg.src = SAT_VAL_SQUARE_LOCATION;
satValImg.style.display = 'block';

var crossHairsImg = document.createElement('img');
crossHairsImg.galleryImg = false;
crossHairsImg.width = 21;
crossHairsImg.height = 21;
crossHairsImg.src = CROSSHAIRS_LOCATION;
crossHairsImg.style.position = 'absolute';

function makeColorSelector(inputBox)
{
    var rgb, hsv
    
    function colorChanged()
    {
        var hex = rgbToHex(rgb.r, rgb.g, rgb.b);
        var hueRgb = hsvToRgb(hsv.h, 1, 1);
        var hueHex = rgbToHex(hueRgb.r, hueRgb.g, hueRgb.b);
        previewDiv.style.background = hex;
        inputBox.value = hex;
        satValDiv.style.background = hueHex;
        crossHairs.style.left = ((hsv.v*199)-10).toString() + 'px';
        crossHairs.style.top = (((1-hsv.s)*199)-10).toString() + 'px';
        huePos.style.top = ((hsv.h*199)-5).toString() + 'px';
    }
    function rgbChanged()
    {
        hsv = rgbToHsv(rgb.r, rgb.g, rgb.b);
        colorChanged();
    }
    function hsvChanged()
    {
        rgb = hsvToRgb(hsv.h, hsv.s, hsv.v);
        colorChanged();
    }
    
    var colorSelectorDiv = document.createElement('div');
    colorSelectorDiv.style.padding = '15px';
    colorSelectorDiv.style.position = 'relative';
    colorSelectorDiv.style.height = '275px';
    colorSelectorDiv.style.width = '250px';
    
    var satValDiv = document.createElement('div');
    satValDiv.style.position = 'relative';
    satValDiv.style.width = '200px';
    satValDiv.style.height = '200px';
    var newSatValImg = fixPNG(satValImg);
    satValDiv.appendChild(newSatValImg);
    var crossHairs = crossHairsImg.cloneNode(false);
    satValDiv.appendChild(crossHairs);
    function satValDragged(x, y)
    {
        hsv.s = 1-(y/199);
        hsv.v = (x/199);
        hsvChanged();
    }
    trackDrag(satValDiv, satValDragged)
    colorSelectorDiv.appendChild(satValDiv);

    var hueDiv = document.createElement('div');
    hueDiv.style.position = 'absolute';
    hueDiv.style.left = '230px';
    hueDiv.style.top = '15px';
    hueDiv.style.width = '35px';
    hueDiv.style.height = '200px';
    var huePos = fixPNG(huePositionImg);
    hueDiv.appendChild(hueSelectorImg.cloneNode(false));
    hueDiv.appendChild(huePos);
    function hueDragged(x, y)
    {
        hsv.h = y/199;
        hsvChanged();
    }
    trackDrag(hueDiv, hueDragged);
    colorSelectorDiv.appendChild(hueDiv);
    
    var previewDiv = document.createElement('div');
    previewDiv.style.height = '50px'
    previewDiv.style.width = '50px';
    previewDiv.style.position = 'absolute';
    previewDiv.style.top = '225px';
    previewDiv.style.left = '15px';
    previewDiv.style.border = '1px solid black';
    colorSelectorDiv.appendChild(previewDiv);
    
    function inputBoxChanged()
    {
        rgb = hexToRgb(inputBox.value, {r: 0, g: 0, b: 0});
        rgbChanged();
    }
    myAddEventListener(inputBox, 'change', inputBoxChanged);
    inputBox.size = 8;
    inputBox.style.position = 'absolute';
    inputBox.style.right = '15px';
    inputBox.style.top = (225 + (25 - (inputBox.offsetHeight/2))).toString() + 'px';
    colorSelectorDiv.appendChild(inputBox);
    
    inputBoxChanged();
    
    return colorSelectorDiv;
}

function makeColorSelectors(ev)
{
    var inputNodes = document.getElementsByTagName('input');
    var i;
    for (i = 0; i < inputNodes.length; i++)
    {
        var node = inputNodes[i];
        if (node.className != 'color')
        {
            continue;
        }
        var parent = node.parentNode;
        var prevNode = node.previousSibling;
        var selector = makeColorSelector(node);
        parent.insertBefore(selector, (prevNode ? prevNode.nextSibling : null));
    }
}

myAddEventListener(window, 'load', makeColorSelectors);

