/*
	sliders.js version 1.0 from 2007-02-20
*/

// general browser information gathering
var str_browser_type							= (navigator && navigator.userAgent)
												? navigator.userAgent.toLowerCase()
												: '';
var str_browser_version							= (navigator && navigator.appVersion) ? navigator.appVersion : '';
var int_browser_version							= parseInt(str_browser_version,10);

// detect opera browser
var int_browser_type_opera						= str_browser_type.indexOf('opera') != -1;
var int_browser_type_opera_version_greater_9	= int_browser_type_opera
												&& int_browser_version >= 9;

// detect Microsoft Internet Explorer browser
var int_browser_type_msie						= !int_browser_type_opera
												&& (str_browser_type.indexOf('msie') != -1);

// detect konqueror browser
var int_browser_type_konqueror					= str_browser_type.indexOf('konqueror') != -1;

// detect mozilla browser
var int_browser_type_mozilla_greater_5			= !int_browser_type_msie
												&& !int_browser_type_opera
												&&	( (str_browser_type.indexOf('netscape') != -1)
													|| (str_browser_type.indexOf('mozilla') != -1) )
												&& (int_browser_version >= 5);

// detect netscape 6
var int_browser_type_netscape_version_6			= (str_browser_type.indexOf('netscape6') != -1);

// main function
function imageSlide(
	str_id_name,
	int_width,
	int_height,
	int_step,
	int_delay,
	int_gap,		// distance between images
	int_trailer,	// distance between rounds
	str_background_color,
	str_config,
	int_slider_border,
	int_image_border
){
	this.slider_border = int_slider_border;
	this.image_border = int_image_border;
	this.id_name = str_id_name;
	this.width = int_width;
	if(	int_browser_type_mozilla_greater_5
	||	int_browser_type_netscape_version_6
	||	int_browser_type_opera_version_greater_9
	){
		this.image_height = int_height - this.image_border * 2;
	}else{
		this.image_height = int_height;
	};

	this.step = int_step;
	this.delay = int_delay;
	this.gap = int_gap;
	this.trailer = int_trailer;
	this.background_color = '#' + str_background_color;
	this.current_step = this.step;
	this.container1_width = 0;
	this.container2 = null;
	this.container3 = null;
	if(str_config != null){
		this.config = str_config;
	}else{
		this.config = new Array();
	};

	this.start();
};

imageSlide.prototype.start = function(){
	var slider_div = document.getElementById(this.id_name);
	var imageSlider = this;

	if(	(typeof(slider_div) == 'undefined')
	||	(slider_div == null)
	){
		setTimeout(	function(){imageSlider.start();},
					300);
		return;
	};

	slider_div.innerHTML = this.sliderContainer();
	setTimeout(	function(){imageSlider.loadImages();},
				300);
};

imageSlide.prototype.loadImages = function(){
	this.container2 = document.getElementById('container2');
	this.container3 = document.getElementById('container3');
	var span_container1 = document.getElementById('container1');
	var imageSlider = this;

	if(	(typeof(this.container2) == 'undefined')
	||	(this.container2 == null)
	||	(typeof(this.container3) == 'undefined')
	||	(this.container3 == null)
	||	(typeof(span_container1) == 'undefined')
	||	(span_container1 == null)
	){
		setTimeout(	function(){imageSlider.loadImages();},
					300);
		return;
	};

	this.container2.innerHTML	= this.sliderImages();
	this.container3.innerHTML	= this.sliderImages();
	this.container1_width		= span_container1.offsetWidth;
	this.container3.style.left	= this.container1_width
								+ this.trailer
								+ 'px';
	document.getElementById(this.id_name).onmouseover = function(){imageSlider.current_step = 0;};
	document.getElementById(this.id_name).onmouseout = function(){imageSlider.current_step = imageSlider.step;};
	setInterval(	function(){imageSlider.slide();},
					this.delay);
};

/*
	span#container1 for msie
*/
imageSlide.prototype.sliderContainer = function(){
	var arr_output = new Array();
	arr_output[arr_output.length]	= '<span id="container1" style="visibility:hidden; position:absolute; left:-1999px; top:-1999px">'
									+ this.sliderImages()
									+ '</span>';
	arr_output[arr_output.length]	= '<table border="0" cellspacing="0" cellpadding="0"><tr><td>';
	arr_output[arr_output.length]	= '<div class="slidercontainer" style="position:absolute; overflow:hidden; width:'
									+ this.width
									+ 'px; height:'
									+ this.image_height
									+ 'px; background-color:'
									+ this.background_color
									+ '" />';
	arr_output[arr_output.length]	= '<div id="container2" style="position:absolute; left:0px; top:0px"></div>';
	arr_output[arr_output.length]	= '<div id="container3" style="position:absolute; left:-1999px; top:0px"></div>';
	arr_output[arr_output.length]	= '</div>';
	arr_output[arr_output.length]	= '</td></tr></table>';
	return arr_output.join('');
};

imageSlide.prototype.sliderImages = function(){
	var arr_output = new Array();
	arr_output[arr_output.length]	= '<nobr>';
	arr_output[arr_output.length]	= '<table border="0" cellspacing="0" cellpadding="0"><tr>';

	for(	var i = 0;
			i < this.config.length;
			i++
	){
		arr_output[arr_output.length]	= '<td>';
		arr_output[arr_output.length]	= '<div class="sliderimages">';
		arr_output[arr_output.length]	= '<img src="'
										+ this.config[i][0]
										+ '" alt="'
										+ this.config[i][1]
										+ '" width="'
										+ this.config[i][2]
										+ '" height="'
										+ this.config[i][3]
										+ '" border="0" />';
		arr_output[arr_output.length]	= '</div>';
		arr_output[arr_output.length]	= '</td>';
		arr_output[arr_output.length]	= '<td><div style="width:'
										+ this.gap
										+ 'px; height:1px; border:0 none transparent;"></div></td>';
	};

	arr_output[arr_output.length] = '</tr></table>';
	arr_output[arr_output.length] = '</nobr>';
	return arr_output.join('');
};

imageSlide.prototype.slide = function(){
	if(	parseInt(this.container2.style.left) > (this.container1_width * (-1) + 9)
	){
		this.container2.style.left = parseInt(this.container2.style.left) - this.current_step + 'px';
	}else{
		this.container2.style.left = parseInt(this.container3.style.left) + this.container1_width + this.trailer + 'px';
	};

	if(	parseInt(this.container3.style.left) > (this.container1_width * (-1) + 9)
	){
		this.container3.style.left = parseInt(this.container3.style.left) - this.current_step + 'px';
	}else{
		this.container3.style.left = parseInt(this.container2.style.left) + this.container1_width + this.trailer + 'px';
	};
};

var int_sliders_loaded = true;
