slideshow = {
	current:0,
	init:function(){
		if(document.getElementById && document.createTextNode){
			var list = document.getElementById('slideshow');
			if(list){
				slideshow.items = list.getElementsByTagName('li');
				slideshow.all = slideshow.items.length;
				if(slideshow.all > 1){
					slideshow.addClass(list, 'js');
					slideshow.createNav(list);
					for (var i=0; i < slideshow.all; i++) 
				 	{   
                        slideshow.currentli = slideshow.items[i];					
					    slideshow.currentlink = slideshow.currentli.getElementsByTagName('a');
						for (var j=0; j < slideshow.currentlink.length; j++) 
						{  
						   slideshow.thispic = slideshow.currentlink[j]; 
						   /*slideshow.currentlink[j].setAttribute('onclick', 'slideshow.show()');	 */
                           slideshow.addEvent(slideshow.thispic, 'click', slideshow.show_next_pic); 						   
						}
	                    	
					}		
				}
			}
		}
		slideshow.show();
	},
	createNav:function(o){
	    var p = document.createElement('p');
		slideshow.addClass(p, 'slidenav');
		var templabel = document.createTextNode('Perspective: 1980 - 2007 ');
		p.appendChild(templabel);
		o.parentNode.insertBefore(p, o); 
		
		var p = document.createElement('p');
		slideshow.addClass(p, 'slidenav');
		slideshow.prev = document.createElement('a');
		slideshow.prev.setAttribute('href', '#');
		var templabel = document.createTextNode('<<');
		slideshow.prev.appendChild(templabel);
		slideshow.addEvent(slideshow.prev, 'click', slideshow.show);		
		p.appendChild(slideshow.prev);
		slideshow.count = document.createElement('span');
		templabel = document.createTextNode( (slideshow.current+1) + ' / ' + slideshow.all);
		slideshow.count.appendChild(templabel);
		p.appendChild(slideshow.count);
		slideshow.next = document.createElement('a');
		slideshow.next.setAttribute('href', '#');
		var templabel = document.createTextNode('>>');
		slideshow.next.appendChild(templabel);
		slideshow.addEvent(slideshow.next, 'click', slideshow.show);		
		p.appendChild(slideshow.next);
		o.parentNode.insertBefore(p, o); 

	},
	show:function(e){
		if(this === slideshow.next || this === slideshow.prev ){
			slideshow.removeClass(slideshow.items[slideshow.current], 'current');
			var addto = (this === slideshow.next || this === slideshow.thispic) ? 1 : -1;  

			slideshow.current = slideshow.current + addto;
			if(slideshow.current < 0){
				slideshow.current = (slideshow.all-1);
			}
			if(slideshow.current > slideshow.all-1){
				slideshow.current = 0;
			}
		}
		var templabel = document.createTextNode( (slideshow.current+1) + ' / ' + slideshow.all);
		slideshow.count.replaceChild(templabel, slideshow.count.firstChild);
		slideshow.addClass(slideshow.items[slideshow.current], 'current');
		slideshow.cancelClick(e);
	},
	show_next_pic:function(e){

		slideshow.removeClass(slideshow.items[slideshow.current], 'current');
		var addto = 1;

		slideshow.current = slideshow.current + addto;
		if(slideshow.current < 0){
			slideshow.current = (slideshow.all-1);
		}
		if(slideshow.current > slideshow.all-1){
			slideshow.current = 0;
		}
		var templabel = document.createTextNode( (slideshow.current+1) + ' / ' + slideshow.all);
		slideshow.count.replaceChild(templabel, slideshow.count.firstChild);
		slideshow.addClass(slideshow.items[slideshow.current], 'current');
		slideshow.cancelClick(e);
	},
	/* helper methods */
	addEvent:function( obj, type, fn ) {
		if ( obj.attachEvent ) {
		 obj['e'+type+fn] = fn;
		 obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
		 obj.attachEvent( 'on'+type, obj[type+fn] );
		} else
		 obj.addEventListener( type, fn, false );
	},
	removeClass:function(o,c){
		var rep=o.className.match(' '+c)?' '+c:c;
		o.className=o.className.replace(rep,'');
	},
	addClass:function(o,c){
		var test = new RegExp("(^|\\s)" + c + "(\\s|$)").test(o.className);
		if(!test){o.className+=o.className?' '+c:c;}
	},
	cancelClick:function(e){
		if (window.event){
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
		if (e && e.stopPropagation && e.preventDefault){
			e.stopPropagation();
			e.preventDefault();
		}
	}
};
slideshow.addEvent(window,'load',slideshow.init);
