// Configuration. All times are in milliseconds.

var DOWTopTextDelay = 5000; 
var DOWTopTextTransitionSpeed = 500;

var DOWBannerDelay = 7500; 
var DOWBannerTransitionSpeed = 500;

// End configuration.
//////////////////////////////////////////////////////////////////////////////

function changeTopText()
{
	if ( typeof changeTopText.items == 'undefined' ) 
		changeTopText.items = $('#topText li');
	
	if(changeTopText.items.length < 2)
		return;
		
	if ( typeof changeTopText.currentIndex == 'undefined' ) 
		changeTopText.currentIndex = 0;
		
	if ( typeof changeTopText.nextIndex == 'undefined' ) 
		changeTopText.nextIndex = 1;	
	
	changeTopText.items.eq(changeTopText.currentIndex).animate({
		top: '-26px'
	}, DOWTopTextTransitionSpeed, function(){ $(this).css('top', '26px'); });
	
	changeTopText.items.eq(changeTopText.nextIndex).animate({
		top: '0px'
	}, DOWTopTextTransitionSpeed,  function(){setTimeout("changeTopText()", DOWTopTextDelay);});
	
	changeTopText.currentIndex = changeTopText.nextIndex;
	
	if(++changeTopText.nextIndex >= changeTopText.items.length)
		changeTopText.nextIndex = 0;
}

function changeTopBanner(userNumber)
{		
	if ( typeof changeTopBanner.stop == 'undefined' ) 
		changeTopBanner.stop = false;
	
	if(!userNumber && changeTopBanner.stop)
		return;
		
	if ( typeof changeTopBanner.items == 'undefined' ) 
		changeTopBanner.items = $('#homeImages li');
		
	if(changeTopBanner.items.length < 2)
		return;
		
	if ( typeof changeTopBanner.currentIndex == 'undefined' ) 
		changeTopBanner.currentIndex = 0;
		
	if ( typeof changeTopBanner.nextIndex == 'undefined' ) 
		changeTopBanner.nextIndex = 1;
		
	if (userNumber)	
	{
		userNumber = parseInt(userNumber) - 1;
		changeTopBanner.stop = true;
		if(userNumber == changeTopBanner.currentIndex)
			return;
		else
			changeTopBanner.nextIndex = userNumber;
	}
	else
	{
		$('#homeImagesSwitch li')
			.eq(changeTopBanner.nextIndex)
			.addClass('active')
			.siblings()
				.removeClass('active');		
	}
		
	changeTopBanner.items.eq(changeTopBanner.nextIndex).css('z-index', '5').animate({
		opacity: '1'
	}, DOWBannerTransitionSpeed,  function(){
		changeTopBanner.items.eq(changeTopBanner.currentIndex)
			.css('opacity', '0')
			.css('z-index', '1');
			
		changeTopBanner.items.eq(changeTopBanner.nextIndex).css('z-index', '2');
		
		changeTopBanner.currentIndex = changeTopBanner.nextIndex;
		if(++changeTopBanner.nextIndex >= changeTopBanner.items.length)
			changeTopBanner.nextIndex = 0;	
		
		if (!changeTopBanner.stop)	
		{		
			setTimeout("changeTopBanner()", DOWBannerDelay);
		}
	});
}

$(document).ready(function(){ 
	//Placeholder for search
	$("#topSearchInput").placeholder();

	// Intializing menu
  $("#menu a").textShadow();
  $("#menu a").hover(
 	 function(){
	    $(this).parent().siblings().children().css('color', '#001649').textShadow({color: '#fff'});
	    $(this).css('color', '#fff').textShadow({color: '#001649'});
	  },
	  function(){
	    $(this).parent().siblings().children().css('color', '#001649').textShadow({color: '#fff'});
	    $(this).css('color', '#001649').textShadow({color: '#fff'});
  });

	// Intializing top text line
	$('#topText li').css('top', '26px').eq(0).css('top','0');
	setTimeout("changeTopText()", DOWTopTextDelay);

	// Intializing top banner
	$('#homeImagesSwitch li').click(function(){
		$(this).siblings().removeClass('active');
		$(this).addClass('active');
		changeTopBanner($(this).text());
	});
	setTimeout("changeTopBanner()", DOWBannerDelay);
});
