//Google load is ascychronous, so need to use the setOnLoadCallback before using $
google.load("jquery", "1.7.0");
google.load("jqueryui", "1.8.16");

google.setOnLoadCallback(function() {

$(document).ready(function() {
		
	$(".maptogglelink").click(function() {
		var linkName= "#"+$(this).attr('ID')+ "div";		
		$(linkName).toggle();		
		return false;	
	});
	
	//Show the comment submit form
	$("#submitcommentlink").click(function() {
		$("#commentadddiv").toggle();
		return false;
	});
	
	//Like/Dislike/interested buttons
	$('input#likebutton').click(function(){
        $(this).addClass("down");
        $("input#dislikebutton").removeClass("down");
        $('a#clearlikebutton').removeClass("down");
        $("#likefield").val('1');
    });
	$('input#dislikebutton').click(function(){
        $(this).addClass("down");
        $("input#likebutton").removeClass("down");
        $('a#clearlikebutton').removeClass("down");
        $("#likefield").val('0');
    });
	$('a#clearlikebutton').click(function(){
       // $(this).addClass("down");
        $("input#likebutton").removeClass("down");
        $("input#dislikebutton").removeClass("down");
        $("#likefield").val('-1');
    });
	
	$('input#interestedbutton').click(function(){
        $(this).addClass("down");
        $("input#notinterestedbutton").removeClass("down");
        $('a#clearinterestedbutton').removeClass("down");
        $("#interestedfield").val('1');
    });
	$('input#notinterestedbutton').click(function(){
        $(this).addClass("down");
        $("input#interestedbutton").removeClass("down");
        $('a#clearinterestedbutton').removeClass("down");
        $("#interestedfield").val('0');
    });
	$('a#clearinterestedbutton').click(function(){
        //$(this).addClass("down");
        $("input#interestedbutton").removeClass("down");
        $("input#notinterestedbutton").removeClass("down");
        $("#interestedfield").val('-1');
    });


	
	// Datepicker
	$('#commentdatepicker').datepicker({
		inline: true
	});
	
	
	//Show the suggestion submit form
	$("#submitsuggestionlink").click(function() {
		$("#suggestionadddiv").toggle();
		return false;
	});
	//Suggestion Voting
	$('input.agreebutton').click(function(){               
        $("#agreevalue").val('1');
        var id = $(this).attr('ID').substring(1);
        $("#suggestionID").val(id);        
        $("form#suggestionvote").submit();
    });
	$('input.disagreebutton').click(function(){        
        $("#agreevalue").val('0');
        var id = $(this).attr('ID').substring(1);
        $("#suggestionID").val(id);
        $("form#suggestionvote").submit();
    });
	
	
	
	/* some drop-downs should auto-submit the closest form */
	$('.selectsubmit').change(function() { 
		 $('.selectsubmit').closest("form").submit();
		 });

	
	
});

});

