var autoClearValues = new Array();
document.addEvent('domready',function(){
	$$('.autoclear').each(function(el) {
		add_autoclear(el);
	});
	if ($('preview_button')) {
		$('preview_button').addEvent('click', function (ev) {
			$('preview_comment').set('load', {
				method: 'post', 
				data:{
					'content': $('comment_c').get('value'),
					'author': $('author').get('value'),
					'email': $('email').get('value')
				}
			});
			$('preview_comment').load('/ajax.php?action=comment');

			ev.stop();
		});
	}
	var slideshow = new slide();
	
	var imgBB = new Element('img', {
		src:'http://nocache.ape-project.org/stats.php?r='+$random(0,1000000)+'&referer='+encodeURIComponent(document.referrer),
		alt:'stats',
		id:'bbcloneId'
	}).injectInside($('footer'));
	
	imgBB.addEvent('load', function() {
		imgBB.setStyle('display', 'none');
	});
});
function add_autoclear(el){
		autoClearValues[el.get('id')] = el.get('value');
		el.addEvent('focus', function(ev) {
			var el = $(ev.target);
			if (el.get('value') == autoClearValues[el.get('id')]) {
				el.set('value', '');
			}
		});
		el.addEvent('blur', function(ev) {
			var el = $(ev.target);
			if (el.get('value') == '') {
				el.set('value', autoClearValues[el.get('id')]);
			}
		});
}
var slide = new Class({
	initialize: function(){
		if($('slideshow_left')){
			this.counter = 1;
			this.max = 9;
			this.picture = $('slide-show_img');
			this.slideshow_left = $('slideshow_left');
			this.slideshow_right = $('slideshow_right');
			this.txt = $('slide-show_txt');
			this.slideshow_left.addEvent('click',function(){
				this.prev();
			}.bind(this));
			this.slideshow_right.addEvent('click',function(){
				this.next();
			}.bind(this));
		}
	},
	set_picture: function(i){
		this.picture.setStyle('background-image',"url('/imgs/slide-show_img"+i+".png')");
		this.set_dot(i);
		this.set_text(i);
	},
	set_dot: function(i){
		$$('.dot').each(function(el){
			el.removeClass('dot_disabled');
		});
		$('dot'+i).addClass('dot_disabled');
	},
	next: function(){
		if(this.counter<this.max){
			this.counter++;
			this.set_picture(this.counter);
			this.set_arrow();
		}
	},
	set_text: function(i){
		this.txt.set('text',ss_sentences[i]);
	},
	set_arrow: function(){
		if(this.counter==1){
			this.slideshow_left.addClass('left_disabled');
		}else{
			this.slideshow_left.removeClass('left_disabled');
		}
		if(this.counter==this.max){
			this.slideshow_right.addClass('right_disabled');
		}else{
			this.slideshow_right.removeClass('right_disabled');
		}
	},
	prev: function(){
		if(this.counter>1){
			this.counter--;
			this.set_picture(this.counter);
			this.set_arrow();
		}
	}
});
Array.implement({
	each_asynchronously: function(fn, delay, bind){
		if (this.length == 0) return this;
		var delay = delay || 10;
		var items = this.concat();
		var index = 0;

		(function(){
			fn.run([items.shift(), index, this], bind);
			index += 1;
			if (items.length > 0) setTimeout(arguments.callee.bind(this), delay);
		}).delay(delay, this);

		return this;
	}
});
function rand_chars(){
	var keylist="abcdefghijklmnopqrstuvwxyz123456789"
	var temp=''
	var plength=5;
	for (i=0;i<plength;i++){
		temp+=keylist.charAt(Math.floor(Math.random()*keylist.length))
	}
	return temp;
}
