// script.aculo.us slider.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008

// Copyright (c) 2005-2007 Marty Haught, Thomas Fuchs 
//
// script.aculo.us is freely distributable under the terms of an MIT-style license.
// For details, see the script.aculo.us web site: http://script.aculo.us/

if (!Control) var Control = { };

// options:
//  axis: 'vertical', or 'horizontal' (default)
//
// callbacks:
//  onChange(value)
//  onSlide(value)
Control.Slider = Class.create({
  initialize: function(handle, track, options) {
    var slider = this;
    
    if (Object.isArray(handle)) {
      this.handles = handle.collect( function(e) { return $(e) });
    } else {
      this.handles = [$(handle)];
    }
    
    this.track   = $(track);
    this.options = options || { };

    this.axis      = this.options.axis || 'horizontal';
    this.increment = this.options.increment || 1;
    this.step      = parseInt(this.options.step || '1');
    this.range     = this.options.range || $R(0,1);
    
    this.value     = 0; // assure backwards compat
    this.values    = this.handles.map( function() { return 0 });
    this.spans     = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
    this.options.startSpan = $(this.options.startSpan || null);
    this.options.endSpan   = $(this.options.endSpan || null);

    this.restricted = this.options.restricted || false;

    this.maximum   = this.options.maximum || this.range.end;
    this.minimum   = this.options.minimum || this.range.start;

    // Will be used to align the handle onto the track, if necessary
    this.alignX = parseInt(this.options.alignX || '0');
    this.alignY = parseInt(this.options.alignY || '0');
    
    this.trackLength = this.maximumOffset() - this.minimumOffset();

    this.handleLength = this.isVertical() ? 
      (this.handles[0].offsetHeight != 0 ? 
        this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) : 
      (this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth : 
        this.handles[0].style.width.replace(/px$/,""));

    this.active   = false;
    this.dragging = false;
    this.disabled = false;

    if (this.options.disabled) this.setDisabled();

    // Allowed values array
    this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
    if (this.allowedValues) {
      this.minimum = this.allowedValues.min();
      this.maximum = this.allowedValues.max();
    }

    this.eventMouseDown = this.startDrag.bindAsEventListener(this);
    this.eventMouseUp   = this.endDrag.bindAsEventListener(this);
    this.eventMouseMove = this.update.bindAsEventListener(this);

    // Initialize handles in reverse (make sure first handle is active)
    this.handles.each( function(h,i) {
      i = slider.handles.length-1-i;
      slider.setValue(parseFloat(
        (Object.isArray(slider.options.sliderValue) ? 
          slider.options.sliderValue[i] : slider.options.sliderValue) || 
         slider.range.start), i);
      h.makePositioned().observe("mousedown", slider.eventMouseDown);
    });
    
    this.track.observe("mousedown", this.eventMouseDown);
    document.observe("mouseup", this.eventMouseUp);
    document.observe("mousemove", this.eventMouseMove);
    
    this.initialized = true;
  },
  dispose: function() {
    var slider = this;    
    Event.stopObserving(this.track, "mousedown", this.eventMouseDown);
    Event.stopObserving(document, "mouseup", this.eventMouseUp);
    Event.stopObserving(document, "mousemove", this.eventMouseMove);
    this.handles.each( function(h) {
      Event.stopObserving(h, "mousedown", slider.eventMouseDown);
    });
  },
  setDisabled: function(){
    this.disabled = true;
  },
  setEnabled: function(){
    this.disabled = false;
  },  
  getNearestValue: function(value){
    if (this.allowedValues){
      if (value >= this.allowedValues.max()) return(this.allowedValues.max());
      if (value <= this.allowedValues.min()) return(this.allowedValues.min());
      
      var offset = Math.abs(this.allowedValues[0] - value);
      var newValue = this.allowedValues[0];
      this.allowedValues.each( function(v) {
        var currentOffset = Math.abs(v - value);
        if (currentOffset <= offset){
          newValue = v;
          offset = currentOffset;
        } 
      });
      return newValue;
    }
    if (value > this.range.end) return this.range.end;
    if (value < this.range.start) return this.range.start;
    return value;
  },
  setValue: function(sliderValue, handleIdx){
    if (!this.active) {
      this.activeHandleIdx = handleIdx || 0;
      this.activeHandle    = this.handles[this.activeHandleIdx];
      this.updateStyles();
    }
    handleIdx = handleIdx || this.activeHandleIdx || 0;
    if (this.initialized && this.restricted) {
      if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
        sliderValue = this.values[handleIdx-1];
      if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
        sliderValue = this.values[handleIdx+1];
    }
    sliderValue = this.getNearestValue(sliderValue);
    this.values[handleIdx] = sliderValue;
    this.value = this.values[0]; // assure backwards compat
    
    this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] = 
      this.translateToPx(sliderValue);
    
    this.drawSpans();
    if (!this.dragging || !this.event) this.updateFinished();
  },
  setValueBy: function(delta, handleIdx) {
    this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta, 
      handleIdx || this.activeHandleIdx || 0);
  },
  translateToPx: function(value) {
    return Math.round(
      ((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) * 
      (value - this.range.start)) + "px";
  },
  translateToValue: function(offset) {
    return ((offset/(this.trackLength-this.handleLength) * 
      (this.range.end-this.range.start)) + this.range.start);
  },
  getRange: function(range) {
    var v = this.values.sortBy(Prototype.K); 
    range = range || 0;
    return $R(v[range],v[range+1]);
  },
  minimumOffset: function(){
    return(this.isVertical() ? this.alignY : this.alignX);
  },
  maximumOffset: function(){
    return(this.isVertical() ? 
      (this.track.offsetHeight != 0 ? this.track.offsetHeight :
        this.track.style.height.replace(/px$/,"")) - this.alignY : 
      (this.track.offsetWidth != 0 ? this.track.offsetWidth : 
        this.track.style.width.replace(/px$/,"")) - this.alignX);
  },  
  isVertical:  function(){
    return (this.axis == 'vertical');
  },
  drawSpans: function() {
    var slider = this;
    if (this.spans)
      $R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
    if (this.options.startSpan)
      this.setSpan(this.options.startSpan,
        $R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
    if (this.options.endSpan)
      this.setSpan(this.options.endSpan, 
        $R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
  },
  setSpan: function(span, range) {
    if (this.isVertical()) {
      span.style.top = this.translateToPx(range.start);
      span.style.height = this.translateToPx(range.end - range.start + this.range.start);
    } else {
      span.style.left = this.translateToPx(range.start);
      span.style.width = this.translateToPx(range.end - range.start + this.range.start);
    }
  },
  updateStyles: function() {
    this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
    Element.addClassName(this.activeHandle, 'selected');
  },
  startDrag: function(event) {
    if (Event.isLeftClick(event)) {
      if (!this.disabled){
        this.active = true;
        
        var handle = Event.element(event);
        var pointer  = [Event.pointerX(event), Event.pointerY(event)];
        var track = handle;
        if (track==this.track) {
          var offsets  = Position.cumulativeOffset(this.track); 
          this.event = event;
          this.setValue(this.translateToValue( 
           (this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2)
          ));
          var offsets  = Position.cumulativeOffset(this.activeHandle);
          this.offsetX = (pointer[0] - offsets[0]);
          this.offsetY = (pointer[1] - offsets[1]);
        } else {
          // find the handle (prevents issues with Safari)
          while((this.handles.indexOf(handle) == -1) && handle.parentNode) 
            handle = handle.parentNode;
            
          if (this.handles.indexOf(handle)!=-1) {
            this.activeHandle    = handle;
            this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
            this.updateStyles();
            
            var offsets  = Position.cumulativeOffset(this.activeHandle);
            this.offsetX = (pointer[0] - offsets[0]);
            this.offsetY = (pointer[1] - offsets[1]);
          }
        }
      }
      Event.stop(event);
    }
  },
  update: function(event) {
   if (this.active) {
      if (!this.dragging) this.dragging = true;
      this.draw(event);
      if (Prototype.Browser.WebKit) window.scrollBy(0,0);
      Event.stop(event);
   }
  },
  draw: function(event) {
    var pointer = [Event.pointerX(event), Event.pointerY(event)];
    var offsets = Position.cumulativeOffset(this.track);
    pointer[0] -= this.offsetX + offsets[0];
    pointer[1] -= this.offsetY + offsets[1];
    this.event = event;
    this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
    if (this.initialized && this.options.onSlide)
      this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
  },
  endDrag: function(event) {
    if (this.active && this.dragging) {
      this.finishDrag(event, true);
      Event.stop(event);
    }
    this.active = false;
    this.dragging = false;
  },  
  finishDrag: function(event, success) {
    this.active = false;
    this.dragging = false;
    this.updateFinished();
  },
  updateFinished: function() {
    if (this.initialized && this.options.onChange) 
      this.options.onChange(this.values.length>1 ? this.values : this.value, this);
    this.event = null;
  }
});



function loadFnlClasses(){
CFnlTools = Class.create({
children:false,
loadQueue:false,
initialize:function(){
	this.children = [];
	this.loadQueue = [];
},
FnlCreate:function(className,params){
	var obj = null;
	switch(className){
		case 'FnlPage':
			obj = new FnlPage(this,params);
			break;
		case 'FnlPageContainer':
			obj = new FnlPageContainer(this,params);
			break;
	}
	this.children.push(obj);
	return obj;
},
inLoadQueue:function(){
	var inQueue = 0;
	for(var i=0;i<this.loadQueue.length;i++){
		if(this.loadQueue[i][1]==0)
			inQueue++;
	}
	return inQueue;
},
inLoadQueueActive:function(target){
	var active = 0;
	for(var i=0;i<this.loadQueue.length;i++){
		if(this.loadQueue[i][1]==1)
			active++;
	}
	return active;
},
processQueue:function(){
	if(this.inLoadQueueActive()<2 && this.loadQueue.length>0){
		for(var i=0;i<this.loadQueue.length && i<2;i++)
			if(this.loadQueue[i][1]==0){
				this.loadQueue[i][1] = 1;
				this.loadQueue[i][0].load();
			}
	}
},
removeFromQueue:function(item){
	for(var i=0;i<this.loadQueue.length;i++){
		if(item==this.loadQueue[i][0]){
			this.loadQueue.splice(i,1);
			this.processQueue();
			return;
		}
	}
},
addToLoadQueue:function(item){
	this.loadQueue.push([item,0]);	
	this.processQueue();	
}
});

FnlTools = new CFnlTools();

FnlPageContainer = Class.create({
duration:1,
timePerPage:2,
slideshowTimer:false,
curIndex:0,
treeOwner:false,
parentDiv:false,
oTarget:false,
target:false,
id:false,
width:false,height:false,
children:false,
navTarget:false,
paddingLeft:0,
paddingTop:0,
navTop:false,
navHeight:false,
navAlign:false,
initialize:function(treeOwner, options){
	this.children = [];
	if(options){
		if(options.parentDiv)this.parentDiv=$(options.parentDiv);
		if(options.width)this.width=options.width;
		if(options.height)this.height=options.height;
		if(options.id)this.id=options.id;
		if(options.paddingLeft)this.paddingLeft=options.paddingLeft;
		if(options.duration)this.duration=options.duration;
		if(options.paddingTop)this.paddingTop=options.paddingTop;
		if(options.navTop)this.navTop=options.navTop;
		if(options.navAlign)this.navAlign=options.navAlign;
		if(options.navHeight)this.navHeight=options.navHeight;
	}
	this.treeOwner = treeOwner;
	if(!this.id){	
		var now = new Date().getTime();
    	this.id = 'fnlPage'+now;
    }
	if(!this.navTarget){
		this.navTarget = new Element('div',{id:this.id + '_nav'});
		if(!this.navHeight)
			this.navHeight = 20;
		if(!this.navTop){
			this.navTop = this.height-this.navHeight;
		}
		if(!this.navAlign)
			this.navAlign = 'left';
		Element.setStyle(this.navTarget,{height:this.navHeight+'px',position:'absolute',top:this.navTop+'px',left:'5px',zIndex:999});
	}
	var dx = this.paddingTop;
    this.target = new Element('div',{id:this.id + '_inner'});
    Element.setStyle(this.target,{left:'0px',top:dx+'px',width:this.width+'px',height:(this.height-dx)+'px',position:'relative'});    	
	this.oTarget = new Element('div',{id:this.id + '_outer'});
	Element.setStyle(this.oTarget,{background:'#ffffff',width:this.width+'px',height:this.height+'px',position:'absolute',overflow:'hidden'});
	this.oTarget.appendChild(this.navTarget);
	this.oTarget.FnlPageContainer = this;
	this.oTarget.appendChild(this.target);
    this.parentDiv.appendChild(this.oTarget);    
},
getChild:function(child){
	for(var i=0;i<this.children.length;i++){
		if(this.children[i]==child)
			return i;
	}
	return -1;
},
contains:function(child){
	if(this.getChild(child)>=0)
		return true;
	else
		return false;
},
positionNavTarget:function(){
	if(this.navAlign=='left')
		Element.setStyle(this.navTarget,{left:'5px'});
	else{
		var dim = Element.getDimensions(this.navTarget);
		Element.setStyle(this.navTarget,{left:(this.width-dim.width-16)+'px'});
	}
},
addChild:function(child){
	if(!this.contains(child)){
		Element.setStyle(this.target,{width:(this.width*(this.children.length+1))+'px'});
		Element.setStyle(child.target,{left:(this.children.length*this.width+(this.children.length+1)*this.paddingLeft)+'px'});
		if(child.body){
			child.target.innerHTML = child.body;
		}
		this.children.push(child);		
		this.target.appendChild(child.target);		
		var nameDiv = new Element('div');
		Element.setStyle(nameDiv,{float:'left',margin:'0',padding:'0px',margin:'0px'});				
		nameDiv.innerHTML = child.name;
		child.nameDiv = nameDiv;
		this.navTarget.appendChild(nameDiv);
		this.positionNavTarget();
		var self = this;
		var index = this.children.length-1;
		nameDiv.observe('click',function(event){
			self.manualNavigateToPage(index);
		});
		if(this.children.length==1)
			child.select();
		return child;
	}
},
navigateToPage:function(index){
	this.children[this.curIndex].unselect();	
	this.curIndex = index;
	this.children[this.curIndex].select();
	var curX = this.target.style.left.split('px')[0];
	var destX = -1*(this.width+ this.paddingLeft)*index;
	var dx = destX - curX;	
	new Effect.Move(this.target,{x:dx,y:0,mode:'relative',duration:this.duration});	
},
manualNavigateToPage:function(index){
	if(this.slideshowTimer){
		clearTimeout(this.slideshowTimer);
		this.slideshowTimer = false;
	}
	this.navigateToPage(index);		
},
slideshow:function(timePerPage){
	this.timePerPage = timePerPage;
	var self = this;
	var id = this.id + '_outer';
	this.slideshowTimer = setTimeout("$('"+id+"').FnlPageContainer.slideNext();",this.duration*1000+timePerPage*1000);
},
slideNext:function(){
	if(this.curIndex+1<this.children.length){
		this.navigateToPage(this.curIndex+1);
		var id = this.id + '_outer';
		this.slideshowTimer = setTimeout("$('"+id+"').FnlPageContainer.slideNext();",this.duration*1000+this.timePerPage*1000);
	}else{
		//this.slideshowTimer = false;
		this.slideRestart();
	}
},
slideRestart:function(){
	var tempD = this.children[this.children.length-1].target.cloneNode(true);
	Element.setStyle(tempD,{left:(-1*(this.width+this.paddingLeft))+'px'});
	var destX = (this.width+ this.paddingLeft);
	this.target.appendChild(tempD);	
	this.tempD = tempD;	
	Element.setStyle(this.target,{left:destX + 'px'});	
	this.navigateToPage(0);
	var id = this.id + '_outer';
	this.curIndex = 0;
	this.slideshowTimer = setTimeout("$('"+id+"').FnlPageContainer.slideNext();",this.duration*1000+this.timePerPage*1000);
	setTimeout("$('"+id+"').FnlPageContainer.removeTemp();",this.duration*1000);
},
removeTemp:function(){
	Element.remove(this.tempD);
	this.tempD = null;
}
});

FnlPage = Class.create({
treeOwner:false,
name:false,
selectedName:false,
uri:false,
params:false,
body:false,
width:100,
height:100,
target:false,
id:false,
nameDiv:false,
initialize:function(treeOwner,options){
	this.treeOwner = treeOwner;
	if(options){
		if(options.uri)this.uri=options.uri;
		if(options.name)this.name=options.name;
		if(options.selectedName)this.selectedName=options.selectedName;
		if(options.body)this.body=options.body;
		if(options.params)this.params=options.params;
		if(options.width)this.width=options.width;
		if(options.height)this.height=options.height;
		if(options.target)this.target=options.target;
		if(options.id)this.id=options.id;
	}	
	if(!this.id){
		var now = new Date().getTime();
    	this.id = 'fnlPage'+now;
    }    
	if(!this.params)
		this.params = [];
	if(!this.target){
		this.target = new Element('div',{id:this.id});
		this.target.innerHTML = '<center>Loading...</center>';
		this.target.setStyle({overflow:'hidden',zIndex:333,width:this.width+'px',height:this.height+'px',top:'0px',position:'absolute'});
	}
},
select:function(){
	if(this.nameDiv){
		this.nameDiv.innerHTML = this.selectedName;
	}
},
unselect:function(){
	if(this.nameDiv){
		this.nameDiv.innerHTML = this.name;
	}
},
prepareParams:function(){
	var str='';
	if(this.params)
		for(var i=0;i<this.params.length;i++)
			str += (str!=''?'&':'') + this.params[i];
	return str; 
},
updateBody:function(newBody){
	this.body = newBody;
	this.target.innerHTML = newBody;
},
load:function(){
	if(this.body){
		this.updateBody(this.body);
		return;
	}	
	var self = this;
    var a = new Ajax.Request(
        self.uri,{
             method:'post',
             postBody:self.prepareParams(),             
             onSuccess: function(transport){
	            self.updateBody(transport.responseText);
	            FnlTools.removeFromQueue(self);
             },
             onFailure: function(transport) {             	
                FnlTools.removeFromQueue(self);
             }
        }
        );	    
}
});

}


  
  
  var PScroller = Class.create({
  	target:false,
  	name:'nope',
  	width: 0,
  	containter:false,
  	initialize: function(element){
	  	var now = new Date().getTime();
	    var name = 'a'+now;
	    this.name = name;
	  	this.target = $(element);
		var d = new Element('div');
		d.setStyle({width:'719px',height:'212px',position:'relative',background:'#ffffff'});
		this.target.appendChild(d);
		var d2 = new Element('div');
		d2.setStyle({position:'relative',top:'0px',left:'0px',overflow:'hidden',height:'212px',width:'719px'});
		d.appendChild(d2);
		var d3 = new Element('div', {id:this.name + '_container'});
		d3.setStyle({width:'6000px',position:'relative'});
		this.container = d3;
		d2.appendChild(d3);
		var e = new Element('div');
		e.setStyle({padding:'2px 0px',background:'url(/includes/fnlscrollbar/bar_bg.gif) no-repeat',width:'719px',height:'18px'});
		this.target.appendChild(e);
		var e2 = new Element('div',{id:this.name+'_slider'});
		e2.setStyle({position:'relative',top:'0px',left:'24px',width:'675px',height:'18px',margin:'0'});
		e.appendChild(e2);
		var e3 = new Element('div',{id:this.name+'_handle'});
	e3.setStyle({width:'10px', height:'13px', background:'url(/includes/fnlscrollbar/drag.gif) no-repeat', cursor:'move',position:'absolute'});
	  	e2.appendChild(e3);	  	
  	},
  	add: function(strObject, width){
  		var str = this.container.innerHTML;
  		str += strObject;    		
  		this.container.innerHTML = str;
  		this.width += width;
  	},  	
  	start: function(){
  		this.container.setStyle({width:this.width + 'px'});
  		var name = this.name;
  		var container = this.container;
	  	new Control.Slider(this.name + '_handle',this.name + '_slider',{
	      range: $R(0, this.width-719),
	      sliderValue: 0,
	      onSlide: function(value) {
	      	container.setStyle({ left: (-1*value) + 'px' });
	      },
	      onChange: function(value) { 
	      container.setStyle({ left: (-1*value) + 'px' });
	      }
	    });  
  	}
  });
  
  
  
  
