// Newsticker
var Ticker = new Class({
	setOptions: function(options) {
		this.options = Object.extend({
			speed: 1000,
			delay: 5000,
			direction: 'vertical',
			onComplete: Class.empty,
			onStart: Class.empty
		}, options || {});
	},
	initialize: function(el,options){
		this.setOptions(options);
		this.el = $(el);
		this.items = this.el.getElements('li');
		this.scrolling = false;
		var w = 0;
		var h = 0;
		
		if(this.options.direction.toLowerCase()=='horizontal') {
			h = this.el.getSize().size.y;
			var minW = 0;
			this.items.each(function(li,index) {
				w += li.getSize().size.x;
				minW = (minW<w)?w:minW;
			});
			w = this.el.getSize().size.x+minW;
		} else {
			w = this.el.getSize().size.x;
			this.items.each(function(li,index) {
				h += li.getSize().size.y;
			});
		}
		this.el.setStyles({
			position: 'absolute',
			top: 0,
			left: 0,
			width: w,
			height: h
		});
		this.fxNext = new Fx.Styles(this.el,{duration:this.options.speed,onComplete:function() {
			var i = (this.current==0)?this.items.length:this.current;
			this.items[i-1].injectInside(this.el);
			this.el.setStyles({
				left:0,
				top:0
			});
			this.scrolling = false;
		}.bind(this)});

		this.fxPrev = new Fx.Styles(this.el,{duration:this.options.speed,onStart:function() {
		}.bind(this),onComplete:function() {
			this.scrolling = false;
		}.bind(this)});

		this.current = 0;
		this.next();
	},
	next: function() {
		this.scrollNext();
			
		this.next.bind(this).delay(this.options.delay+this.options.speed);
	},
	
	scrollPrev: function() {
		if(!this.scrolling){
			this.scrolling = true;

			this.current--;
			if (this.current < 0) {
				this.current = this.items.length-1;
			}
			var pos = this.items[this.current];
			pos.inject(this.el,'top');
			this.el.setStyles({
				left:-pos.getSize().size.x,
				top:0
			});
				
			this.fxPrev.start({
				top: pos.offsetTop,
				left: pos.offsetLeft
			});		
		}	
	},
	
	scrollNext: function() {
		if(!this.scrolling){
			this.scrolling = true;
				
			this.current++;
			if (this.current >= this.items.length) this.current = 0;

			var pos = this.items[this.current];

			this.fxNext.start({
				top: -pos.offsetTop,
				left: -pos.offsetLeft
			});
		}
	}
});


// ElementSlider

var ElementSlider = new Class({
	setOptions: function(options) {
		this.options = Object.extend({
			speed: 5000,
			delay: 5000,
			onComplete: Class.empty,
			onStart: Class.empty
		}, options || {});
	},
	initialize: function(el,options){
		this.setOptions(options);
		this.el = $(el);
		this.items = this.el.getElements('li');
		var w = 0;
		var h = 0;

		for (i=0;i<4;i++)
		{
		  this.current = i;
		  this.items[this.current].setStyles({
		  	display:'block'
		  });
		}

		this.current = 3;

		this.next();
	},

	next: function() {

		this.current-=3;
			if (this.current == -1) { this.current = this.items.length-1; }
			if (this.current == -2) { this.current = this.items.length-2; }
			if (this.current == -3) { this.current = this.items.length-3; }
		this.items[this.current].setStyles({
			display:'none'
		});

		this.current+=4;
			if (this.current == this.items.length) this.current = 0;
			if (this.current == this.items.length+1) this.current = 1;
			if (this.current == this.items.length+2) this.current = 2;
			if (this.current == this.items.length+3) this.current = 3;
		this.items[this.current].setStyles({
			display: 'block'
		});
		
		this.next.bind(this).delay(this.options.delay+this.options.speed);
	}
});



window.addEvent('domready', function(){
        $('fontLarge').addEvent('click', function() {
                        $('wrapper').style.fontSize="1.0em";
                        Cookie.set("font-size", "large"); //save this for 1 year
                        location.reload();
                });
        $('fontMed').addEvent('click', function() {
                        $('wrapper').style.fontSize="0.8em";
                        Cookie.set("font-size", "medium"); //save this for 1 year
                        location.reload();                        
                })
        $('fontSmall').addEvent('click', function() {
                        $('wrapper').style.fontSize="0.7em";
                        Cookie.set("font-size", "small"); //save this for 1 year
                        location.reload();                        
                })
        //check for font size cookie
        if(Cookie.get("font-size") == "large"){
          $('wrapper').style.fontSize="1.0em";

        }else if(Cookie.get("font-size") == "small"){
          $('wrapper').style.fontSize="0.7em";
     
        }else{
      
          //do nothing, leave default
        }
});

window.addEvent('domready', function(){
        var accordion = new Accordion('h2.atStart', 'div.atStart', {
            opacity: false
        }, $('accordion'));
});



