﻿var Samet = (function() {
    var app = this,
            $ = null;
    app.init = function(config) {
        if ($ === null) {
            $ = config.jQuery;
        };
        if (config.ProjectMap !== undefined) {
            app.projectMap.init(config.ProjectMap);
        };
    };
    app.projectMap = {
        latitude: null,
        longitude: null,
        markers: [],
        mapTypeId: null,
        zoom: 9,
        map: null,
        mapCanvas: null,
        init: function(config) {
            app.projectMap.latitude = config.Latitude;
            app.projectMap.longitude = config.Longitude;
            app.projectMap.mapTypeId = config.MapTypeId === null ? google.maps.MapTypeId.ROADMAP : config.MapTypeId;
            app.projectMap.mapCanvas = config.MapCanvasId;
            app.projectMap.markers = config.Markers;
            app.projectMap.zoom = config.Zoom === null ? 8 : config.Zoom;
            app.projectMap.showMap();
            $.map(app.projectMap.markers, function(val) {
                app.projectMap.addMarker(val.latitude, val.longitude, val.name, val.description);
            });
        },
        addMarker: function(latitude, longitude, name, description) {
            var info = new google.maps.InfoWindow({
                content: description
            });
            var marker = new google.maps.Marker({
                position: new google.maps.LatLng(latitude, longitude),
                map: app.projectMap.map,
                title: name
            });
            google.maps.event.addListener(marker, 'click', function() {
                info.open(app.projectMap.map, marker);
            });
        },
        showMap: function() {
            app.projectMap.map = new google.maps.Map(document.getElementById(app.projectMap.mapCanvas),
            {
                zoom: app.projectMap.zoom,
                mapTypeId: app.projectMap.mapTypeId
            });
            app.projectMap.map.setCenter(new google.maps.LatLng(app.projectMap.latitude, app.projectMap.longitude));
        }
    };
    return app;
} ());
