// JavaScript Document
var mapA;
var latLon;

$(function(){
		   
	$('#dropNavigation>ul>li').each( function(){
		var index = $('#dropNavigation>ul>li').index(this);	
		
		/*
		if(index < 3){
			$(this).css({'margin-top': 0-index});
		} else {
			$(this).css({'margin-top': -1 + (index -3) });
		}
		*/
		
		$(this).children('ul').hide();
		
		$(this).mouseover(function(){
			  if($(this).children('ul').html()){
				  $(this).children('ul').show();
				  $(this).children('a').addClass('hov');
			  } else {
				  $(this).children('a').addClass('sel');
			  }
		});
		
		$(this).mouseout(function(){
			  if($(this).children('ul').html()){
				  $(this).children('ul').hide();
				  $(this).children('a').removeClass('hov');
			  } else {
				  $(this).children('a').removeClass('sel');
			  }
		});
		
	});
	
	$('#map').each(function(){
		if (GBrowserIsCompatible()) {
			
			var mapData = $(this).clone();
			
			$(this).empty();
			
			mapA = new GMap2(this);
			mapA.addControl(new GSmallMapControl());
			mapA.addControl(new GMapTypeControl());

        	geocoder = new GClientGeocoder();
			
			counter = 0;
			
			mapData.find('.location').each(function(){
													
				var building = $(this).find('.bld').html();
				var sTaddress = $(this).find('.st').html();
				var sTlat = $(this).find('.lat').html();
				var sTlng = $(this).find('.lng').html();
				var sFaddress = $(this).find('.sf').html();
				var sTdirections = 'http://www.google.com/maps?f=d&hl=en&saddr=' + '' + '&daddr=' + sTaddress;
				var sFdirections = 'http://www.google.com/maps?f=d&hl=en&saddr=' + sTaddress + '&daddr=';
	
				var sTinfo = '<div style="text-align: left;">' + building + '<br>' + sFaddress + '<br><br>Get directions: <a href="' + sTdirections + '">To here</a> - <a href="' + sFdirections + '">From here</a><br><br></div>';
				//$(this).empty();
				
				showAddress(new GLatLng(sTlat, sTlng), sTinfo, mapData.find('.location').length);	
			
			});
			
			if(mapData.find('.location').length > 1){
				mapA.setCenter(new GLatLng(42.91, -78.73), 8);
			}
		
		}	
	});
		   
	$('p[id*=faq]').hide();
	$('span[id*=partner]').hide();
	
	$('.splashDisplay').alignCenter();
	
});

// Hide Div
function hide(id) {
	$("#" + id).empty().hide();
}

// 
function showAddress(point, info, center) {
	if (geocoder) {
		//geocoder.getLatLng( address, function(point) {
			if (!point) {
				//alert(address + " not found");
            } else {
				if(center == 1){
					mapA.setCenter(point, 15);
				}
				
				var marker = new GMarker(point);
				mapA.addOverlay(marker);
			  
				GEvent.addListener(marker, "click", function() {
					marker.openInfoWindowHtml(info);
				});
            }
		//});
	}
}

// Translate
$.translate().ready(function(){ 
	if(lang != 'en'){
		$('#mainContent').translate('en',lang, {

			start:          function() {  $('#translateOverlayID').show(); },
			complete:    	function() {	$('#translateOverlayID').hide(); },
			error:         	function() {  $('#translateOverlayID').hide(); }

        });
	}
});