function Switchable(options) {
	options = options || {};
	this.id = options.id,
	this.child = options.child || "li",
	this.next = options.next || "ul",
	this.current = options.current || "current",
	this.hide = options.hide || "hide";
	return this;
}
Switchable.prototype.check = function() {
	return !!this.id;
}
Switchable.prototype.exec = function() {
	var oThis = this;
	if(!oThis.check()) {
		return;
	}
	var oNode = $(oThis.id),
		childs = oNode.getElements(oThis.child),
		nexts = oNode.getAllNext(oThis.next),
		last = childs[0],
		show = nexts[0];
	childs.each(function(item, index) {
		item.addEvent("mouseover", function() {
			last.removeClass(oThis.current);
			item.addClass(oThis.current);
			last = item;
			show.addClass(oThis.hide);
			show = nexts[index];
			show.removeClass(oThis.hide);
		});
	});
}
Switchable.prototype.exec2 = function() {
	var oThis = this;
	if(!oThis.check()) {
		return;
	}
	var oNode = $(oThis.id),
		childs = oNode.getElements(oThis.child),
		nexts = oNode.getParent().getAllNext(oThis.next),
		last = childs[0],
		show = nexts[0];
	childs.each(function(item, index) {
		item.addEvent("mouseover", function() {
			last.removeClass(oThis.current);
			item.addClass(oThis.current);
			last = item;
			show.addClass(oThis.hide);
			show = nexts[index];
			show.removeClass(oThis.hide);
		});
	});
}

/*popWin*/
var PopWin = new Class({
	initialize:function(id){
		this.target = $(id);	 
		this.target.setStyle('right',0);
		this.target.setStyle('z-index','10000'); 			
		this.min = this.target.getElement('#min');
		this.close = this.target.getElement('#close');
		this.min.addEvent('click',this.showHalf.bindWithEvent(this));
		this.close.addEvent('click',this.dispose.bindWithEvent(this));

		if(Browser.Engine.trident ){ this.doIeSix.periodical(2,this); } else { this.w3cWay(); }
	},	  	
	showHalf:function(event){
		 this.target.setStyle('height','30px');
		 event.target.removeEvents();
		 event.target.set('id','max');
		 event.target.addEvent('click',this.showFull.bindWithEvent(this));
	},
	showFull:function(event){		  
		 this.target.setStyle('height','262px');
		 event.target.set('id','min');
		  event.target.removeEvents();
		 event.target.addEvent('click',this.showHalf.bindWithEvent(this));
	},
	dispose:function(event){
			this.target.dispose();		  				
	},	 
	w3cWay:function(){		
		this.target.setStyle('position','fixed'); 
		this.target.setStyle('bottom',0); 
	},
	doIeSix:function(){	
			this.target.setStyle('position','absolute'); 
			var y = getScroll().y		+ getCoordinates().height - this.target.getStyle('height').toInt()
			this.target.setStyle('top',y);			
	}	
});	
var Slide = new Class({
	Implements: [Options], options:{ speed: 2000,fx:{transition: Fx.Transitions.Cubic.easeOut,duration: 500,link:'cancel'}},

	initialize:function(options, id, id2)
	{
		this.setOptions(options);
		this.wrapper = $(id);
		this.titles = $(id2);
		this.linkss = this.wrapper.getElements('a');
		this.wrapper.setStyle('overflow','hidden');
		this.content = new Element('div',{'styles':{'position':'absolute'}}); this.content.adopt(this.wrapper.getChildren(),'top');
		this.wrapper.adopt(this.content,'top');
		this.myFx =new Fx.Tween(this.content,this.options.fx);
		this.slides = this.content.getElements('img');
		this.n = this.slides.length;
		this.pos = 0;this.clock = 2;
		this.wrapper.addEvent('mouseenter',this.stop.bindWithEvent(this));
		this.wrapper.addEvent('mouseleave',this.start.bindWithEvent(this));
		this.generateBar();	
		this.titles.set('html', "<h2><a href="+this.linkss[0]+" target='_blank'>"+this.linkss[0].getElement("img").get("alt")+"</a></h2>" || "");	
		this.start();
	}, numbers:[],
	generateBar:function(){
		var bar = new Element('ul',{styles:{'position':'absolute','right':'5px','bottom':'5px','font-family':'verdana','font-size':'10px','z-index':'20'}});
		this.slides.each(function(item,index){
			var rel= (index+1);
			var html = '<a href="'+this.linkss[index]+'">' +rel+'</a>';
			var number = new Element('li',{'html':html,'rel':rel,'styles':{'cursor':'pointer'}});
			number.store('whichOne',index+1);
			this.numbers[index] = number.inject(bar); this.numbers[index].set('title',item.get('alt'));
		},this);
		this.numbers.each(function(number,index)		{
			number.addEvent('click',this.showThis.bindWithEvent(this));
			number.addEvent('mouseover',this.showThis.bindWithEvent(this));
		},this);
		this.numbers[0].addClass('current');
		bar.inject(this.wrapper);
	},
	showThis : function(event){
		event.stopPropagation();
		var temp = $(event.target).getParent().get('rel');
		this.showSlides(temp);
	},
	showSlides : function(x){
		var arg =$pick(x,this.clock);
		this.clock = arg.toInt()+1;
		if(this.clock>this.n) this.clock=1;
		this.numbers.each(function(number){number.removeClass('current'); });
		var y = -(this.slides[0].offsetHeight*(arg-1)).toInt();
		this.myFx.start('top',this.pos,(this.pos=y));
		this.numbers[arg-1].addClass('current');
		if(this.titles != null){
			this.titles.set('html', "<h2><a href="+this.linkss[arg-1]+" target='_blank'>"+this.linkss[arg-1].getElement("img").get("alt")+"</a></h2>" || "");
		}
	},
	start:function(){		
		this.running = this.showSlides.periodical(this.options.speed,this);
	},
	stop:function(event){ event.stopPropagation(); $clear(this.running); 	}
});
window.addEvent('domready',function(){
	var iptTexts = 0 || $$('input[type=text]');
	iptTexts.each(function(ipt){
		ipt.store('dValue',ipt.get('value'))	;
		ipt.addEvent('focus',function(event){
			var tmp = this.retrieve('dValue');
			this.value =(this.value == tmp)? "" : this.value;
		});
		ipt.addEvent('blur',function(event){
			var tmp = this.retrieve('dValue');
			this.value = (this.value == "")? tmp : this.value;
		})
	})
	
})