// JScript source code
var navigation = new Class({
	initialize: function(options) {
		if(options.entryselector){
			this.elementlist = $$(options.entryselector);
			if(this.elementlist && this.elementlist.length) {
				for(var i=0; i<this.elementlist.length; i++) {
					var current		= this.elementlist[i];
					var thelink		= current.getChildren('a')[0];
					if(thelink) {
						if(thelink.hasClass('leftbottom')) {
							thelink.setStyle('position', 'absolute');
						}
						var morph		= new Fx.Morph(thelink, {'duration':200});
						thelink.addEvent('mouseenter', this.up.bindWithEvent(morph));
						thelink.addEvent('mouseleave', this.down.bindWithEvent(morph));
					}
					/*
					if(thelink) {
						var theclone	= thelink.clone();
						theclone.setStyles({'position':'absolute', 'left':'0px', 'top':'0px', 'font-size':options.fontsize, 'color':options.fontcolor, 'font-weight':options.fontweight  });
						if(options.adjustment && options.adjustment.length) {
							for(var j=0; j<options.adjustment.length; j++) {
								var adjust = options.adjustment[j];
								if(adjust.classname && theclone.hasClass(adjust.classname)) {
									theclone.setStyles({'left':adjust.left + 'px', 'top':adjust.top + 'px'});
								}
							}
						}
						var defs = {'hoveranim':new Fx.Morph(theclone), 'normalanim':new Fx.Morph(thelink), 'parent':current, 'normal':thelink, 'hover':theclone};
						
						//current.addEvent('mouseenter', this.showhover.bindWithEvent(defs));
						//current.addEvent('mouseleave', this.hidehover.bindWithEvent(defs));
						thelink.addEvent('mouseenter', this.showhover.bindWithEvent(defs));
						theclone.addEvent('mouseleave', this.hidehover.bindWithEvent(defs));
						thelink.addEvent('mouseleave', this.hidehover.bindWithEvent(defs));
						
						defs.hoveranim.set({opacity:0.0});
						theclone.inject(current);
					}*/
				}
			}
		}
	},
	up:function(ev) {
		this.cancel();
		this.start({color:'#FF0000', 'font-size':14, 'fontweight':'bold', 'top':-2});
	},
	down: function(ev) {
		this.cancel();
		this.start({color:'#747474', 'font-size':12, 'fontweight':'normal', 'top':0});
	},
	hidehover:function(ev) {
		
		var normal	= this.normalanim;
		var hover	= this.hoveranim;
		if(normal && hover) {
			normal.cancel()
			hover.cancel;
			hover.start({opacity:0.0});
			normal.start({opacity:1.0});
			ev.stop();
		}
	},
	showhover:function(ev) {
	
		if(this.hoveranim && this.normalanim) {
			this.hoveranim.cancel();
			this.normalanim.cancel();
			this.hoveranim.start({opacity:1.0});
			this.normalanim.start({opacity:0.0});
			ev.stop();
		}
	}
}); 

var attachImageToggle = new Class({
	initialize: function(options) {
		if(options && options.link && options.image) {
			this.link = $(options.link);
			this.image = $(options.image);
			if(this.link && this.image) {
				this.src	= this.image.getProperty('src');
				this.altsrc = this.image.getProperty('altsrc');
				if(this.src && this.altsrc) {
					this.link.addEvent('mouseenter', this.showAlt.bindWithEvent(this));
					this.link.addEvent('mouseleave', this.hideAlt.bindWithEvent(this));
				}
			}
		}
	},
	showAlt:function(ev) {
		this.image.src = this.altsrc;
	},
	hideAlt:function(ev) {
		this.image.src = this.src;
	}
});

var imageToggle = new Class({
	initialize: function(options) {
		if(options && options.image) {
			this.image = $(options.image);
			if(this.image) {
				this.src	= this.image.getProperty('src');
				this.altsrc = this.image.getProperty('altsrc');
				if(this.src && this.altsrc) {
					this.image.addEvent('mouseenter', this.showAlt.bindWithEvent(this));
					this.image.addEvent('mouseleave', this.hideAlt.bindWithEvent(this));
				}
			}
		}
	},
	showAlt:function(ev) {
		this.image.src = this.altsrc;
	},
	hideAlt:function(ev) {
		this.image.src = this.src;
	}
});

var panetoggler = new Class({
	initialize: function(options) {
		if(options.elements && options.elements.length > 1) { 
			this.elements = [];
			for(var i=0; i<options.elements.length; i++) {
				var trigger = options.elements[i].trigger;
				var pane	= $(options.elements[i].pane);
				if(pane && trigger && trigger.length) {
					pane['anim'] = new Fx.Morph(pane);
					for(var j=0; j<trigger.length; j++) {
						$(trigger[j])['index'] = i;
						$(trigger[j]).addEvent('click', this.showPane.bindWithEvent(this));
						$(trigger[j]).addClass('interactive');
					}
					this.elements.push({trigger:trigger, pane:pane});
					if(options.initialindex != i) {
						pane.anim.set({'opacity':0.0});
					} else {
						pane.anim.set({'opacity':1.0});
						this.current = i;
					}
				}
			}
		}
	},
	showPane: function(ev) {
		var trigger = $(ev.target);
		while(!$defined(trigger.index)) {
			trigger = trigger.getParent();
		} 
		if(trigger && trigger.index != this.current) {
			var new_element = this.elements[trigger.index];
			var cur_element = this.elements[this.current];
			new_element.pane.anim.cancel();
			new_element.pane.anim.start({'opacity':1.0}); 
			cur_element.pane.anim.cancel();
			cur_element.pane.anim.start({'opacity':0.0});
			this.current =  trigger.index;
		}
	} 
});

