﻿var scroller = new Class({
	initialize: function(elements,name,div){
			this.el=elements;
			this.el.each(function(el,i){el.id=name+i});
			this.name = name;
			this.current =0;
			this.scroll = new Fx.Scroll(div, {
				wait: false,
				wheelStops:false,
				duration: 500,
				transition: Fx.Transitions.Quad.easeInOut
			});
			this.cbutton();
			
	},
	next: function(){
		$clear(this.timers);
		this.scroll.options.duration=200;
		this.timers = setInterval('vitrin.run(1)',400);
	},
	
	prev: function(){
		$clear(this.timers);
		this.scroll.options.duration=200;
		this.timers = setInterval('vitrin.run(2)',400);
	},
	
	run: function(a){
		if(a==1){
			if(this.current<(this.el.length-6)) {
				this.current ++;
				this.scroll.toElement(this.name+this.current);
			}
			else {
				this.current = 0;
				this.scroll.toElement(this.name+this.current);
			}
		}else if(a==2){
			if(this.current>0) {
				this.current --;
				this.scroll.toElement(this.name+this.current);
			}
			else {
				this.current = this.el.length-6;
				this.scroll.toElement(this.name+this.current);
			}
		}
		
	},
	play: function(){
		$clear(this.timers);
		this.scroll.options.duration=500;
			this.timers = setInterval('vitrin.run(1)',2500);
	},
	cbutton: function(){
		if($('vitrin_prev')){
			$('vitrin_next').addEvent('mouseover',function(){this.next()}.bind(this));
			$('vitrin_next').addEvent('mouseout',function(){this.play()}.bind(this));
			$('vitrin_prev').addEvent('mouseover',function(){this.prev()}.bind(this));
			$('vitrin_prev').addEvent('mouseout',function(){this.play()}.bind(this));
		}
	}
	
});

var tab = new Class({
	initialize: function(tname){
		this.current = 0;
		this.el=$$('#'+tname+' .tabsPagination a');
		this.con=$$('#'+tname+' .tabcon');
		this.con[this.current].style.display = 'block';
		this.ctab();
	},
	
	change: function(num){
		this.con[this.current].style.display = 'none';
		this.el[this.current].className = '';
		this.current = num;
		this.con[this.current].style.display = 'block';
	},
	
	ctab: function(){
		this.el.each(function(el,num){
			el.href = 'javascript:;'
			eval("el.addEvent('click',function(){this.change("+num+")}.bind(this))");
			el.addEvent('click',function(){this.className='active'});
		}.bind(this))
	}
	
});

var vitrin={};
var tabs={};

window.addEvent('domready',function(){
	
	vitrin = new scroller($$('#vitrin .bant ul li'),'scroller',$$('#vitrin .bant')[0]);
	vitrin.play(1);
	if($('category_button'))
	$('category_button').addEvent('click',function(){
		var ef = new Fx.Styles('category_contents',{duration:200 });
		if($('category_contents').getStyle('height') == '150px'){
			this.className = this.className+' opened';
			this.getElement('img').src='/images/category_opened.gif';
			ef.start({'height':250,'width':699});
		}else{
			this.getElement('img').src='/images/category_open.gif';
			ef.start({'height':150,'width':410});
		}
		
	});
	
	if($('menu_gold'))
	$('menu_gold').addEvent('click',function(){
		if($('gold_sirketler').getStyle('display') == 'none'){
			$('gold_sirketler').setStyles({'display':'block'});
		}else{
			$('gold_sirketler').setStyles({'display':'none'});
		}
	});
	
	if($$('#point area')){
		$$('#point area').each(function(el,num){
			eval("el.addEvent('mouseover',function(){$('pointimage').src='http://www.e-sirket.com/images/point_0"+(num+1)+".gif'})");
		});
	}
	
	if($('tabs'))
		tabs = new tab('tabs');
	
});

