$(window).load (function(){ 
	
	init();
});

function init() {
	
	if (typeof(DD_belatedPNG) != "undefined") {
		DD_belatedPNG.fix(
				'#sponsors img, .replaced, .seperator, .png, .post, .commentlist, .comment, #event_tabs .leftcol, .tabbottom, .ui-tabs-panel, #tabtitles, .wpcf7-not-valid-tip, #contact_us .wpcf7-response-output, #pigbg, .wpcf7-not-valid-tip, #event_tabs .content');
	}
	
	/*OLD SLIDESHOW
	if ($('.home').length > 0) {
		$('#sliderphotos').jCarouselLite({
	        visible:1,
	        easing: 'easeOutExpo',
	        auto:3000,
	        speed:1000
	    });
	}
	*/
	if ($('#event_tabs').length > 0) {
		//initMap();
		
		var initTab = 0;
		
		if (document.URL.indexOf('#register_tab') > -1 || 
				window.location.href.indexOf('#register_tab') > -1) {
			initTab = 5;
		}
		else if (document.URL.indexOf('#bands_tab') > -1 || 
				window.location.href.indexOf('#bands_tabs') > -1) {
			initTab = 3;
		}
		
		var $tabs = $('#event_tabs').tabs({ selected: initTab });
		
		$('#register_btn a').click(function() { // bind click event to link
			$tabs.tabs('select', 5); 
			return false;
		});
		$('#signupBtn').click(function() { // bind click event to link
		    $tabs.tabs('select', 5); 
		    return false;
		});
		
	}
	
	if ($('#contact_us').length > 0 && typeof(DD_belatedPNG) == "undefined") {
		initVanishingLabels($('#contact_us form :input:not(:submit):not(:hidden)'));
	}
	if ($('#news_email_field').length > 0) {
	
		initVanishingLabels($('#news_email_field'));
		
	}
	
	
}

function initVanishingLabels(inputs) {
	inputs.focus(inputFocus);
	inputs.blur(inputBlur);
	inputs.val("");
	
}
function inputFocus() {
	$("label[for='"+$(this).attr("id")+"']").hide();
	//$(this).prev('label').hide();
}

function inputBlur() {
	if ($.trim($(this).val()).length == 0) {
		$("label[for='"+$(this).attr("id")+"']").show();
	}
}

/**
 * Google map on event page.
 */
function initMap() {
	var mapCenter =  new google.maps.LatLng(29.99800, -90.09545);
	var cookoffSpot = new google.maps.LatLng(29.994832, -90.094694);
	    var myOptions = {
	      zoom: 15,
	      center: mapCenter,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    };
	    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	    var marker = new google.maps.Marker({
	        position: cookoffSpot,
	        map:map,
	        title:'Hogs for the Cause 2011'
	       
	    });
	    	    
	    
	    // To add the marker to the map, call setMap();
	    marker.setMap(map);
	    
	    
	    var contentString = '<b>Hogs for the Cause 2011</b><br/>City Park - March 25 & 26, 2011';
		
	var infowindow = new google.maps.InfoWindow({
	    content: contentString
	});
	infowindow.open(map,marker);
	$('#event_tabs').bind('tabsshow', function(event, ui) {
	    if (ui.panel.id == "locationcontent") {
	    	google.maps.event.trigger(map, 'resize');
	    	map.panTo(mapCenter);
	    	marker.setVisible(true);
	    }
	});

}
	
