$(document).ready(function() {
	equalHeight($("li.v2_parent ul"));
	var sec, curSection;

	$('li.v2_parent').mouseover(function() {
		clearInterval(intervalID );
		$('.v2_hovered').removeClass('v2_hovered').find('.v2_tabTitle').removeClass('v2_activeTab');
		$(this).addClass("v2_hovered").find('.v2_tabTitle').addClass('v2_activeTab');
		if(sec != $(this).attr("rel")) {
			sec = $(this).attr("rel");
			$('#v2_imageContainer').find('.v2_curSelected').stop().fadeTo('fast',0).removeClass('v2_curSelected').parent().find('#'+sec).fadeTo('fast', 1).addClass('v2_curSelected');
		}
	}, function() {
		$('.v2_hovered').removeClass('v2_hovered').find('.v2_tabTitle').removeClass('v2_activeTab');
		
	});




	$('#v2_imageContainer').mouseover(function() {
		clearInterval(intervalID);
		curSelectedID = $('.v2_curSelected','#v2_imageContainer').attr("id");
		$li = $('li[rel='+curSelectedID+']');
		$('.v2_hovered').removeClass('v2_hovered').find('.v2_tabTitle').removeClass('v2_activeTab');
		$li.addClass("v2_hovered").find('.v2_tabTitle').addClass('v2_activeTab');
	}, 
	function() {
		$('.v2_hovered').removeClass('v2_hovered').find('.v2_tabTitle').removeClass('v2_activeTab');
	});

	$('#v2_imageContainer').mouseout(function() {
		intervalID = setInterval ( "rotateImages()", 10000 );
	});


	intervalID = setInterval ( "rotateImages()", 10000 );


});


function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
/* 	if($.browser.msie) { tallest = tallest+50; } */
	group.height(tallest);
}


function rotateImages() {
	$curSelected = $('.v2_curSelected','#v2_imageContainer');
	sectionName = $curSelected.attr("class");
	pattern=/section(\d{1})/
	result=pattern.exec(sectionName);
	curSection = result[1];
	if(curSection < 5) { curSection++; } else { curSection = 1; }
	$curSelected.stop().fadeTo('fast',0).removeClass('v2_curSelected').parent().find('.section'+curSection).fadeTo('fast',1).addClass('v2_curSelected');
	$('.v2_hovered').removeClass('v2_hovered').find('.v2_tabTitle').removeClass('v2_activeTab');

}