var submenu = new Class({
	initialize: function(id){
		this.mainObj = $(id);
		this.getSubs();
	},
	getSubs:function(){
		var $this = this;
		this.subs = [];
		this.activators = this.mainObj.getElements('div.ac');
		this.activators.each(function(item,i){
			if(item.getElements('div.submenu')[0]){
				$this.subs[i] = item.getElements('div.submenu')[0];
				var _this = $this;
				item.addEvents({
					'mouseenter':function(){
						_this.showSub(i);
					},
					'mouseleave':function(){
						_this.hideSub(i);
					}
				})
			}						
		})
		this.subs.each(function(item,i){
			if (item) {
				var it = item;
				item.setStyles({
					'display': 'block',
					'opacity': '0'
					
				});
				item.height = item.getStyle('height');
				item.setStyles({
					'height': '0',
					'overflow': 'hidden',
					'opacity': '0.9',
					'border': 'none'
				});
				var it = item;
				item.subFx = new Fx.Styles(item, {duration: 500, transition: Fx.Transitions.linear,
					onStart: function(){
						if(this.from.height == 0){
							item.setStyles({'padding':'1px 1px 0px 1px'});
							item.setStyles({'border':'1px solid #FFFFFF'});
						}
					},
 					onComplete: function(){
 						if(this.from.height != 0){
 							item.setStyles({'padding':'0'})
						}
					}				
				});
			}
		})
	},
	showSub:function(i){
		var $this = this;
		this.subs[i].subFx.stop();
		this.subs[i].subFx.start({
			'height': [0, (this.subs[i].height)],
			'opacity': [0, 0.9]
		});
	},
	hideSub:function(i){
		this.subs[i].subFx.stop();
		this.subs[i].subFx.start({
			'height': [(this.subs[i].height, 0)],
			'opacity': [0.9, 0]
		});
		this.subs[i].subFx.start(this.subs[i].getStyle('height'),0);
	}
});


var kAccordion = new Class({
	options: {
		tabHeight: 'auto',
		handlerClass: 'accHandler_i' ,
		handlerClassA: 'accHandler_a',
		boxClass:'accContent' 
	},
	initialize: function(id, options){
		var $this = this;
		this.setOptions(options);
		this.mainObj = $(id);
		if (location.href) {
			var anchor = location.href.substr(location.href.lastIndexOf('#') + 1).replace("tab=", '');
			if (anchor) {
				this.startTab = parseInt(anchor);
			}
			if (!this.startTab) {
				this.startTab = 0;
			}
		}
		this.acc = new Accordion('h3.'+this.options.handlerClass, 'div.'+this.options.boxClass, {
			opacity:false,
			alwaysHide: true,
			display: $this.startTab,
			onActive: function(toggler, element){
				toggler.className = $this.options.handlerClassA;
				this.options.alwaysHide = false;
			},
			onBackground: function(toggler, element){
				toggler.className = $this.options.handlerClass;
			}
		},this.mainObj);
		this.setBoxes();
	},
	setBoxes: function(){
		var $this = this;
		this.boxes = $(this.mainObj).getElements('div.'+this.options.boxClass+'');
		this.boxes.each(function(item){
			item.setStyles({'height':$this.options.tabHeight})
		});
	}
});
kAccordion.implement(new Options);

function pageStart() {
	window.addEvent('domready', function(){
		if($('fade')){ 
			fx = new Fx.Style($('fade'), 'opacity', {duration: 1500, wait: false}).set(0);
			fx.start(1);		
		}
		if($('fade2')){ 
			fx2 = new Fx.Style($('fade2'), 'opacity', {duration: 1500, wait: false}).set(0);
			fx2.start(1);
		}
		if($('fade3')){ 
			fx3 = new Fx.Style($('fade3'), 'opacity', {duration: 1500, wait: false}).set(0);
			fx3.start(1);	
		}
		if($('fade4')){ 
			fx4 = new Fx.Style($('fade4'), 'opacity', {duration: 1500, wait: false}).set(0);
			fx4.start(1);
		}
	}); 
}


var horsesSliderCounter = 0;
var horsesSliderCount = 0;
var horsesSliderFx;
function horsesSliderGallery()
{
	horsesSliderCounter = 0;
	var itemWidth= 272;
	if ( $('horse_scroll_gallery') == null ) return;
	
	var list = $$("#horse_scroll_gallery .item ")
	
	horsesSliderFx = new Fx.Scroll('horse_scroll_gallery');
	
	horsesSliderCount =list.length;
	
	$('horse_scroll_gallery_container').setStyle('width',horsesSliderCount*itemWidth);
	$('horsesSliderCount').innerHTML = horsesSliderCount;
}

function horseSliderPrev()
{
	horsesSliderCounter--;
	if ( horsesSliderCounter < 0 )
	{
		horsesSliderCounter = horsesSliderCount-1;
	}
	$('horsesSliderCounter').innerHTML = horsesSliderCounter+1;
	
	horsesSliderFx.toElement('item'+horsesSliderCounter);
}
function horseSliderNext()
{
	horsesSliderCounter++;
	if ( horsesSliderCount == horsesSliderCounter )
	{
		horsesSliderCounter = 0;
	}
	$('horsesSliderCounter').innerHTML = horsesSliderCounter+1;
	horsesSliderFx.toElement('item'+horsesSliderCounter);
}
