var arrow1index = 0;

$(document).ready(function(){
	
	$('#homepage-three-right-tab-div ul li').click(function()
	{
		for(var i=1; i<4; i++)
		{
			$('#three-tab-'+i).addClass('three-tab-sl');
			$('#three-utab-'+i).removeClass('sl');
		}
		
		var id = $(this).attr('id').replace('three-utab-', '');
		$('#three-tab-'+id).removeClass('three-tab-sl');
		$('#three-utab-'+id).addClass('sl');
	});
						   


	var _timeout2 = 0;
	var lng2 = $('#homepage-two-right-bottom li');
	var _rindex2 = 0;
	
	function rotate2(isRight)
	{
		$(lng2[_rindex2]).fadeIn();
		$(lng2[_rindex2]).css('display', 'none');
		//
		if(isRight)
			_rindex2++;
		else
			_rindex2--;
		//
		if(_rindex2 < 0)
			_rindex2 = lng2.length-1;
		if(_rindex2 >= lng2.length)
			_rindex2 = 0;
		//
		$(lng2[_rindex2]).fadeIn();
		//
		clearTimeout(_timeout2);
		_timeout2 = setTimeout(rotate2, 5500, true);
	}
	//
	$('#homepage-two-right-bottom-arrow-right').click(function(){rotate2(true)});
	$('#homepage-two-right-bottom-arrow-left').click(function(){rotate2(false)});
	rotate2(true);
	
						   
/*						   
	$('#homepage-two-right-bottom-arrow-right, #homepage-two-right-bottom-arrow-left').click(function()
	  {
		  var div = $('#homepage-two-right-bottom-div');
		  var n = ($(this).attr('id')) == 'homepage-two-right-bottom-arrow-right' ? 1 : -1;
		arrow1index += n;
		if(arrow1index < 1) arrow1index = 0;
		if(arrow1index > 4) arrow1index = 4;
		div.animate({scrollLeft : (arrow1index * 239) + 'px'}, 'slow');
	  });
	*/
	//
/*
	var lng = $('#homepage-two-left-content li');
	var _rindex = 0;
*//*
	var _timeout = 0;
	var arrow1index = 0;
	
	function rotate()
	{
		var div = $('#homepage-two-left-content');
		arrow1index++;
		if(arrow1index > 2) 
			arrow1index = 0;
		div.animate({scrollLeft : (arrow1index * 365) + 'px'}, (arrow1index == 0 ? 300 : 'slow' ));
		//
		clearTimeout(_timeout);
		_timeout = setTimeout(rotate, 4500);
	}
	//
	$('#homepage-two-left-content').click(rotate);
	//
	rotate();
	*/
	
	
	
	
	var topObjs = $('#homepage-two-left-content li');
	var _timeoutx;
	var topBtnsHtml = '';
	for(var i=0; i<topObjs.length; i++)
	{
		topBtnsHtml += '<li class="top-btn '+ (i == 0 ? 'selectedb' : '') +'" id="topbtnp-'+(i+1)+'" title="'+(i+1)+'"> </li>';
	}
	topBtnsHtml = '<ul>' + topBtnsHtml + '</ul>' 
	$('#homepage-two-btns').html(topBtnsHtml);
	$('.top-btn').click(function()
	{
		var h = $('.top-btn');
		for(var i=0; i<h.length; i++)
			$(h[i]).removeClass('selectedb');
		
		var j = parseInt( $(this).attr('title') );
		
		$(this).addClass('selectedb');
		j--;
		$('#homepage-two-left-content').animate({scrollLeft : (j * 365) + 'px'}, (j == 0 ? 300 : 'slow' ));
	
		clearTimeout(_timeoutx);
		_timeoutx = setTimeout(rotateTop, 4500);
	});
	function rotateTop()
	{
		var tops = $('#homepage-two-left-content li');
		var j = parseInt( $('.selectedb').attr('title') );
		
		var h = $('.top-btn');
		for(var i=0; i<h.length; i++)
			$(h[i]).removeClass('selectedb');
			
		if(j+1 > tops.length)
			j = 0;
		
		$('#topbtnp-' + (j+1)).addClass('selectedb');
		$('#homepage-two-left-content').animate({scrollLeft : (j * 365) + 'px'}, (j == 0 ? 300 : 'slow' ));
		
		//
		clearTimeout(_timeoutx);
		_timeoutx = setTimeout(rotateTop, 4500);
	}
	rotateTop()
	
	
	
	
	var incityAuto;
	var incityAutoNmber = 0;
	$('#homepage-two-right-bottom-div-a a').mouseover(function()
	{
		var j = $(this).attr('id').replace('incity', 'incityi');
		var h = $('#homepage-two-right-bottom-div-img a');
		var h2 = $('#homepage-two-right-bottom-div-a a');
		
		for(var i=0; i<h.length; i++)
			$(h[i]).addClass('disable');
		
		for(i=0; i<h2.length; i++)
			$(h2[i]).removeClass('enable');
			
		$('#' + j).removeClass('disable');
		//
		incityAutoNmber = parseInt( j.replace('incityi-', '') );
		clearTimeout(incityAuto);
	});
	
	function incityAutoChange()
	{
		incityAutoNmber++;
		
		if(incityAutoNmber > $('#homepage-two-right-bottom-div-img a').length)
			incityAutoNmber = 1;
		
		var h = $('#homepage-two-right-bottom-div-img a');
		var h2 = $('#homepage-two-right-bottom-div-a a');
		for(var i=0; i<h.length; i++)
			$(h[i]).addClass('disable');
		
		for(i=0; i<h2.length; i++)
			$(h2[i]).removeClass('enable');
			
		$('#incityi-' + incityAutoNmber).removeClass('disable');
		$('#incity-' + incityAutoNmber).addClass('enable');
		
		clearTimeout(incityAuto);
		incityAuto = setTimeout(incityAutoChange, 2000);
	}
	incityAutoChange();
	
	
	
	
	
});
