﻿var UI;

$(document).ready(function(){

    UI = {
    
        PlaceNames: $('.tip'),
        BookButton: $('.bookButton'),
        
        Init: function(){
            
            if(Master.ExcursionId > 0){
                $.ajax({
                    type: 'POST',
                    url: 'http://www.superjeep.is/Services/PlaceService.svc/GetPlaces',
                    data: '{"excursionId":' + Master.ExcursionId + '}',
                    processData: false,
                    contentType: "application/json; charset=utf-8",
                    dataFilter: function(data) {
                        var msg;
                     
                        if (typeof (JSON) !== 'undefined' && typeof (JSON.parse) === 'function')
                          msg = JSON.parse(data);
                        else
                          msg = eval('(' + data + ')');
                        
                        if (msg.hasOwnProperty('d')) 
                          return msg.d;
                        else 
                          return msg;
                    },
                    success: function(data){
                        $.each(data, function(i,v){
                            var marker = GMap.CreateMarker(new GLatLng(this.Latitude, this.Longitude), true);
                            GMap.CreateInfoWindow(marker, this.Name, this.IcelandicName, this.Image.FileUrl, this.Description);
                            GMap.AddMarker(marker);
                            
                        });
                    }                  

                }); 
                
                UI.BookButton.click(function(){
                    BookingForm.Dialog.dialog('open');
                });
                
                UI.PlaceNames.tooltip();
            };
        }

    }

    UI.Init();


});
