/* 
 * Buscopension @ Panoramio
 */
var Panoramiomarker = new Array();
var Panoramioinfo = new Array();


function loadPanoramio() {
    var value_cookie = $.cookie("bp_panoramioshow");
    if(value_cookie == "on") {
        var bounds = map.getBounds();

        var lat1 = bounds.getNorthEast().lat();
        var lng1 = bounds.getNorthEast().lng();
        var lat2 = bounds.getSouthWest().lat();
        var lng2 = bounds.getSouthWest().lng();

        var url = "http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=public&from=0&to=25&minx="+lng2+"&miny="+lat2+"&maxx="+lng1+"&maxy="+lat1+"&size=thumbnail&callback=?";

        $.getJSON(url,{},
            function(data){
                $.each(data.photos, function(i,Item){
                    if(Panoramiomarker[Item.photo_id] == undefined) {

                        Panoramiomarker["\""+Item.photo_id+"\""] = new google.maps.Marker({
                            position: new google.maps.LatLng(Item.latitude,Item.longitude),
                            map: map,
                            icon: "/img/panoramio.png",
                            title: 'Panoramio.com'
                        });

                        Panoramioinfo["\""+Item.photo_id+"\""] = new google.maps.InfoWindow({
                            content: "<div id='infowin'>" +
                            "<p><a href='http://www.panoramio.com/' target='_blank'>" +
                            "<img src='http://www.panoramio.com/img/logo-small.gif' border='0' width='119px' height='25px' alt='Panoramio logo' /><\/a></p>" +
                            "<a id='photo_infowin' style='text-align:center;' target='_blank' href='" + Item.photo_url + "'>" +
                            "<img border='0' width='" + Item.width + "' height='" + Item.height + "' src='" + Item.photo_file_url + "' \/><\/a>" +
                            "<div style='overflow: hidden; '>" +
                            "<p><a target='_blank' class='photo_title' href='" + Item.photo_url +
                            "'><strong>" + Item.photo_title + "<\/strong><\/a></p>" +
                            "<p>Posted by <a target='_blank' href='" + Item.owner_url + "'>" +
                            Item.owner_name + "<\/a></p><\/div>" +
                            "<\/div>"
                        });

                        google.maps.event.addListener(Panoramiomarker["\""+Item.photo_id+"\""], 'click', function() {
                            Panoramioinfo["\""+Item.photo_id+"\""].open(map,Panoramiomarker["\""+Item.photo_id+"\""]);
                        });

                    }
                });

            });
    }

}

function panoramio_cookies() {
    var value_cookie = $.cookie("bp_panoramioshow");

    if(value_cookie == "on") {
        $("#bt-panoramio").val("desactivar");
    }
    else if(value_cookie == "off") {
        $("#bt-panoramio").val("activar");
    }
    else {
        $.cookie("bp_panoramioshow","on");
        $("#bt-panoramio").val("desactivar");
    }
}