Peek_Inside=function(container){
	this.current_index=0;
	this.container=container;
	
	this.items=DOM.getElementsByTagName("a",container);

	for(var i=0;i<this.items.length;i++){
		this.items[i].onclick=STD.delegate(this,this.item_click);
	}

	var button;

	button=DOM.createElement("div");
	button.onclick=STD.delegate(this,this.next);
	button.className="scroll-arrow scroll-next";
	this.container.appendChild(button);

	button=DOM.createElement("div");
	button.onclick=STD.delegate(this,this.prev);
	button.className="scroll-arrow scroll-prev";
	this.container.appendChild(button);
	
	this.change(this.items[this.current_index]);
}
Peek_Inside.load=function(){
	var elements=DOM.getElementsByClassName("peek-inside");

	for(var i=0;i<elements.length;i++){
		new Peek_Inside(elements[i]);
	}
}
Peek_Inside.prototype.item_click=function(event){
	var target=STD.target(event);

	var i=0;
	var item;
	var found=false;
	
	while(found==false && i<this.items.length){
		item=this.items[i];
		
		if(item==target){
			this.current_index=i;
			found=true;
		}else{
			++i;
		}
	}
	
	this.change(target);

	return false;
}
Peek_Inside.prototype.change=function(link){
	if(this.image==null){
		this.image=DOM.createElement("img");
		this.image.setAttribute("id","peek-inside-current-image");
		
		this.container.appendChild(this.image);
	}

	var href=link.getAttribute("href");

	this.image.setAttribute("src",href);
	this.image.setAttribute("alt",link.firstChild.nodeValue);

	
}
Peek_Inside.prototype.next=function(){
	if(this.current_index<this.items.length-1){
		++this.current_index;
	}
	
	this.change(this.items[this.current_index]);
}
Peek_Inside.prototype.prev=function(){
	if(this.current_index>0){
		--this.current_index;
	}
	
	this.change(this.items[this.current_index]);
}
