function createMarker(point,html) {
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);
    });
    return marker;
}

function mapLoad() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("google-map"));
        map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(40.775, -73.985), 13);
        
        var point = new GLatLng(40.769165, -73.994887);
        var marker = createMarker(point,'<div style="width:180px;height:110px"><p style="line-height:1.5"><img style="float:none" src="/_images/map-logo.png"/><br/>55th St and West Side Highway<br/>New York, NY 10019</p></div>');
        map.addOverlay(marker);
    }
}



$(document).ready(function(){

    // Nav Accordion
    var $nav = $('#navigation>ul');

    $nav.accordion({
        active: ".selected",
        header: 'a.more',
        autoHeight: false,
        //fillSpace: true, // Use this OR change autoHeight to false
        animated: 'slide' // Or some other easing equation
    });

		$('#promos').cycle({
			fx: 'fade',
			pause: 1
		});
		
		
    
    // Homepage flash
    $.swfobject.embedSWF(
        '/_flash/piers-homepage.swf', 
        "homeflash", 
        "720", 
        "400", 
        "8.0"
    );
    
    $('#google-map').css({
        height: 350, 
        width: 450
    });
    
    if ($('#map,#google-map').length > 0)
    {
     mapLoad(); // Google Maps
    }


		// Galleria
		var $gallery = $('#gallery');

		$gallery.wrap('<div class="gallery_outer_wrapper"/>')
		  .find('li:first')
		    .addClass('active')
		    .end()
		  .find('li:nth-child(9)')
		    .addClass('last');

		if ( $gallery.length > 0 ) {

			var analyticsname;
			if ($gallery.attr('class') == 'lamart galleria') {
				analyticsname = 'LAMart Image Gallery';
			} else if( $gallery.attr('class') == 'mmart galleria') {
				analyticsname = 'MMart Image Gallery';
			} else {
				analyticsname = '7W Image Gallery';
			}

			$gallery.galleria({
			  history: false,
			  onImage: function(image,caption,thumb) { // let's add some image effects for demonstration purposes
								if (pageTracker) {
									pageTracker._trackEvent( analyticsname, 'thumbnail', image.attr('src') );
								}
			  				// fade in the image & caption
								image.css('display','none').fadeIn(600);
			  				//caption.css('display','none').fadeIn(1000);

			  				// fetch the thumbnail container
			  				var _li = thumb.parents('li');

			  				// fade out inactive thumbnail
			  				_li.siblings().children('img.selected').fadeTo(500,0.4);

			  				// fade in active thumbnail
			  				thumb.fadeTo('fast',1).addClass('selected');

			  				// add a title for the clickable image
			  				image.attr('title','Next image >>');
			  			},
				onThumb: function(thumb) { // thumbnail effects goes here

					// fetch the thumbnail container
					var _li = thumb.parents('li');

					// if thumbnail is active, fade all the way.
					var _fadeTo = _li.is('.active') ? '1' : '0.4';

					// fade in the thumbnail when finnished loading
					thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);

					// hover effects
					thumb.hover(
						function() { thumb.stop().fadeTo('fast',1); },
						function() { _li.not('.active').children('img').stop().fadeTo('fast',0.4); } // don't fade out if the parent is active
					);
				}

			});
		};
		$gallery.show();
    
});