JAME=function(){};JAME=JAME.prototype=function(){};JAME.VERSION=0.01;JAME.$=function(A){if(document.getElementById){JAME.$=function(B){if(document.getElementById(B)){return document.getElementById(B)}}}if(document.getElementById(A)){return document.getElementById(A)}};JAME.Package=function(B){var H=B.split(".")||[B];var A=H.length;var C=window;var G=function(){};for(var D=0;D<A;D++){var E=H[D];if(typeof (C[E])==="undefined"){C=C[E]=G;C=C.prototype=G}else{C=C[E]}}};JAME.Import=function(){var A=arguments.length;for(var B=0;B<A;B++){var C=arguments[B];if(C.Export!==undefined){C.Export()}else{if(C.prototype.Export!==undefined){C.prototype.Export()}}}};JAME.Exporter=function(B,A){if(!A){A=""}for(var C in B){if(C==="Export"||/^_/.test(C)){continue}window[A+C]=B[C]}};JAME.Export=function(){JAME.Exporter({Package:JAME.Package,Import:JAME.Import})};function extend(A,D){function C(E){if(typeof E._super=="undefined"){E._super=function(){var F=arguments[0];var G=arguments[1];this["__parent_methods"][F].apply(this,G)}}if(typeof E.__parent_methods=="undefined"){E.__parent_methods={}}}for(var B in D){if(typeof A[B]!="undefined"){C(A);A.__parent_methods[B]=D[B]}else{A[B]=D[B]}}}JAME.extend=function(A,C){if(typeof A.__parent_methods=="undefined"){A.__parent_methods={}}if(typeof A.SUPER=="undefined"){A.SUPER=function(){var D=arguments[0];var E=arguments[1];this["__parent_methods"][D].apply(this,E)}}for(var B in C){if(typeof A[B]!="undefined"){A.__parent_methods[B]=C[B]}else{A[B]=C[B]}}};JAME.Package("JAME.Util.String");JAME.Util.String={camelize:function(A){return A.replace(/-(.)/g,function(B,C){return C.toUpperCase()})},hyphenize:function(A){return A.replace(/([A-Z])/g,function(B,C){return"-"+C.toLowerCase()})},firstToUpperCase:function(A){return A.replace(/^([a-z])/,function(B,C){return C.toUpperCase()})},trim:function(A){return A.replace(/^\s+|\s+$/g,"")},Export:function(){JAME.Exporter(this)}};JAME.Package('JAME.Util.Number');JAME.Util.Number={d2h:function(A){return A.toString(16)},h2d:function(A){return parseInt(A,16)},Export:function(){JAME.Exporter(this)}};JAME.Package("JAME.Util.Queue");JAME.Util.Queue=function(A){this.q=[];this.paused=false;if(A){extend(this,A)}};extend(JAME.Util.Queue.prototype,{queue:function(){for(var A=0;A<arguments.length;A++){this.q.push(arguments[A])}return this},dequeue:function(){if(!this.empty()){this.q.pop()}return this},next:function(){if(this.empty()){this.inProgress=false;return }this.paused=false;this.inProgress=true;this.q.shift().apply(this);return this},flush:function(){while(!this.empty()){this.next()}},empty:function(){if(this.q.length==0){return true}return false}});JAME.Package("JAME.Util.Color");(function(){var B=JAME.Util.Number.d2h;var A=JAME.Util.Number.h2d;JAME.Util.Color={rgb2h:function(E,D,C){return[B(E),B(D),B(C)]},h2rgb:function(D,E,C){return[A(D),A(E),A(C)]},hexStr2rgbArray:function(C){return JAME.Util.Color.h2rgb(C.substring(1,3),C.substring(3,5),C.substring(5,7))},rgbStr2rgbArray:function(C){return C.substring(4,C.length-1).split(",")},cssColor2rgb:function(C){if(C.indexOf("rgb")<=-1){return JAME.Util.Color.hexStr2rgbArray(C)}return JAME.Util.Color.rgbStr2rgbArray(C)},Export:function(){JAME.Exporter(this)}}})();JAME.Package("JAME.HTMLMixin");JAME.HTMLMixin={set:function(B){B=B||{};for(var A in B){if(A=="class"){this.elm.className=B[A]}this.elm[A]=B[A]}return this},getElement:function(){return this.elm},add:function(){for(var A=0,B=arguments.length;A<B;A++){this.elm.appendChild(arguments[A].getElement());this.elm._elements.push(arguments[A])}return this},toQueryString:function(F){if(!F){return null}var D=[];for(var E in F){var A=F[E];A=(typeof A=="string")?[A]:A;for(var B=0,C=A.length;B<C;B++){D.push(encodeURIComponent(E)+"="+encodeURIComponent(A[B]))}}return D.join("&")},val:function(){}};JAME.Package("JAME.Form");JAME.Form=function(A,B){if(/form/i.test(A.nodeName)){B=A;A={}}this.elm=B||document.createElement("form");JAME.extend(this,JAME.HTMLMixin);this.set(A);this.elm._elements=[];this.getChildren()};JAME.extend(JAME.Form,JAME.HTMLMixin);JAME.Form.serialize=function(D){if(!D){return JAME.Form.toQueryString(D)}if(D.nodeName==="undefined"){return JAME.Form.toQueryString(D)}var F=D.elements;var E={};for(var B=0,C=F.length;B<C;B++){var G=F[B];if(!G.disabled){if(!/file/i.test(G.nodeName)){if(!E[G.name]){var A=JAME.Form.val(G);if(A&&A.length>0){E[G.name]=A}}}}}return JAME.Form.toQueryString(E)};JAME.Form.val=function(G){if(/select/i.test(G.nodeName)){var F=G.selectedIndex;var I=[];var J=G.options;if(F>0){for(var C=F,H=J.length;C<H;C++){var E=J[C];if(E.selected){value=(window.attachEvent&&!E.attributes.value.specified)?E.text:E.value;I.push(value)}}return I}}if(/text|hidden|password|file/i.test(G.type)||/textarea/i.test(G.nodeName)){if(G.value&&G.value!=""){var B=G.value;B=B.replace(/\r/,"");return[B]}}if(/checkbox|radio/i.test(G.type)){var I=[];var A=JAME.Form.getForm(G);var D=document.getElementsByName(G.name);if(D.length==1&&G.checked){return[G.value]}for(var C=0,H=D.length;C<H;C++){if(JAME.Form.getForm(D[C])===A&&D[C].checked){I.push(D[C].value)}}return I}return[]};JAME.Form.getForm=function(A){do{A=A.parentNode;if(/form/i.test(A.nodeName)){return A}}while(A)};JAME.extend(JAME.Form.prototype,{getChildren:function(){var C=this.elm.elements;for(var A=0,B=C.length;A<B;A++){var D=this.elm[A];if(/select/i.test(D.nodeName)){this.elm._elements.push(new JAME.SelectField(D))}else{this.elm._elements.push(new JAME.InputField(D))}}},getVals:function(){var E=this.elm._elements;var D={};for(var B=0,C=E.length;B<C;B++){var F=this.elm._elements[B];if(!F.getElement().disabled){if(!/file/i.test(F.getElement().nodeName)){if(!D[F.getElement().name]){var A=F.val();if(A.length>0){D[F.getElement().name]=A}}}}}return D}});JAME.Package("JAME.InputField");JAME.InputField=function(B,A){JAME.extend(this,JAME.HTMLMixin);if(B.nodeName){this.elm=B;return this}if(B=="textarea"){this.textarea(A)}else{this.input(B,A)}return this};JAME.extend(JAME.InputField.prototype,{val:function(){var A=this.elm.value||this.elm.innerHTML;if(A&&A!=""){A=A.replace(/\r/,"");return[A]}return[]},input:function(B,A,C){this.elm=C||document.createElement("input");this.elm.type=B;this.set(A);return this},textarea:function(A){this.elm=document.createElement("textarea");if(A.value){this.elm.innerHTML=A.value;delete A.value}this.set(A);return this}});JAME.Package("JAME.SelectField");JAME.SelectField=function(A,B){JAME.extend(this,JAME.HTMLMixin);if(/select/i.test(A.nodeName)){this.elm=A;return this}this.select(A,B);return this};JAME.extend(JAME.SelectField.prototype,{val:function(){var C=this.elm.selectedIndex;var A=[];var B=this.elm.options;if(C>=0){for(var D=C,F=B.length;D<F;D++){var E=B[D];if(E.selected){value=(window.attachEvent&&!E.attributes.value.specified)?E.text:E.value;A.push(value)}}return A}return[]},select:function(B,A){this.elm=document.createElement("select");this.set(B);for(var D in A){var C=document.createElement("option");C.value=D;C.innerHTML=A[D];this.elm.appendChild(C)}return this}});JAME.Package("JAME.Ajax");JAME.Ajax=function(A){this.options={url:A.url||"",type:A.type||"",method:A.method||"",vars:A.vars||null,timeout:A.timeout||16000,retryDelay:A.retryDelay||100,retryLimit:A.retryLimit||3,every:A.every||0,everyDecay:A.everyDecay||0,async:A.async||true,onSuccess:A.onSuccess||function(){},onError:A.onError||function(){}};this.retryCount=0;this.guessMethod();this.guessURL();this._init()};JAME.extend(JAME.Ajax.prototype,{_init:function(){var B=this;this.timer=setTimeout(function(){B.abortXHR();if(B.retryCount<B.options.retryLimit){B.retryCount++;setTimeout(function(){B._init()},B.options.retryDelay)}},this.options.timeout);this.xhr=this.getXHR();var C="";var A="";if(this.options.method=="POST"){C=JAME.Form.serialize(this.options.vars)}else{A=this.appendQueryString(JAME.Form.serialize(this.options.vars))}this.xhr.open(this.options.method,this.options.url+A,this.options.async);if(this.options.method=="POST"){this.xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");if(this.xhr.overrideMimeType){this.xhr.setRequestHeader("Connection","close")}}this.handleResponse();this.xhr.send(C)},guessURL:function(){if(this.options.url){return }var A=this.options.vars;if(A&&A.nodeName!=="undefined"){this.options.url=A.action;return }},guessMethod:function(){if(this.options.method){return }var A=this.options.url;if(/\?/.test(A)){this.options.method="GET";return }if(this.options.vars){this.options.method="POST";return }this.options.method="GET"},appendQueryString:function(B){var A=this.options.url;if(/\?.+/.test(A)){B="&"+B}else{if(/\?$/.test(A)){}else{if(this.options.vars){B="?"+B}}}return B||""},getXHR:function(){if(window.XMLHttpRequest){JAME.Ajax.prototype.getXHR=function(){return new XMLHttpRequest()}}else{if(window.ActiveXObject){var E;var B=["Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];for(var A=0,C=B.length;A<C;A++){try{E=function(){return new ActiveXObject(B[A])};E()}catch(D){continue}break}JAME.Ajax.prototype.getXHR=E}else{throw new Error("XMLHTTPRequest not supported...")}}return JAME.Ajax.prototype.getXHR()},handleResponse:function(){var A=this;this.xhr.onreadystatechange=function(){if(A.xhr.readyState==4){if(A.isStatusOK()){clearTimeout(A.timer);A.options.onSuccess(A.normalizeResponse())}else{A.options.onError()}A.xhr=null}}},isStatusOK:function(){try{if((!this.xhr.status&&window.location.protocol=="file:")||(this.xhr.status>=200&&this.xhr.status<300)||this.xhr.status==304||(navigator.userAgent.indexOf("Safari")>=0&&typeof this.xhr.status==="undefined")){return true}}catch(A){}return false},normalizeResponse:function(){var contentType=this.xhr.getResponseHeader("content-type")||-1;var data=(!this.options.type&&contentType.indexOf("xml")>=0);this.guessType();data=(this.options.type=="xml"||data)?this.xhr.responseXML:this.xhr.responseText;if(this.options.type=="js"){eval.call(window,data)}return data},guessType:function(){if(this.options.type){return this.options.type}if(/\.xml$/.test(this.options.url)){return"xml"}if(/\.js$/.test(this.options.url)){return"js"}},abortXHR:function(){if(this.xhr){this.xhr.abort()}clearTimeout(this.timer)}});JAME.Package("JAME.DOM");JAME.DOM={lastNode:function(A){if(!A.lastChild){return false}A=A.lastChild;return(A&&A.nodeType!=1)?JAME.DOM.prevNode(A):A},prevNode:function(A){if(!A){return false}do{A=A.previousSibling}while(A&&A.nodeType!=1);return A},nextNode:function(A){if(!A){return false}do{A=A.nextSibling}while(A&&A.nodeType!=1);return A},firstNode:function(A){if(!A.firstChild){return false}A=A.firstChild;return(A&&A.nodeType!=1)?JAME.DOM.nextNode(A):A},getText:function(D){var A=[];D=D.childNodes;for(var B=0,C=D.length;B<C;B++){A.push((D[B].nodeType!=1)?D[B].nodeValue:JAME.DOM.getText(D[B]))}return A.join("")},Ready:function(A){if(JAME.DOM.Ready.done){return A()}if(!JAME.DOM.Ready.timer){JAME.DOM.Ready.todo=[A];JAME.DOM.Ready.timer=setInterval(JAME.DOM.__isDOMReady,13)}else{JAME.DOM.Ready.todo.push(A)}},__isDOMReady:function(){if(JAME.DOM.Ready.done){return false}if(document&&document.getElementsByTagName&&document.getElementById&&document.body){clearInterval(JAME.DOM.Ready.timer);JAME.DOM.Ready.timer=null;var A=JAME.DOM.Ready.todo.length;for(var B=0;B<A;B++){JAME.DOM.Ready.todo[B]()}JAME.DOM.Ready.todo=null;JAME.DOM.Ready.done=true}},createNode:function(A){return document.createElement(A)},wrapNode:function(D,C){var B=JAME.DOM.createNode(C);var A=D.cloneNode(true);B.appendChild(A);oparent=D.parentNode;JAME.DOM.insertAfter(B,D);oparent.removeChild(D);return B},insertAfter:function(C,B){var A=B.parentNode;if(B==A.lastChild){A.appendChild(C)}else{A.insertBefore(C,JAME.DOM.nextNode(B))}},Export:function(){JAME.Exporter(this)}};JAME.Package("JAME.Events.EventDispatcher");JAME.Events.EventDispatcher=function(){this.listeners={}};extend(JAME.Events.EventDispatcher.prototype,{dispatch:function(C){var B=(this.listeners[C])?this.listeners[C].length:0;for(var A=0;A<B;A++){this.listeners[C][A].apply(this,arguments)}return this},addListener:function(B,A){if(this.listeners[B]){this.listeners[B].push(A)}else{this.listeners[B]=[A]}},removeListener:function(E,D){var A=this.listeners[E];for(var B=0,C=A.length;B<C;B++){if(A[B]===D){this.listeners[E].splice(B,1)}}}});JAME.Package("JAME.Events.Normalize");JAME.Events.Normalize=function(B){B=B||window.event;if(window.event){B.preventDefault=function(){this.returnValue=false};B.stopPropagation=function(){this.cancelBubble=true};B.target=B.srcElement;B.relatedTarget=(B.fromElement==B.target)?B.toElement:B.fromElement}if(B.target.nodeType==3){B.target=B.target.parentNode}if(B.pageX==null&&B.clientX!=null){var C=document.documentElement,A=document.body;B.pageX=B.clientX+(C&&C.scrollLeft||A.scrollLeft||0);B.pageY=B.clientY+(C&&C.scrollTop||A.scrollTop||0)}if(B.layerX==null&&B.offsetX!=null){B.layerX=B.offsetX||0;B.layerY=B.offsetY||0}if(!B.which&&(B.charCode||B.keyCode)){B.which=B.charCode||B.keyCode}if(!B.metaKey&&B.ctrlKey){B.metaKey=B.ctrlKey}if(!B.which&&B.button){B.which=(B.button&1?1:(B.button&2?3:(B.button&4?2:0)))}return B};var selectors=[" ",".","#","+",">","~",":","::","*","[","]",","];var keywords=[];function parse(H){var A=H.split("");var C=undefined;var F=undefined;if(A.length==1&&H=="*"){return $T("*")}for(var D=0,G=A.length;D<G;D++){if(selectors.indexOf(A[D])!=-1){C=A[D]}if(/[a-zA-Z0-9_-]/.test(A[D])){regex="^.{"+D+"}([a-zA-Z0-9_-]+)";var B=new RegExp(regex);var J=B.exec(H);var I=J[1];var E=getByClass(I,D,A,C,F);if(E){F=E;D=I.length-1+D;continue}var E=getId(I,D,A,C,F);if(I.length==A.length&&E){return E}if(E){F=E;D=I.length-1+D;continue}var E=getHTMLList(I,D,A,C,F);if(I.length==A.length&&E){return E}if(E){F=E;D=I.length-1+D;continue}var E=getDirectChildOf(I,D,A,C,F);if(I.length==A.length&&E){return E}if(E){F=E;D=I.length-1+D;continue}var E=getFirstSiblingOf(I,D,A,C,F);if(I.length==A.length&&E){return E}if(E){F=E;D=I.length-1+D;continue}D=I.length-1+D}}return F}function getId(B,D,E,A,C){if(A=="#"){return JAME.$(B)}return false}function getHTMLList(B,D,E,A,C){if((A==" "||!A)){return $TS(B,C)}return false}function getDirectChildOf(B,D,I,G,A){if(G==">"){tags=$TS(B,A);if(!tags){return }var E=[];for(var C=0,F=tags.length;C<F;C++){var J=tags[C];var H=J.parentNode;if(H&&H===A[0]){E.push(J)}}return E}return false}function getDirectSiblingOf(B,D,H,G,A){if(G=="+"){B=B.toLowerCase();var E=[];for(var C=0,F=A.length;C<F;C++){var I=A[C];I=next(I);if(n&&n.nodeName.toLowerCase()==B){E.push(n)}}return E}return false}function getFirstSiblingOf(C,E,I,H,B){if(H=="~"){C=C.toLowerCase();var F=[];B=(B.constructor===Array)?B:[B];for(var D=0,G=B.length;D<G;D++){var A=B[D];do{A=next(A);alert(A.nodeName)}while(A&&A.nodeName.toLowerCase()!=C);if(A){F.push(A)}}return F}return false}function getByClass(B,D,E,A,C){if(A=="."){if(/ /.test(E[D-2])){C=$TS(" ",C)}return $C(B,C)}return false}function $A__(A,C,B){if(B[A]==C){return B}if(parseInt(B[A])===C){return B}if(parseInt(B[A])===parseInt(C)){return B}}function $AS(A,G,E){E=(E.constructor!==Array)?[E]:E;var D=[];for(var B=0;B<E.length;B++){var C=E[B];var F=$A__(A,G,C);if(F){D.push(F)}}return(D.length>1)?D:D[0]}function $C(C,D){var A=[];D=D||document.body.getElementsByTagName("*");var F;for(var B=0,E=D.length;B<E;B++){F=D[B];if(F.className){if(F.className===C){A.push(F)}}}if(A.length==0){return }return(A.length>1)?A:A[0]}function $T(A,E){if(A=="body"){return document.body}var D=(E||document).getElementsByTagName(A);if(D.length==0){return }var B=[];for(var C=0,F=D.length;C<F;C++){B.push(D[C])}return(B.length>0)?B:undefined}function $TS(A,F){if(F===undefined){return $T(A)}F=(F.constructor!==Array)?[F]:F;var E=[];for(var C=0;C<F.length;C++){var D=F[C][0]||F[C];var G=$T(A,D);if(G){for(var B=0;B<G.length;B++){E.push(G[B])}}}return(E.length>1)?E:E[0]}if(!Array.prototype.indexOf){Array.prototype.indexOf=function(B){var A=this.length;var C=Number(arguments[1])||0;C=(C<0)?Math.ceil(C):Math.floor(C);if(C<0){C+=A}for(;C<A;C++){if(C in this&&this[C]===B){return C}}return -1}};JAME.Package('JAME.CSS');
JAME.CSS={
   setOpacity : function (obj,amount) {
      JAME.CSS.setOpacity=(window.attachEvent)
        ? function (obj,amount) {
            obj.style.zoom = 1;
            obj.style.filter = "alpha(opacity=" + amount*100 + ")";
			obj.style.opacity = amount;
          }
        : function (obj,amount) {
            obj.style.opacity = amount;
          }
       JAME.CSS.setOpacity(obj,amount);
   },
   _float : function() {
      var prop = (window.attachEvent) ? 'styleFloat' : 'cssFloat';
      JAME.CSS._float=function() { return prop; };
      return prop;
   },
   setStyle : function (elm,prop,val) {
      elm = (elm.constructor===Array) ? elm : [elm];
      for(var i=0;i<elm.length;i++) {
        if(prop=='opacity') { 
           JAME.CSS.setOpacity(elm[i],parseFloat(val));
           continue;
         }
         if(prop=='float')   prop = JAME.CSS._float();
         prop = JAME.Util.String.camelize(prop);
         unit=(prop=='zIndex'||prop=='zoom'||/olor/.test(prop)) ? '':'px';
		 if(prop=='zIndex') {
			elm[i].style[prop] = parseInt(val);
		 }
		 else {
         	try  { elm[i].style[prop] = (typeof val=='string') ? val : val+unit; }
			catch(e) {}
		}
      }
   },
   setStyles : function (elm,props) {
      for(var prop in props) {
        JAME.CSS.setStyle(elm,prop,props[prop]);
      }
   },
   getStyle : function (elm,style) {

        if (document.defaultView && document.defaultView.getComputedStyle) {
            JAME.CSS.getStyle = function(elm, style){

				if(!elm) return;
				style = JAME.Util.String.camelize(style);
                if(elm.style[style]) return elm.style[style];
				style = JAME.Util.String.hyphenize(style);
                var val = document.defaultView.getComputedStyle(elm, "").getPropertyValue(style);
                if (!/^[0-9]+/.test(parseInt(val)) && (style == 'height' || style == 'width')) {
                    val = JAME.CSS._getXorY(elm, style);
                }
                return val;
            }
        }
        else if (elm.currentStyle) {
            JAME.CSS.getStyle = function(elm, style){
       		    if(style=='float')   style = 'styleFloat';
				if(!elm) return;
				style = JAME.Util.String.camelize(style);
                if(elm.style && elm.style[style]) return elm.style[style];
                	var val= elm.currentStyle[style];
                	if (!/^[0-9]+/.test(parseInt(val)) && (style == 'height' || style == 'width')) {
                    	val = JAME.CSS._getXorY(elm, style);
                	}
                return val;
            }
        }
        return JAME.CSS.getStyle(elm,style);
    },
    _getXorY : function(elm,XY) {
        var mXY = (XY=='height') ? 'Height' : 'Width';

        if(JAME.CSS.getStyle(elm,'display')!='none') {
            return elm["offset"+mXY]>=0 ? elm["offset"+mXY] : JAME.CSS.getStyle(elm,XY);
		}
        var oldStyle = {
            display    : JAME.CSS.getStyle(elm,'display'),
            visibility : JAME.CSS.getStyle(elm,'visibility'),
            position   : JAME.CSS.getStyle(elm,'position')
        };
        JAME.CSS.setStyles(elm,{display:'',visibility:'hidden',position:'absolute'});
        var val = elm["client"+mXY]>=0 ? elm["offset"+mXY] : JAME.CSS.getStyle(elm,XY);
        JAME.CSS.setStyles(elm,oldStyle);
        return val;
    },
    Export : function() {
        JAME.Exporter(this);
    }
};
JAME.Package("JAME.FX");JAME.FX=function(A){A=A||{};this.duration=A.duration||700;this.fps=A.fps||40;this.easing=A.easing||function(C,B,E,D){return B+(E/D)*C};this.async=A.async||false;this.behavior=A.behavior||"stop:link";this.interval=Math.ceil(1000/this.fps);this.totalframes=Math.ceil(this.duration/this.interval);this.frame=1};JAME.extend(JAME.FX.prototype,{Tween:function(C,A){JAME.extend(this,new JAME.Util.Queue());JAME.extend(this,new JAME.Events.EventDispatcher());if(arguments[2]){this.paused=true}this.elm=C||this.elm;this.props=A||this.props;this.setProperties();this.setMultiInstance(arguments[2]);if((C&&A)||!this.tweener){this.tweener=new JAME.FX.CSSTweener(this.elm,this.props,this.totalframes,this.easing)}if(!this.setBehavior()){return this}this.elm.__ON=true;this.startingTime=new Date().getTime();var B=this;this.elm.effect=B;this.dispatch("onStart");this.timer=setInterval(function(){B.setAnimation.apply(B)},this.interval);return this},setAnimation:function(){this.actualTime=new Date().getTime();this.tweener.compute(parseInt((this.actualTime-this.startingTime)/this.interval));this.dispatch("onTween");if(this.actualTime>=this.startingTime+this.duration){this.stop()}},setProperties:function(){for(var A in this.extendProperties){if(A=="prototype"){continue}this.extendProperties[A].apply(this)}},reverse:function(){var B=this.props;for(var C in B){var A=this.props[C].end;this.props[C].end=this.props[C].start;this.props[C].start=A}this.elm=(this.elms&&this.elms.length)?this.elms.reverse():this.elm;this.Tween()},stop:function(){clearInterval(this.timer);this.tweener.compute(this.totalframes);this.paused=false;this.elm.__ON=false;this.dispatch("onComplete");this._cleanOut();this.next();return this},addToQueue:function(B){var A=this;B.queue(function(){return B.Tween(A.elm,A.props,1)})},_cleanOut:function(){this.elm.effect=null;this.elm.__ON=null},setBehavior:function(){if(this.elm.__ON===true){var A=this.elm.effect;if(this.behavior=="stop:link"){var B=A.props;for(var C in B){if(this.props[C]){this.props[C].start=A.elm.style[C]}}if(this.empty()){this.addToQueue(A)}A.stop();return }else{if(this.behavior=="stop:play"){clearInterval(A.timer);this.q=[];return true}else{if(this.behavior=="finish:play"||this.behavior=="finish:link"){this.addToQueue(A);return }else{if(this.behavior=="finish:skip"){return }else{this.elm.__ON=false;clearInterval(A.timer);this.q=[];return }}}}}return true},setMultiInstance:function(){var A=arguments[0];if(this.elm&&this.elm.constructor===Array){this.elms=this.elm;var C=this;if(this.async){for(var B=1;B<this.elm.length;B++){(function(){var D=C.elm[B];C.Tween(D,C.props)})()}}else{if(A===undefined){for(var B=1;B<this.elm.length;B++){(function(){var D=C.elm[B];C.queue(function(){C.Tween(D,C.props)})})()}}else{for(var B=this.elm.length-1;B>0;B--){(function(){var D=C.elm[B];C.q.unshift(function(){C.Tween(D,C.props)})})()}if(A){C.paused=false}}this.elm=this.elms[0]}}}});JAME.FX.prototype.extendProperties={CSS:function(){if(this.props.selector){var C=(this.props.selector.style)?this.props.selector.style:undefined;if(this.style!=C){this.style=C;var B=new JAME.E4CSS(C);var D=B[this.props.selector.start];var A=B[this.props.selector.end];for(var E in D){this.props[E]={start:D[E],end:A[E]}}}delete this.props.selector}},Auto:function(){var A={};for(var B in this.props){A[B]={};if(this.props[B].length==1){A[B]["end"]=this.props[B][0];A[B]["start"]=JAME.CSS.getStyle(this.elm,B)}if(this.props[B].length==2){A[B]["start"]=this.props[B][0];A[B]["end"]=this.props[B][1]}if(!this.props[B].length){A[B]["start"]=this.props[B]["start"];A[B]["end"]=this.props[B]["end"]}}this.props=A;A=null}};JAME.Package('JAME.FX.CSSTweener');
JAME.FX.CSSTweener = function(elm,props,frames,easing) {
this.elm = elm;this.props  = props;this.frames = frames;this.easing = easing; }
JAME.FX.CSSTweener.prototype ={
     compute : function(frame) {
       this.frame=frame;
       for(var prop in this.props){
	   this.prop = prop;
	   this.from = this.props[prop].start;
	   this.to   = this.props[prop].end;
          var method=JAME.Util.String.camelize(JAME.Util.String.firstToUpperCase(prop));
          if(this[method]) { this[method](); }
          else if(/[0-9]+/.test(parseInt(this.from)) && !/\s/.test(this.from)) {
 	       this.Numeric(); }
          else { this.String();}
     }
  },
  String : function(obj,ratio) {
	ratio=ratio || 0.2;var set = ((this.frame/this.frames)>=ratio) ? this.to : this.from;JAME.CSS.setStyle(this.elm,this.prop,set);
  },
  Numeric : function () {
      var begin  = (/[a-z]/.test(this.from)) ? parseInt(this.from)*10000 : this.from*10000;
      var end    = (/[a-z]/.test(this.to))   ? parseInt(this.to)  *10000 : this.to  *10000;
      var displacement = this.easing(this.frame, begin, end-begin, this.frames);
	  try {JAME.CSS.setStyle(this.elm,this.prop,displacement/10000);}catch(e){};
  }
};
JAME.Package('JAME.FX.Transition');JAME.FX.Transition.Linear=function(t, b, c, d) {return b + (c/d)*t;}
JAME.Package('JAME.FX.Transition.Sine');
JAME.FX.Transition.Sine ={
    In: function (t, b, c, d) { return -c * Math.cos(t/d * (Math.PI/2)) + c + b;},
    Out : function (t, b, c, d) { return c * Math.sin(t/d * (Math.PI/2)) + b;},
    InOut : function (t, b, c, d) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;}
}
JAME.Package('JAME.FX.Transition.Back');

JAME.FX.Transition.Back={
    In : function (t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c*(t/=d)*t*((s+1)*t - s) + b;
    },
    Out : function (t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
    },
    InOut : function (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;
    }
};
JAME.Package('JAME.FX.Transition.Basic');

JAME.FX.Transition.Basic= {

    table : {1:'Quad',2:'Cubic',3:'Quart',4:'Quint'},

    In : function(pow) {
	return this['In'+this.table[pow]];
    },
    Out : function(pow) {
	return this['Out'+this.table[pow]];
    },
    InOut : function(pow) {
	return this['InOut'+this.table[pow]];
    },
    InQuad : function (t, b, c, d) {
        return c*(t/=d)*t + b;
    },
    InCubic : function (t, b, c, d) {
        return c*(t/=d)*t*t + b;
    },
    InQuart : function (t, b, c, d) {
        return c*(t/=d)*t*t*t + b;
    },
    InQuint : function (t, b, c, d) {
        return c*(t/=d)*t*t*t*t + b;
    },
    OutQuad : function (t, b, c, d) {
        return -c *(t/=d)*(t-2) + b;
    },
    OutQuart : function (t, b, c, d) {
        return -c * ((t=t/d-1)*t*t*t - 1) + b;
    },
    OutCubic : function (t, b, c, d) {
        return c*((t=t/d-1)*t*t + 1) + b;
    },
    OutQuint : function (t, b, c, d) {
        return c*((t=t/d-1)*t*t*t*t + 1) + b;
    },
    InOutQuint : function (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;
    },
    InOutCubic : function (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;
    },
    InOutQuart : function (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;
    },
    InOutQuad : function (t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t + b;
        return -c/2 * ((--t)*(t-2) - 1) + b;
    }
};
JAME.Package('JAME.FX.Transition.Bounce');

JAME.FX.Transition.Bounce={
    In : function (t, b, c, d) {
         return c - JAME.FX.Transition.Bounce.Out(d-t, 0, c, d) + b;
    },
    Out : function (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; }
   },
   InOut : function (t, b, c, d) {
       if (t < d/2) return JAME.FX.Transition.Bounce.In(t*2, 0, c, d) * .5 + b;
       return JAME.FX.Transition.Bounce.Out(t*2-d, 0, c, d) * .5 + c*.5 + b;
   },
   Export : function() {
		JAME.Exporter(this,'Bounce');
   }
}
JAME.Package('JAME.FX.Transition.Circ');

JAME.FX.Transition.Circ={
    In : function (t, b, c, d) {
        return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
    },
    Out : function (t, b, c, d) {
        return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
    },
    InOut : function (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;
    }
};
JAME.Package('JAME.FX.Transition.Elastic');

JAME.FX.Transition.Elastic={

    //a: amplitude (optional), p: period (optional)
    In : function (t, b, c, d, a, p) {
        if (t==0) { return b; } 
        if ((t/=d)==1) { return b+c; }
        if (!p) { p=d*.3; }
        if (c==0 || a < Math.abs(c)) {  a=b+c; s=p/4; }
        else { a=Math.abs(c); 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;
    },
    Out : function (t, b, c, d, a, p) {
        if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
        if (c==0 || a < Math.abs(c)) { a=b+c; var s=p/4; }
        else {   a=Math.abs(c); 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;
    },
    InOut : function (t, b, c, d, a, p) {
        if (t==0) return b;  
        if ((t/=d/2)==2) return b+c;  
        if (!p) p=d*(.3*1.5);
        if (c==0 || a < Math.abs(c)) { a=b+c; var s=p/4; }
        else {a=Math.abs(c);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;
    },
    Export : function() {
        JAME.Exporter(this,'E');
    }
}
JAME.Package('JAME.FX.Transition.Expo');

JAME.FX.Transition.Expo={
    In : function (t, b, c, d) {
        return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
    },
    Out : function (t, b, c, d) {
        return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
    },
    InOut : function (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;
    }
};

    function $C(t,s) {
        var ar=[];

        s= s || document.body.getElementsByTagName('*');
        var e;
        for(var i=0,ln=s.length;i<ln;i++) {
            e=s[i];

            if(e.className) if(new RegExp('\s*'+t+'\s*').test(e.className)) ar.push(e);
        }
        if(ar.length==0) return;
        return (ar.length>1) ? ar : ar[0];
    }
JAME.extend(JAME.FX.CSSTweener.prototype, { 

    _position : ['Top','Right','Bottom','Left'],

    Padding : function () {
	this.setMultiPart('Numeric');
    },
    Margin : function () {
	this.setMultiPart('Numeric');
    },

    setMultiPart : function (method,sub) {
	var elms = this.splitMultiPart();
	if(sub==undefined) sub='';
	var i=0,j=0,k=0,l=0;
	if(elms.start.length==2) i=0,j=1,k=0,l=1;
	if(elms.start.length==3) i=0,j=1,k=2,l=1;
	if(elms.start.length==4) i=0,j=1,k=2,l=3;

	var v = [i,j,k,l];

	var prop=this.prop;

	for(var m=0;m<v.length;m++) {
		this.prop   = prop+this._position[m]+sub;
		this.from   = elms.start[v[m]];
		this.to     = elms.end[v[m]];
		this.bezier = elms.bezier[v[m]];
	   this[method]();
	}
    }, 
    splitMultiPart : function () {
	var start = this.from.replace(/(, )/g,function(m,l) { return ','});
	var end   = this.to.replace(/(, )/g,function(m,l) { return ','});

	var starts  = start.split(/\s/) || [];
	var ends    = end.split(/\s/)   || [];
	var beziers = (this.bezier) ? this.bezier.split(/\s/) : [];
	return {start:starts,end:ends,bezier:beziers};
    }
});
JAME.extend(JAME.FX.CSSTweener.prototype, { 
    BackgroundPosition : function () {
	     this.setBGMultiPart('Numeric');
    },
    setBGMultiPart : function (method) {
	    var elms = this.splitMultiPart();
      var begin  = (/[a-z]/.test(elms.start[0])) ? parseInt(elms.start[0])*10000 : elms.start[0]*10000;
      var end    = (/[a-z]/.test(elms.end[0]))   ? parseInt(elms.end[0])  *10000 : elms.end[0]  *10000;
      var displacementX = this.easing(this.frame, begin, end-begin, this.frames)/10000;
      begin  = (/[a-z]/.test(elms.start[1])) ? parseInt(elms.start[1])*10000 : elms.start[1]*10000;
      end    = (/[a-z]/.test(elms.end[1]))   ? parseInt(elms.end[1])  *10000 : elms.end[1]*10000;
      var displacementY = this.easing(this.frame, begin, end-begin, this.frames)/10000;
	  var value=displacementX+'px '+displacementY+'px';
      JAME.CSS.setStyle(this.elm,this.prop,value);
    }
});
JAME.Package('JAME.Events.EventDispatcher');JAME.Events.EventDispatcher=function() { this.listeners={} ; };JAME.extend(JAME.Events.EventDispatcher.prototype,{
    dispatch : function(event) {
        if(this.listeners[event]) {
        	for(var i=0;i<this.listeners[event].length;i++) {
            	this.listeners[event][i].apply(this,arguments);
			}
		}
        return this;
    },
    addListener : function (event,func) {
        if(this.listeners[event]) this.listeners[event].push(func);
        else this.listeners[event]=[func];
    },
    removeListener : function (event,func) {
        var funcs = this.listeners[event] || [];
        for (var i = 0, ln = funcs.length; i < ln; i++) {
			if (funcs[i] === func) {
				this.listeners[event].splice(i,1);
			}
		}

    }
});
function getDirectChildOf(searchTag,inLoop,aSelection,lastSelector,elms) {
    if(lastSelector=='>'){
        tags = $TS(searchTag,elms);

        if(!tags) return; 
        var ret=[];
        for(var i=0,ln=tags.length;i<ln;i++) { 
            var s=tags[i];
            var parent=s.parentNode;
            if(parent) for(var j=0,ln2=elms.length;j<ln2;j++) if(parent===elms[j]) ret.push(s);
        }

        return ret;
    }
    return false;
}
JAME.Package('JAME.DOM.Load');

JAME.DOM.Load = function ( F ) {
     var oldOnload = window.onload;
     if (typeof window.onload !== 'function') {
         window.onload = F;
     } else {
         window.onload = function() {
            oldOnload();
            F();
         };
     }
}

JAME.Package('JAME.E4CSS');

(function() {

    var instance;

    JAME.E4CSS = function (val) {
         if (instance) {
		 	if(instance.styleSheet===-1)
		 	return instance;
			
		 }
         instance = (this instanceof JAME.E4CSS) ? this.parse(val) : new JAME.E4CSS(val);
         return instance;
    }

})();

JAME.E4CSS.prototype={

      styleSheet:0,

      sheets: (document.styleSheets) ? document.styleSheets : undefined,

      lookupTable:{},

      getCssRules : function(val) {

        if(typeof val==='number') {
            this.styleSheet=val;
            if(val > this.sheets.length) return;
            return this.sheets[val]['cssRules'] || this.sheets[val]['rules'];
        }

        var regex=new RegExp(val);

        for(i=0; i< this.sheets.length;i++) {
            if(regex.test(this.sheets[i].href)) {
                this.styleSheet=i;
                return this.sheets[i]['cssRules']|| this.sheets[i]['rules'];
            }
        }
        return undefined;
    },

    getAll : function () {
        for(i=0; i< this.sheets.length;i++)
            this.parse(i);
		this.styleSheet=-1;//loaded everything
    },

    parse : function(cssFileName) {

        if(cssFileName===undefined) {
            this.getAll();
            extend(this,JAME.E4CSS.prototype);
            return this;
        }

        var rule=this.getCssRules(cssFileName);
        if(!rule) return;

        for(var i=0;i<rule.length;i++) {

            //get the selector of first rule
            var selector=rule[i].selectorText;
            if(!selector) continue;

            //get all the attributes of above selector
            var csss=rule[i].style.cssText.split(';');

            //temporary object to hold the actual selector
            var props={};

            for(var j=0;j<csss.length;j++) {

                    //split the string by :, get the attribute and value in array
                    //ie display in display: none;
                    var attr=csss[j].split(/:\s?/);

                    if(attr[0].length==1 || !attr[0] || !attr[1]) continue;

                    //lowercase the attribute as IE put all tags in uppercase
                    //and put in camel case
                    var tmp=JAME.Util.String.camelize(attr[0].toLowerCase());

                    //add the attribute with its value to the tmp obj;
                    props[JAME.Util.String.trim(tmp)]=attr[1];
            }

            //browsers are not consistent : some of them keep comma separated 
            //attributes as one selector, other change it into several one
            //therefore h1,h2{...}; can be h2 {...}; h1 {..};
            var selectors=selector.split(',') || [selector];

            for(k=0;k<selectors.length;k++) {

                //if we already have the selector in our main object
                //we add/overwrite the above values
                if(this[selectors[k]]) {
                    for(var attr in props)
                        this[selectors[k].toLowerCase()][attr]=props[attr];
                }
                //if the selector is not in the main object,
                // we just add the temporary object into it
                else 
                    this[selectors[k].toLowerCase()]=props;	

                // we keep track from where the selector comes, ie the style sheet number
                this.lookupTable[selectors[k].toLowerCase()]=this.styleSheet;
            }
        }

        return this;
    }
};


JAME.FX.prototype.extendProperties={

        CSS  : function() {


            if(this.props['selector']) {

               var style = (this.props['selector'][2]) ? this.props['selector'][2] : 0;
               if(this.style!=style) {
                    this.style=style;
                    var css    = new JAME.E4CSS(style);
                    var starts = css[this.props['selector'][0]];
                    var ends   = css[this.props['selector'][1]];
                    for(var prop in starts)  {
						this.props[prop]={};
						this.props[prop]["start"]=starts[prop];
						this.props[prop]["end"]  =ends[prop];
					}
               }
               delete this.props['selector'];
           }
       },
        Auto : function() {

            var nprops={};
            for(var prop in this.props) {
                nprops[prop]={};
                if (this.props[prop].length == 1) {
                    nprops[prop]["end"]   = this.props[prop][0];
                    nprops[prop]["start"] = JAME.CSS.getStyle(this.elm,prop);
                }
                if (this.props[prop].length == 2) {
                    nprops[prop]["start"] = this.props[prop][0];
                    nprops[prop]["end"]   = this.props[prop][1];
                }
                if (!this.props[prop].length) {
                    nprops[prop]["start"] = this.props[prop]["start"];
                    nprops[prop]["end"]   = this.props[prop]["end"];
                }
            }

            this.props=nprops;
			nprops=null;
       }
};
if(!Array.prototype.each) {
Array.prototype.each=function (fn,bind) {
    var that=this ||bind;
    for(var i=0;i < this.length ;i++) {
        (function() {
            var c=i;
            fn.call(that,that[c],c,that);
        })();
    }
}
}


JAME.Package('JAME.Components');

JAME.Components.Accordeon= function(options) {

	this.hidden     = options.hidden;
	this.hidden     = this.hidden && this.hidden.constructor===Array ? this.hidden : this.hidden ? [this.hidden] : [];
	this.visible    = options.visible;
	this.visible    = this.visible && this.visible.constructor===Array ? this.visible : this.visible ? [this.visible] : [];
	this.onExpand   = options.onExpand   || function() {};
	this.onClose    = options.onClose    || function() {};
	this.postExpand = options.postExpand || function() {};
	this.postClose  = options.postClose  || function() {};
	this.closing    = options.closing;
	this.hidden.each(
		function(link,i) {
			var maxHeight = parseInt(JAME.CSS.getStyle(link,'height'))+parseInt(JAME.CSS.getStyle(link,'padding-bottom'))+parseInt(JAME.CSS.getStyle(link,'padding-top'));
			var olink = JAME.DOM.wrapNode(link,'div');
			olink.style.overflow='hidden';
			olink.maxH=maxHeight;
			olink.style.display='none';
		}
	);

	this.openedAccordeon = (options.opened===-1) ? undefined : options.visible[options.opened] || options.visible[0];

	if(this.openedAccordeon) {
		this.openedAccordeon.opened=true;
		this.expand(this.openedAccordeon);
	}

	var me = this;

	this.visible.each(
		function(title,i) {
			title.pos=i;
			title.originalColor=title.style.color;
			 title.opened=false;
			if(i===options.opened)  title.opened=true;
			title.style.cursor='pointer';
			title.onclick=function(e) {
				e = JAME.Events.Normalize(e);
				title.event=e;

				if(me.isAnimating || me.isAnimating2) return;
				if(me.openedAccordeon===title && !me.closing) return;
				if(me.openedAccordeon===title){
					 me.toggle(me.openedAccordeon);
					me.openedAccordeon=undefined;
					return;
				}
				var opened = me.openedAccordeon;
				var ret  = me.toggle(this);
				if(!ret) {
					if(opened) me.toggle(opened);
				}
			}
		}
	);

	
};

JAME.Components.Accordeon.prototype = {
	close : function (elm) {
		var me = this;
		me.onClose(elm);
		if(!elm) return;
		var sibling = JAME.DOM.nextNode(elm);
		if(!sibling) return 	elm.opened=false;
		this.isAnimating=true;
		new JAME.FX({duration:550,easing:JAME.FX.Transition.Expo.Out}).Tween(sibling,{height:[sibling.maxH,0]}).queue(
		function() {
			sibling.style.display='none';
			me.postClose(elm);
			me.isAnimating=false;
		});
		elm.opened=false;
	},
	expand : function (elm) {
		var me = this;
		var ret = me.onExpand(elm);
		if(ret) return ret;
		if(!elm) return ;
		var sibling = JAME.DOM.nextNode(elm);
		if(!sibling) {
			elm.opened=true;
			this.openedAccordeon = elm;
			return;
		}
		this.isAnimating2=true;
		var mfx = new JAME.FX({duration:1550,easing:JAME.FX.Transition.Expo.Out}).Tween(sibling,{height:[0,sibling.maxH],display:['none','block']});
		mfx.queue(function() {
			me.postExpand(elm);
			me.isAnimating2=false;
		});
		elm.opened=true;
		this.openedAccordeon = elm;
	},
	toggle : function(elm) {
		if(elm && elm.opened)
			return this.close(elm);
		return this.expand(elm);
	}
};

JAME.Package('JAME.Components.BGRound');


JAME.Components.BGRound = function(options) {

	this.setMaxImage(options.maxImage);
	this.setPath(options.path);
	this.mainContainer = options.mainContainer;
	this.containerWrap = options.containerWrap;
	this.lastItems=[];
 	this.shuffle      = options.shuffle || false;
	this.topImage     = options.topImage || 1;
	this.img.src = this.path+this.topImage+'.jpg';
	var self=this;
	JAME.extend(this,new JAME.Events.EventDispatcher());
	this.img.onload=function() {

		JAME.CSS.setStyles(self.mainContainer,{
			backgroundImage:'url('+self.path+self.topImage+'.jpg'+')',
			backgroundPosition:'0px 0px'
		});

		self.next =self.topImage+1;
		if(self.next>self.maxImage) self.next=1;

		self.setHiddenBG(self.path+self.next+'.jpg');
		self.topImage     =self.next;

		if(self.maxImage>1) self.start();
		self.img.onload=null;
	}
};

JAME.Components.BGRound.prototype={

	setPath     : function(path) {
		if(!path) throw new Error('must provide a path');
		this.path     = path;
	},

	setMaxImage : function(int) {
		this.maxImage= int ? parseInt(int) : 4;
	},

	stop : function() {
		if(this.interval) clearTimeout(this.interval);
	},

	start : function() {
		var self=this;
		this.stop();
		this.dispatch('onBGDisplay',this.topImage);
		this.interval = setTimeout(function() {
			self.slideBG();
		},6000);
	},

	effects : [
		'435px 0px',
		'0px -500px',
		'-435px 0px',
		'0px 500px'
	],
	img : JAME.DOM.createNode('img'),

	slideBG : function(doesNext) {

		var self = this;
		this.stop();

		if(this.lastItems.length==2) this.lastItems=[];

		this.lastItems.push(self.topImage);

		this.img.onload=function() {

			var effect = self.effects[Math.round(Math.random()*3)];
				if(self.shuffle){
					self.next = 1+Math.round(Math.random()*(self.maxImage));

					for(var i=0;i<self.lastItems.length;i++) {
						if(self.next===self.lastItems[i]) self.next = 1+Math.round(Math.random()*(self.maxImage));
					}
				}
				else 	
				 self.next++;



				if(self.next > self.maxImage) self.next=1;
				self.setHiddenBG(self.path+self.next+'.jpg');
				self.topImage=self.next;
			var fx   = new JAME.FX({duration:1200,easing:JAME.FX.Transition.Back.In}).Tween(self.mainContainer, 
			{
				backgroundPosition:['0px 0px',effect]
			});


			fx.addListener('onComplete',function() {

				JAME.CSS.setStyles(self.mainContainer,{
					backgroundPosition:'0px 0px',
					backgroundImage:'url('+self.path+''+self.topImage+'.jpg)'
				});

				if(!doesNext) self.start();
			});
		}

		this.img.src = self.path+self.topImage+'.jpg';

	},

	setHiddenBG: function(path) {
		JAME.CSS.setStyles(this.containerWrap,{backgroundImage:'url('+path+')',backgroundPosition:'1px 1px'
});
	}
	
};

JAME.Package('JAME.Components');

JAME.Components.Checkbox = function(options){

		this.container = options.container;
		this.labelText = options.label;
		this.name      = options.name;
		this.value     = options.value;
		this.checked   = options.checked;
		JAME.extend(this,new JAME.Events.EventDispatcher());
		this._createCheckBox();
};

JAME.Components.Checkbox.prototype = {

	value : function() {
		return this.checkBox.checked ? this.value : undefined;
	},
	getElement : function() {
		return this.checkBoxContainer;
	},
	_createCheckBox : function() {

		this.checkBoxContainer = JAME.DOM.createNode('div');
		var me  = this;
		this.checkBox = JAME.DOM.createNode('div');
		this.checkBox.value = function() {
			return me.checkBox.checked ? me.value : undefined;
		}
		this.checkBox.className = 'jcheckbox';
		var me = this;
		this.checkBoxContainer.onclick = function(e) {
				e = JAME.Events.Normalize(e);
				me.checkBox.checked ? me.uncheck() : me.check();
				me.dispatch('click',me.checkBox);
		}

		this.checkBoxContainer.appendChild(this.checkBox);

		JAME.CSS.setStyles(this.checkBox,{
			width:7,
			height:7,
			fontSize:1,
			backgroundColor:'white',
			border:'1px solid #555',
			'margin-right':5,
			cursor:'pointer',
			float:'left',
			zIndex:5000
		});
		JAME.CSS.setStyles(this.checkBoxContainer,{
			height:7
		});
		this.checkedBox = JAME.DOM.createNode('div');
		JAME.CSS.setStyles(this.checkedBox,{
			width:5,
			height:5,
			backgroundColor:'black',
			'margin':1
		});
		this.checkedBox.value = function() {
			return me.checkBox.checked ? me.value : undefined;
		}
		this.checkBox.appendChild(this.checkedBox);

		this.checked ? this.check() : this.uncheck();

		this.label           = JAME.DOM.createNode('div');
		this.label.innerHTML = this.labelText;
		JAME.CSS.setStyles(this.label,{
			height:7,
			lineHeight:7,
			fontSize:9,
			display:'inline'
		});
		this.checkBoxContainer.appendChild(this.label);

	},
	uncheck : function() {
		this.checkedBox.style.visibility='hidden';
		this.checkBox.checked = false;
	},
	check : function() {
		this.checkedBox.style.visibility='visible';
		this.checkBox.checked = true;
	}
};
JAME.Components.CrossFader= function(options) {	

		this.delay      = options.delay      || 7000;
		this.transition = options.transition || 2000;
		this.current    = 0;
		this.imgs       = options.imgs      || parse('.JCrossFader img');
		this.imgs       = this.imgs && this.imgs.constructor===Array ? this.imgs : this.imgs ? [this.imgs] : undefined;
		this.imgsToLoad = options.imgsToLoad ||[];
		this.container  = options.container;

		if(!this.imgs) throw('no images to cross-fade');

		if(this.imgs.length==1 && this.imgsToLoad.length==0) return;

		this.max = this.imgs.length-1;

		this.setImgsStyle();
		if(this.imgsToLoad.length==0)
			this.start();
		
};

JAME.Components.CrossFader.prototype = {

	start:function(){
		var me =this;
		this.running=true;
		new JAME.FX({duration:10}).Tween(this.imgs[0],{opacity:[0,1]}).addListener('onComplete',function() {me.round()});
	},
	setImgsStyle : function() {
		var me=this;
		this.imgs.each(function(elm) {
			me.setImgStyle(elm);
		});
	},
	setImgStyle:function(elm){

		if(elm.nodeName.toLowerCase()!=='img') return;

		JAME.CSS.setStyles(elm,{
			opacity:0,
			position:'absolute',
			top:0,
			left:0,
			zIndex:1
		});
	},
	stop : function() {
		this.running=false;
	},
	restart : function() {
		if(this.running===false) {
			this.running=true;
			this.round();
		}
	},
	fadein : function(current) {
		var effect        = {};
		effect['opacity'] = [0,1];

		var transition=this.transition;
		effect['left'] = [this.current%2 ? -5:5,0];
		return new JAME.FX({duration:transition,easing:JAME.FX.Transition.Sine.Out}).Tween(this.imgs[current],effect);
	},
	fadeout : function(current) {
		var effect        = {};
		effect['opacity'] = [1,0];
		var transition    = this.transition;
		return new JAME.FX({duration:transition}).Tween(this.imgs[current],effect);
	},
	round : function() {
		var me=this;
		if(!this.running) {
			clearTimeout(this.timeout);
			return;
		}
		this.current++;

		if(this.current>this.max && this.imgsToLoad.length>0) {
			clearTimeout(this.timeout);
			var newImg = this.imgsToLoad.shift();
			var img    = JAME.DOM.createNode('img');
			img.onload = function(e){
				me.imgs.push(img);
				me.max=me.imgs.length-1;
				me.current=me.max;
				me.setImgStyle(img);
				me.container.appendChild(img);
				me.goRound();
			}
			img.onabort=img.onerror=function(e){
				me.round();
			}
			img.src=newImg;
			return;
		}
		
		if(this.current>this.max) {
			this.current=0;
		}
		this.goRound();
	},
	goRound:function(){
		var me = this;
		this.timeout = setTimeout(function() {

			me.fadein(me.current).addListener('onComplete',function() { me.round() });
			me.fadeout(me.current===0 ? me.max : me.current-1);

		},this.delay);
	}
};

JAME.Components.Panels = function(options) {

	this.container          = options.container;
	this.navContainer       = options.navContainer || this.container;
	this.panels             = options.panels;
	this.panelWidth         = options.panelWidth;
	this.onCreateNavigation = options.onCreateNavigation || function() {};
	this.isNavigationOff    = options.navigationOff      || false;
	this.speed              = options.transition         || false;
	this.onNavigationClick  = options.onNavigationClick  || function(){};
	options.padding			= options.padding || 0;
	this.interval           = undefined;
	options.customId		= options.customId||'';
	if(JAME.$('jpanels-gallery-nav')){
		++JAME.Components.Panels.counter;
		options.customId='panel'+JAME.Components.Panels.counter+'_';
	}
	JAME.extend(this,new JAME.Events.EventDispatcher());

	this.animationInstance  = undefined;
	var me = this;

	options.to   	   = options.to || 'left';

	var moveOf		   =(options.to=='top') ? ['height','bottom','top'] : ['width','left','right'];

	var width          = parseInt(JAME.CSS.getStyle(this.container,moveOf[0]));
	var totalWidth     = 0;
	var links          = '';

	for(var i=0,ln=this.panels.length;i<ln;i++) {
		var w      = this.panelWidth || parseInt(JAME.CSS.getStyle(this.panels[i],moveOf[0]));
		totalWidth+=w;
		totalWidth+=parseInt(JAME.CSS.getStyle(this.panels[i],'padding-'+moveOf[1]));
		totalWidth+= parseInt(JAME.CSS.getStyle(this.panels[i],'padding-'+moveOf[2]));
		var style = {
			float:(options.to=='left')?'left':'none',
			textAlign:'center'
		};
		style[moveOf[0]]=w;
		JAME.CSS.setStyles(this.panels[i],style);

		if(this.isNavigationOff) {
			continue;
		}
		var display = this.onCreateNavigation(this.panels[i],i) || i+1;

		links+='<a href="#" class="'+options.customId+'goto" id="'+options.customId+'counter_'+i+'">'+display+'</a>';
	};

	if(totalWidth<=width) return this;


	var containerWidth = this.panelWidth || width;

	var style={};
	style[moveOf[0]]=parseInt(containerWidth)*(this.panels.length+2);

	JAME.CSS.setStyles(this.container,style);

	var style={
		position:JAME.CSS.getStyle(this.container,'position'),
		left   : JAME.CSS.getStyle(this.container,'left'),
		top    : JAME.CSS.getStyle(this.container,'top')
	};

	var basePosition = JAME.CSS.getStyle(JAME.$(me.container.id),'position');
	JAME.CSS.setStyles(this.container,{
		position:'static',
		overflow:'hidden'
	});

	var div = JAME.DOM.wrapNode(this.container,'div');
	div.id=options.customId+"jpanels-container-overflow";
	var style={overflow:'hidden',clear:'both'};
	style[moveOf[0]]=width;
	JAME.CSS.setStyles(div,style);

	if(!this.isNavigationOff) {
		var customId = options.customId ? '<div id='+options.customId+'>' : '<div>';
		var nav = customId+'<div id="'+options.customId+'jpanels-gallery-nav">'+
			'<div><a href="#" class="goPrev">&laquo;&laquo;</a>'+
			'<span style="margin:0px;padding:0px;position:relative;top:0px;">'+
			'<div id="scrollbar"></div>';
		nav+=links;
		nav+='</span><a href="#" class="goNext">&raquo;&raquo;</a></div><br /></div></div>';
		var insert=JAME.DOM.createNode('div');
		insert.innerHTML=nav;
		div.parentNode.insertBefore(insert,div);
	JAME.CSS.setStyles(JAME.$('scrollbar'),{width:JAME.CSS.getStyle(parse('#'+options.customId+'jpanels-gallery-nav .goto')[0],'width')});

	}

	var elm_per_view = 0;
	var moveBy	     = 0;
	if(width>parseInt(JAME.CSS.getStyle(this.panels[0],moveOf[0]))) {
		moveBy = parseInt(JAME.CSS.getStyle(this.panels[0],moveOf[0])) + options.padding;
		var elm_per_view = Math.floor(width/parseInt(JAME.CSS.getStyle(this.panels[0],moveOf[0])))-1;
	}
	else 
		moveBy=width+options.padding;


	var actualImg = 0;
	var maxPos    = this.panels.length - elm_per_view;
	var topos     = parse("."+options.customId+"goto") || undefined;


	var activeStyles = {
		color : '#885544'
	};

	var setActiveStyle= (!options.isStyling) ? function(pos) {
		if(!topos) return;
		if(!topos[pos]) return;

		if(!topos[pos].oldStyle) {
			topos[pos].oldStyle={};
			for(var style in activeStyles) {
				if(JAME.CSS.getStyle(topos[pos],style))
				topos[pos].oldStyle[style]=JAME.CSS.getStyle(topos[pos],style);
			}
		}
		JAME.CSS.setStyles(topos[pos],activeStyles);
	} : function(pos) {
		if(!topos) return;
		if(!topos[pos]) return;
				topos[pos].className+=' activated';
		};

	var deactivateStyle= (!options.isStyling) ? function(pos) {
		if(!topos) return;
		if(!topos[pos]) return;

		if(topos[pos].oldStyle) {
			JAME.CSS.setStyles(topos[pos],topos[pos].oldStyle);
		}
	} : function(pos) {
			topos[pos].className = (topos[pos].className) ? topos[pos].className.replace('activated','') : '';
		};

	setActiveStyle(0);

	if(basePosition=='absolute') {
		var effectBase = {
			position:['absolute','absolute'],
			opacity:[.9,0.5]
		};
	}
	else {
		var effectBase = {
			position:['relative','relative'],
			opacity:[.9,0.5]
		};
	}

	this.goNext = function() {
		
		var pos = actualImg;

		deactivateStyle(pos);
		actualImg = (pos==maxPos-1) ? -1 : parseInt(actualImg); 
		actualImg=actualImg+1;

		me.moveScrollBar(actualImg);
		setActiveStyle(actualImg);
		var from = -(moveBy*pos);
		var to   = -(moveBy*actualImg);
		effectBase[options.to]=[from,to];
		me.animationInstance = new JAME.FX({duration:400}).Tween(JAME.$(me.container.id),effectBase);
		me.animationInstance.addListener('onComplete',function() {
			me.animationInstance=undefined;
			new JAME.FX({duration:200,easing:JAME.FX.Transition.Sine.In}).Tween(JAME.$(me.container.id),{opacity:[1]});
			if(me.isSlideShow && !me.interval) me.startSlideShow(me.isSlideShow);
		});
	}

	this.goPrev = function() {
	
		var pos = actualImg;
		deactivateStyle(pos);

		actualImg = (actualImg==0) ? parseInt(maxPos) : actualImg; 
		actualImg = parseInt(actualImg) - 1 ;

		me.moveScrollBar(actualImg);
		setActiveStyle(actualImg);
		var from = -(moveBy*pos);
		var to   =-(moveBy*actualImg);
		effectBase[options.to]=[from,to];
		me.animationInstance = new JAME.FX({duration:400}).Tween(JAME.$(me.container.id),effectBase);
		me.animationInstance.addListener('onComplete',function() {
			me.animationInstance=undefined;
			new JAME.FX({duration:200,easing:JAME.FX.Transition.Sine.In}).Tween(JAME.$(me.container.id),{opacity:[1]});
			if(me.isSlideShow && !me.interval) me.startSlideShow(me.isSlideShow);
		});

	}

	var me = this;
	var goNextListener = function(e) {
		e = JAME.Events.Normalize(e);
		e.stopPropagation();
		e.preventDefault();
		if(me.animationInstance)
			return;
		if(me.interval)
			me.stopSlideShow();
		me.goNext();
	}

	var goPrevListener = function(e) {
		e = JAME.Events.Normalize(e);
		e.stopPropagation();
		e.preventDefault();
		if(me.animationInstance) 
			return;
		if(me.interval) 
			me.stopSlideShow();
		me.goPrev();
	}

	
	this.moveScrollBar = (topos) ? function(pos) {
		var upTo=0;
		for(var i = 0;i<pos;i++) upTo+=parseInt(JAME.CSS.getStyle(topos[i],'width'));		

		new JAME.FX({duration:600,easing:JAME.FX.Transition.Back.InOut}).Tween(JAME.$('scrollbar'),{
			left : [parseInt(JAME.CSS.getStyle(JAME.$('scrollbar'),'left')),upTo],
			width: [parseInt(JAME.CSS.getStyle(JAME.$('scrollbar'),'width')),parseInt(JAME.CSS.getStyle(topos[pos],'width'))]
		});
	} :function(){};

	this.go = function(e) {

		e = JAME.Events.Normalize(e);
		if(e) e.preventDefault();
		var a=e.target;
		while(a) {
			if(a.nodeName.toLowerCase()==='a' && a.id.match('counter_')) {
				pos = a.id;
				a=undefined;
			}
			if(a) a = a.parentNode;
		}


		var parts = pos.split('counter_');
		pos = parts[1];
		me.onNavigationClick(actualImg,pos);
		me.moveTo(pos);
	}
	this.moveTo = function(pos) {

		if(!me.isNavigationOff) {
			me.moveScrollBar(pos);
			deactivateStyle(actualImg);
			setActiveStyle(pos);
		}
		effectBase[options.to]=[-moveBy*actualImg,-moveBy*pos];
		me.animationInstance = new JAME.FX({duration:400}).Tween(JAME.$(me.container.id),effectBase);
		me.dispatch('movingTo',pos);

		me.animationInstance.addListener('onComplete',function() {
			me.animationInstance=undefined;
			new JAME.FX({duration:200,easing:JAME.FX.Transition.Sine.In}).Tween(JAME.$(me.container.id),{opacity:[1]});
		});
		actualImg = pos;
	}

	if(this.isNavigationOff) return;

	if(topos) {
		topos.each(function(lm) {
			lm.onclick=me.go;
		});
	}
	var next  = parse("#"+options.customId+"jpanels-gallery-nav a.goNext");
	var prev  = parse("#"+options.customId+"jpanels-gallery-nav a.goPrev");
	next.onclick = goNextListener;
	prev.onclick = goPrevListener;
	this.isSlideShow = false;
	this.startSlideShow = function(time) {
		me.isSlideShow = time;
		me.interval = setInterval(function() {
			me.goNext();
		},time);
	}
	this.stopSlideShow = function() {
		clearInterval(me.interval);
		me.interval=undefined;
	}


}
JAME.Components.Panels.counter=0;

JAME.Package('JAME.Preloader');

JAME.Preloader  = function(elms,exts) {
	JAME.extend(this,new JAME.Util.Queue());
	JAME.extend(this,new JAME.Events.EventDispatcher());	

	var me = this;
	if(elms.length==0) 	{ 
		setTimeout(function() {
			me.dispatch('onLoadInit');
			me.dispatch('onLoadComplete');
		},100);
		return;
	}
	this.loaded,this.succeed,this.failed = 0;
	this.exts    = ['jpg','jpeg','png','gif'] || exts;
	this.findAssets(elms);
	this.assets = this.q.length;
	this.steps  = 300/this.assets;
	this.next();
	this.dispatch('onLoadInit');
};

JAME.Preloader.prototype = {
	loadAsset: function(elm,url) {
		var me  = this;
		var img = new Image();
		img.onload = img.onerror = img.onabort= function(e) {
			e = e || window.event;
			me.loaded++;
			me[e.type=='load' ? 'succeed' : 'failed']++;
			setTimeout(function() { me.next(); },50); //ie hangs if too much images too load
			me.dispatch('onLoadProgress',elm,url);
		};
		img.src = url;
	},
    findAssets : function(elms) {
		var me = this;
		elms.each(function(elm,i) {

			if(!elm) return;
			
			var bg  = JAME.CSS.getStyle(elm,'backgroundImage');

			var src = elm.src;
			if(src && /jpe*g|gif|png/i.test(src))
				me.queue(function() { me.loadAsset(elm,src);});
			if(bg &&  bg!=='none') {
				var url = bg.substring(4,bg.length-1).replace(/"/g,'');
				if(url) me.queue(function() { me.loadAsset(elm,url); });
			}
		});
		me.queue(function() { me.dispatch('onLoadComplete') });
	}
};
JAME.Components.Scroller = function(options) {

		this.container           = options.container;
		this.contained           = options.contained;
		this.maxHeight           = options.maxHeight;
		this.maxWidth            = options.maxWidth;
		this.speed				 = options.speed || 1;
		this.scrollY             = (options.scrollY!==undefined) ?options.scrollY:  true;
		this.scrollX             = (options.scrollX!==undefined) ?options.scrollX:  true;
		this.interval            = undefined;
		this.container.maxHeight = parseInt(this.maxHeight) || parseInt(JAME.CSS.getStyle(this.container,'height'));
		this.container.maxWidth  = parseInt(this.maxWidth)  || parseInt(JAME.CSS.getStyle(this.container,'width'));
		this.contained.maxHeight = parseInt(JAME.CSS.getStyle(this.contained,'height'));


//		this.contained.maxWidth  = parseInt(JAME.CSS.getStyle(this.contained,'width'));

		if(JAME.CSS.getStyle(JAME.DOM.firstNode(this.contained),'float')=='left'){
			var tagName=JAME.DOM.firstNode(this.contained).tagName.toLowerCase();
			var tags = this.contained.getElementsByTagName(tagName);
			this.contained.maxWidth  =tags[0].offsetWidth*tags.length;
		}
		else {
			this.contained.maxWidth  = parseInt(JAME.CSS.getStyle(this.contained,'width'));
		}
		if(this.contained.maxWidth!=0 && this.contained.tagName.toLowerCase()!='img') this.contained.style.width  = this.contained.maxWidth+'px';





		this.downContainer  = options.downContainer || undefined;
		this.upContainer  = options.upContainer || undefined;
		JAME.CSS.setStyles(this.container,{
			overflow       :'hidden',	
			cursor         :'pointer',
			position       :'relative',
			height         : this.container.maxHeight,
			width          : this.container.maxWidth
		});
		JAME.CSS.setStyles(this.contained,{
			position       :'relative',	
			top            : 0,
			left 		   : 0
		});
		this._setCenter();
		this._setDiffXY();
		this._setCurrentXY(this._getCenter('X',0),0);
		if(this.isActive()) 
			this.downContainer ? this._handleMouseDown() : this._handleMouseMove();

		JAME.extend(this,new JAME.Events.EventDispatcher());

};

JAME.Components.Scroller.prototype = {

	isActive : function() {
		return (this.diffX>=0 && this.diffY>=0) ? false : true;
	},
	//clear interval and put image the contents centered
	_resetState : function() {
		if(this.interval) clearInterval(this.interval);
		this._setCurrentXY(this._getCenter('X',0),this._getCenter('Y',0));
	},
	//calculate the diff between the container width/height and the contained width/height
	_setDiffXY  : function() {
		this.diffX  = this.container['maxWidth']  - this.contained['maxWidth'];
		this.diffY  = this.container['maxHeight'] - this.contained['maxHeight'];
	},
	//set the actual position of the contained
	_setCurrentXY : function(X,Y) {
		if(this.scrollY) JAME.CSS.setStyle(this.contained,'top',Y);
		if(this.scrollX) JAME.CSS.setStyle(this.contained,'left',X);	
	},

	//adjust contained position according to mouse position
	_calculateContainedPosition : function(axe,mousePosition,containedPosition) {

		var XorY = axe ==='Y' ? 'Height' : 'Width';
		var newPosition = 0;

		//how far the mouse is from the center point (300,-300)
		var ratio   = this['center'+axe] - mousePosition;
		//a proportional expression of the distance from the center point (1.15,-1.15)
		    ratio   = this.contained['max'+XorY]*(ratio/this.container['max'+XorY])/100;
		//add the ratio to the contained actual position: 420+1.15

		newPosition     = containedPosition + ratio*this.speed;

		//below logic is:
		//ex : container height : 450
		//containee height : 1820
		// diff (boundary) = 450 -1820 = -1370
		// new position = -1550
        //if we go that far (because we don't have any boundary value to check against)
		// the element won't be visible anymore
		// so reset to the above diff -1370 
		// basically the element can't go up to a point where it is not visible
		//if(axe==='Y') JAME.$('searchstring').value = parseInt(newPosition)+':'+this['diff'+axe];
		if(newPosition <= this['diff'+axe]) newPosition = this['diff'+axe];
		// the same thing but the other way round
		if(newPosition>=0) newPosition=0;
		//else new position between the boundaries
		return newPosition;

	},
	getElementTop:function(obj,parent){
    var topValue= 0;
    while(obj && obj!==parent){
	topValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    return topValue;
	},
	getElementLeft:function(obj,parent){
    var leftValue= 0;
    while(obj && obj!==parent){
	leftValue+= obj.offsetLeft;
	obj= obj.offsetParent;
    }
    return leftValue;
	},
	_setCenter : function() {
		this.centerX  = parseInt(parseInt(this.container.maxWidth)/2);
		this.centerY  = parseInt(parseInt(this.container.maxHeight)/2);
	},

	_getCenter : function(axe,current) {

		var XorY = axe ==='Y' ? 'Height' : 'Width';

		if(current==0 && this.container['max'+XorY]-this.contained['max'+XorY]>0) {
			var mid = parseInt(this.contained['max'+XorY])/2;
			return this['center'+axe]-mid;
		}
		return current;

	},

	_setActiveScrolling : function(X,Y) {

		this.scrollingTop    = (Y==0)                  ? false : true;
		this.scrollingBottom = (Y <= this['diffY'])    ? false : true;
		this.scrollingLeft   = (X==0)                  ? false : true;
		this.scrollingRight  = (X <= this['diffX'])    ? false : true;
	},

	scrollTop : function() {
		if(this.interval) clearInterval(this.interval);
		new JAME.FX({duration:800}).Tween(this.contained,{top:[0]});
		this._setActiveScrolling(parseFloat(JAME.CSS.getStyle(this.contained,'left')),0);
		this.dispatch('onScroll',parseFloat(JAME.CSS.getStyle(this.contained,'left')),0);
	},
	scrollBottom : function() {
		if(this.interval) clearInterval(this.interval);
		new JAME.FX({duration:800}).Tween(this.contained,{top:[this.diffY]});
		this._setActiveScrolling(parseFloat(JAME.CSS.getStyle(this.contained,'left')),this.diffY);
		this.dispatch('onScroll',parseFloat(JAME.CSS.getStyle(this.contained,'left')),this.diffY);
	},

	_handleMouseDown : function() {

		var me = this;

		this.downContainer.handler=-1;
		this.upContainer.handler =1;
		this.upContainer.onmousedown = this.downContainer.onmousedown=function(e){

			var e = JAME.Events.Normalize(e);
			
			if(me.interval) clearInterval(me.interval);
			if(me.contained.__ON) return;
			var self = this;

			me.interval = setInterval(function() {
				var currentX = parseInt(me.contained.style.left);
				var currentY = parseInt(me.contained.style.top);
				currentX += (self.handler==-1) ? -10 : 10;
				currentY += (self.handler==-1) ? -10 : 10;
				//calculate Y
				if(me.scrollY) {
					if(currentY <= me['diffY']) currentY = me['diffY'];
					if(currentY>=0) currentY=0;
					
					currentY = me._getCenter('Y',currentY);
				}

				//calculate X
				if(me.scrollX) {
					if(currentX <= me['diffX']) currentX = me['diffX'];
					if(currentX>=0) currentX=0;
				    currentX = me._getCenter('X',currentX);
				}
				if((currentX==me['diffX'] || currentX==0) && (currentY==me['diffY'] || currentY==0) )
					clearInterval(me.interval);
				me._setActiveScrolling(currentX,currentY);
				me.dispatch('onScroll',currentX,currentY);

				me._setCurrentXY(currentX,currentY);

			},20);
		}
		this.container.onmouseout= this.upContainer.onmouseup=this.downContainer.onmouseup=function(e){
			if(me.interval) clearInterval(me.interval);
		}

	},


	_handleMouseMove : function() {

		var me = this;

		this.container.onmousemove=function(e){

			var e = JAME.Events.Normalize(e);
			
			if(me.interval) clearInterval(me.interval);
			if(me.contained.__ON) return;
			//get the actual position of the target
			var currentX = parseInt(me.contained.style.left);
			var currentY = parseInt(me.contained.style.top);

			//layerX/Y gives us the relative position of the target
			//even if we're listing to container, the bubble can send us the containee positions
			//we want to get the mouse position relative to the container
			//if the mouse is on the containee, we need to substract its position to get the position
			//relative to the container
			var position = JAME.CSS.getStyle(e.target,'position');
			var mouseX = e.layerX+( ((e.target!==me.container && position=='static') || (e.target===me.contained)) ? currentX : 0);
			var mouseY = e.layerY+( ((e.target!==me.container && position=='static')|| (e.target===me.contained)) ? currentY  : 0);


			//if the target has a relative position 
			//we need to add to the mouse position the element actual offset
			//relative to the main containee
			//IE sends the coordinate relative to the target, 
			//even if the target is not positioned relatively
			//so we should always add the offset 

			if( (window.attachEvent && e.target.nodeName.toLowerCase()==='img')
				|| (e.target!==me.container && e.target!==me.contained && position && position!='static') )
			{
				mouseY+= me.getElementTop(e.target,me.contained);
				mouseX+= me.getElementLeft(e.target,me.contained);
			}

			me.dispatch('onMouseMove',e,mouseX,mouseY,currentX,currentY,position);
			me.interval = setInterval(function() {

				//calculate Y
				if(me.scrollY) {
					currentY = me._calculateContainedPosition('Y',mouseY,currentY);
					currentY = me._getCenter('Y',currentY);
				}

				//calculate X
				if(me.scrollX) {
				   currentX = me._calculateContainedPosition('X',mouseX,currentX);
				   currentX =me._getCenter('X',currentX);
				}

				me._setActiveScrolling(currentX,currentY);
				me.dispatch('onScroll',currentX,currentY);

				me._setCurrentXY(currentX,currentY);

			},10);
		}
		this.container.onmouseout=function(e){
			var e = JAME.Events.Normalize(e);
			var to = e.relatedTarget || document;
			do {
				if(to===me.container) return;
				to = to.parentNode
			} while(to);
			if(me.interval) clearInterval(me.interval);
		}
	}
};
JAME.Components.TimeMachine = function(options) {

	options = options || {};
	JAME.extend(this, new JAME.Util.Queue(this));
	JAME.extend(this, new JAME.Events.EventDispatcher());

	this.mainContainer = options.container || JAME.$('dl-preview');
	this.baseZIndex    = options.baseZIndex    || 3000;
	this.previews      = parse('#'+this.mainContainer.id+' img');
	if(!this.previews || 
	   (this.previews && this.previews.constructor===Array && this.previews.length<=1)) return; 
	this.maxWidth      = this.previews[0].width;
	this.centerX       = this.maxWidth/2;
	this.imgNumber     = this.previews.length;
	this.isTravelling  = false;
	this.cancelTopImageClick = options.cancelTopImageClick || false;
	this._createTitleContainer();

};

JAME.Components.TimeMachine.prototype = {

	_createTitleContainer : function() {

		this.titleContainer= JAME.DOM.createNode('div');
		this.titleContainer.id="jtime-machine-title";
	
		this.right= parseInt(JAME.CSS.getStyle(this.previews[0],'border-right-width'));

		JAME.CSS.setStyles(this.titleContainer,{
			position:'absolute',
			zIndex:this.baseZIndex+this.imgNumber,
			opacity:0,
			left:this.right,
			top:this.right,
			height:0,
			width:this.maxWidth-this.right*2
		});
		this.mainContainer.appendChild(this.titleContainer);
	},

	_setElementStyle : function(elm,ratio) {


		var width      = elm.resizedWidth*elm.ratio/(ratio+1);	
		elm.resizedWidth = width;

		var height     = elm.resizedHeight*elm.ratio/(ratio+1);
		elm.resizedHeight = height;
		return {
			width  : [width],
			height : [height],
			top    : [(-10 * ratio)],
			left   : [this.centerX - (width/2)],
			zIndex : [(1000 + this.imgNumber - ratio)],
			opacity :[1/(ratio+1)]
		};
	},

	effects : {
		borderOn : {border:'5px solid #e24631'},
		borderOff: {border:'5px solid #EEEEEE'},
		cinq     : {duration:400},	
		two      : {duration:150}
	},

	setBorderOn : function(elm) {
		JAME.CSS.setStyles(elm,this.effects.borderOn);
	},

	setBorderOff : function(elm) {
		JAME.CSS.setStyles(elm,this.effects.borderOff);
	},

	setTitle : function(alt) {
		this.titleContainer.innerHTML=alt;
	},

	showTitle : function() {
		var me = this;
		new JAME.FX(this.effects.cinq).Tween(this.titleContainer,{
			opacity:[.85],
			height:[20],
			top:[me.top],
			left:[me.right],
			width:[this.maxWidth-me.right*2]
		}).queue(function() {
			me.dispatch('onTitleDisplayed'); 
		});
	},

	hideTitle : function() {
		new JAME.FX(this.effects.cinq).Tween(this.titleContainer,{opacity:[0]});
	},

	animateTop : function(elm) {
		this.setTitle(elm.alt);
		var me = this;
		this.animatingTop=true;
		var effect = this._setElementStyle(elm,0);

		effect['zIndex']= [this.baseZIndex+this.imgNumber+1,this.baseZIndex+this.imgNumber];
		effect['left']  = [0];
		effect['top']   = [0];
		new JAME.FX({duration:500}).Tween(elm,effect).queue(function() { 
				elm.ratio = 1;
				me.showTitle(); 
				me.dispatch('onTargetDisplayed',elm); 
				me.animatingTop=false;
				new JAME.FX({duration:10}).Tween(elm,effect);
				if(me.empty())
					me.isTravelling=false;
		});

	},
	animateBack : function(elm,effect,nextRatio) {	
		var me = this;
		new JAME.FX({duration:100}).Tween(elm,effect).queue(function() { 
				new JAME.FX({duration:10}).Tween(elm,effect);
				elm.ratio=nextRatio;me.next();
		});
	},

	goForth : function() {

		var me = this;

		this.previews.push(this.previews.shift());

		this.previews.each(function(elm,i) {

			if(i===me.imgNumber-1 || i===0) return; 

			var elm = me.previews[i];
			var result = me._setElementStyle(elm,i);

			me.queue(function() { me.animateBack(elm,result,i+1); });

		});

		this.queue(function() {
			var last   = me.previews[me.imgNumber-1];
			new JAME.FX({duration:700}).Tween(last,me._setElementStyle(last,me.imgNumber-1)).queue(
				function() {	
					last.ratio = me.imgNumber;
					me.next();
				});
		});

		this.hideTitle();
		new JAME.FX({duration:100}).Tween(this.previews[this.imgNumber-1],{left:[1500],opacity:[1,0]});

		setTimeout(function() {
			me.next();
			me.animateTop(me.previews[0]);
		},400);
		this.queue(function() {if(me.animatingTop===false) { me.isTravelling=false}});
	},

	goTo : function(elm,ratio) {

		if(ratio<=2) return this.goForth();

		var me = this;

		this.hideTitle();

		//imgs before the target go down
			me.animateTop(elm);

			for (var k = 0; k <ratio-1; k++) {
				(function(n) {
					var elm = me.previews[n];
					var ratio = elm.ratio;
					elm.ratio=1;	
					var width  = elm.resizedWidth*ratio;
					elm.resizedWidth = width;
					var height = elm.resizedHeight*ratio;
					elm.resizedHeight = height;

					me.queue(function() {				
						new JAME.FX({duration:50}).Tween(elm,{
							top:[500],
							left:[500],
							height:[height],
							width:[width],
							opacity:[.5,0]
						}).queue(function() { me.next();	}); 
					});

				})(k);
			}
		
		//shift the imgs before the target and put them at the end of the queue
		this.queue(function() {	
			for (var k = 0; k <ratio-1; k++)
				me.previews.push(me.previews.shift());	
			me.next();
		});

		//now animate imgs after the target to advance by one
		for (var k = 1; k < this.imgNumber; k++) {
			(function(n) {
				me.queue(function() {
					var el = me.previews[n];
					me.animateBack(el,me._setElementStyle(el,n),n+1);
				});
			})(k);
		}

		me.queue(function() { 
			if(me.animatingTop===false && me.empty()) { me.isTravelling=false}
		});

		this.next();

	},

	start : function() {

		var me = this;

		this.previews.each(function(elm,i) {

			elm.ratio=i+1;
			elm.nodeNumber = i;

			var width = elm.width/elm.ratio;
			var height = elm.height/elm.ratio;
			JAME.CSS.setStyles(elm,{
				height : height,
				width  : width,
				zIndex : me.baseZIndex + me.imgNumber - i,
				top    : -10 * i,
				left   : me.centerX - width/2,
				opacity: 1/elm.ratio
			});
			//IE rounds up the value if applied to elm.style.width/height
			//so keep the float values there and work with that for calculation
			elm.resizedWidth = width;
			elm.resizedHeight= height;

			elm.onmouseover = function() {
				if(me.isTravelling) return;
				me.setBorderOn(this);
				current=i;
			}
			elm.onmouseout = function() {
				me.setBorderOff(this);
				current=i;
			}
			elm.onclick = function() {
				if(me.isTravelling) return;

				if(this.ratio==1 && me.cancelTopImageClick) {
					me.dispatch('onTopImageClicked',elm);
					return;
				}
				me.isTravelling=true;
				if(this.ratio!==1) me.dispatch('onTargetClicked',elm);
				else me.dispatch('onTargetClicked',me.previews[1]);
				me.goTo(this,this.ratio);
				current=i;
			}
		});
		this.dispatch('onTargetClicked',this.previews[0]);
		this.dispatch('onTargetDisplayed',this.previews[0]);
		this.setTitle(this.previews[0].alt);
		this.showTitle();
	}
};

JAME.Components.ToolTip = function(displayBox,rootListener,mouseover,mouseout,leftMin,leftMax,className,eventType) {

		this.displayBox         = displayBox;
		JAME.CSS.setStyle(this.displayBox,'opacity',0);
		this.rootListener       = rootListener || document;
		this.mouseover 			= mouseover;
		this.mouseout  			= mouseout || function() {};
		this.leftMin            = leftMin;
		this.leftMax		    = leftMax;
		this.timer              = undefined;
		this.actualDisplayed    = undefined;
		this.className          = className || 'tooltip';
		this.classNameReg       = new RegExp('\s*'+this.className+'\s*');
		this.currentToolTip     = undefined;
		var self = this;
		this.timer1 = undefined;
		if(eventType) { 
			this.rootListener.onclick     = function(e) { self.handleClick(e) };	
		}
		else {
			this.rootListener.onmouseover = function(e) { 

					self.handleMouseover(e); 
			};
			this.rootListener.onmouseout  = function(e) { 
					if(self.timer1) clearTimeout(self.timer1); 
					self.handleMouseout(e)  
			};
		}

}

JAME.Components.ToolTip.prototype = {

	displayHTML : function(e,contents,timeout) {

		this.displayBox.innerHTML=contents;

		var left = parseInt(e.pageX+20);

        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
		if(left > this.leftMax) left=this.leftMax;
		if(left < this.leftMin) left=this.leftMin;

		var effect     = {};

		effect["left"] = [left];
		effect["top"]  = (getWindowHeight()-e.pageY < JAME.CSS.getStyle(this.displayBox,'height')) 
						 ? [parseInt(e.pageY -100 -JAME.CSS.getStyle(this.displayBox,'height'))] 
						       : [parseInt(e.pageY+50)];

		var windowSize = document.documentElement.scrollTop;
		var boxSize    = JAME.CSS.getStyle(this.displayBox,'height');
		
		if((effect["top"]-windowSize < 0)) {
			effect["top"]  = [parseInt(windowSize+JAME.CSS.getStyle(this.displayBox,'height'))]
		}

		if(JAME.CSS.getStyle(this.displayBox,'opacity')<.9) {
			effect["opacity"] = [.9];
			effect["zIndex"] = [0,100000000];
		}
		if(this.timer1) clearTimeout(this.timer1);
		var self = this;
		this.timer1=setTimeout(function() {
			new JAME.FX({duration:400,easing:JAME.FX.Transition.Sine.Out}).Tween(self.displayBox,effect);
		},150);


		if(!timeout) {
			this.timer = setTimeout(function() { 
				new JAME.FX({duration:400,easing:JAME.FX.Transition.Sine.Out}).Tween(self.displayBox,{opacity:[1,0],zIndex:[1000000,-1]});	
			},5500);
		}
	},
	handleMouseover: function(e) {

			var e = JAME.Events.Normalize(e);
			if(this.classNameReg.test(e.target.className)) {
				if(this.timer) clearTimeout(this.timer);
				var elm = e.target;
				var content = this.mouseover(elm);
				this.displayHTML(e,content);
			}
	},
	handleClick: function(e) {

			var e = JAME.Events.Normalize(e);
				var elm = e.target;
			if(this.currentToolTip) {
				this.mouseout(elm);
				this.currentToolTip=undefined;
			}
			if(this.classNameReg.test(e.target.className)) {
				var content = this.mouseover(elm);
				this.currentToolTip=elm;
				if(content)
				this.displayHTML(e,content,true);
			}
	},
	handleMouseout : function(e) {
		var e = JAME.Events.Normalize(e);
		var self = this;
		if(this.classNameReg.test(e.target.className)) {
			clearTimeout(this.timer);
			if(e.relatedTarget && !this.classNameReg.test(e.relatedTarget.className) && JAME.CSS.getStyle(self.displayBox,'opacity')>0) {
				this.timer = setTimeout(function() {
					new JAME.FX({duration:200,easing:JAME.FX.Transition.Sine.Out}).Tween(self.displayBox,{opacity:[1,0],zIndex:[100000,-1]});	
					clearTimeout(self.timer);
				},200);
			}
			this.mouseout(e.target);
		}
	}


};
function getWindowHeight() {

  return  window.innerHeight 
			  ? window.innerHeight 
			  : (document.documentElement && (document.documentElement.clientHeight ) )
				? document.documentElement.clientHeight
				: ( document.body && (document.body.clientHeight ) )
				  ? document.body.clientHeight : 0;
 }
function getWindowWidth() {

  return  window.innerWidth 
			  ? window.innerWidth 
			  : (document.documentElement && (document.documentElement.clientWidth ) )
				? document.documentElement.clientWidth
				: ( document.body && (document.body.clientWidth ) )
				  ? document.body.clientWidth : 0;
 }

JAME.Package('JAME.Components.TreeMenu');


JAME.Components.TreeMenu = function(options) {

	this.startingDepth      = options.startingDepth || 2;
	this.mainMenu          = options.mainMenu;
	this.breadCrumb		   = options.breadCrumb;
	this.mainMenu.isOpened = options.isOpened;
	this.expandedLI        = undefined;
	this.root			   = options.root || parse('#globalmenu ol.tree');
	this.olList			   = this.root.getElementsByTagName('ol');
	this.onClick   	       = this.onClick||function(){};
	this.onColor  		   = options.onColor  || 'red';
	this.offColor		   = options.offColor || 'white';
	this.closedHeight      = options.closedHeight  || 20;
	this.openedHeight	   = options.openedHeight || 150;
	this.isDot		       = (options.isDot!==undefined) ? options.isDot: true;
	JAME.extend(this,new JAME.Events.EventDispatcher());
	this.ols=[];
	for(var i=0;i<this.olList.length;i++) this.ols.push(this.olList[i]);
	//hide all ols
	this.ols.each(function(elm,i) { elm.style.display='none'; });

	this.getMenuLis();
	if(this.isDot) this.drawSquare();
	this.handleMainMenuClickEvent();

	//closed the menu at first
	this.closeMainMenu();
	var doOpen = this.initPageLoadBreadCrumb();
	if(doOpen) this.openMainMenu();

	var self  = this;
	this.closingTimer = setTimeout(function() {
		self.closeMainMenu();
	},5000);

};


window.getDepth = function(elm,root) {

	var depth = 0;
	do {

		if(elm===root) return depth;
		elm=elm.parentNode;
		depth++;

	} while(elm);

}

window.getElementTop  = JAME.Components.Scroller.prototype.getElementTop;
window.getElementLeft = JAME.Components.Scroller.prototype.getElementLeft;

window.getPosition = function(elm,root) {

	var elms = root.getElementsByTagName('li');
	var ln   = elms.length;

	if(JAME.DOM.lastNode(root)  === elm) return ln;
	if(JAME.DOM.firstNode(root) === elm) return 1;
	for(var i=1;i<ln-1;i++)
		if(elms[i]===elm) return i+1;	
}


JAME.Components.TreeMenu.prototype={

	initPageLoadBreadCrumb : function() {

		var breadTree = this.breadCrumb.getElementsByTagName('a');
		var root = undefined;
		if(breadTree.length>this.startingDepth) {

			for(var i=0,ln=this.headLinks.length; i<ln; i++) {

				if(JAME.DOM.firstNode(this.headLinks[i]).href === breadTree[this.startingDepth].href){
					root = this.headLinks[i];
					JAME.CSS.setStyles(JAME.DOM.firstNode(this.headLinks[i]),{color:this.onColor});
					continue;
				}
			}

			this.openMainMenu();
			if(!root) return;

			var submenus = root.getElementsByTagName('ol');
			if(submenus[0]) {
				submenus[0].style.display='block';
				this.startingDepth+=1;
				this.highlightPath(submenus[0],breadTree,this.startingDepth);
				return true;
			}
		}
		return false;
	},

	getAncestorTree : function(li) {

		var ancestors = [];
		var ol= li.parentNode;
		var ols = ol.getElementsByTagName('ol');
		if(ols[0]) ancestors.push(ols[0]);
		ancestors.push(ol);		
		do {
			ol = ol.parentNode;
			if(ol && ol.nodeName.toLowerCase()==='ol') ancestors.push(ol);
		}while(ol && ol!==this.root);
		return ancestors;
	},

	hideExpandedTree : function(target) {
		
		if(!this.expandedLI) return;


		//same level
		if(this.expandedLI.parentNode===target.parentNode) {
			JAME.CSS.setStyles(JAME.DOM.firstNode(this.expandedLI),{color:this.offColor});
			var ols = this.expandedLI.getElementsByTagName('ol');
			if(ols[0]) ols[0].style.display='none';
			return;
		}


		if(!this.isChild(this.expandedLI,target,this.root)) {

			do {

				if(this.expandedLI.nodeName.toLowerCase()==='li') {
					JAME.CSS.setStyles(JAME.DOM.firstNode(this.expandedLI),{color:this.offColor});
					if(this.expandedLI.getElementsByTagName('ol')[0] && this.expandedLI.parentNode!==target.parentNode) {
						this.expandedLI.getElementsByTagName('ol')[0].style.display='none';
					}
				}
				if(this.expandedLI.nodeName.toLowerCase()==='ol' && target.parentNode!==this.expandedLI) {
					this.expandedLI.style.display='none';
				}
				this.expandedLI=this.expandedLI.parentNode;

			} while(this.expandedLI && (this.expandedLI!==this.root && this.expandedLI!==target.parentNode));
		}

	},

	handleMainMenuClickEvent : function() {

		var self = this;

		this.mainMenu.onclick  = function(e) {

			//normalize the event
			e = JAME.Events.Normalize(e);
			e.preventDefault();
			e.stopPropagation();

			var target = e.target;
			//check what triggered the event and get the li tag
			if(target.tagName.toLowerCase()==='a') target=target.parentNode;
			if(target.tagName.toLowerCase()!=='li') return;

			if(self.closingTimer) clearTimeout(self.closingTimer);

			self.dispatch('onClick',target);

			// added by hiruta while not sure if this is a right fix.
			if(self.expandedLI) {
				var hostname   = window.location.protocol+'//'+hostname+'/';
				var clickedURL = JAME.DOM.firstNode(target).href;
				if(clickedURL.indexOf(hostname)==-1)
					clickedURL=hostname+clickedURL;

				var seenURL = hostname+window.location.hash.replace('#/','');


				if(seenURL==clickedURL && self.expandedLI===target && self.mainMenu.isOpened) return self.closeMainMenu();
				var ancestors = self.getAncestorTree(self.expandedLI);
				var headLink = ancestors[ancestors.length-2].parentNode;
				if(headLink===target && self.mainMenu.isOpened) return self.closeMainMenu();
			}

			//var ancestors = self.getAncestorTree(self.expandedLI);

			if(target.parentNode===self.root && target.getElementsByTagName('ol')[0]) self.openMainMenu();

			if(self.expandedLI && self.expandedLI.parentNode!==self.root) {

				var ancestors = self.getAncestorTree(self.expandedLI);
				var link=JAME.DOM.firstNode(ancestors[ancestors.length-2].parentNode).href;
				if(link && JAME.DOM.firstNode(target).href===link) {

					return;
				}
			}
			
			self.hideExpandedTree(target);

			self.expandedLI=target;

			JAME.CSS.setStyles(JAME.DOM.firstNode(target),{color:this.onColor});

			//try to get the target submenu
			var submenu = target.getElementsByTagName('ol')[0];

			self.onClick(target,submenu);
			//if  we have a submenu
			if(submenu) {
				self.moveDot(getElementTop(self.expandedLI),getElementLeft(self.expandedLI));
				var OLLiChildren = self.hideLiElements(submenu);
				//display the submenu
				self.displayOLElement(submenu);
				self.showLiElements(OLLiChildren);
				return;
			}
		
//			self.moveDot(e.clientY,e.clientX);

			//close the menu again in 3.5s
			self.closingTimer = setTimeout(function() {
				self.closeMainMenu();
			},1000);

			//set the url address in the bar
			SWFAddress.setValue(window.Value(e.target.href)[1]);
			//JAME.CSS.setStyles(self.square,{opacity:0});
			//self.closeMainMenu();
		}
	},


	getMenuLis : function() {
		var allLis = this.root.getElementsByTagName('li');
		this.headLinks=[];
		for(var i=0,ln=allLis.length;i<ln;i++)
			if(allLis[i].parentNode===this.root) this.headLinks.push(allLis[i]);
	},

	drawSquare : function() {
		this.square = JAME.DOM.createNode('div');
		this.square.id='JTreeMenuSquare';

		JAME.CSS.setStyles(this.square,{
			fontSize:1,
			position:'absolute',
			top:0,
			left:0,
			opacity:0
		});

		document.body.appendChild(this.square);
	},

	moveDot : function(top,left) {

		if(this.square) {//move the dot
		new JAME.FX({duration:100}).Tween(this.square,{
			top:[top + 3],
			left:[left - 12],
			opacity:[1]
		});
		}

	},

	isChild : function(assumeParent,assumeChild,limit) {
		do {
			if(assumeChild===assumeParent) return true;
			assumeChild = assumeChild.parentNode;
		} while(assumeChild && assumeChild!==limit);
		return false;
	},

	hideLiElements : function(OLparent) {

		var lis = OLparent.getElementsByTagName('li')
		var alis=[];
		for(var i=0;i<lis.length;i++) { 

			if(lis[i].parentNode===OLparent){
				 alis.push(lis[i]);
				 JAME.CSS.setStyles(lis[i],{opacity:0});
			}
		}
		return alis;
	},

	showLiElements : function(lis) {
		new JAME.FX({duration:100}).Tween(lis,{opacity:[0,1]});
	},

	displayOLElement : function(ol) {
		if(ol) ol.style.display='block';
	},

	closeMainMenu : function() {
		if(this.closingTimer) clearTimeout(this.closingTimer); 
		new JAME.FX({duration:250}).Tween(this.mainMenu,{height:[this.closedHeight]});
		var ols = this.root.getElementsByTagName('ol');
		for(var i=0;i<ols.length;i++) ols[i].style.visibility='hidden';
		if(this.square) JAME.CSS.setStyles(this.square,{opacity:0});
		this.mainMenu.isOpened = false;
		
	},

	openMainMenu : function() {
		if(this.closingTimer) clearTimeout(this.closingTimer); 
		new JAME.FX({duration:250}).Tween(this.mainMenu,{height:[this.openedHeight]});
		var ols = this.root.getElementsByTagName('ol');
		for(var i=0;i<ols.length;i++) ols[i].style.visibility='visible';
		this.mainMenu.isOpened = true;
	},

	highlightPath : function(ol,elms,depth) {

		var z = depth;

		if(!ol) return;

	    //get the children, hide them first
		var lis = ol.getElementsByTagName('li');

		var doDisplay=false;

		for(var j=0;j<lis.length;j++) {

			if(lis[j].parentNode === ol) {

				if(elms[z] && JAME.DOM.firstNode(lis[j]).href===elms[z].href) {
					JAME.CSS.setStyles(JAME.DOM.firstNode(lis[j]),{color:this.onColor});
					this.expandedLI=lis[j];
					doDisplay=lis[j];
					continue;
				}
			}
		}
		if(!doDisplay) return;

		var alis=[];
		for(var j=0;j<lis.length;j++) { 
			if(lis[j].parentNode===ol){
				 alis.push(lis[j]);
				JAME.CSS.setStyles(lis[j],{opacity:0});
			}
		}
			
		//display the submenu
		ol.style.display='block';
		if(alis.length>0) new JAME.FX({duration:100}).Tween(alis,{opacity:[0,1]});
		if(doDisplay.getElementsByTagName('ol')[0]) {
			this.highlightPath(doDisplay.getElementsByTagName('ol')[0],elms,++z);
		}

	}

};

JAME.Components.Twicker = function(options) {	

	this.root 		   = options.root;
    JAME.CSS.setStyles(this.root,{position:'relative'});
	this.elms          = options.elms;
	this.to			   = options.to || 'top';
	var moveOf		   =(this.to=='top') ? ['height','bottom','top'] : ['width','left','right'];
	this.elmHeight     = parseInt(JAME.CSS.getStyle(this.elms[0],moveOf[0]))+parseInt(JAME.CSS.getStyle(this.elms[0],'padding-'+moveOf[1]))+parseInt(JAME.CSS.getStyle(this.elms[0],'padding-'+moveOf[2]));
	this.elms_per_view = options.elmsPerView  || 1;
	this.elmsNumber    = this.elms.length - this.elms_per_view;
	this.displayTime  = options.displayTime || 5000;
	this.animationBehavior = options.animation || {duration: 800};
	this.interval	   = undefined;
	this.animation     = undefined;
	this.running	   = true;
	this.move();
};


JAME.Components.Twicker.prototype = {

	stop : function() {
		this.running=false;
	},
	setDisplayTime : function(time) {
		this.displayTime=time;
	},
	move : function() {

		if(!this.running) {
			clearInterval(this.interval);
			return;
		}

		var me = this;
		this.interval  = setInterval(function() {
			me.calculateNewPosition();
		},this.displayTime);

	},
	calculateNewPosition: function() {
		var prev_top = parseInt(JAME.CSS.getStyle(this.root,this.to));
		var next_top = (prev_top <= - (this.elmHeight * this.elmsNumber)) ? 0 : prev_top - this.elmHeight;
		var styles={};
		styles[this.to]=[prev_top,next_top];
		this.animation = new JAME.FX(this.animationBehavior).Tween(this.root,styles);
		this.animation.addListener('onComplete',function() {
			this.animation=undefined;
		});

	}
};
JAME.Components.Zoomifier= function(options) {	

		this.target    = options.target;
		this.host      = options.host;
		this.initZoom  = options.initZoom || 1;
		this.fitToContainer = options.fitToContainer || false;
		this.zoomRatio =  1;
		this.steps     = options.zoomSteps    || .1;
		this.minRatio  = options.zoomMinRatio || .6;
		this.getImage  = options.getImage     || function(elm) { 
			do { 
				if(elm.nodeName.toLowerCase()==='img') return elm.src;
				elm = elm.parentNode;
			} while(elm);
		};

		var div = JAME.DOM.createNode('div');
		var img = JAME.DOM.createNode('img');

		div.appendChild(img);
		this.host.appendChild(div);

		var width = parseInt(JAME.CSS.getStyle(this.host,'width'))+parseInt(JAME.CSS.getStyle(this.host,'margin-left'))+parseInt(JAME.CSS.getStyle(this.host,'margin-right'));
		var height = parseInt(JAME.CSS.getStyle(this.host,'height'))+parseInt(JAME.CSS.getStyle(this.host,'margin-top'))+parseInt(JAME.CSS.getStyle(this.host,'margin-bottom'));
		JAME.extend(this,new JAME.Components.Scroller({
				container : div,
				contained : img,
				maxWidth  : parseInt(options.maxWidth)  || width,
				maxHeight : parseInt(options.maxHeight) || height
			})
		);


		this.container.id = 'jzoomifier-container';
		
		JAME.CSS.setStyles(this.container,{
			position       :'absolute',
			height         :0,
			top            :0,
			left           :0,
			backgroundColor:'#FFFFFF',
			zIndex         :4000000
		});

		this._createZoomHandlers();	
		this._handleMouseClick();
		this._handleZoomIn();
		this._handleZoomOut();
		
		var me = this;
		this.contained.onload = function() {

				me.contained.maxWidth  = me.contained.realWidth  = parseInt(me.contained.width);
				me.contained.maxHeight = me.contained.realHeight = parseInt(me.contained.height);
				while(me.initZoom <= me.zoomRatio-me.steps) me._ZoomOut();
				if(me.fitToContainer) me._fitToContainer();
				me._setCenter();
				me._setDiffXY();
				me._handleMouseMove();
				me._setCurrentXY(me._getCenter('X',0),me._getCenter('Y',0));
		}


		me.target.onclick=function(e){

			var e = JAME.Events.Normalize(e);
			e.preventDefault();
			e.stopPropagation();

			var src = me.getImage(e.target);
			me.contained.src = src;
			
			new JAME.FX().Tween(me.container,{height:[0,me.container.maxHeight]});

		}
};

JAME.Components.Zoomifier.prototype = {


	_fitToContainer : function() {
		var o = this.container;
		var i = this.contained;
		while (this.zoomRatio>this.minRatio && (i.maxWidth>o.maxWidth || i.maxHeight>o.maxHeight)) {
					this._ZoomOut();
		}

	},

	_resetState : function() {
		if(this.interval) clearInterval(this.interval);

		JAME.CSS.setStyles(this.zoomIn,{opacity:.2});	
		JAME.CSS.setStyles(this.zoomOut,{opacity:1});	
	    this.zoomRatio=1;

		this.contained.maxWidth  = this.contained.width  = this.contained.realWidth;
		this.contained.maxHeight = this.contained.height = this.contained.realHeight;

		this._setCurrentXY(this._getCenter('X',0),this._getCenter('Y',0));

	},

	_handleMouseClick : function() {
		var me = this;
		this.container.onclick=function(e) {
			var e = JAME.Events.Normalize(e);
			e.preventDefault();
			e.stopPropagation();
			new JAME.FX().Tween(me.container,{height:[0]});
			clearInterval(me.interval);
		}
	},

	_handleZoomIn : function() {

		var me = this;

		this.zoomIn.onclick=function(e) {

			e = JAME.Events.Normalize(e);
			e.stopPropagation();

			me.zoomRatio = (me.zoomRatio+me.steps)*100/100;
			if(me.zoomRatio>1) {
				me.zoomRatio=1;
				JAME.CSS.setStyles(me.zoomIn,{opacity:.2});	
				return;
			}
			else {
				if(me.zoomRatio==1) JAME.CSS.setStyles(me.zoomIn,{opacity:.2});	
				JAME.CSS.setStyles(me.zoomOut,{opacity:1});	
			}
			me.contained.maxWidth  = me.contained.width  = parseInt(me.contained.maxWidth)  / (me.zoomRatio-me.steps);
			me.contained.maxHeight = me.contained.height = parseInt(me.contained.maxHeight) / (me.zoomRatio-me.steps);
			me._setDiffXY();
			me._setCurrentXY(me._getCenter('X',0),me._getCenter('Y',0));
		};

	},

	_ZoomOut : function(force) {

		this.zoomRatio = (this.zoomRatio-this.steps)*100/100;
		if(this.zoomRatio<this.minRatio) {
			this.zoomRatio = this.minRatio;
			JAME.CSS.setStyles(this.zoomOut,{opacity:.2});	
			return;
		}
		else {
			if(this.zoomRatio==this.minRatio) JAME.CSS.setStyles(this.zoomOut,{opacity:.2});	
			JAME.CSS.setStyles(this.zoomIn,{opacity:1});	
		}
		this.contained.maxWidth  = this.contained.width  = parseInt(this.contained.maxWidth) * this.zoomRatio;
		this.contained.maxHeight = this.contained.height = parseInt(this.contained.maxHeight)* this.zoomRatio;

		this._setDiffXY();
		this._setCurrentXY(this._getCenter('X',0),this._getCenter('Y',0));

	},
	_handleZoomOut : function() {
		var me = this;
		this.zoomOut.onclick=function(e) {
			e = JAME.Events.Normalize(e);
			e.stopPropagation();
			me._ZoomOut();
		};
	},

	_createZoomHandlers : function() {
		var styles = {
			position:'absolute',
			bottom:40,
			left:20,
			height:20,
			zIndex:4000000,
			opacity:1,
			backgroundColor:'#ddd',
			width:20,
			textAlign:'center'
		};
		this.zoomOut    = this._createZoomHandler('-','jZoomOut',styles);
		styles.left    = 40;	
		styles.opacity = .2;
		this.zoomIn     = this._createZoomHandler('+','jZoomIn',styles);
	},

	_createZoomHandler : function(symbol,id,styles) {
		var zoom = JAME.DOM.createNode('h1');
		zoom.innerHTML=symbol;
		zoom.id=id;
		JAME.CSS.setStyles(zoom,styles);
		this.container.appendChild(zoom);
		return zoom;
	}
};
