$(document).ready(function(){
	(function(){
		var header_ul = $('ul#header-nav');
		var header_selected_li = $(header_ul).find('li.selected:first');

		var selected_li_timer = null;
		var selected_li_timeout = 500;
		var selected_li_timer_arr = [];
		var sub_li_timer = null;
		
			/* 
			 * ie7 and ie8 have problems with the selected page png images. I have no idea why, but
			 * it has something with how IE implements png support and how jquery handles fading. So,
			 * for that reason, do not do fading if the browsers is IE 7 or 8. (ie 6 works perfectly. irony.)
			 */
		var is_ie7_8 = /MSIE (7|8)/.test(navigator.userAgent);

		$(header_ul).find('li').hover(
		  function () {
			var li = this;
			if($(li).parent().attr('id') == $(header_ul).attr('id')){
				if($(li).hasClass('selected') && !is_ie7_8){
					$(li).find('a').fadeTo('slow', 1);
				}else{
					if(!is_ie7_8){
						if(!$(header_selected_li).hasClass('faded')){
							$(header_selected_li).addClass('faded').find('a').fadeTo('slow', .2);
						}
					}
				}
			}

			var a_arr = $(li).addClass('active').find('ul li a');
			var base = 100;
			
				//make sure opacity is reset
			$(a_arr).css('opacity',0).css('filter', 'alpha(opacity=0)');
			$(a_arr).each(function(){
				var _a = this;
				setTimeout(
						function(){
							$(_a).fadeTo(base, 1.0);
						},
						base	
				);
				base += 100;
			});
		  },
		  function () {
			var li = this;
			$(li).removeClass('active').find('ul li a').css('opacity', 0).css('filter', 'alpha(opacity = 0)');

			if($(li).hasClass('selected')) $(li).removeClass('faded');
			
			if($(li).parent().attr('id') == 'header-nav'){
				setTimeout(
					function(){
						if(!$(header_ul).find('li.active:first').length && $(header_selected_li).hasClass('faded')){
							$(header_selected_li).removeClass('faded').find('a').fadeTo('slow', 1.0);
						}
					}, 
					selected_li_timeout
				);
			}
		  }
		);
	}());		

});

function load_iframe(iframe_id, src){
	if(!iframe_id || !src) return;
	$('#'+iframe_id).attr('src', src);
}

$(window).load(function(){
	(function init_locations_gmap(){

	    var options = {
	      zoom: 16,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    }
	    map = new google.maps.Map(document.getElementById("map-bella-bellies"), options);
	    map.setCenter(new google.maps.LatLng(40.738576, -74.028797));
	    
	    var marker = new google.maps.Marker({
            map: map, 
            title: "Bella Bellies Studio",
            position: new google.maps.LatLng(40.738576, -74.028797)
        });  
	   
	    map = new google.maps.Map(document.getElementById("map-333-river"), options);
	    map.setCenter(new google.maps.LatLng(40.74064, -74.027596));
	    marker = new google.maps.Marker({
            map: map, 
            title: "333 River St.",
            position: new google.maps.LatLng(40.74064, -74.027596)
        });  
	    
	    map = new google.maps.Map(document.getElementById("map-monroe-center"), options);
	    map.setCenter(new google.maps.LatLng(40.746997, -74.037724));
	    marker = new google.maps.Marker({
            map: map, 
            title: "Monroe Center for the Arts - Movement Center Studios",
            position: new google.maps.LatLng(40.746997, -74.037724)
            
        });  
        
	}());
});

