var Venison= Class.create(
/** @scope Venison.prototype */
{
  initialize : function () {
    Venison.Splash.init();
  }
});

/**
 * Make the image/text rotator for the front page. Ported from the marshill.cc
 * version.
 *
 *  ----------------------------------------------------------------
 *  Project:	MarsHill.cc
 *  Author: 	R. Marie Cox, Artypapers
 *  Author URI:	http://www.artypapers.com
 *  Date:		March/April 2007
 *  ---------------------------------------------------------------- 
 */
Venison.Splash = {
	timer:true,
	timer_delay:12000,// 1000 = 1 second
	timer_id:'',
	current_id:5,
	item_count:0,
	div_id:'homepage_splash',
	image_div_id:'homepage_splash_image',
	image_prefix:'',	
	item_id_prefix:'hs_',
	class_name:'homepage_splash_item',
	control_item_class:'item',
	control_item_selected_class:'item this',
	init:function() 
	{
		if ($(this.div_id)) {
			var obj = document.getElementsByClassName(this.class_name);	
			this.item_count = obj.length;
			
			Venison.Splash.select(this.current_id);			
		}
	},
	select:function(i)
	{
		this.current_id = i;
		
		css.hideClass(this.class_name);
		$(this.item_id_prefix+i).style.display = 'block';
		
		this.setImage();
		this.highlightItemLink();
		
		if (this.timer == true) {
			this.timer_id = window.setTimeout("Venison.Splash.next()", this.timer_delay);		
		}
	},
	setImage:function()
	{	
		fx.doFadeIn(this.image_div_id);
		//fx.doFadeIn(this.item_id_prefix+this.current_id);
		$(this.image_div_id).innerHTML = '<img src="stocks/'+this.image_prefix+this.current_id+'.jpg" style="border-width:0;padding-top:5px;" alt="Venison" />';
	},
	next:function()
	{
		this.current_id++;
		Venison.Splash.chkBounds();			
		Venison.Splash.select(this.current_id);		
	},
	prev:function()
	{
		this.current_id--;
		Venison.Splash.chkBounds();			
		Venison.Splash.select(this.current_id);		
	},
	get:function(i)
	{
		this.stopTimer();		
		this.select(i);
	},
	getNext:function()
	{
		this.stopTimer();
		this.next();
	},
	getPrev:function()
	{
		this.stopTimer();
		this.prev();
	},	
	stopTimer:function()
	{
		this.timer = false;
		if (this.timer_id) { window.clearTimeout(this.timer_id); }
	},
	chkBounds:function()
	{
		if (this.current_id <= 0) {
			this.current_id = this.item_count;
		} else if (this.current_id > this.item_count) {	
			this.current_id = 1;
		}
	},
	highlightItemLink:function()
	{
		var obj = document.getElementsByClassName(this.control_item_class);
		for(i = 0; i < obj.length; i++) {
			if (i == (this.current_id - 1)) {
				obj[i].className = this.control_item_selected_class;
			} else {
				obj[i].className = this.control_item_class;
			}
		}	
	}
}

var css = {
	hideClass:function (class_name) {
		var obj = document.getElementsByClassName(class_name);
		for(i = 0; i < obj.length; i++) {
			obj[i].style.display = 'none';
		}
	},
	showClass:function (class_name) {
		var obj = document.getElementsByClassName(class_name);
		for(i = 0; i < obj.length; i++) {
			obj[i].style.display = 'block';
		}
	}
}

var fx = {
	timer_id:'',
	timer_delay:100,
	doFadeIn:function (id) 
	{
		if (this.timer_id) { window.clearTimeout(this.timer_id); }
	
		this.setOpacity($(id), 0);
		$(id).style.visibility = "visible";
		this.fadeIn(id,0);
	},
	fadeIn:function (id, opacity) 
	{
		if (document.getElementById) {
			obj = document.getElementById(id);
			if (opacity <= 100) {
				this.setOpacity(obj, opacity);
				opacity += 10;
				this.timer_id = window.setTimeout("fx.fadeIn('"+id+"',"+opacity+")", this.timer_delay);
			}
		}
	},
	doFadeOut:function (id) 
	{
		if (this.timer_id) { window.clearTimeout(this.timer_id); }	
	
		this.setOpacity($(id), 100);
		$(id).style.visibility = "visible";
		this.fadeOut(id,100);
	},	
	fadeOut:function (id, opacity) 
	{
		if (document.getElementById) {
			obj = document.getElementById(id);
			if (opacity >= 0) {
				this.setOpacity(obj, opacity);
				opacity -= 10;
				this.timer_id = window.setTimeout("fx.fadeOut('"+id+"',"+opacity+")", this.timer_delay);
			}
		}
	},	
	setOpacity:function (obj, opacity) 
	{
		opacity = (opacity == 100)?99.999:opacity;
		obj.style.filter = "alpha(opacity:"+opacity+")";	// IE/Win
		obj.style.KHTMLOpacity = opacity/100;				// Safari<1.2, Konqueror
		obj.style.MozOpacity = opacity/100;					// Older Mozilla and Firefox
		obj.style.opacity = opacity/100;					// Safari 1.2, newer Firefox and Mozilla, CSS3
	}
};

// Load scripts on DOM loaded event
document.observe("dom:loaded", function () { new Venison() });

