/* Javascript specific to the spot template */

function initialize_spot(name, rating, lat, lon) {
    var show_back_to_map = false;
    if(rating)
	    $('#stars').css('width',23*rating);
    render_ratings();
    init_lightbox(name);
    $(".videopreview[rel]").each(function(i) {
	    var vid_url = this.getAttribute('alt');
	    var title = this.getAttribute('title');
	    $(this).overlay( { expose: '#000',
			               onLoad: function() { show_video(vid_url, title); },
			               onBeforeClose: function() { remove_video(); },
			             } );
	});
    $('#flag_action').click(function() {$('.modal').modal({ containerCss: {
		height: 142,
		width: 400}})});
    initialize_spotmap();
    latlng = new GLatLng(lat,lon);
    spotmap.setCenter(latlng,15);
    spotmap.setMapType(G_HYBRID_MAP);
    //spotmap.disableDragging();
    var customUI = spotmap.getDefaultUI();
    customUI.controls.maptypecontrol = false;
    customUI.maptypes.physical = false;
    spotmap.setUI(customUI);
    //GEvent.addListener(spotmap, "zoomend", function() { spotmap.setCenter(latlng); });
    markSpot(latlng);
    /* If referrer is search page, unhide "back to map" link */
    if(document.referrer.indexOf(window.location.host + "/map") > -1)
        $('#backtomap').show()
    /* Show or hide side buttons based on window side */
    showLeftSideTabs = function() { 
        if($(window).width() < 1055)
            $('.leftsidetabcontainer').hide();
        else
            $('.leftsidetabcontainer').show();
    }
    $(window).resize(showLeftSideTabs);
    showLeftSideTabs();
};


function flagSpot(id) {
    var reason = $('#flag_reason').val();
    var comment = $('#flag_comment').val();
    $('#flag_dialog').html('<div class="modal_message">Thank you for your feedback</div>');
    // Submit the flag form, ajax style
    $.post("flag/"+id+"/", { 'reason': reason, 'comment': comment });
    window.setTimeout($.modal.close , 2000);
}

function show_video(url, title) {
    var params = { allowScriptAccess: "always", allowfullScreen: "true" };
    var atts = { id: "myytplayer" };
    $('#video .video_title').html(title);
    swfobject.embedSWF(url+"&enablejsapi=1&playerapiid=ytplayer", 
                       "video_player", "640", "385", "8", null, null, params, atts);
}
function remove_video() {
  swfobject.removeSWF('myytplayer');
    $('#video .video_title').html('');
    $('#video').append('<div id="video_player"></div>');
}

