/*
 * Homepage Feature rotation
 */

var featureDelay = 8000;

// setup feature tabs
jQuery(function($) {
	$('#feature .tabs a').each(function(i, elem) {
		$(this).data('pos', i);
	});

	// animate feature
	$('#feature .tabs a').click(function() {
		$(this).addClass('selected').siblings().removeClass('selected');
		var offset = $(this).data('pos') * -680;
		$('#feature .window').animate({left:offset}, 300)
		if ($('#feature').data('timer')) clearTimeout($('#feature').data('timer'));
		
		return false;
	});
	$('#feature .tabs a').filter(':first').addClass('selected').end().filter(':last').addClass('last');

});

function rotateFeatures() {
	var $ = jQuery;

	if ($('#feature').data('timer')) clearTimeout($('#feature').data('timer'));
	var current = $('#feature .tabs a.selected');
	if (current.next().length > 0) {
		current.next().click()
	} else {
		$('#feature .tabs a:first').click();
	}
	$('#feature').data('timer',  setTimeout(rotateFeatures, featureDelay));
}
jQuery(function($) {
	$('#feature').data('timer',  setTimeout(rotateFeatures, featureDelay));
});



jQuery(function($) {
	var info = $('#map a.info');
	
	$('#map').hover(function() {
		info.addClass('hover').hide()
	}, function() {
		info.removeClass('hover')
		info.html('Click on the map to<br> see our locations')
		info.attr('style', '').fadeIn();
	});
	$('#map map area').mouseover(function() {
		info.attr('href', $(this).attr('href'));
		info.text($(this).attr('alt'));
		var coords = $(this).attr('coords').split(",")
		var left = coords[0]+'px'
		var top = coords[1]+'px'
		info.css({top:top,left:left}).fadeIn();
	});
});
