jQuery(document).ready(function(){
	Store.init();
});


var Store = function() {

	var gmap;

	/**
	 * Store.init
	 * Initializes the Google Map application
	 *
	 * @param void
	 * @return void
	 */
	var init = function()
	{
		if (!document.getElementById('map')) { return false; }

		gmap = new Map();
        gmap.init();
        gmap.setTargetDirections('route');
        gmap.setHomeMarkerIcon('/skin/frontend/telecombinatie/default/images/icons/home_icon.gif');
        gmap.setDefaultMarkerIcon('/skin/frontend/telecombinatie/default/images/icons/marker.png');
        gmap.setDefaultMarkerGreyIcon('/skin/frontend/telecombinatie/default/images/icons/marker.png');
        gmap.addControl('show','large');
        gmap.addControl('type','menu');
        gmap.setFindZoomlevel(14);
//        gmap.center(4.4446578, 52.2378743, 10);
		
		if (markers) {
			for(i=0, il=markers.length; i<il; i++) {
				gmap.addMarker(markers[i]);
			}
		}
	};
	var findStores = function (search, radius, maxStores, business) {

        if(!search && jQuery('#adr').val()) {
            search = jQyery('#adr').val();
        }
        
        if(business) {
        	gmap.setBusiness(business);
        }
        
        if(!radius) {
            radius = 10;
        }
        if(!maxStores) {
            maxStores = 10;
        }

        if(search.indexOf(', netherlands') == -1) {
            search += ', netherlands';
        }
    	gmap.findStores(search, radius, maxStores);

    	return false;
    };
    var getMap = function () {
    	return gmap;
    }

	return {
		init : function() { init(); },
		findStores : function(search, radius, business) { findStores(search, radius, business); },
		getMap : function() { return getMap(); }
	};
}();
