/*global ort, window, document, XMLHttpRequest, ActiveXObject,  */

/* do not edit this file */

if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(elt, f) {
        var len = this.length,
            from = Number(arguments[1]) || 0; // won't pass lint
            
        from = (from < 0) ? Math.ceil(from) : Math.floor(from);
        if (from < 0) {
            from += len;
        }
        for (; from < len; from++) {
            if (from in this && this[from] === elt) {
                return from;
            }
        }
        return -1;
    };
}

ort = window.ort || {};

ort.hsh = 0;

ort.insx = function (src) {
    var head = document.getElementsByTagName("head")[0],
        script = document.createElement("script"),
        querySrc = src;
        
    script.id = "upload-script" + ort.hsh;
    script.setAttribute("type", "text/javascript");
    script.setAttribute("src", src);
    if (script.src !== src) {
        script.src = src;
    }
    
    script.onload = function () {
        return true;
    };
    
    if (head) {
        head.appendChild(script);
    } else {
        document.write("<scr" + "ipt type=\"text/javascript\" src=\"" + src + "\"></scr" + "ipt>");
    }
    return script;
};
        

ort.load = function (str, noclobber) {
    var scripts = document.getElementsByTagName("script"),
        i, len,
        newScript;
    
    for (i = 0, len = scripts.length; i !== len; i++) {
        if (scripts[i].src === str) {
            return {
                oncomplete: function (fn) {
                    fn();
                }
            };
        }
    }
    newScript = ort.insx(str);
    if (/*@cc_on!@*/false) {
        newScript.oncomplete = function (fn) {
            newScript.onreadystatechange = function () {
                if (this.readyState !== "loaded" && this.readyState !== "complete") {
                    return;
                } else {
                    fn();
                }
            };
        };
    } else {
        newScript.oncomplete = function (fn) {
            if (newScript.addEventListener && /HTMLScriptElement/.test(newScript)) {
                newScript.addEventListener("load", function () {
                    fn();
                }, false);
            } else {
                newScript.onload = fn;
                return newScript;
            }
            return null;
        };
    }
    
    return newScript;
};

ort.loadAll = function (s) {
    var modules = s.replace(/[\s]/gi, "").split(","),
        loadedModules = [],
        callback,
        i,
        moduleLoaded = function (url) {
            var allLoaded = false,
                j;
            for (j = 0; j != modules.length; j++) {
                if (url === modules[j]) {
                    loadedModules[j] = true;
                }
                if (!!loadedModules[j]) {
                    allLoaded = true;
                } else {
                    allLoaded = false;
                }
            }
            if (!!allLoaded && typeof callback === "function") {
                callback();
            }
        };
        
    for (i = 0; i !== modules.length; i++) {
        (function () {
            var m = modules[i], j = i;
            loadedModules[j] = false;
            ort.load(m, true).oncomplete(function () {
                moduleLoaded(m);
            });
        }());
    }
    
    
    return {
        oncomplete: function (cb) {
            callback = cb;
        }
    };
};

ort.xhr = function () {
    var handleReadyState = function (o, callback, onerror) {
        if (o && o.readyState === 4 && o.status === 200) {
            if (callback) {
                callback(o);
            }
        } else if (o && o.readyState === 4 && o.status !== 200) {
            onerror();
        }
    },
    getXHR = function () {
        var http, i, len, msxml;
        try {
            // won't pass lint
            http = new XMLHttpRequest;
            getXHR = function () {
                return new XMLHttpRequest;
            };
        } catch (e) {
            msxml = [
                'MSXML2.XMLHTTP.3.0',
                'MSXML2.XMLHTTP',
                'Microsoft.XMLHTTP'
            ];
            
            for (i = 0, len = msxml.length; i < len; ++i) {
                try {
                    http = new ActiveXObject(msxml[i]);
                    getXHR = function () {
                        return new ActiveXObject(msxml[i]);
                    };
                    break;
                } catch (er) {}
            }
        }
        return http;
    };
    
    return function (method, uri, callback, postData, onerror) {
        var http = getXHR();
        http.open(method, uri, true);
        http.onreadystatechange = function () {
            handleReadyState(http, callback, onerror);
        };
        http.send(postData || null);
        return http;
    };
}();


ort.delegate = function() {};
ort.delegate.create = function (o, f) {
    var a = [];
    var l = arguments.length ;
    for (var i = 2; i < l; i++) {
        a[i - 2] = arguments[i];
    }
    
    return function() {
        var aP = [].concat(arguments, a);
        f.apply(o, aP);
    };
};

ort.Tween = function(obj, prop, func, begin, finish, duration, suffixe, preffixe) {
    this.init(obj, prop, func, begin, finish, duration, suffixe, preffixe);
};

/* enclosure so we don't pollute the global namespace */
ort.Tween.___set = function(_) {
    var t = ort.Tween.prototype;

    t.obj = {};
    t.prop='';
    t.func = function (t, b, c, d) { return c*t/d + b; };
    t.begin = 0;
    t.change = 0;
    t.prevTime = 0;
    t.prevPos = 0;
    t.looping = false;
    t._duration = 0;
    t._time = 0;
    t._pos = 0;
    t._position = 0;
    t._startTime = 0;
    t._finish = 0;
    t.name = '';
    t.suffixe = '';
    t._listeners = []; 
    /**
     * @function {private} setTime
     */
    t.setTime = function(t){
        this.prevTime = this._time;
        if (t > this.getDuration()) {
            if (this.looping) {
                this.rewind (t - this._duration);
                this.update();
                this.broadcastMessage('onMotionLooped',{target:this,type:'onMotionLooped'});
            } else {
                this._time = this._duration;
                this.update();
                this.stop();
                this.broadcastMessage('onMotionFinished',{target:this,type:'onMotionFinished'});
            }
        } else if (t < 0) {
            this.rewind();
            this.update();
        } else {
            this._time = t;
            this.update();
        }
    };
    /**
     * @function {private} getTime
     */
    t.getTime = function(){
        return this._time;
    };
    /**
     * @function {private} setDuration
     */
    t.setDuration = function(d){
        this._duration = (d === null || d <= 0) ? 100000 : d;
    };
    /**
     * @function {private} getDuration
     */
    t.getDuration = function(){
        return this._duration;
    };
    /**
     * @function {private} setPosition
     */
    t.setPosition = function(p){
        this.prevPos = this._pos;
        var a = this.suffixe !== '' ? this.suffixe : '';
        if (!this.preffixe) {
            _a = " ";
        } else {
            _a = this.preffixe;
        }
        this.obj[this.prop] = _a + Math.round(p) + a;
        this._pos = p;
        this.broadcastMessage('onMotionChanged',{target:this,type:'onMotionChanged'});
    };
    /**
     * @function {private} getPosition
     */
    t.getPosition = function(t){
        if (typeof t === undefined) {
            t = this._time;
        }
        return this.func(t, this.begin, this.change, this._duration);
    };
    /**
     * @function {private} setFinish
     */
    t.setFinish = function(f){
        this.change = f - this.begin;
    };
    /**
     * @function {private} getFinish
     */
    t.getFinish = function(){
        return this.begin + this.change;
    };
    /**
     * @function {private} init
     */
    t.init = function(obj, prop, func, begin, finish, duration, suffixe, preffixe){
        if (!arguments.length) { return; }
        this._listeners = [];
        this.addListener(this);
        if (suffixe) { this.suffixe = suffixe; }
        if (preffixe) { this.preffixe = preffixe; }
        this.obj = obj;
        this.prop = prop;
        this.begin = begin;
        this._pos = begin;
        this.setDuration(duration);
        if (func !== null && func !== '') {
            this.func = func;
        }
        this.setFinish(finish);
    };
    /**
     * @function {private} start
     */
    t.start = function(){
        this.rewind();
        this.startEnterFrame();
        this.broadcastMessage('onMotionStarted',{target:this,type:'onMotionStarted'});
    };
    /**
     * @function {private} rewind
     */
    t.rewind = function(t){
        this.stop();
        this._time = (t === undefined) ? 0 : t;
        this.fixTime();
        this.update();
    };
    /**
     * @function {private} fforward
     */
    t.fforward = function(){
        this._time = this._duration;
        this.fixTime();
        this.update();
    };
    t.update = function(){
        this.setPosition(this.getPosition(this._time));
    };
    t.startEnterFrame = function(){
        this.stopEnterFrame();
        this.isPlaying = true;
        this.onEnterFrame();
    };
    t.onEnterFrame = function(){
        if (this.isPlaying) {
            this.nextFrame();
            setTimeout(ort.delegate.create(this, this.onEnterFrame), 0);
        }
    };
    t.nextFrame = function(){
        this.setTime((this.getTimer() - this._startTime) / 1000);
    };
    t.stop = function(){
        this.stopEnterFrame();
        this.broadcastMessage('onMotionStopped',{target:this,type:'onMotionStopped'});
    };
    t.stopEnterFrame = function(){
        this.isPlaying = false;
    };

    t.continueTo = function(finish, duration){
        this.begin = this._pos;
        this.setFinish(finish);
        if (typeof this._duration !== undefined) {
            this.setDuration(duration);
        }
        this.start();
    };
    t.resume = function(){
        this.fixTime();
        this.startEnterFrame();
        this.broadcastMessage('onMotionResumed',{target:this,type:'onMotionResumed'});
    };
    t.yoyo = function (){
        this.continueTo(this.begin,this._time);
    };

    t.addListener = function(o){
        this.removeListener (o);
        return this._listeners.push(o);
    };
    t.removeListener = function(o){
        var a = this._listeners;    
        var i = a.length;
        while (i--) {
            if (a[i] == o) {
                a.splice (i, 1);
                return true;
            }
        }
        return false;
    };
    t.broadcastMessage = function(){
        var arr = [];
        for(var i = 0; i < arguments.length; i++){
            arr.push(arguments[i]);
        }
        var e = arr.shift();
        var a = this._listeners;
        var l = a.length;
        for (var j = 0; j < l; j++){
            if (a[j][e]) {
                a[j][e].apply(a[j], arr);
            }
        }
    };
    
    t.fixTime = function(){
        this._startTime = this.getTimer() - this._time * 1000;
    };
    
    t.getTimer = function(){
        return new Date().getTime() - this._time;
    };
    
}();
/* end closure */

ort.fns = {
    easeInOutQuad: function (t, b, c, d) {
        if ((t/=d/2) < 1) { return c/2*t*t + b; }
        return -c/2 * ((--t)*(t-2) - 1) + b;
    }
};

/**
 * Opacity tweening
 * @constructor OpacityTween
 */
ort.OpacityTween = function(obj, func, fromOpacity, toOpacity, duration){
    this.targetObject = obj;
    this.init({},'x',func,fromOpacity,toOpacity,duration);
};

ort.OpacityTween.prototype = new ort.Tween();
ort.OpacityTween.prototype.constructor = ort.Tween;
ort.OpacityTween.superclass = ort.Tween.prototype;

/* enclosure so we don't pollute global namespace */
ort.OpacityTween.__set = function(_) {
    var o = ort.OpacityTween.prototype;
    o.targetObject = {};
    o.onMotionChanged = function(evt) {
        var v = evt.target._pos;
        var t = this.targetObject;
        t.style['opacity'] = v / 100;
        t.style['-moz-opacity'] = v / 100;
        t.style.zoom = "1";
        if (typeof t.filters === "unknown") {
            return;
            // wtf is up with IE there?
        }
        if (t && t.filters) {
            try {
                t.filters.alpha['opacity'] = v;
            } catch (e) {
                // do nothing. IE is stupid
            }
        }
    };
}();

ort.getPageScroll = function () {
    var yScroll;
    if (window.pageYOffset) {
        yScroll = window.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop){
        // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if(document.body) {
        // all other Explorers
        yScroll = document.body.scrollTop;
    }
    return ['',yScroll];
};

ort.hasClass = function(el, clss) {
    var re = el.className.split(' ');
    return -1 !== re.indexOf(clss);
};

ort.getElementsByClassName = function(clss, p, t) {
    var elements = [],
        tg = t || '*',
        prnt = p || document,
        list = prnt.getElementsByTagName(tg), i;
        
    for (i = 0; i < list.length; ++i) {
        if (list[i] && list[i].nodeType == "1" && ort.hasClass(list[i], clss)) {
            elements.push(list[i]);
        } 
    }
    return elements;
};


ort.clone = function(o) {
     function F() {}
     F.prototype = o;
     return new F();
};



ort.getEventTarget = function(e) { 
    var ev = e || window.event;
    if (typeof ev === "undefined") {
        return false;
    }
    var targ = ev.target || ev.srcElement; 
    if (targ.nodeType === 3) { 
        // defeat Safari bug 
        targ = targ.parentNode; 
    } 
    return targ;
};


ort.accordion = function(opts) {
    var root = ort.getElementsByClassName(opts.klass)[0],
        elems = [],
        i, len, running = false,
        expandos = [],
        baseHeights = [],
        lastHeight = null,
        activeExpando = null,
        activeElem = null,
        tweenIn, tweenOut, oTweenIn, oTweenOut,
        change = function (elem, r, to, force) {            
            var resizo = r,
                tweenIn,
                tweenOut;
                
            if (typeof resizo === "undefined") {
                return;
            }
            
            if (running) {
                return false;
            }
                       
            running = true;
                 
            if (force || ort.hasClass(elem, "off")) {

               if (activeElem && activeExpando && activeElem !== elem && ort.hasClass(activeElem, "on")) {
                    tweenOut = new ort.Tween(activeExpando.style, "height", ort.fns.easeInOutQuad, lastHeight, 0, 0.5, "px");
                    tweenOut.start();
                    tweenOut.onMotionFinished = function() {
                        activeExpando.className = activeExpando.className.replace(/on/gi, "off");
                        activeElem.className = activeElem.className.replace(/on/gi, "off");
                    };
                    
                oTweenOut = new ort.OpacityTween(activeExpando, ort.fns.easeInOutQuad, 100, 0, 0.5);
                oTweenOut.start();                    
                }
                
                
                if (resizo.className.indexOf("on") === -1) {
                    resizo.className += " on ";
                }
                resizo.style.left = "0";

                tweenIn = new ort.Tween(resizo.style, "height", ort.fns.easeInOutQuad, 0, to, 0.6, "px");
                tweenIn.start();
                tweenIn.onMotionFinished = function() {
                    resizo.className = resizo.className.replace(/off/gi, "on");
                    elem.className = elem.className.replace(/off/gi, "on");
                    running = false;
                    if (r !== null) {   
                        lastHeight = to;
                        activeExpando = r;
                        activeElem = elem;
                    }
                };    
                oTweenIn = new ort.OpacityTween(resizo, ort.fns.easeInOutQuad, 0, 100, 0.6);
                oTweenIn.start();    
            } else if (ort.hasClass(elem, "on")) {
                tweenIn = new ort.Tween(resizo.style, "height", ort.fns.easeInOutQuad, to, 0, 0.6, "px");
                tweenIn.start();
                tweenIn.onMotionFinished = function() {
                    resizo.className = resizo.className.replace(/on/gi, "off");
                    elem.className = elem.className.replace(/on/gi, "off");
                    running = false;
                    lastHeight = null;
                    activeExpando = null;
                    activeElem = null;
                };
                
                oTweenIn = new ort.OpacityTween(resizo, ort.fns.easeInOutQuad, 0, 100, 0.6);
                oTweenIn.start();           
            } 
        };
        
    
    elems = ort.getElementsByClassName(opts.clicker, root);
    expandos = ort.getElementsByClassName(opts.expando, root);

    
    for (i = 0, len = elems.length; i !== len; i++) { 
        if (expandos[i]) {
            baseHeights[i] = expandos[i].offsetHeight || expandos[i].childNodes[0].offsetHeight|| expandos[i].clientHeight;
            elems[i].className += " off ";
            expandos[i].style.position =  "static";
            expandos[i].style.height = "0px";
            expandos[i].className += " off ";
            expandos[i].style.overflow = "hidden";
            (function () {
                var p = i;
                elems[p].onclick = function () {
                    change(this, expandos[p], baseHeights[p]);
                };
            }());
        }
    }

    return {
        open: function (idx) {
            change(elems[idx], expandos[idx], baseHeights[idx], true);
        }
    };
    
};

ort.initAccordion = function () {
    var accordion = ort.accordion({"klass": "listCol", "clicker": "imageHeader", "expando": "ulWrapper"});
    accordion.open(0);
};

