var img = {};
img.init = function() {
	this.texts = $("#images .config div div");
	if (this.texts.length<1) return false;
	this.imgs = $("#images .config div img");
	this.links = $("#images .links a");
	this.slider = $("#images .slider");
	this.informer = $("#images .informer div");
	this.current = 0;
	this.prev = $("#images .prev");
	this.next = $("#images .next");
	
	this.links.click(function(){
		img.set(this.rel);
		return false;
	});
	
	img.set(Math.round(Math.random()*2));
}

img.set = function (p){
	img.links.removeClass("current");
	$(img.links[p]).addClass("current");
	
	img.prev.css({"background-image": "url('"+img.imgs[img.current].src+"')", opacity: 1});
	img.prev.animate({opacity: 0}, "slaw");
	img.next.css("background-image", "url('"+img.imgs[p].src+"')");
	
	img.informer.text(img.texts[p].innerHTML);
	img.slider.animate({left: img.links[p].offsetLeft + img.links[p].clientWidth/2}, "slaw");
	
	img.current = p;
}
$(function(){
	// css fixes
	$("#acc .subitems a:last-child").addClass("last");
	
	
	// main animation
	img.init();
});
