MainNavigation = function(ElementId)
{
	navRoot = document.getElementById(ElementId).getElementsByTagName("ul")[0];
	for (i=0; i<navRoot.childNodes.length; i++)
	{
		node = navRoot.childNodes[i];
		if (node.nodeName=="li")
		{
			node.onmouseover=function()
			{
				this.className+=" sfhover";
			}
			node.onmouseout=function()
			{
				this.className=this.className.replace("sfhover", "");
			}
		}
	}
}

$(function(){
	$('.b-features .b-features__item').setEqualBlocksHeight({
		count:3
	});
	$(".fancybox").fancybox({
		'titleShow' : false
	});
})
function TabberWrap(){
	$('.tabbertab.general').wrapInner('<div class="tab-container" />');
}

function initMapPreview(){

var $expandable=$('.b-expandable__content', ".b-expandable"),
	$openLink=$('.js-open-area'),
	$closeLink = $('.js-close-area'),
	showMap,
	hideMap,
	showLink;
	showMap=function(animated){
		if(animated){
			$expandable.slideDown('slow');
		}else{
			$expandable.show();
		}
		
		$openLink.css("visibility", "hidden");
	};
	
	hideMap=function(animated){
		if(animated){
			$expandable.slideUp('slow', showLink);
		}else{
			$expandable.hide();
			showLink();
		}
		
	};
	
	showLink = function(){
		$openLink.css("visibility", "visible");
	}
	
	
	$openLink.click(function(){
		showMap(true);	
		return false;
	});
	$closeLink.click(function(){
		hideMap(true);
		return false;
	});
	
	hideMap();
};





$(document).ready(function(){
	TabberWrap();
	MDA.Map.enable();
	initMapPreview();

});



// To initially run the function:





// application logic
var MDA = {
	Map : {
		enable : function() {		
			if(!document.getElementById("map")) { return; }	
			
			// reset opacity to help jquery make calculations
			jQuery('#map div.customer').css({opacity:0});			
			
			// bind events for toggling details
			// focus doesn't have a corresponding blur event to allow tabbing through tooltip content
			// any active item is hide when a new one is shown instead
			jQuery('#map').delegate('a.pin','focus click',function(e){		
				MDA.Map.show(jQuery(this));
				return false;																								
			}).delegate('li','mouseenter mouseleave',function(e){
				
				MDA.Map[e.type == "mouseenter" ? "show" : "hide"](jQuery(this));
			});
					
		},
		show : function(obj) {	
			// depending on if coming from focus or mouseover, won't have the same target. normalize it.
			var detail = obj.parents('li').or(obj).not('.active');
			
			// if the target isn't already active, hide existing active items and make it so. otherwise don't do anything
			if(detail.length) {
				MDA.Map.hide(jQuery("#map li.active"));	
						
				detail.addClass('active').find('div.customer')
					.stop(true,true).animate({
								opacity : 1,
								bottom : '+=6' }, 250, 'linear');		
			}
		},		
		hide : function(obj) {
			// normalize object and hide
			// animate callback resets object for next time
			obj.parents('li').or(obj).filter('.active').find('div.customer')
				.stop(true,true).animate({
							opacity : 0,
							bottom : '+=24' }, 150, 'linear', function(){ jQuery(this).css({bottom:'6px'}).parents('li').removeClass('active'); });		
		}	
	}
};
// first selector || second selector
jQuery.fn.or = function(s) { return jQuery(this).length ? jQuery(this) : jQuery(s); };

function trace(args){
	console.log(args);
}
