$(document).ready(function() {

	// subscribe input
	$('#subscribe #email').each(function(){
		var title = $(this).attr('title');

		if( $(this).val() == '' || $(this).val() == title ){
			$(this).val(title).addClass('dim');
		}
		$(this).focus(function(){
			if( $(this).hasClass('dim') ){
				$(this).val('').removeClass('dim');
			}
		});
		$(this).blur(function(){
			if( $(this).val() == '' || $(this).val() == title ){
				$(this).val(title).addClass('dim');
			}
		});
	});
	
	// fancybox elements
	if( $('.fb').length > 0 ){
		$('.fb').fancybox({autoScale: false, scrolling: false, overlayOpacity: .6, overlayColor: '#000'});
	}
	
	// tabs
	$('.tabs li a').click(function(e){
		e.preventDefault();
		var target = $(this).attr('href');
		var li = $(this).parent('li');
		var content = li.parent('ul').next('.tabs_content');
		
		$('> .tab', content).removeClass('on').addClass('off');
		$(target).removeClass('off').addClass('on');
		li.siblings('li').removeClass('on');
		li.addClass('on');
	});
	
	//////////////////////////////////////
	// map
	
	function highlightNav(sector){
		$('#map_nav li').removeClass('current');
		$('#sec_' + sector).parent('li').addClass('current');
	}
	
	function showCaption(sector){
		$('#map_holder .caption:visible').slideUp('fast');
		if( sector ){
			//console.log("sector found: " + sector);
			$('#cap_' + sector).slideDown('slow');//.css({zIndex:10})
		}
	}
	
	function showZoom(target){
		var sector = target.attr('id').replace('#','');
		var current = $('#map_holder .on');
		
		highlightNav(sector);
		
		showCaption(sector);
		
		current.css({zIndex:1});
		target.css({zIndex:9}).addClass('on').removeClass('off').children('img').css({opacity:0}).animate({opacity:1}, 250, function(){
			current.removeClass('on').addClass('off').css({zIndex:1}).children('img').fadeOut();
		});
		if( sector == 'all' ){
			$('#map_corner_east').show();
		}
	}
	
	$('#map_nav .sector, #all .map_overlay').click(function(e){
		e.preventDefault();
		var target = $( $(this).attr('href') );
		showZoom(target);
	});
	
	$('#all .map_overlay').hover(function(){
		var sector = $(this).attr('id').replace('ov_','');
		highlightNav(sector);
		showCaption(sector);
	},
	function(){
		if( $('#map_holder .on:not(#all)').length == 0 ){
			highlightNav('all');
			showCaption(false);
		}
	});
	
	//////////////////////////////////////

//    $(".box").mouseenter(function() {
//    	$(this).addClass('over'); 
//    	$(this).find("h2").animate({"left" : 0}, 425);
//    });
//    $(".box").mouseleave(function() {
//    	$(this).removeClass('over');  
//    	$(this).find("h2").animate({"left" : 165}, 425);
//    });
    
});
