$(document).ready(function(){ $('a').focus(function(){ this.blur(); }); });

function InitSlideShow(name){
	var cnt = $(name +' img.slideshow').length;
	if(cnt <= 1) { ShowSlide(name, 0); return; }
	var html = '';
	html += LinkButton('<img src="./img/arrow_l.gif" style="position: absolute; left: 0px;" />', 'PrevSlide(\''+ name +'\')');
	for(i = 0; i < cnt; i++) {
		var btn = '<img src="./img/btn_slide.gif" class="button'+ (i == 0 ? ' first' : '') +'"/>';
		html += LinkSlide(btn, name, i);
	}
	html += LinkButton('<img src="./img/arrow_r.gif" style="position: absolute; right: 0px;" />', 'NextSlide(\''+ name +'\')');
	$(name +' div.buttons').html(html);
	ShowSlide(name, 0);
}

function ShowSlide(name, index) {
	$(name).attr('selected', index);
	$(name +' img.slideshow').hide();
	$(name +' img.button').attr('src', './img/btn_slide.gif');
	$(name +' img.slideshow:eq('+ index +')').show();
	$(name +' img.button:eq('+ index +')').attr('src', './img/btn_slide_active.gif');
}

function PrevSlide(name) {
	var index = parseInt($(name).attr('selected'));
	var cnt = $(name +' img.slideshow').length;
	index--;
	if (index < 0) { index = cnt - 1; }
	ShowSlide(name, index);
}

function NextSlide(name) {
	var index = parseInt($(name).attr('selected'));
	var cnt = $(name +' img.slideshow').length;
	index++;
	if (index >= cnt) { index = 0; }
	ShowSlide(name, index);
}

function LinkSlide(html, name, index) {
	var fct = 'ShowSlide(\''+ name +'\','+ index +')';
	return LinkButton(html, fct);
}

function LinkButton(html, fct) {
	var ret = '';
	ret += '<a href="javascript:void(0);"';
	ret += ' onfocus="this.blur();"';
	ret += ' onclick="'+ fct +';"';
	ret += '>';
	ret += html;
	ret += '</a>';
	return ret;
}

function FadeOut() {
	if (!animate) { window.setTimeout("FadeOut()", 2000); return; }
	var img = $('#container img:last');
	img.fadeOut(1200, 'easeInOutCubic', FadeImage);
}

function FadeImage() {
	$('#container img:last').remove();
	var mover = $('#container');
	for(var i = mover.find('img').length; i <= 2; i++)
	{
		step++;
		if(step >= imgs.length) { step = 0; }
		var img = $('<img src="'+ imgs[step] +'" style="position: absolute;"/>');
		mover.prepend(img);
	}
	window.setTimeout("FadeOut()", 5000);
}

