// JavaScript Document

function hidediv(id) {
	
		if (document.getElementById) { 
			document.getElementById(id).style.display = 'none';
		}
		else {
			if (document.layers) { // Netscape 4
				document.id.display = 'none';
			}
			else { // IE 4
				document.all.id.style.display = 'none';
			}
		}
	}
	
	function showdiv(id) {
	
		
		if (document.getElementById) { 
			document.getElementById(id).style.display = 'block';
		}
		else {
			if (document.layers) { // Netscape 4
				document.id.display = 'block';
			}
			else { // IE 4
				document.all.id.style.display = 'block';
			}
		}
	}
	
	function switchtab(tabname,n){
		x=0;
		for(i=0;i<n;i++){
			x++;
			document.getElementById('tab'+x+'1').className='tab1';
			document.getElementById('tab'+x+'2').className='tab2';
			document.getElementById('tab'+x+'3').className='tab3';
			
		}
		document.getElementById(tabname+'1').className='tab1active';
		document.getElementById(tabname+'2').className='tab2active';
		document.getElementById(tabname+'3').className='tab3active';
		hidediv('contenttab1')	;
		hidediv('contenttab2')	;
		
		showdiv('content'+tabname);
	}
	
function menubar(id){
		hidediv('boxabout');
		hidediv('boxnews');
		hidediv('boxsearch');
		showdiv(id);
}
function showsearch(){
	hidediv('boxabout');
	hidediv('boxnews');
	showdiv('boxsearch');
}
Slideshow.implement(new Options);

var ImageLoader = new Class({
	
	version:'.5-olmo-ver',
	
	options: {
		loadingDiv    : false,
		loadingPrefix : 'loading images: ',
		loadingSuffix : '',
		path		  : '',
		removeDiv	  : true
	},
	
	initialize: function(sources, options){
		this.setOptions(options);
		this.loadingDiv = $(this.options.loadingDiv);
		this.images     = [];
		this.index      = 0;
		this.total      = 0;
		
		if(this.loadingDiv) {
			this.loadingText = new Element('div').injectInside(this.loadingDiv);
			this.progressBar = new Element('div', {
				styles: {
					width: 100,
					padding: 1,
					margin: '5px auto',
					textAlign: 'left',
					overflow: 'hidden',
					border: 'solid 1px #333'
				}
			}).adopt(new Element('div', {
				styles: {
					width: '0%',
					height: 10,
					backgroundColor: '#333'
				}
			})).injectInside(this.loadingDiv);
		}
		
		this.loadImages.delay(200, this, [sources]);
	},
	
	reset: function() {
		this.index = 0;
		if(this.loadingDiv) {
			this.progressBar.getFirst().setStyle('width', '0%');
			this.loadingText.setHTML(this.options.loadingPrefix);
		}
	},
	
	loadImages: function(sources) {
		this.reset();
		this.images  = [];
		this.sources = sources;
		
		this.timer = setInterval(this.loadProgress.bind(this), 100);
		for(var i = 0, j = sources.length; i < j; i++) {
			this.images[i] = new Asset.image((this.sources[i].path || this.options.path) + this.sources[i].file, {
				title: this.sources[i].title,
				alt: this.sources[i].desc,
				'onload'  : function(){ this.index++; }.bind(this),
				'onerror' : function(){ this.index++; this.images.splice(i,1); }.bind(this),
				'onabort' : function(){ this.index++; this.images.splice(i,1); }.bind(this)
			});
		}
	},
	
	loadProgress: function() {
		if(this.loadingDiv) {
			this.loadingText.setHTML(this.options.loadingPrefix + this.index + '/' + this.total + this.options.loadingSuffix);
			this.progressBar.getFirst().setStyle('width', (!this.total ? 0 : this.index.toInt()*100 / this.total) + '%');
		}
		
		if(this.index >= this.total) {
			this.loadComplete();
		} 
	},
	
	loadComplete: function(){
		$clear(this.timer);
		if(this.loadingDiv) {
			this.loadingText.setHTML('Loading Complete');
			
			if(this.options.removeDiv) {
				this.loadingDiv.empty().remove();
			}
		}
		this.fireEvent('onComplete', this.images);
	},
	
	cancel: function(){
		$clear(this.timer);
	}
	
});

ImageLoader.implement(new Events, new Options);
