var slideshowTimer = null;
var mytime = 5000;
var delay = 1000;
var currObj = null;
var nextObj = null;

$(document).ready(function(){
						   
	$('INPUT.auto-hint').each(function(i, el){
        if($(this).val() == ''){
            $(this).val($(this).attr('title'));
			$(this).css('font-style', 'italic');
        }
        $(el).focus(function(){
            if ($(this).val() == $(this).attr('title')) {
                $(this).val('');
				$(this).css('font-style', 'normal');
            }       
        });
        $(el).blur(function(){
            if ($(this).val() == '') {
                $(this).val($(this).attr('title'));
				$(this).css('font-style', 'italic');
            }
        });
    });
	
	$('.slider UL LI').css('z-index', '1').css('opacity', 0);	
	$('.slider UL LI.current').css('z-index', '50').css('opacity', 1);	

	if($('.slider UL').length > 0){
		slideshowTimer = setTimeout("doSlideshow('slider UL', true, mytime)", mytime);
	}
	
	$('.slider-nav UL LI A').click(function(){
		if ($(this).parent().hasClass('active')) return false;
		$('.slider UL LI').stop(true, true);
		
		$('.slider-nav UL LI.active').removeClass('active');
		
		
			if	(slideshowTimer != null){
				clearTimeout(slideshowTimer);
				slideshowTimer = null;
			}
		
		currObj = $('.slider UL li.current');
		nextObj = $('.slider UL li').eq(parseInt($(this).attr('class'))-1);
		
		nextObj.addClass('current');
		nextObj.css('opacity', 0).css('z-index','2');
		currObj.removeClass('current').css('z-index','1');
		//$('.button-nav li.'+nextObj.attr('id')+' a').addClass('active');
		currObj.animate({opacity:0}, delay);
		nextObj.animate({opacity:1}, delay);
		
		if (($.browser.msie) && (parseInt($.browser.version) == 6)) {
			setTimeout("$('.controls li').eq($('.slider UL li').index($('.slider UL li.current'))).addClass('active');", 100);
		} else {
			$('.controls li').eq($('.slider UL li').index($('.slider UL li.current'))).addClass('active');
		}
		
		
		
		//$('.button-nav li.'+currObj.attr('id')+' a').removeClass('active');	
		//#content .slider-container .slider-nav UL LI A SPAN.title-nav
		
		slideshowTimer = setTimeout('doSlideshow("slider UL", false, ' + mytime + ');', mytime);
		return false;
	});
	
	
});

function isVisible(obj) { return (obj.css('display') == 'block'); }

function doSlideshow(objid, start, time){
	if(!$('.' + objid) || !isVisible($('.' + objid))){
		if(slideshowTimer != null){
			clearTimeout(slideshowTimer);
			slideshowTimer = null;
		}
		return;
	}
	
	if(start){
		clearTimeout(slideshowTimer);
		slideshowTimer = null;
	}
	
	var currObj = $('.' + objid + ' li.current');
	var nextObj = currObj.next();
	if($('.' + objid + ' li:last').hasClass('current')){ 
		nextObj = $('.' + objid + ' li:first');
	}

	nextObj.addClass('current');
	nextObj.css('opacity', 0).css('z-index','2');
	currObj.removeClass('current').css('z-index','1');
	//$('.button-nav li.'+nextObj.attr('id')+' a').addClass('active');
	currObj.animate({opacity:0}, 2000);
	nextObj.animate({opacity:1}, 2000);
	//$('.button-nav li.'+currObj.attr('id')+' a').removeClass('active');	
	$('.controls li.active').removeClass('active');
	$('.controls li').eq($('.slider UL li').index($('.slider UL li.current'))).addClass('active');		

	slideshowTimer = setTimeout('doSlideshow("' + objid + '", false, ' + time + ');', time);
}