$(document).ready(function(){
	
	$('#tabbed > ul').tabs();
	

	
/* Set up the specials*/	
	$(".showSpecials").click(function(){$("#details_" + this.id).show();})
	$(".hideSpecials").click(function(){$("#details_" + this.id).hide();})
	
/* Set up the shout functions */
	$("#addShout").click(function(){$("#shoutForm").slideDown();})
	$("#cancelShout").click(function(){$("#shoutForm").slideUp();})
    // bind form using 'ajaxForm' 
    $('#FrmShout').ajaxForm({beforeSubmit: shoutRequest, success: shoutResponse,dataType: 'json'}); 
	
		
/* Setup the review functions */		
	$(".addReview").click(function(){
		$("#reviewForm").show();
		$("#noReviews").hide();
		// attach the rating star to each item to be rated
	      $(".rate").each(function(){
	      	 $("#" + $(this).attr("id") + "_scale").rater(null , {maxvalue:5} , function(el , value) {
				$("#" + $(el).attr("id") + "_value").val(value);
			});	      
	      });
	});	
	
	$("#cancelReview").click(function(){
		$("#reviewForm").hide();
		$("#reviewStatus").hide();		
	})	
 
    // bind form using 'ajaxForm' 
    $('#FrmReview').ajaxForm({beforeSubmit: reviewRequest, success: reviewResponse,dataType: 'json'}); 

});

/* The shout helper functions */
	function shoutRequest(formData, jqForm, options) {return true;} 
	 
	// post-submit callback 
	function shoutResponse(json, statusText)  { 
		if(json.SUCCESSFUL == '1'){
			$('#FrmShout #shout').clearFields();
			$("#shoutForm").slideUp();
			$("#startShouts").after(json.APPEND);	
		}else{
			// this will handle failures
			
		}
	} 

// pre-submit callback 
function reviewRequest(formData, jqForm, options) {
	$("#reviewStatus").hide();
	$("#submitContainer").hide();
	$('#savingContainer').show();
	return true;
	} 
 
// post-submit callback 
function reviewResponse(json, statusText)  { 
	if(json.SUCCESSFUL == '1'){
		$("#start-reviews").after(json.APPEND);	
		$('#FrmReview').clearForm();		
		$("#reviewForm").hide();		
		$(".noReviews").hide();	
		$("#reviewStatus").attr("class", "success");
		$('#savingContainer').html('Saved!');
		$('#reviewsTab').html('Reviews (' + json.REVIEWCOUNT + ')');		
	}else{
		// this will handle failures
		$("#reviewStatus").attr("class", "warning");	
		$("#reviewStatus").slideDown();	
		$("#reviewStatus").html(json.MESSAGE);	
		$("#savingContainer").hide();
		$("#submitContainer").show();
	}
	$("#reviewStatus").html(json.MESSAGE);	
} 

/* setup the map */
 	// Create a map object
 	var myPano;   
 	function load() {
      if (GBrowserIsCompatible()) {
      	var lat = $("#lat").val();
      	var long = $("#long").val();
        var map = new GMap2(document.getElementById("profileMap"));
        map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(lat, long), 14);
        
        var point = new GLatLng(lat, long);
		map.addOverlay(new GMarker(point));
        
      }
    } 
    
