function regionShow(i){
	if( i == "first") i = $("#top_tabs ul li").length - 1;
	var $tab = $("#top_tabs ul li").removeClass("selected").eq(i).addClass("selected"),
	    count = $("#top_tabs ul li").length - 1,
	    left = $tab[0].offsetLeft,
	    width = $tab.width();
	left = left + (width/2) + 8;
	
	$("#top_topic img.top_arrow").animate({left : left+'px'},500);
	var x = $("div.topic").filter(".selected");
	$("#topics").fadeOut(500,function(){
		x.removeClass("selected");
		$("div.topic").eq(count-i).addClass("selected");
		$("#topics").fadeIn(500);
	})
	if (x.length==0){
		$("#topics").hide();
		$("div.topic").eq(count-i).addClass("selected");
		$("#topics").fadeIn(500);
		
	}
}

$(function(){
	if( ($("#top_tabs ul li").length > 0) ) regionShow(2);

	$("#top_tabs ul li").click(function(){
		var index = $(this).prevAll("li").length;
		regionShow(index);
	}).hover(
		function(){$(this).addClass("hover");},
		function(){$(this).removeClass("hover");}
	);
			
	$("#center h1:first").remove();
	
	
	$("div.area_feature_details h3").click(function(){
		var $l = $(this).nextAll("a.learn_more");
		window.location.href = $l.attr("href");	
	}).hover(
		function(){$(this).css("textDecoration","underline");},
		function(){$(this).css("textDecoration","none");}
	);
	
	$("div.small_topic h4").click(function(){
		var $l = $(this).nextAll("a.learn_more");
		window.location.href = $l.attr("href");		
	}).hover(
		function(){$(this).css("textDecoration","underline");},
		function(){$(this).css("textDecoration","none");}
	);
	
	$("div.right_part").height( $("#key_areas").height());


	$("#explore_tabs div.explore_topic:first").hover(
		function(){
			$("#explore_tabs div.explore_topic:first").children("div.explore_popup").show();
		},
		function(){
			$("#explore_tabs div.explore_topic:first").children("div.explore_popup").hide();
	});

	$("#explore_tabs div.explore_topic:eq(1)").hover(
		function(){
			$("#explore_tabs div.explore_topic:eq(1)").children("div.explore_popup").show();
		},
		function(){
			$("#explore_tabs div.explore_topic:eq(1)").children("div.explore_popup").hide();
	});

	///////////flash replacement/////////////////////////////////
	
	$('#features .feature:first').addClass('selected').animate({'width':'293px'},200);
	$('#features .feature:first').find('.scroll_area').children().hide();
	$('#features .feature:first').find('h2').fadeIn(400);
	$('#features .feature:first').find('.feature_long_description').fadeIn(600);
	$('#features .feature:first').find('img').fadeIn(800);

	$('#features .feature').hover(
		function(){			
			
			if(!($(this).hasClass('selected'))){	
				
				$('#features .feature').stop();
				
				$('#features .feature.selected').find('img').hide();
				$('#features .feature.selected').find('.feature_long_description').hide();
				$('#features .feature.selected').find('.feature_short_description').show();
				$('#features .feature.selected').css('width','140px').removeClass('selected');
				
				$(this).find('.scroll_area').children().hide();
				$(this).addClass('selected').animate({'width':'293px'},200);
				
				$(this).find('h2').fadeIn(400);
				$(this).find('.feature_long_description').fadeIn(600);
				$(this).find('img').fadeIn(800);
			}

		},
		function(){
			//TO DO
		});
});
