function ucFirst(string) {
	return string.substring(0, 1).toUpperCase() + string.substring(1).toLowerCase();
}
/**
 * Google maps settings for islive
 * @author Mike De Smet <mike@ratus.nl>
 **/
(function($){

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});


function popitup(url, focus, target)
{
   if (!focus)
       focus = '';
   
   if (!target)
       target = '_blank';
   
   window.open(url+'&focusme=' + focus, target);
}

var currentlyUsedDomain = document.domain.split('.');

switch (currentlyUsedDomain[currentlyUsedDomain.length - 1])
{	
	case 'mike':
	case 'test':
		currentlyUsedDomain[currentlyUsedDomain.length - 1] = 'mike';
		break;
	case 'isl':
	case 'lab':
		currentlyUsedDomain[currentlyUsedDomain.length - 1] = 'isl';
		break;
	case 'nl':
	default:
		currentlyUsedDomain[currentlyUsedDomain.length - 1] = 'nl';
		break;
}

$.islivegoogleMapSettings = {
    imagePath: 'http://resources.' + window.location.hostname.replace(/^(?:[^\.]*\.)*([^\.]*\.[^\.]+)/, '$1') +  '/img/externals/maps/',
    styles: [
      {
        featureType: "road",
        stylers: [
          {visibility: "off"}
        ]
      },{
        featureType: "landscape",
        stylers: [
          {visibility: "on"},
          {hue: "#ff3300"}
        ]
      },{
        featureType: "poi",
        stylers: [
          {hue: "#ff0000"}
        ]
      },{
        featureType: "transit",
        stylers: [
          {hue: "#ff0000"}
        ]
      },{
        featureType: "administrative",
        stylers: [
          {hue: "#ff0000"}
        ]
      },{
        featureType: "administrative.province",
        stylers: [
          {visibility: "simplified"}
        ]
      },{
        featureType: "administrative.neighborhood",
        stylers: [
          {visibility: "off"}
        ]
      },{
        featureType: "administrative"
      }
    ],
    bounds: [
        [53.27560, 7.427140500000001], // NE of Netherlands
        [50.75038370, 3.33160], // SW of Netherlands
    ],
    markerClass: HTMLMarker,
    zoomControlOptions: { style: google.maps.ZoomControlStyle.LARGE },
    reCenterOnMinZoom: true,
  //  markerUrls: ['/profiel/[model].html', '/wallet.html?m=[model]'],
    markerClick: function(event) {
                var model = this.marker.modelnaam;
                var markerUrls = this.settings.markerUrls;
                if (!$.isArray(markerUrls))
					markerUrls = [];
					
				event.preventDefault();
					
				var extraParams = this.settings.extraMarkerClickParams ? this.settings.extraMarkerClickParams : window.$ && window.$.islive ? window.$.islive.params : '';
					
                if (event.target.tagName === 'SPAN')
                {
                    event.preventDefault();
					if (markerUrls[0])
					{
                        popitup(markerUrls[0].replace(/\[model\]/g, model) + '&' + extraParams, 1, this.settings.target);
						return false;
					}
					
                    popitup("./?sect=profile&m=" +  escape(model) + "&" + extraParams, 1, this.settings.target);
                   
                }
                else
                {
					if (markerUrls[1])
					{
						popitup(markerUrls[1].replace(/\[model\]/g, model) + "&" + extraParams, 1, this.settings.target);
						return false;
					}
					
                    startchat(model);
                }
                return false;
    },
    callbacks: {
        getMarkerOptions: function (marker)
        {
            var settings = $(this).googlemap('settings');
            var latLng = new google.maps.LatLng(parseFloat(marker['lat'],10), parseFloat(marker['long'], 10));
			var clickCallback = settings.markerClick;
			if (clickCallback)
				clickCallback = $.proxy(settings.markerClick, {marker: marker, settings: settings, map: this});
			
            var options = {
                data: marker,
                position: latLng
            };

            if (!settings.markerClusterer)
            {
                options.map = settings.map;

                if (settings.randomDrop)
                    options.animation = google.maps.Animation.DROP;
            }

            options.title = marker.modelnaam;
            options.template = '<div class="photo" rel="${modelnaam}" title="Nu live webcammen met ${ucFirst(modelnaam)}? Klik!"><div><div class="header">${modelnaam} (${leeftijd})</div><div class="hover" style="position:relative"><img class="img hover" alt="" src="http://images.islive.nl/snapshot/${modelnaam}/125x94.jpg" /><img class="online hover" src="http://resources.islive.nl/img/maps/maps-online.png" /></div><img class="img" src="http://images.islive.nl/snapshot/${modelnaam}/125x94.jpg" alt="${modelnaam}" /><span title="Alles over me weten? Klik!"></span><div class="footer">${city}</div></div></div>';
            options.zIndex = 500;
            if (clickCallback)
				options.click = clickCallback;


            return options;
        }
    },
    
    getMarkersUrl: 'http://maps.islive.' + currentlyUsedDomain[currentlyUsedDomain.length - 1] + '/',
    getMarkersRequestType: 'get',
	getMarkersExtraParams: {country: 'NL'},
    maxZoom: 11
};

if ($.getUrlVar('focusme'))
    window.focus();

})(typeof jQueryForExternals === 'undefined' ? jQuery : jQueryForExternals);

