/* google.load("maps", "2.x"); */
jQuery(document).ready(function($) {
	if (typeof($.fn.superfish) != "undefined") {
		$('#navigation ul.level_1').addClass('sf-menu').superfish({
			pathClass: 'true',
			delay: 750,
			pathLevels: 0,
			animation: { speed: 'fast', height:'show'}
		});
	}

	function getMap(el, centerAddress) {

		if (typeof(GBrowserIsCompatible) != "undefined" && GBrowserIsCompatible) {

			var gc = new GClientGeocoder();
			var zoom = 5;
			if (centerAddress.match(/,/)) {
				zoom = 9;
			}
			if (!centerAddress) {
				centerAddress = 'Europe';
				zoom = 1;
			}  

			if (!el.id) {
				el.id = 'el' + Math.round(Math.random() * 1000);
			}
			gc.getLatLng(centerAddress, function(point) {

				var map = new GMap2(document.getElementById(el.id));
				map.setMapType(G_NORMAL_MAP);
				map.setCenter(point, zoom);

				var mm = new GMarkerManager(map);
				var marker = new GMarker(point);

				mm.addMarker(marker, 2); 
				mm.refresh();

			}); 

			return true;
		}

		return false;
	} 

	/**
	 * The Alt attribute is often wanted as Title as well. 
	 * So let us take care of that
	 */
	$('img').each(function() {
		if (!this.title && this.alt) {
			this.title = this.alt;
		}
	});
	/** 
	 * The h2 has a nice background image, which should start
	 * next to the text. The span helps with that
	 */
	/*
	$('body.lb h1, h2').livequery(function() {
		 $(this).wrapInner('<span></span>');
	});
	*/

	/**
	 * Turn a location string into a Google Map
	 */
	$('.locationMap').each(function() {
		var map 	= getMap(this, $.trim($(this).text()));
	});
	$('textarea.autogrow, .intranet_participant .form textarea').each(function() {
		$(this).autogrow({
			'expandBy': 5,
			'minHeight': $(this).height(),
			'lineHeight': 16,
			'maxHeight': 1000
		});
	
	});

	$('form.lbsubmit').submit($.lbsubmit);

	$('input.bg').val(' ');

	$(document).bind('reveal.facebox', function() {
		$('#facebox h1,#facebox h2, #facebox h3, #facebox h4').wrapInner('<span>');
	});

	// give all forms a default submit handler
	// except for the dialogged ones
	$('form').not('.confirm').submit(function() {
		var $f = $(this);
		$f.find('input[type=submit]').disable();
		$f.addClass('sending');
		return true;
	});

	$('#family-links').prepend('<div class="slider-arrow slider-arrow-up"></div>');
	$('#more h3 a').click(function() {
		$('#family-links').slideToggle();
		return false;
	});
	/**
	 * Change all objects and embeds to have wmode=transparent
	 */
	try {
		$('object').append('<param name="wmode" value="transparent" />');
		$('embed').attr('wmode', 'transparent');
	} catch (e) { }
});
/**
 * Hook into lytebox in order to track images
*/
(function() {
if (typeof(LyteBox) != "undefined") {
	var orig = LyteBox.prototype.changeContent;
	LyteBox.prototype.changeContent = function(imageNum) {

		orig.apply(this, arguments);
		if (!this.isLyteframe) {

			var src = (this.isSlideshow ? this.slideArray[this.activeSlide][0] : this.imageArray[this.activeImage][0]);
			pageTracker._trackPageview(src);

		}
	};

}
})();

function fbs_click() {
	/** 
	 * Just to make sure stage is never referenced
	*/
	var u=location.href.replace('stage', 'www').replace('esc2009.dev', 'www').replace('dev', 'wwww');
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

