//Firebug
if (!window.console || !console.firebug){
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {}
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}}

function toggleVis(classPath) {
	$$(classPath).each(function(e){
            if(e.style.display == ''){
          	e.style.display = 'none';
       	    }else{
          	e.style.display = '';
	    }
       	});
}


//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.

MooTools.More={version:"1.2.3.1"};Fx.Scroll=new Class({Extends:Fx,options:{offset:{x:0,y:0},wheelStops:true},initialize:function(b,a){this.element=this.subject=document.id(b);
this.parent(a);var d=this.cancel.bind(this,false);if($type(this.element)!="element"){this.element=document.id(this.element.getDocument().body);}var c=this.element;
if(this.options.wheelStops){this.addEvent("start",function(){c.addEvent("mousewheel",d);},true);this.addEvent("complete",function(){c.removeEvent("mousewheel",d);
},true);}},set:function(){var a=Array.flatten(arguments);this.element.scrollTo(a[0],a[1]);},compute:function(c,b,a){return[0,1].map(function(d){return Fx.compute(c[d],b[d],a);
});},start:function(c,h){if(!this.check(c,h)){return this;}var e=this.element.getSize(),f=this.element.getScrollSize();var b=this.element.getScroll(),d={x:c,y:h};
for(var g in d){var a=f[g]-e[g];if($chk(d[g])){d[g]=($type(d[g])=="number")?d[g].limit(0,a):a;}else{d[g]=b[g];}d[g]+=this.options.offset[g];}return this.parent([b.x,b.y],[d.x,d.y]);
},toTop:function(){return this.start(false,0);},toLeft:function(){return this.start(0,false);},toRight:function(){return this.start("right",false);},toBottom:function(){return this.start(false,"bottom");
},toElement:function(b){var a=document.id(b).getPosition(this.element);return this.start(a.x,a.y);},scrollIntoView:function(c,e,d){e=e?$splat(e):["x","y"];
var h={};c=document.id(c);var f=c.getPosition(this.element);var i=c.getSize();var g=this.element.getScroll();var a=this.element.getSize();var b={x:f.x+i.x,y:f.y+i.y};
["x","y"].each(function(j){if(e.contains(j)){if(b[j]>g[j]+a[j]){h[j]=b[j]-a[j];}if(f[j]<g[j]){h[j]=f[j];}}if(h[j]==null){h[j]=g[j];}if(d&&d[j]){h[j]=h[j]+d[j];
}},this);if(h.x!=g.x||h.y!=g.y){this.start(h.x,h.y);}return this;}});var Drag=new Class({Implements:[Events,Options],options:{snap:6,unit:"px",grid:false,style:true,limit:false,handle:false,invert:false,preventDefault:false,modifiers:{x:"left",y:"top"}},initialize:function(){var b=Array.link(arguments,{options:Object.type,element:$defined});
this.element=document.id(b.element);this.document=this.element.getDocument();this.setOptions(b.options||{});var a=$type(this.options.handle);this.handles=((a=="array"||a=="collection")?$$(this.options.handle):document.id(this.options.handle))||this.element;
this.mouse={now:{},pos:{}};this.value={start:{},now:{}};this.selection=(Browser.Engine.trident)?"selectstart":"mousedown";this.bound={start:this.start.bind(this),check:this.check.bind(this),drag:this.drag.bind(this),stop:this.stop.bind(this),cancel:this.cancel.bind(this),eventStop:$lambda(false)};
this.attach();},attach:function(){this.handles.addEvent("mousedown",this.bound.start);return this;},detach:function(){this.handles.removeEvent("mousedown",this.bound.start);
return this;},start:function(c){if(this.options.preventDefault){c.preventDefault();}this.mouse.start=c.page;this.fireEvent("beforeStart",this.element);
var a=this.options.limit;this.limit={x:[],y:[]};for(var d in this.options.modifiers){if(!this.options.modifiers[d]){continue;}if(this.options.style){this.value.now[d]=this.element.getStyle(this.options.modifiers[d]).toInt();
}else{this.value.now[d]=this.element[this.options.modifiers[d]];}if(this.options.invert){this.value.now[d]*=-1;}this.mouse.pos[d]=c.page[d]-this.value.now[d];
if(a&&a[d]){for(var b=2;b--;b){if($chk(a[d][b])){this.limit[d][b]=$lambda(a[d][b])();}}}}if($type(this.options.grid)=="number"){this.options.grid={x:this.options.grid,y:this.options.grid};
}this.document.addEvents({mousemove:this.bound.check,mouseup:this.bound.cancel});this.document.addEvent(this.selection,this.bound.eventStop);},check:function(a){if(this.options.preventDefault){a.preventDefault();
}var b=Math.round(Math.sqrt(Math.pow(a.page.x-this.mouse.start.x,2)+Math.pow(a.page.y-this.mouse.start.y,2)));if(b>this.options.snap){this.cancel();this.document.addEvents({mousemove:this.bound.drag,mouseup:this.bound.stop});
this.fireEvent("start",[this.element,a]).fireEvent("snap",this.element);}},drag:function(a){if(this.options.preventDefault){a.preventDefault();}this.mouse.now=a.page;
for(var b in this.options.modifiers){if(!this.options.modifiers[b]){continue;}this.value.now[b]=this.mouse.now[b]-this.mouse.pos[b];if(this.options.invert){this.value.now[b]*=-1;
}if(this.options.limit&&this.limit[b]){if($chk(this.limit[b][1])&&(this.value.now[b]>this.limit[b][1])){this.value.now[b]=this.limit[b][1];}else{if($chk(this.limit[b][0])&&(this.value.now[b]<this.limit[b][0])){this.value.now[b]=this.limit[b][0];
}}}if(this.options.grid[b]){this.value.now[b]-=((this.value.now[b]-(this.limit[b][0]||0))%this.options.grid[b]);}if(this.options.style){this.element.setStyle(this.options.modifiers[b],this.value.now[b]+this.options.unit);
}else{this.element[this.options.modifiers[b]]=this.value.now[b];}}this.fireEvent("drag",[this.element,a]);},cancel:function(a){this.document.removeEvent("mousemove",this.bound.check);
this.document.removeEvent("mouseup",this.bound.cancel);if(a){this.document.removeEvent(this.selection,this.bound.eventStop);this.fireEvent("cancel",this.element);
}},stop:function(a){this.document.removeEvent(this.selection,this.bound.eventStop);this.document.removeEvent("mousemove",this.bound.drag);this.document.removeEvent("mouseup",this.bound.stop);
if(a){this.fireEvent("complete",[this.element,a]);}}});Element.implement({makeResizable:function(a){var b=new Drag(this,$merge({modifiers:{x:"width",y:"height"}},a));
this.store("resizer",b);return b.addEvent("drag",function(){this.fireEvent("resize",b);}.bind(this));}});Drag.Move=new Class({Extends:Drag,options:{droppables:[],container:false,precalculate:false,includeMargins:true,checkDroppables:true},initialize:function(c,b){this.parent(c,b);
this.droppables=$$(this.options.droppables);this.container=document.id(this.options.container);if(this.container&&$type(this.container)!="element"){this.container=document.id(this.container.getDocument().body);
}var a=this.element.getStyle("position");if(a=="static"){a="absolute";}if([this.element.getStyle("left"),this.element.getStyle("top")].contains("auto")){this.element.position(this.element.getPosition(this.element.offsetParent));
}this.element.setStyle("position",a);this.addEvent("start",this.checkDroppables,true);this.overed=null;},start:function(f){if(this.container){var b=this.container.getCoordinates(this.element.getOffsetParent()),c={},e={};
["top","right","bottom","left"].each(function(g){c[g]=this.container.getStyle("border-"+g).toInt();e[g]=this.element.getStyle("margin-"+g).toInt();},this);
var d=this.element.offsetWidth+e.left+e.right;var a=this.element.offsetHeight+e.top+e.bottom;if(this.options.includeMargins){$each(e,function(h,g){e[g]=0;
});}if(this.container==this.element.getOffsetParent()){this.options.limit={x:[0-e.left,b.right-c.left-c.right-d+e.right],y:[0-e.top,b.bottom-c.top-c.bottom-a+e.bottom]};
}else{this.options.limit={x:[b.left+c.left-e.left,b.right-c.right-d+e.right],y:[b.top+c.top-e.top,b.bottom-c.bottom-a+e.bottom]};}}if(this.options.precalculate){this.positions=this.droppables.map(function(g){return g.getCoordinates();
});}this.parent(f);},checkAgainst:function(c,b){c=(this.positions)?this.positions[b]:c.getCoordinates();var a=this.mouse.now;return(a.x>c.left&&a.x<c.right&&a.y<c.bottom&&a.y>c.top);
},checkDroppables:function(){var a=this.droppables.filter(this.checkAgainst,this).getLast();if(this.overed!=a){if(this.overed){this.fireEvent("leave",[this.element,this.overed]);
}if(a){this.fireEvent("enter",[this.element,a]);}this.overed=a;}},drag:function(a){this.parent(a);if(this.options.checkDroppables&&this.droppables.length){this.checkDroppables();
}},stop:function(a){this.checkDroppables();this.fireEvent("drop",[this.element,this.overed,a]);this.overed=null;return this.parent(a);}});Element.implement({makeDraggable:function(a){var b=new Drag.Move(this,a);
this.store("dragger",b);return b;}});var Asset={javascript:function(f,d){d=$extend({onload:$empty,document:document,check:$lambda(true)},d);var b=new Element("script",{src:f,type:"text/javascript"});
var e=d.onload.bind(b),a=d.check,g=d.document;delete d.onload;delete d.check;delete d.document;b.addEvents({load:e,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){e();
}}}).set(d);if(Browser.Engine.webkit419){var c=(function(){if(!$try(a)){return;}$clear(c);e();}).periodical(50);}return b.inject(g.head);},css:function(b,a){return new Element("link",$merge({rel:"stylesheet",media:"screen",type:"text/css",href:b},a)).inject(document.head);
},image:function(c,b){b=$merge({onload:$empty,onabort:$empty,onerror:$empty},b);var d=new Image();var a=document.id(d)||new Element("img");["load","abort","error"].each(function(e){var f="on"+e;
var g=b[f];delete b[f];d[f]=function(){if(!d){return;}if(!a.parentNode){a.width=d.width;a.height=d.height;}d=d.onload=d.onabort=d.onerror=null;g.delay(1,a,a);
a.fireEvent(e,a,1);};});d.src=a.src=c;if(d&&d.complete){d.onload.delay(1);}return a.set(b);},images:function(d,c){c=$merge({onComplete:$empty,onProgress:$empty,onError:$empty,properties:{}},c);
d=$splat(d);var a=[];var b=0;return new Elements(d.map(function(e){return Asset.image(e,$extend(c.properties,{onload:function(){c.onProgress.call(this,b,d.indexOf(e));
b++;if(b==d.length){c.onComplete();}},onerror:function(){c.onError.call(this,b,d.indexOf(e));b++;if(b==d.length){c.onComplete();}}}));}));}};Hash.Cookie=new Class({Extends:Cookie,options:{autoSave:true},initialize:function(b,a){this.parent(b,a);
this.load();},save:function(){var a=JSON.encode(this.hash);if(!a||a.length>4096){return false;}if(a=="{}"){this.dispose();}else{this.write(a);}return true;
},load:function(){this.hash=new Hash(JSON.decode(this.read(),true));return this;}});Hash.each(Hash.prototype,function(b,a){if(typeof b=="function"){Hash.Cookie.implement(a,function(){var c=b.apply(this.hash,arguments);
if(this.options.autoSave){this.save();}return c;});}});
// Dependency on Loop.js

/*
---

script: Loop.js

description: Runs a class method on a periodical

license: MIT-style license.

authors: Ryan Florence <http://ryanflorence.com>

docs: http://moodocs.net/rpflo/mootools-rpflo/Loop

requires:
- core:1.2.4/'*'

provides: [Loop]

...
*/

var Loop = new Class({

    loopCount: 0,
    isStopped: true,
    isLooping: false,
    loopMethod: $empty,

    setLoop: function(fn,delay){
        if(this.isLooping) {
            this.stopLoop();
            var wasLooping = true;
        } else {
            var wasLooping = false;
        }
        this.loopMethod = fn;
        this.loopDelay = delay || 3000;
        if(wasLooping) this.startLoop();
        return this;
    },

    stopLoop: function() {
        this.isStopped = true;
        this.isLooping = false;
        $clear(this.periodical);
        return this;
    },

    startLoop: function(delay) {
        if(this.isStopped){
            var delay = (delay) ? delay : this.loopDelay;
            this.isStopped = false;
            this.isLooping = true;
            this.periodical = this.looper.periodical(delay,this);
        };
        return this;
    },

    resetLoop: function(){
        this.loopCount = 0;
        return this;
    },

    looper: function(){
        this.loopCount++;
        this.loopMethod(this.loopCount);
        return this;
    }

});




// THE CLASS

/*
---

script: SlideShow.js

description: Easily extendable, class-based, slideshow widget. Use any element, not just images. Comes with packaged transitions but is easy to extend and create your own transitions.  The class is built to handle the basics of a slideshow, extend it to implement your own navigation piece and custom transitions.

license: MIT-style license.

authors: Ryan Florence

docs: http://moodocs.net/rpflo/mootools-rpflo/SlideShow

requires:
  - Loop

provides: [SlideShow]

...
*/


var SlideShow = new Class({
    
    Implements: [Options, Events, Loop],
        
        options: {
            /*
            onShow: $empty,
            onShowComplete: $empty,
            onReverse: $empty,
            onPlay: $empty,
            onPause: $empty
            */
            delay: 7000,
            transition: 'crossFade',
            duration: '500',
            autoplay: false
        },
    
    initialize: function(element, options){
        this.setOptions(options);
        this.setLoop(this.showNext, this.options.delay);
        this.element = document.id(element);
        this.slides = this.element.getChildren();
        this.current = this.slides[0];
        this.setup();
        if(this.options.autoplay) this.startLoop();
    },
    
    setup: function(){
      this.setupElement();
      this.setupSlides();
        return this;
    },
    
    setupElement: function(){
        var el = this.element;
        if(el.getStyle('position') != 'absolute' && el != document.body) el.setStyle('position','relative');
        return this;
    },
    
    setupSlides: function(){
        this.slides.each(function(slide, index){
            this.storeTransition(slide).reset(slide);
            if(index != 0) slide.setStyle('display','none');
        }, this);
        return this;
    },
    
    storeTransition: function(slide){
        var classes = slide.get('class');
        var transitionRegex = /transition:[a-zA-Z]+/;
        var durationRegex = /duration:[0-9]+/;
        var transition = (classes.match(transitionRegex)) ? classes.match(transitionRegex)[0].split(':')[1] : this.options.transition;
        var duration = (classes.match(durationRegex)) ? classes.match(durationRegex)[0].split(':')[1] : this.options.duration;
        slide.store('ssTransition', transition);
        slide.store('ssDuration', duration);
        return this;
    },
    
    getTransition: function(slide){
        return slide.retrieve('ssTransition');
    },
    
    getDuration: function(slide){
        return slide.retrieve('ssDuration');
    },
    
    show: function(slide){
        this.fireEvent('show');
        if(slide != this.current){
            var transition = this.getTransition(slide);
            var duration = this.getDuration(slide);
            var previous = this.current.setStyle('z-index', 1);
            var next = this.reset(slide);
            this.transitions[transition](previous, next, duration, this);
            (function() { 
                previous.setStyle('display','none');
                this.fireEvent('showComplete');
            }).bind(this).delay(duration);
            this.current = next;
        }
        return this;
    },
    
    reset: function(slide){
        return slide.setStyles({
            'position': 'absolute',
            'z-index': 0,
            'display': 'block',
            'left': 0,
            'top': 0
        }).fade('show');
        return this;
    },
    
    nextSlide: function(){
        var next = this.current.getNext();
        return (next) ? next : this.slides[0];
    },

    previousSlide: function(){
        var previous = this.current.getPrevious();
        return (previous) ? previous : this.slides.getLast();
    },
    
    showNext: function(){
        this.show(this.nextSlide());
        return this;
    },
    
    showPrevious: function(){
        this.show(this.previousSlide());
        return this;
    },
    
    play: function(){
        this.startLoop();
        this.fireEvent('play');
        return this;
    },
    
    pause: function(){
        this.stopLoop();
        this.fireEvent('pause');
        return this;
    },
    
    reverse: function(){
        var fn = (this.loopMethod == this.showNext) ? this.showPrevious : this.showNext;
        this.setLoop(fn, this.options.delay);
        this.fireEvent('reverse');
        return this;
    }
    
});

SlideShow.adders = {
    
    transitions:{},
    
    add: function(className, fn){
        this.transitions[className] = fn;
        this.implement({
            transitions: this.transitions
        });
    },
    
    addAllThese : function(transitions){
        $A(transitions).each(function(transition){
            this.add(transition[0], transition[1]);
        }, this);
    }
    
}

$extend(SlideShow, SlideShow.adders);
SlideShow.implement(SlideShow.adders);

SlideShow.add('fade', function(previous, next, duration, instance){
    previous.set('tween',{duration: duration}).fade('out');
    return this;
});

SlideShow.addAllThese([

    ['none', function(previous, next, duration, instance){
        previous.setStyle('display','none');
        return this;
    }],

    ['crossFade', function(previous, next, duration, instance){
        previous.set('tween',{duration: duration}).fade('out');
        next.set('tween',{duration: duration}).fade('in');
        return this;
    }],
    
    ['fadeThroughBackground', function(previous, next, duration, instance){
        var half = duration/2;
        next.set('tween',{
            duration: half
        }).fade('hide');
        previous.set('tween',{
            duration: half,
            onComplete: function(){
                next.fade('in');
            }
        }).fade('out');
    }],

    ['pushLeft', function(previous, next, duration, instance){
        var distance = instance.element.getStyle('width').toInt();
        next.setStyle('left', distance);
        [next, previous].each(function(slide){
            var to = slide.getStyle('left').toInt() - distance;
            slide.set('tween',{duration: duration}).tween('left', to);
        });
        return this;
    }],
    
    ['pushRight', function(previous, next, duration, instance){
        var distance = instance.element.getStyle('width').toInt();
        next.setStyle('left', -distance);
        [next, previous].each(function(slide){
            var to = slide.getStyle('left').toInt() + distance;
            slide.set('tween',{duration: duration}).tween('left', to);
        });
        return this;
    }],
    
    ['pushDown', function(previous, next, duration, instance){
        var distance = instance.element.getStyle('height').toInt();
        next.setStyle('top', -distance);
        [next, previous].each(function(slide){
            var to = slide.getStyle('top').toInt() + distance;
            slide.set('tween',{duration: duration}).tween('top', to);
        });
        return this;
    }],
    
    ['pushUp', function(previous, next, duration, instance){
        var distance = instance.element.getStyle('height').toInt();
        next.setStyle('top', distance);
        [next, previous].each(function(slide){
            var to = slide.getStyle('top').toInt() - distance;
            slide.set('tween',{duration: duration}).tween('top', to);
        });
        return this;
    }],
    
    ['blindLeft', function(previous, next, duration, instance){
        var distance = instance.element.getStyle('width').toInt();
        next
            .setStyles({
                'left': distance,
                'z-index': 1
            })
            .set('tween',{duration: duration})
            .tween('left', 0);
        return this;
    }],

    ['blindRight', function(previous, next, duration, instance){
        var distance = instance.element.getStyle('width').toInt();
        next
            .setStyles({
                'left': -distance,
                'z-index': 1
            })
            .set('tween',{duration: duration})
            .tween('left', 0);
        return this;
    }],
    
    ['blindUp', function(previous, next, duration, instance){
        var distance = instance.element.getStyle('height').toInt();
        next
            .setStyles({
                'top': distance,
                'z-index': 1
            })
            .set('tween',{duration: duration})
            .tween('top', 0);
        return this;
    }],
    
    ['blindDown', function(previous, next, duration, instance){
        var distance = instance.element.getStyle('height').toInt();
        next
            .setStyles({
                'top': -distance,
                'z-index': 1
            })
            .set('tween',{duration: duration})
            .tween('top', 0);
        return this;
    }],
    
    ['blindDownFade', function(previous, next, duration, instance){
        this.blindDown(previous, next, duration, instance).fade(previous, next, duration, instance);
    }],
    
    ['blindUpFade', function(previous, next, duration, instance){
        this.blindUp(previous, next, duration, instance).fade(previous, next, duration, instance);
    }],
    
    ['blindLeftFade', function(previous, next, duration, instance){
        this.blindLeft(previous, next, duration, instance).fade(previous, next, duration, instance);
    }],
    
    ['blindRightFade', function(previous, next, duration, instance){
        this.blindRight(previous, next, duration, instance).fade(previous, next, duration, instance);
    }]
    
]);

/**
 * ReMooz - Zoomer
 *
 * Inspired by so many boxes and zooms
 *
 * @version		1.0
 *
 * @license		MIT-style license
 * @author		Harald Kirschner <mail [at] digitarald.de>
 * @copyright	Author
 */

var ReMooz = new Class({

	Implements: [Events, Options, Chain],

	options: {
		link: null,
		type: 'image',
		container: null,
		className: null,
		centered: false,
		dragging: true,
		closeOnClick: true,
		shadow: (Browser.Engine.trident) ? 'onOpenEnd' : 'onOpen', // performance
		resize: true,
		margin: 20,
		resizeFactor: 0.95,
		resizeLimit: false, // {x: 640, y: 640}
		fixedSize: false,
		cutOut: true,
		addClick: true,
		opacityLoad: 0.6,
		opacityResize: 1,
		opacityTitle: 0.9,
		resizeOptions: {},
		fxOptions: {},
		closer: true,
		parse: false, // 'rel'
		parseSecure: false,
		temporary: false,
		onBuild: $empty,
		onLoad: $empty,
		onOpen: $empty,
		onOpenEnd: $empty,
		onClose: $empty,
		onCloseEnd: $empty,
		generateTitle: function(el) {
			var text = el.get('title');
			if (!text) return false;
			var title = text.split(' :: ');
			var head = new Element('h6', {'html': title[0]});
			return (title[1]) ? [head, new Element('p', {'html': title[1]})] : head;
		}
	},

	initialize: function(element, options) {
		this.element = $(element);
		this.setOptions(options);
		if (this.options.parse) {
			var obj = this.element.getProperty(this.options.parse);
			if (obj && (obj = JSON.decode(obj, this.options.parseSecure))) this.setOptions(obj);
		}
		var origin = this.options.origin;
		this.origin = ((origin) ? $(origin) || this.element.getElement(origin) : null) || this.element;
		this.link = this.options.link || this.element.get('href') || this.element.get('src');
		this.container = $(this.options.container) || this.element.getDocument();
		this.bound = {
			'click': function(e) {
				this.open.delay(1, this);
				return false;
			}.bind(this),
			'close': this.close.bind(this),
			'dragClose': function(e) {
				if (e.rightClick) return;
				this.close();
			}.bind(this)
		};
		if (this.options.addClick) this.bindToElement();
	},

	destroy: function() {
		if (this.box) this.box.destroy();
		this.box = this.tweens = this.body = this.content = null;
	},

	bindToElement: function(element) {
		($(element) || this.element).addClass('remooz-element').addEvent('click', this.bound.click);
		return this;
	},

	getOriginCoordinates: function() {
		var coords = this.origin.getCoordinates();
		delete coords.right;
		delete coords.bottom;
		return coords;
	},

	open: function(e) {
		if (this.opened) return (e) ? this.close() : this;
		this.opened = this.loading = true;
		if (!this.box) this.build();
		this.coords = this.getOriginCoordinates();
		this.coords.opacity = this.options.opacityLoad;
		this.coords.display = '';
		this.tweens.box.set(this.coords);
		this.box.addClass('remooz-loading');
		ReMooz.open(this.fireEvent('onLoad'));
		this['open' + this.options.type.capitalize()]();
		return this;
	},

	finishOpen: function() {
		this.tweens.fade.start(0, 1);
		this.drag.attach();
		this.fireEvent('onOpenEnd').callChain();
	},

	close: function() {
		if (!this.opened) return this;
		this.opened = false;
		ReMooz.close(this.fireEvent('onClose'));
		if (this.loading) {
			this.box.setStyle('display', 'none');
			return this;
		}
		this.drag.detach();
		this.tweens.fade.cancel().set(0).fireEvent('onComplete');
		if (this.tweens.box.timer) this.tweens.box.clearChain();
		var vars = this.getOriginCoordinates();
		if (this.options.opacityResize != 1) vars.opacity = this.options.opacityResize;
		this.tweens.box.start(vars).chain(this.closeEnd.bind(this));
		return this;
	},

	closeEnd: function() {
		if (this.options.cutOut) this.element.setStyle('visibility', 'visible');
		this.box.setStyle('display', 'none');
		this.fireEvent('onCloseEnd').callChain();
		if (this.options.temporary) this.destroy();
	},

	openImage: function() {
		var tmp = new Image();
		tmp.onload = tmp.onabort = tmp.onerror = function(fast) {
			this.loading = tmp.onload = tmp.onabort = tmp.onerror = null;
			if (!tmp.width || !this.opened) {
				this.fireEvent('onError').close();
				return;
			}
			var to = {x: tmp.width, y: tmp.height};
			if (!this.content) this.content = $(tmp).inject(this.body);
			else tmp = null;
			this[(this.options.resize) ? 'zoomRelativeTo' : 'zoomTo'].create({
				'delay': (tmp && fast !== true) ? 1 : null,
				'arguments': [to],
				'bind': this
			})();
		}.bind(this);
		tmp.src = this.link;
		if (tmp && tmp.complete && tmp.onload) tmp.onload(true);
	},

	/**
	 * @todo Test implementation
	 */
	openElement: function() {
		this.content = this.content || $(this.link) || $E(this.link);
		if (!this.content) {
			this.fireEvent('onError').close();
			return;
		}
		this.content.inject(this.body);
		this.zoomTo({x: this.content.scrollWidth, y: this.content.scrollHeight});
	},

	zoomRelativeTo: function(to) {
		var scale = this.options.resizeLimit;
		if (!scale) {
			scale = this.container.getSize();
			scale.x *= this.options.resizeFactor;
			scale.y *= this.options.resizeFactor;
		}
		for (var i = 2; i--;) {
			if (to.x > scale.x) {
				to.y *= scale.x / to.x;
				to.x = scale.x;
			} else if (to.y > scale.y) {
				to.x *= scale.y / to.y;
				to.y = scale.y;
			}
		}
		return this.zoomTo({x: to.x.toInt(), y: to.y.toInt()});
	},

	zoomTo: function(to) {
		to = this.options.fixedSize || to;
		var box = this.container.getSize(), scroll = this.container.getScroll();
		var pos = (!this.options.centered) ? {
			x: (this.coords.left + (this.coords.width / 2) - to.x / 2).toInt()
				.limit(scroll.x + this.options.margin, scroll.x + box.x - this.options.margin - to.x),
			y: (this.coords.top + (this.coords.height / 2) - to.y / 2).toInt()
				.limit(scroll.y + this.options.margin, scroll.y + box.y - this.options.margin - to.y)
		} :  {
			x: scroll.x + ((box.x - to.x) / 2).toInt(),
			y: scroll.y + ((box.y - to.y) / 2).toInt()
		};
		if (this.options.cutOut) this.element.setStyle('visibility', 'hidden');
		this.box.removeClass('remooz-loading');
		var vars = {left: pos.x, top: pos.y, width: to.x, height: to.y};
		if (this.options.opacityResize != 1) vars.opacity = [this.options.opacityResize, 1];
		else this.box.set('opacity', 1);
		this.tweens.box.start(vars).chain(this.finishOpen.bind(this));
		this.fireEvent('onOpen');
	},

	build: function() {
		this.addEvent('onBlur', function() {
			this.focused = false;
			this.box.removeClass('remooz-box-focus').setStyle('z-index', ReMooz.options.zIndex);
		}, true);
		this.addEvent('onFocus', function() {
			this.focused = true;
			this.box.addClass('remooz-box-focus').setStyle('z-index', ReMooz.options.zIndexFocus);
		}, true);

		var classes = ['remooz-box', 'remooz-type-' + this.options.type, 'remooz-engine-' + Browser.Engine.name + Browser.Engine.version];
		if (this.options.className) classes.push(this.options.className);
		this.box = new Element('div', {
			'class': classes.join(' '),
			'styles': {
				'display': 'none',
				'top': 0,
				'left': 0,
				'zIndex': ReMooz.options.zIndex
			}
		});

		this.tweens = {
			'box': new Fx.Morph(this.box, $merge({
					'duration': 400,
					'unit': 'px',
					'transition': Fx.Transitions.Quart.easeOut,
					'chain': 'cancel'
				}, this.options.resizeOptions)
			),
			'fade': new Fx.Tween(null, $merge({
					'property': 'opacity',
					'duration': (Browser.Engine.trident) ? 0 : 300,
					'chain': 'cancel'
				}, this.options.fxOptions)).addEvents({
					'onComplete': function() {
						if (!this.element.get('opacity')) this.element.setStyle('display', 'none');
					},
					'onStart': function() {
						if (!this.element.get('opacity')) this.element.setStyle('display', '');
					}
				}
			)
		};
		this.tweens.fade.element = $$();

		if (this.options.shadow) {
			if (Browser.Engine.webkit420) {
				this.box.setStyle('-webkit-box-shadow', '0 0 10px rgba(0, 0, 0, 0.7)');
			} else if (!Browser.Engine.trident4) {
				var shadow = new Element('div', {'class': 'remooz-bg-wrap'}).inject(this.box);
				['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'].each(function(dir) {
					new Element('div', {'class': 'remooz-bg remooz-bg-' + dir}).inject(shadow);
				});
				this.tweens.bg = new Fx.Tween(shadow, {
					'property': 'opacity',
					'chain': 'cancel'
				}).set(0);
				this.addEvent(this.options.shadow, this.tweens.bg.set.bind(this.tweens.bg, 1), true);
				this.addEvent('onClose', this.tweens.bg.set.bind(this.tweens.bg, 0), true);
			}
		}

		if (this.options.closer) {
			var closer = new Element('a', {
				'class': 'remooz-btn-close',
				'events': {'click': this.bound.close}
			}).inject(this.box);
			this.tweens.fade.element.push(closer);
		}
		this.body = new Element('div', {'class': 'remooz-body'}).inject(this.box);

		var title = this.options.title || this.options.generateTitle.call(this, this.element);
		if (title) { // thx ie6
			var title = new Element('div', {'class': 'remooz-title'}).adopt(
				new Element('div', {'class': 'remooz-title-bg', 'opacity': this.options.opacityTitle}),
				new Element('div', {'class': 'remooz-title-content'}).adopt(title)
			).inject(this.box);
			this.tweens.fade.element.push(title);
		}
		this.tweens.fade.set(0).fireEvent('onComplete');

		this.drag = new Drag.Move(this.box, {
			'snap': 15,
			'preventDefault': true,
			'onBeforeStart': function() {
				if (!this.focused && !this.loading) ReMooz.focus(this);
				else if (this.loading || this.options.closeOnClick) this.box.addEvent('mouseup', this.bound.dragClose);
			}.bind(this),
			'onSnap': function() {
				this.box.removeEvent('mouseup', this.bound.dragClose);
				if (!this.options.dragging) this.drag.stop();
				else this.box.addClass('remooz-box-dragging');
			}.bind(this),
			'onComplete': function() {
				this.box.removeClass('remooz-box-dragging');
			}.bind(this)
		});
		this.drag.detach();

		this.fireEvent('onBuild', this.box, this.element);
		this.box.inject(this.element.getDocument().body);
	}

});

ReMooz.factory = function(extended) {
	return $extend(this, extended);
};

ReMooz.factory(new Options).factory({

	options: {
		zIndex: 41,
		zIndexFocus: 42,
		query: 'a.remooz',
		modal: false
	},

	assign: function(elements, options) {
		return $$(elements).map(function(element) {
			return new ReMooz(element, options);
		}, this);
	},

	stack: [],

	open: function(obj) {
		var last = this.stack.getLast();
		this.focus(obj);
		if (last && this.options.modal) last.close();
	},

	close: function(obj) {
		var length = this.stack.length - 1;
		if (length > 1 && this.stack[length] == obj) this.focus(this.stack[length - 1]);
		this.stack.erase(obj);
	},

	focus: function(obj) {
		var last = this.stack.getLast();
		obj.fireEvent('onFocus', [obj]);
		if (last == obj) return;
		if (last) last.fireEvent('onBlur', [last]);
		this.stack.erase(obj).push(obj);
	}

});



Element.implement({
    getHeight: function () {
        return this.getSize().y;
    },
    getWidth: function () {
        return this.getSize().x;
    },
    hide: function () {
        return this.addClass('hide');
    },
    show: function () {
        return this.removeClass('hide');
    },
    fadeIn: function (duration, callback) {
        var self = this;
        this.setStyle('opacity', 0);
        this.set('tween', {
            'duration': duration,
            'onComplete': function () {
                if (callback) callback.attempt(false, self);
            }
        }).tween('opacity', 1);
    },
    fadeOut: function (duration, callback) {
        var self = this;
        this.set('tween', {
            'duration': duration,
            'onComplete': function () {
                if (callback) callback.attempt(false, self);
            }
        }).tween('opacity', 0);
    },
    slideIn: function (duration, callback) {
        if (!duration) duration = 300;
        if (!callback) callback = function () {};
        this.removeClass('hide');
        var h = this.getHeight();
        var o = this.getStyle('overflow');
        this.addClass('hide');
        this.setStyle('height', 0).setStyle('overflow', 'hidden').removeClass('hide').set('tween', {
            duration: duration,
            onComplete: function () {
                this.setStyle('overflow', o);
                callback.attempt();
            }.bind(this)
        }).tween('height', h);
    },
    slideOut: function (duration, callback) {
        if (!duration) duration = 300;
        if (!callback) callback = function () {};
        var h = this.getHeight();
        var o = this.getStyle('overflow');
        this.setStyle('overflow', 'hidden').set('tween', {
            duration: duration,
            onComplete: function () {
                this.setStyle('overflow', o).addClass('hide').setStyle('height', h);
                callback.attempt();
            }.bind(this)
        }).tween('height', 0);
    },
    isParent: function (element) {
        t = this;
        element = $(element);
        while (t.getParent()) {
            if (t == element) return true;
            t = t.getParent();
        }
        return false;
    }
});

var Loader = new Class({
    Implements: [Options, Events],
    options: {
        delay: 500
    },
    initialize: function (options) {
        this.setOptions(options);
        this.loaded = false;
        this.loading = false;
        this.timer = false;
        this.func = function (t) {
            if (this.loaded) return true;
            this.fireEvent('onStart', t);
        };
    },
    start: function (t) {
        this.loaded = false;
        this.loading = true;
        this.timer = this.func.delay(this.options.delay, this, t);
    },
    stop: function (t) {
        this.loaded = true;
        this.loading = false;
        this.fireEvent('onStop', t);
        $clear(this.timer);
    }
});

var modal = {
    container: $('modal'),
    blocker: false,
    onOpen: $empty,
    onClose: $empty,
    onSubmit: $empty,
    preloader: new Loader({
        'onStart': function () {
            new Element('div').set('id', 'modal-preloader').inject(document.body);
        },
        'onStop': function () {
            if ($('modal-preloader')) $('modal-preloader').destroy();
        }
    }),
    loader: new Loader({
        'onStart': function (msg) {
            var l = new Element('div').set('id', 'modal-loader').set('html', '<p>' + msg + '…</p>').inject('modal-content', 'before').fadeIn(200);
        },
        'onStop': function () {
            if ($('modal-loader')) $('modal-loader').destroy();
        }
    }),
    open: function (id) {
	this.container = $(id);
        var scroll = $(document.body).getScroll().y;
        //var view = parsed[0];
        //this.clean(view);
        this.preloader.start();
        this.onOpen.attempt();
        if (!this.blocker) this.blocker = new Element('div', {
            id: 'blocker'
        }).addClass('blocker').addClass('modal').addEvent('click', this.close.bind(this)).inject(this.container, 'before');
        this.container.setStyle('top', -6000);
	this.container.setStyle('display', 'block');
        modal.container.setStyle('top', -modal.container.getHeight())
        modal.container.set('tween', {
            duration: 150
        }).tween('top', 0);
        modal.preloader.stop();
        modal.register(this.container);
        //modal.focus();
        window.scrollTo(0, scroll);
    },
    register: function (el) {
        el.getElements('.tab').each(function (t) {
            var id = t.get('id').replace('modal-tab-', '');
            modal.callback(id, 'load', this);
        }, this);
    },
    clean: function (view) {
        if (view == this.view) return true;
        this.view = view;
    },
    kill: function () {
        this.container.destroy();
        this.container = false;
        if (this.blocker) this.blocker.destroy();
        this.blocker = false;
        this.onClose.attempt();
    },
    submit: function () {
	var oldBtn = this.container.getElement('.Doc2Form input.button');
	new Element('input', {
    		'type': 'hidden',
    		'name': oldBtn.get('name'),
		'onclick': oldBtn.get('onclick')
	}).inject($('aspnetForm'));
        document.forms['aspnetForm'].submit();
    },
    close: function () {
        this.onClose.attempt();
        if (this.loader.loading) return false;
        if (!this.container) return false;
        if (this.container.hasClass('html')) return window.close();
        this.container.set('tween', {
            duration: 200,
            onComplete: function (element) {
                //this.container.destroy();
                //this.container = false;
                //if (!window.webkit) $$('.quicktime').removeClass('hide');
            }.bind(this)
        }).tween('top', -this.container.getHeight());
        if (this.blocker) this.blocker.destroy();
        this.blocker = false;
    },
    showTab: function (id) {
	console.log(this.container)
        this.hideMSG();
        if (this.loader.loading) return false;
        this.container.getElements('div.modal-menu li.active').removeClass('active');
        $('modal-menu-' + id).addClass('active');
	this.container.getElements('.tab').each(function (t) {
            t.removeClass('active');
        }, this);
        //$$('.tab').removeClass('active');
        var tab = $('modal-tab-' + id);
        if (tab) tab.addClass('active');
        this.focus();
        this.callback(id, 'focus', id);
    },
    showMSG: function (msg, type) {
        this.hideMSG();
        $('modal').addClass('msg');
        var m = new Element('div').set('id', 'modal-msg').set('html', '<p>' + msg + '</p>').addClass(type).addEvent('click', this.hideMSG.bind(this)).inject('modal-content', 'before');
        return m;
    },
    hideMSG: function () {
        $('modal').removeClass('msg');
        if (this.timer) $clear(this.timer);
        if ($('modal-msg')) $('modal-msg').destroy();
    },
    showError: function (msg) {
        modal.showMSG(msg, 'error');
        modal.focus();
    },
    showSuccess: function (msg) {
        modal.showMSG(msg, 'success');
        modal.timer = modal.hideMSG.delay(2000);
    },
    showQuestion: function (msg, callback) {
        var m = this.showMSG(msg, 'question');
        var b = new Element('div').addClass('buttons').inject(m);
        var no = new Element('a').set('href', './').set('text', 'no').addEvent('click', function (e) {
            e.stop();
            modal.hideMSG();
        }).inject(b)
        var yes = new Element('a').set('href', './').set('text', 'yes').addEvent('click', function (e) {
            e.stop();
            modal.hideMSG();
            if (callback) callback.attempt();
        }).inject(b)
    },
    focus: function (field) {
        var element = (field) ? this.field(field) : this.container.getElement('.tab.active .focus');
        if (element) element.focus();
    },
    field: function (name) {
        return this.container.getElement('.tab.active [name=' + name + ']');
    },
    value: function (name) {
        var field = this.field(name);
        return (field) ? field.get('value') : false;
    },
    callback: function (id, func, args) {
        return (modal[id] && modal[id][func]) ? modal[id][func].attempt(args, modal) : -1;
    }
};

//Lock & Load

window.addEvents({
    'domready': function () {
	if (Browser.Engine.trident4){
		$$('body')[0].addClass('ie6');
	}
	var brag = $$('div.Doc2Form .ticketStatus_li select');
	if(brag.length > 0){
		brag[0].addEvent('change', function(){
			console.log(this.options[this.selectedIndex].innerHTML == "Closed")
			if(this.options[this.selectedIndex].innerHTML == "Closed"){
    				$$('div.Doc2Form .ticketBrag_li')[0].setStyle('visibility', 'visible');
			}else{
				$$('div.Doc2Form .ticketBrag_li')[0].setStyle('visibility', 'hidden');
			}
		});
	}

	if($('filelist')){
		console.log("Filelist")
		var checkedItems = [];
		var storeCSV = $$('#fileStateStore textarea')[0];
    		var formCSV = $$('form')[0];
		var checkboxes = $$('#filelist input.fileCheck')
		checkedItems = storeCSV.get('value').split(',');

		checkboxes.each(function(item, i) {
			item.set('checked', false);
			item.set('disabled', false);
			if(checkedItems.indexOf(item.get('value')) != -1){
				item.set('checked', true);
			}
    			item.addEvent('click', function(){
				$('statusField').set('text', "Saving...").setStyle('color', 'red');
				checkboxes.each(function(item, i) {
					item.set('disabled', true);
				});
				var arrayTest = checkedItems.indexOf(item.get('value'));
				if(item.get('checked') && arrayTest == -1){
					checkedItems.push(item.get('value'));
				}else if(!item.get('checked') && arrayTest != -1){
					checkedItems.splice(arrayTest, 1);
				}else{
					//Nothing	
				}
				storeCSV.set('value', checkedItems);
				new Element('input', {
					type: 'hidden',
					name: $$('form input[type=submit]')[0].get("name")
				}).inject(formCSV)
					
				formCSV.submit();
			}); 
  		});
	}

	if($('slides')){
	mySlideShow = new SlideShow('slides',{
        	delay: 2000,
        	autoplay: true
    	});
	}
	$$('div.imageNode a').each(function(element) {
        	// Constructor, takes the element and options as arguments
        	new ReMooz(element, {
            		centered: true, // Zoom the center of the screen
            		origin: element.getElement('div') // Take the image inside as origin for the zooming element
        	});
    	});
	$$('tr.images a').each(function(element) {
        	// Constructor, takes the element and options as arguments
        	new ReMooz(element, {
            		centered: true, // Zoom the center of the screen
            		origin: element.getElement('div') // Take the image inside as origin for the zooming element
        	});
    	});
	var errorSummery = $$('div.Doc2Form div.vsummary')[0];
	if(errorSummery){
	if(errorSummery.get('html').length > 10){
		$('errorHolder').setStyle('display', 'block');
		$('errorText').set('html' , errorSummery.get('html'));
	}
	}

        switch(location.hash){
            case "#login": modal.open('modal'); break;
        }
    },
    'keydown': function (event) {
        if (event.key == 'esc' && !event.target.hasClass('custom-esc')) modal.close();
    }
});
