var RouteMap = function() {
    return {
        address: false,
        url: false,
        init: function() {
            //do this only if there's a route map available
            if(0 < $('#small-map').length) {
                var map_opts = {
                    zoom: 2,
                    mapTypeId: google.maps.MapTypeId.ROADMAP,
                    mapTypeControl: false,
                    navigationControl: false
                };
                var map = new google.maps.Map(document.getElementById("small-map"), map_opts);
                if(RouteMap.address) {
                    geocoder = new google.maps.Geocoder();
                    if (geocoder) {
                        geocoder.geocode( { 'address': RouteMap.address}, function(results, status) {
                            if (status == google.maps.GeocoderStatus.OK) {
                                map.setCenter(results[0].geometry.location);
                                map.setZoom(12);
                                  /*var marker = new google.maps.Marker({
                                      map: map,
                                      position: results[0].geometry.location
                                  });*/
                            } else {
                              //alert("Geocode was not successful for the following reason: " + status);
                            }
                        });
                    }
                }
            }
        },
        open: function() {
            $('#route-map').show();
            $('#route-map iframe').attr('src', RouteMap.url);
            $('#frm_cruk select').hide();
            RouteMap.extendBground();
            return false;
        },
        close: function() {
            $('#route-map').hide();
            $('#frm_cruk select').show();
            return false;
        },
        extendBground: function() {
            if(document.body.clientHeight) {
                $('#route-map').css("height", $('#wrapper').height() +'px');
                $('#route-map').css("width", document.body.clientWidth +'px');
                //calculate left
                var spare = document.body.clientWidth - $('#route-map .overlaycontent').width();
                if(0 < spare) {
                    //$('#route-map').css("left", '-' + Math.round(spare/2) + 'px');
                }
                
            } else {
                $("body").css("overflow","hidden");
            }
        }
    };
}();

$(document).ready( function() {
    //RouteMap.init();
    if($('#route-map').is(':visible')) {
        $('#frm_cruk select').hide();
        RouteMap.extendBground();
    }
});

$(document).resize(function() {
    if($('#route-map').is(':visible')) {
        RouteMap.extendBground();
    }
});


