
/* 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].express_install&&!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.express_install,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.express_install=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.express_install=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""},express_installCallback: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}}}}}();


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built In easIng capabilities added In jQuery 1.1
 * to offer multiple easIng options
 *
 * Copyright (c) 2007 George Smith
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});






/*
 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
 * in FIPS PUB 180-1
 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for details.
 */

/*
 * Configurable variables. You may need to tweak these to be compatible with
 * the server-side, but the defaults work in most cases.
 */
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
 * These are the functions you'll usually want to call
 * They take string arguments and return either hex or base-64 encoded strings
 */
function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}

/*
 * Perform a simple self-test to see if the VM is working
 */
function sha1_vm_test()
{
  return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
}

/*
 * Calculate the SHA-1 of an array of big-endian words, and a bit length
 */
function core_sha1(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << (24 - len % 32);
  x[((len + 64 >> 9) << 4) + 15] = len;

  var w = Array(80);
  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;
  var e = -1009589776;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;
    var olde = e;

    for(var j = 0; j < 80; j++)
    {
      if(j < 16) w[j] = x[i + j];
      else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
      var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
                       safe_add(safe_add(e, w[j]), sha1_kt(j)));
      e = d;
      d = c;
      c = rol(b, 30);
      b = a;
      a = t;
    }

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
    e = safe_add(e, olde);
  }
  return Array(a, b, c, d, e);

}

/*
 * Perform the appropriate triplet combination function for the current
 * iteration
 */
function sha1_ft(t, b, c, d)
{
  if(t < 20) return (b & c) | ((~b) & d);
  if(t < 40) return b ^ c ^ d;
  if(t < 60) return (b & c) | (b & d) | (c & d);
  return b ^ c ^ d;
}

/*
 * Determine the appropriate additive constant for the current iteration
 */
function sha1_kt(t)
{
  return (t < 20) ?  1518500249 : (t < 40) ?  1859775393 :
         (t < 60) ? -1894007588 : -899497514;
}

/*
 * Calculate the HMAC-SHA1 of a key and some data
 */
function core_hmac_sha1(key, data)
{
  var bkey = str2binb(key);
  if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
  return core_sha1(opad.concat(hash), 512 + 160);
}

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
 * to work around bugs in some JS interpreters.
 */
function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
 * Bitwise rotate a 32-bit number to the left.
 */
function rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

/*
 * Convert an 8-bit or 16-bit string to an array of big-endian words
 * In 8-bit function, characters >255 have their hi-byte silently ignored.
 */
function str2binb(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
  return bin;
}

/*
 * Convert an array of big-endian words to a string
 */
function binb2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
  return str;
}

/*
 * Convert an array of big-endian words to a hex string.
 */
function binb2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);
  }
  return str;
}

/*
 * Convert an array of big-endian words to a base-64 string
 */
function binb2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * (3 -  i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}





Smirk = {

	popIndex: 0,	
	smirks: 0,

	// callback from every smirk swf when it is loaded
	smirkIsLoaded: function(domId) {
		
	},

	processingSmirk: function(smirkId) {
		var sid = "smirk-"+smirkId;	
		document.getElementById(sid).processingIcon();	
	},

	finishedSmirk: function(smirkId) {
		document.getElementById("smirk-"+smirkId).getIcon(smirkId);		
		Smirk.updateCurrent(smirkId) 
	},
	
	processingNewSmirk: function(smirkId) {
		
		document.getElementById("smirk-000").processingIcon(); // this fails on a new page
	},

	finishedNewSmirk: function(smirkId) {

	},

	smirkClicked: function(smirkId) {

		$("#iid-display").empty().append("iid is: " + smirkId);

		// show green border on selected icon
		$(".icon").each(function() {	

			var t = $(this).attr("id");
	
			if (t && t != "smirk-"+smirkId) {
				document.getElementById(t).unselect();
			}

		});

		
		document.getElementById("maker-swf").switchMode('edit');
		document.getElementById("maker-swf").getIcon(smirkId);
		$("#btn-new").css({zIndex: "5"}).addClass("inactive").removeClass('cancel');
		$("#smirk-000").remove();
		
		// populate SHARE info
		var embd = '<object width="160" height="160" type="application/x-shockwave-flash" data="/swf/smirk.swf"><param name="allowScriptAccess" value="always"/><param name="flashvars" value="uuid='+smirkUuid+'&loop=1"/><embed src="/swf/smirk.swf" type="application/x-shockwave-flash" width="160" height="160" allowscriptaccess="always" flashvars="uuid='+smirkUuid+'&loop=1"></embed></object>';
		
		$("#icon-embed-code").attr("value", embd);
			
		$.getJSON("/iid_version.php?u="+smirkUuid+"&i="+smirkId, function(j) {
				$("#icon-gif").replaceWith('<img id="icon-gif" src="/images/no-smirk.jpg" width="80" height="80" alt="my icon"/>');
				$("#icon-gif").addClass("uuid-is-"+j.iid);
				
				Smirk.smirkAnimatorStart();
		});
		
		
	},

	updateCurrent: function(newCurrent) {
		
		var oldCurrent = smirkIid;
		var uid = smirkUuid;
		if (newCurrent) {
			
			try { // this will fail on NEW
				$(".current-sm").remove();
				var l = $("#smirk-"+newCurrent).position().left - 19;
				var t = $("#smirk-"+newCurrent).position().top - 21;
				var flag = $("<img src='/images/current-sm.png'>")
					.css({
						position: "absolute",
						top: t,
						left: l,
						width: 110,
						height: 79,
						zIndex: 100
					})
					.addClass("current-sm")
				$("#smirk-"+newCurrent).parent().append(flag);				
			}
			catch(er){
				
			}
			var nc = newCurrent;
			
			$.getJSON("/smirks/update_smirk_jax?iid="+newCurrent, function(d) {
				document.getElementById("maker-swf").getIcon(newCurrent);
				
				$(Smirk.smirks).each(function(i) {
	
					if (this.smirk_mode == newCurrent) {
						smirkIid = newCurrent;
						$("#iid-display").empty().append("iid is: " + newCurrent);
						$("#twit-link").attr('href', 'http://twitter.com/home?status=I\'m feeling ' + this.blerb + ' /' + smirkLogin);
						//$("#icon-gif").attr('src', this.thumb);
					
						//$("#download-frame a:first").attr('href', this.thumb);
						//$("#icon-buddy a:first").attr('href', "aim:BuddyIcon?src=" + this.thumb);
					
						$.getJSON("/iid_version.php?u="+uid+"&i="+newCurrent, function(j) {
							$("#icon-gif").addClass("uuid-is-"+j.iid);
							Smirk.smirkAnimatorStart();
						});
					
					}
						
				});
				
				
				setTimeout(function() {
					try {
						document.getElementById("smirk-" + oldCurrent ).showAsCurrent(false);
					} catch(er){}
					try {
						document.getElementById("smirk-"+nc).showAsCurrent(true);
					} catch(er){}
				}, 500);
				
	
			});
		}
		
	},


	
 	loadEmUp: function() {

		
		
    // render default links, etc to the current selected icon
		var uid = smirkUuid;
		var smirkId = smirkIid;
		// populate SHARE info
		var embd = '<object width="160" height="160" type="application/x-shockwave-flash" data="/swf/smirk.swf"><param name="allowScriptAccess" value="always"/><param name="flashvars" value="uuid='+uid+'&loop=1"/><embed src="/swf/smirk.swf" type="application/x-shockwave-flash" width="160" height="160" allowscriptaccess="always" flashvars="uuid='+uid+'&loop=1"></embed></object>';
		
		$("#icon-embed-code").attr("value", embd);
  
			
	},
	

	nameHunt: function(formElementId) {

		var u = $("#"+formElementId).attr('value');
		$.getJSON("/name_hunter.php?u="+u, function(j) {
			if (j.stat == 'taken') {
			
				alert('Some loser is already using that user name, try another?');
				$("#"+formElementId).focus();
			}	
		});
	
	},
	
	parseNvClasses: function(classValue) {
		var nvPairs = "{";
		var cls = classValue.split(/\s+/);
		$(cls).each(function() {
			if (this.indexOf("-is-") > 0) { // regex?
				var a = this.split("-is-");
				if (nvPairs.length > 1) nvPairs += ",'"+a[0]+"' : '"+a[1]+"'";
				else nvPairs += "'"+a[0]+"' : '"+a[1]+"'";
			}
		});
		nvPairs += "}";
		//alert(nvPairs)
		return eval('('+nvPairs+')');
	},
	
	animating: false,
	
	smirkAnimatorStart: function() {
		
		if (Smirk.animating) {
			clearInterval(Smirk.animating);
			Smirk.animating = false;
		}
		
		// #icon-gif
		//var anim = false;
		var currentFrame = 1;
		var nv = Smirk.parseNvClasses($("#icon-gif").attr("class"));
		
		$("#icon-gif").attr("src", "/vids/"+smirkUuid[0]+smirkUuid[1]+"/"+smirkUuid+"/"+nv.uuid+"1.jpg");
		$("#download-frame").attr('href', "/vids/"+smirkUuid[0]+smirkUuid[1]+"/"+smirkUuid+"/"+nv.uuid+"1.jpg");
		$("#icon-buddy a:first").attr('href', "aim:BuddyIcon?src=/vids/"+smirkUuid[0]+smirkUuid[1]+"/"+smirkUuid+"/"+nv.uuid+"1.jpg");
		
		$("#icon-gif").unbind("mouseover").unbind("mouseout");
		
		$("#icon-gif")
			.bind("mouseover", function() {
				if (Smirk.animating) {
					clearInterval(Smirk.animating);
					Smirk.animating = false;
				}
				var smirkFrames = 21;
				var imageObjects = new Array(); // total frames is 21 for now
				
				//alert(imageObjects.length);
				
				for (var i=0; i<smirkFrames; i++) {
					var imgStub = new Image();
					imgStub.src = "/vids/"+smirkUuid[0]+smirkUuid[1]+"/"+smirkUuid+"/"+nv.uuid+""+(i+1)+".jpg";
					
					imageObjects.push(imgStub);
				}
				
				
				var forwards = true;
				var targetElement = this;
				
				Smirk.animating = setInterval(function() {
					if (currentFrame > smirkFrames) {
					
						currentFrame = smirkFrames - 1;
						forwards = false;
						
					}
					
					else if (currentFrame < 1) {
					
						currentFrame = 2;
						forwards = true;
						
					}
					
					
					$(targetElement).attr("src", imageObjects[currentFrame-1].src);
					$("#download-frame").attr('href', imageObjects[currentFrame-1].src);
					$("#icon-buddy a:first").attr('href', "aim:BuddyIcon?src=" + imageObjects[currentFrame-1].src);
					
					if (forwards)	currentFrame ++;
					else currentFrame --;
				
				}, 130);
			
			})
			.bind("mouseout", function() {
				
				if (Smirk.animating) {
					clearInterval(Smirk.animating);
					Smirk.animating = false;
				}
				
			})
	
	}
	

} // end Smirk



// hook in listeners on password field and other globals

$(function() {
	
	function pwListen() {
		$("#smirk-password")
			.focus(function() {
				$(this).addClass("field-focused");
				if(this.value=='Password') {
					$(this).replaceWith('<input type="password" id="smirk-password" class="field-focused" name="p" value="">');
					$("#smirk-password").focus();
					pwListen();
				}
			})
			.blur(function() {
				
				if(this.value.length < 1) {
					$(this).replaceWith('<input type="text" id="smirk-password" name="p" value="Password">');
					pwListen();
				}
				else {
					$(this).removeClass("field-focused");
				}
				
			});
	}
	
	
	$("#smirk-user")
		.focus(function() {
			$(this).addClass("field-focused");
			if(this.value=='Username') this.value='';
		})
		.blur(function() {
			$(this).removeClass("field-focused");
			if(this.value.length < 1) this.value='Username';
			
		});
	
	pwListen();	
	
	$("#smirk-submit")
		.click(function() {
			$('#smirk-password').attr('value', hex_sha1($('#smirk-password').attr('value')))
		});

});



var smirkAnimatorStart;
var smirkAnimatorReload; // gets smirkAnimatorReload(smirk, uuid, "#maker-jpg", true);
var smirkAnimatorLoad;

(function() {

	var smirkQueue = Array();
	var __frameDelay = 120;
	var animationRef = false;
	var currentIid = 0;
	
	function parseNvClasses(classValue) {
		var nvPairs = "{";
		var cls = classValue.split(/\s+/);
		jQuery(cls).each(function() {
			if (this.indexOf("-is-") > 0) {
				var a = this.split("-is-");
				if (nvPairs.length > 1) nvPairs += ",'"+a[0]+"' : '"+a[1]+"'";
				else nvPairs += "'"+a[0]+"' : '"+a[1]+"'";
			}
		});
		nvPairs += "}";
		return eval('('+nvPairs+')');
	}

  
  function coreAnimator($, sa, smirk) {
    if (smirk) {
      
      currentIid = smirk.iid;

			sa.imgBase = smirk.tiled;
		  
		  
		  // calculate the current image width / height, scale based on that
		  var origWidth = $(sa.targetElement).innerWidth();
		  sa.increment = origWidth;  // this tells us how much to move each frame
		  
		  //var origHeight = $(sa.targetElement).outerHeight();  // don't really need, has to be square?
		                                                         // how will this affect uploaded 16x9?  
		                                                         // will need to crop at ffmpeg level!
		  
		  var scale = origWidth / 144; // 144 is the standard width
		  var displayScale = Math.floor(720 * scale);
		  
		  sa.targetElement.src = sa.imgBase;
		  
      var currentClasses = $(sa.targetElement).attr("class");
      var currentId = $(sa.targetElement).attr("id");
					
			$(sa.targetElement)
			  .attr("class", "")
			  .attr("id", "")
			  .wrap(
			    $("<div id='" + currentId + "' class='" + currentClasses + "'>")
			      .css({position: "relative", overflow: "hidden", width: origWidth, height: origWidth})						
			  )
			  .attr("width", displayScale)
			  .attr("height", displayScale)
			  .css({position: "absolute", top: 0, left: 0})
			  

		  $(sa.targetElement).load(function() {
		  
				smirkQueue.push( sa );
        startAnimationLoop();
		  });
			
			
		}
  
  }

  smirkAnimatorReload = function($, smirk, uuid) {
    
			
		var sa = new smirkAnimation();
		sa.uuid = uuid;
		sa.iid = (smirk.iid) ? smirk.iid : 0;
		sa.loop = true; // comes over as a string, not bool
		
		sa.targetElement = smirkQueue[0].targetElement;
			
		var divReference = $(sa.targetElement).closest("div");
		var currentClasses = divReference.attr("class");
    var currentId = $(sa.targetElement).closest("div").attr("id");
    var w = parseInt($(sa.targetElement).css("width"));
    var h = parseInt($(sa.targetElement).css("height"));
					
		$(sa.targetElement)
		  .attr("id", currentId)
		  .attr("class", currentClasses)
		  .attr("width", w)
		  .attr("height", h)
		  .attr("style", "")
		  .insertBefore(divReference);
		
		divReference.remove();
		
		coreAnimator($, sa, smirk);
  
  }
  
  

  smirkAnimatorStart = function($) {
    
       
		$(".smirktacular").each(function() {
		  
			var nv = parseNvClasses($(this).attr("class"));
			
			var sa = new smirkAnimation();
			sa.uuid = nv.uuid;
			sa.iid = (nv.iid) ? nv.iid : 0;
			sa.targetElement = this;
			sa.loop = nv.loop == 'true' ? true : false; // comes over as a string, not bool
			if (! sa.loop) { 
				var index = smirkQueue.length;
				sa.shouldAnimate = false;
				$(this)
					.bind("mouseover", function() {
						smirkQueue[index].shouldAnimate = true;
					})
					.bind("mouseout", function() {
						smirkQueue[index].shouldAnimate = false;
					});
			}
			$.getJSON("/smirks/jsonp?u="+sa.uuid+"&i="+sa.iid+"&jsoncallback=?", function(json) {
				
				if (json) {
				  
				  coreAnimator($, sa, json.smirk);
				  
				}
				else return;
			
			});
			
		});
		
	}
	
	startAnimationLoop = function() {
	 if (! animationRef) { 
	 
	   if (animationRef) clearInterval(animationRef);
				  
		  animationRef = setInterval(function() {
		
				for (var x = 0; x < smirkQueue.length; x++) {
				
					var sa = smirkQueue[x];
					if (sa.shouldAnimate) {
					
						if (sa.currentFrame > sa.smirkFrames) {
						
							sa.currentFrame = sa.smirkFrames - 1;
							sa.forwards = false;
							
						}
						
						else if (sa.currentFrame < 1) {
						
							sa.currentFrame = 2;
							sa.forwards = true;
							
						}
						
						// calculate top and left offsets
						var rows = Math.floor(sa.currentFrame / 5)
						var cols = sa.currentFrame % 5;
						var top = rows * sa.increment * -1;
						var left = cols * sa.increment * -1;
						
									
						$(sa.targetElement).css({top: top, left: left})
							
						if (sa.forwards) sa.currentFrame ++;
						else sa.currentFrame --;
					}
				}
			
			}, __frameDelay);
	 
	  }
	}
	
	
	smirkAnimatorLoad = function($) {
	
		$(function() {
		
			if ($(".smirktacular").length > 0) {
  	
  			if (typeof(smirkFrameDelay) != 'undefined') __frameDelay = smirkFrameDelay;
  			smirkAnimatorStart($)
		
			}
			
		});
	
	}
	
	function smirkAnimation() {
		this.imageObjects = Array();
		this.imageBase = "";
		this.smirkFrames = 24; // there are 25 frames, but 0 counts.
	  this.imageObjects = new Array(24); // total frames is 25 for now
		this.forwards = true;
		this.currentFrame = 1;
		this.isS3 = false;
		this.shouldAnimate = true;
		this.uuid = "";
		this.targetElement = "";
		this.increment = 0;
	}
	
	if (typeof(jQuery) == 'undefined') {
		var jq = document.createElement("script")
		jq.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js";
		document.documentElement.getElementsByTagName("HEAD")[0].appendChild(jq);
		var jqLoad = setInterval(function() {
			if (typeof(jQuery) != 'undefined') {
				jQuery.noConflict();
				clearInterval(jqLoad);
				smirkAnimatorLoad(jQuery);
			}
		}, 25);
	}
	else {
		smirkAnimatorLoad(jQuery);
	}

	
	
})();




$(function() {

  $("#sign-up-link").click(function() {
  
    $("#smirk-login-form-home").hide();
    $("#smirk-signup-form").show().css({height: 520});
    
    $(".tab-selected").removeClass("tab-selected").addClass("tab");
    $(this).addClass("tab-selected");
    
    $("#log-in-link").empty().append("Login");
    
    $(this).empty();
    $(this).append(
      $("<img src='/images/btn-close-login-up.png'>").click(function(e) {
        e.stopPropagation();
       	$(".tab-selected").removeClass("tab-selected").addClass("tab");
        $("#sign-up-link").empty().append("Sign up");
        $("#sign-in-drawer").animate({height: 1}, 100, function() {
          $("#sign-in-drawer").hide();
        });
      })
    );
     
    // add flag to default the LB view to NEW
    $("#sign-in-drawer").css({overflow: "hidden", height: 1}).show().animate({height: 400}) 
  
    return false;
  });
  
  
  $("#log-in-link").click(function() {

    $("#smirk-signup-form").hide();
    $("#smirk-login-form-home").css({height: 250}).show();
    
    $("#sign-up-link").empty().append("Sign up")
    $(".tab-selected").removeClass("tab-selected").addClass("tab");
    $(this).addClass("tab-selected");
    $(this).empty();
    
    $(this).append(
      $("<img src='/images/btn-close-login-up.png'>").click(function(e) {
        e.stopPropagation();
				$(".tab-selected").removeClass("tab-selected").addClass("tab");       
        $("#log-in-link").empty().append("Login");
        $("#sign-in-drawer").animate({height: 1}, 100, function() {
          $("#sign-in-drawer").hide();
        });
      })
    );
    
    $("#sign-in-drawer").css({overflow: "hidden", height: 1}).show().animate({height: 230})
    
    return false;
  });
  
  
  // robo animator  
  $("#robo").animate({ left: 90 }, 1500, "easeInOutSine", function() {
    $("#robo").animate({ left: 10 }, 800, "easeInOutExpo");
  });
  
  
  
	// Marketing Animator ******************************************************************
	
  var c = 1;
  var n = c + 1;
  
	function rotateDivs()
	{ 
		// page animation	
		$(".page-active").slideUp();
		$(".page-active").removeClass("page-active");
		$("#page-" + n).addClass("page-active");
		$(".page-active").slideDown();
		
		// paginator
		$(".m-page-active").addClass("m-page-inactive");
		$(".m-page-active").removeClass("m-page-active");
   	$("#p-" + n).removeClass("m-page-inactive");
    $("#p-" + n).addClass("m-page-active");	 
    
    // move the robot!
    if (n == 4)
    {
  	  $("#robo").animate({ left: 300 }, 600, "easeInSine", function() {
   		 $("#robo-self").animate({ left: 90 }, 600, "easeOutSine");
   		 openEyes();
   		});
    }
    else 
    {
    	$("#robo").animate({ left: 10 }, 1500, "easeInOutSine");
    	$("#robo-self").animate({ left: -250 }, 1100, "easeInOutSine");
    }
 
 		// turn the page appropriately
    c = n;
		if (c+1 == 5)
		{
			n = 1;
		}
		else
		{
			n = c + 1;
		}
	}
	
	// this is our ferris wheel friend
	var marketingAnimator = setInterval(rotateDivs, 7000);
	
	//this make the rec blipper blip
	var recBlipper = setInterval(doBlip, 500);
	var blipIsShowing = true; //start with it showing
	
	function doBlip() 
	{
		if (blipIsShowing) 
		{
			$("#rec-blip").hide();
			blipIsShowing = false;
		}
		else
		{
			$("#rec-blip").show();
			blipIsShowing = true;
		}	
	}


	//this makes ROBO BLINK!!!
	var roboBlink = setInterval(doBlink, 500);
	
	function doBlink() 
	{
		var r = Math.floor(Math.random()*4);
		
		if (r == 3)
		{
			$("#robo-eyes").slideDown(80);
			$("#robo-eyes-mid").slideDown(80);
			$("#robo-eyes-sm").slideDown(80, openEyes); // show eyes closed
			
		}
	}
	
	function openEyes()
	{
		$("#robo-eyes").slideUp(150); // reveal open eyes
		$("#robo-eyes-mid").slideUp(150);
		$("#robo-eyes-sm").slideUp(150);
	}

	
	// make the little guys clickable for the impatient ones
	
	$("#p-1").click(function()
	{	
		n = 1;
		rotateDivs();
	});
	$("#p-2").click(function()
	{	
		n = 2;
		rotateDivs();
	});
	$("#p-3").click(function()
	{	
		n = 3;
		rotateDivs();
	});
	$("#p-4").click(function()
	{	
		n = 4;
		rotateDivs();
	});
  
  
  
  
  
});

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var windowTimer = false;
var animationRunner = false;

$(document).ready(function(){
	////////////////////////////////////////////////////////
	//////////// handle description pop up boxes
	////////////////////////////////////////////////////////
	/*

	var x = 0;
	var y = 0;
	
	$().mousemove(function(e){
			x = e.pageX;
			y = e.pageY;
	});
	
	var hoverTimer = false;
	var descriptionShowing = false;
	
	function setTimedHover(thisElement) {
			hoverTimer = setTimeout(function(){
					var w = 0;
					var h = 0;
					var calcXpos = 0;
					var calcYpos = 0;
					
					var roboTip = $(thisElement).attr('robotip');
					
					descriptionShowing = true;
					$('#description-box').empty().append(roboTip);
					w = $('#description-box').width();
					h = $('#description-box').height();
					
					calcXpos = x - (w + 30);
					calcYpos = y - (h + 30);
					
					if(calcXpos < 0 || calcYpos < 0) {
							$('#description-box').css({top:y + 20, left:x + 20}).fadeIn(900);
					}else{
							$('#description-box').css({top:calcYpos, left:calcXpos}).fadeIn(900);
					}
					
					
					hoverTimer = false;
			
			}, 1000);
	}
	
	function cancelTimedHover() {
			if(hoverTimer) {
					clearTimeout(hoverTimer);
					hoverTimer = false;
			}
	} 

	$('.description-hover').hover(
			function(){
					var thisElement = this;
					setTimedHover(thisElement);
			}, 
			function(){
					cancelTimedHover();
					if(descriptionShowing == true) {
							$('#description-box').fadeOut(500, function(){descriptionShowing = false;});
					}
			}
	);
	
	*/
	////////////////////////////////////////////////////////
	
	
	////////////////////////////////////////////////////// abuse
  $('#report-abuse').click(function() {
  		if( $('#report-abuse-box').css('display') == 'none' ) {
  				$('#report-abuse-box').slideDown(300);
  		}else{
  				$('#report-abuse-box').slideUp(300);
  		}
  		return false;
  });

	$('#abuse-report-textarea').focus(function(){
			if( $('#abuse-report-textarea').attr('value') == $('#abuse-report-textarea').attr('defaultvalue') ) {
					$('#abuse-report-textarea').attr('value', '');
			}	
	});
	
	$('#abuse-report-submit').click(function() {
			var wl = window.location;
			$.getJSON('/users/report_abuse', $('#abuse-form').serialize()+'&tv=false'+'&wl='+wl, function(data){
					if(data.response == 'worked') {
							$('#abuse-report-textarea').attr('value', $('#abuse-report-textarea').attr('defaultvalue') );
							$('#report-abuse-box').slideUp(300);
							$('#abuse-report-feedback').empty().append('Received').slideDown(300);
					}
			});
	});
	
	$('#abuse-cancel').click(function(){
			$('#report-abuse-box').slideUp(300);
			return false;
	});
	//////////////////////////////////////////////////////
	
	
	
	
	///////////////////////////////////////////////////////////////////// hover jpeg animator
	var animatorOnTimer = 400; // how long it takes on mouseover to activate the animator (lower number is faster)
	var animatorSpeed = 75; // play back speed (lower number is faster)
	var framesPerRow = 5; // right now the tiles are 5 by 5, but if that changes, the values go here
	var frameRows = 5;  // right now the tiles are 5 by 5, but if that changes, the values go here
	
	var windowTimer = false;
	var animationRunner = false;
	var contextWidth = false;
	var contextHeight = false;
	
	$('.smirk-animated').live('mouseover', function() {
			var thisImg = this;
			var sid = $(thisImg).attr('sid');
			

			if (animationRunner) {
			 clearInterval(animationRunner);
			 animationRunner = false;
		  }

			clearTimeout(windowTimer);
			windowTimer = false;
			windowTimer = setTimeout(function() { // hover timer
					
					$.getJSON('/smirks/get_animated', 'sid='+sid, function(data) {
							
							if(data.response == 'worked') {
									
									contextWidth = parseInt( $(thisImg).attr('defaultsizesquared') ); // find original thumbnail dimensions so we can scale the tiles
									contextHeight = parseInt( $(thisImg).attr('defaultsizesquared') );
									
									var tmpImage = new Image();
									tmpImage.src = data.tiled;
									tmpImage.onload = function() {
									
											
											var w = tmpImage.width;
											var h = tmpImage.height;
											var frameWidth = w / framesPerRow; // calculate frame width and height from how many frames there are in the image
											var frameHeight = h / frameRows;
											
											
											// get scale
											var scale = contextWidth / frameWidth;
											
											$(thisImg).css({height:h * scale, width:w * scale}).attr('src', data.tiled); // recalculate image size and place in tiled image
											
											$(thisImg).addClass('animating');
											
											var x = 1;
											var y = 1;
											animationRunner = setInterval(function() {
													if(x < framesPerRow) { // go through columns
															$(thisImg).css({left: - ( (x * frameWidth) * scale)});
															x++;
													}else if(y < frameRows){ // go through rows
															$(thisImg).css({left: 0, top: - ( (y * frameHeight) * scale)});
															y++;
															x = 1;
													}else{ // reset to first row, first column
															$(thisImg).css({left: 0, top: 0});
															y = 1;
															x = 1;
													}
											
											}, animatorSpeed);
											
									} // end tmpImage.onload = function() {
							} // end if(data.response == 'worked') {
					});
					windowTimer = false;
			}, animatorOnTimer);
	});
	
	$('.smirk-animated').live('mouseout', function() {
			if(animationRunner) {
					clearInterval(animationRunner);
					animationRunner = false;
			}
			clearTimeout(windowTimer);
			windowTimer = false;
	});
	/////////////////////////////////////////////////////////////////////
	
	
	
	
});