/* Volley

*/

SIGNUP_CONFIGURATION = {
	"input": {
		"formclass": "signup",
		"message": "Enter your email address..."
	}
}

STOCKISTS_CONFIGURATION = {
	"input": {
		"formclass": "search",
		"message": "Enter your suburb or postcode"
	},
	"filter": {
		"formclass": "filter",
		"message": "Filter results..."
	}
}

var clemSite = {

	/**
	* Initialize the application
	*/
	initialize: function() {
		
		if($('#ie-container').length > 0) clemSite.ieWarning();
		
		//Setup stockists
		if($('div#s-map').length > 0) Stockists.initialize();
		
		//Input Forms
		if($('input.signup').length > 0) clemSite.setupAddForm(SIGNUP_CONFIGURATION);
		if($('input.search').length > 0) clemSite.setupAddForm(STOCKISTS_CONFIGURATION);
		
		//Category Page
		if($('ul#categoryList').length > 0) clemSite.setupCategoryGal();
		
		//Product Rating
		if($('#productRating').length > 0)  clemSite.setupRating();
		if($('#productRating div.rating a').length > 0)  clemSite.setupRatingSelection();
		
		//Product Detail Images
		if($("#shoeAngles").length > 0) clemSite.setupImageSwap();
		
		//Setup Category
		if($('#sortProducts').length > 0) clemSite.setupCategoryPagination();
		
		//History Page
		if($('#historySlider').length > 0) clemSite.initCarousel();
	
		if($('#MailinglistChildSelectorId').length > 0) clemSite.setupMailinglistChildren();
			
		$("a.fancybox").fancybox({
			'hideOnContentClick': true,
			'autoDimensions': true
		});
		
	},
	
	setupMailinglistChildren: function (){
		$('[placeholder]').focus(function() {
		  var input = $(this);
		  if (input.val() == input.attr('placeholder')) {
			input.val('');
			input.removeClass('placeholder');
		  }
		}).blur(function() {
		  var input = $(this);
		  if (input.val() == '' || input.val() == input.attr('placeholder')) {
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		  }
		}).blur();
		
		$('[placeholder]').parents('form').submit(function() {
		  $(this).find('[placeholder]').each(function() {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
			  input.val('');
			}
		  })
		});
		
		$('#MailinglistChildSelectorId').change( function(){
				clemSite.showMailinglistChildren( this.value );
			}
		);
		clemSite.showMailinglistChildren($('#MailinglistChildSelectorId').val());
	},
	
	showMailinglistChildren: function(value){
		$('.children').hide();
	 	var i = 1;
		while(i <= value){
			$('#child_'+i).show(); i++;
		}
	},
	
	preloadCountry: function(){
		$("#MailinglistCountry option[value="+country_selected+"]").attr('selected', 'selected');
	},

	setupCategoryGal: function() {
		var shoeLi = $('ul#categoryList li');
		var rollOver = $("div.rollOver");
		
		$("#main ul#categoryList div.rollOver div.colourOptions a:nth-child(3)").addClass("last");
		
		shoeLi.hover(
		  function () {
			$(this).find("div.rollOver").show();
		  }, 
		  function () {
			$(this).find("div.rollOver").hide();
		  }
		);
		
		
	},
	setupRating: function(){
		$('#productRating div.rating a').click( function(e){
			e.stopPropagation(); e.preventDefault();
			var c = "p-"+$(this).attr('res');
			if (clemSite.getCookie(c) == false){
				clemSite.setCookie(c, true);
				$.ajax({
					   	url:"/ratings/rate",
						type: "POST",
						data: { 'rating' 	: this.id, 
								'product_id': $(this).attr('res') },
					   	success:function(data) {
							obj = jQuery.parseJSON(data);
							$('#productRating div.rating')
								.addClass('rated'+obj.stars.toString().replace('.', '_'))
								.html('');
							$('#r_count').html(obj.count);
							$('#r_average').html(obj.average);
					   	},
					   	error:function(error) {
						  	$('#productRating div.rating').html('Could not rate at this time.');
					   	}
					}
				, 'json');
			}
		});
	},
	
	setCookie: function (c_name,value){
		var c_value=escape(value);
		document.cookie=c_name + "=" + c_value;
	},
	
	getCookie: function(c_name){
		var i,x,y,ARRcookies=document.cookie.split(";");
		for (i=0;i<ARRcookies.length;i++){
	  		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	  		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	  		x=x.replace(/^\s+|\s+$/g,"");
	  		if (x==c_name){
	    		return unescape(y);
	    	}
	  	}
		return false;
	},
	
	setupCategoryPagination: function(){
		$('#sortProducts, #perPageProducts').change( function(e){
			e.stopPropagation(); e.preventDefault();
			$('#showForm').submit();
		});
	},
	
	setupRatingSelection: function(){
		
		var cont = $("#productRating div.rating");		
		var currentRating = cont.attr("data-rating");
		
		$('#productRating div.rating a').hover(
		  	function () {
				var c = "p-"+$(this).attr('res');
				if (clemSite.getCookie(c) == false){
					var newRating = $(this).attr('id');
			 		cont.removeClass("rated" + currentRating);
 			 		cont.addClass("rated" + newRating);
				}
		  	}, 
		  	function () {
				var c = "p-"+$(this).attr('res');
				if (clemSite.getCookie(c) == false){
					var curRating = $(this).attr('id');
					cont.removeClass("rated" + curRating);
 					cont.addClass("rated" + currentRating);
				}
		  	}
		);
	},
	
	setupImageSwap: function(){
		var container = $("#main div.shoeImages");

		$("#shoeAngles li img").click(function(){
			var imgName = $(this).attr('src');
			newSrc = imgName.replace("/s/", "/l/");
			container.find(".main img").attr('src', newSrc);
			$("#shoeAngles li.active").removeClass("active");
			$(this).parent().addClass("active");
		});
	},

	
	ieWarning: function() {
		var ieContainer = $('#ie-container');
		ieContainer.slideDown(2000);
		ieContainer.find('a.close').click(function() {
			ieContainer.slideUp(100);
			return false;
		});
	},
	
	setupAddForm: function(CONFIGURATION) {	
		
		$.each(CONFIGURATION, function(key, value){
			$("." + value.formclass).addClass('fallback').val(value.message).focusin(function(){
				if($(this).val() == value.message) $(this).removeClass('fallback').val("");
			}).focusout(function(){
				if($(this).val() == "") $(this).addClass('fallback').val(value.message);
			});
		});
		
		if(CONFIGURATION['input']['class'] == 'signup') {
			$('form#SignupAddForm').submit(function() {
				var signup = $(this).find('input.signup');
				switch(signup.val()) {
					case CONFIGURATION['input']['message']:
					case "":
						signup.focus();
						return false;
						break;
				}
			});
		}
		
	},
	
	

	displayModalWindow:function(content) {
		$.fancybox(content, {
			'width'			: 500,
			'height'		: 150,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'easingIn'      : 'easeOutBack',
			'easingOut'     : 'easeInBack',
			'speedIn'		: 800,
			'autoDimensions': false,
			'overlayColor'	: '#000',
			'onCleanup'		: false,
			'overlayOpacity': 0.5,
			'centerOnScroll': true,
			'titleShow'		: false,
			'scrolling'		: 'no'
		});
	},
	
	lightbox:function() {
	
		$("body").addClass("gallery");		
		
		$("ul#gallery li a").fancybox({
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	true,
			'showNavArrows' : 	true,
			'cyclic'		: 	true
		});
	},
	
	initCarousel:function() {
		
		$("#historySlider").jcarousel({
			scroll: 1,
		    initCallback: mycarousel_initCallback,
			itemVisibleInCallback: {
				onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
       		 },
			// This tells jCarousel NOT to autobuild prev/next buttons
			buttonNextHTML: null,
			buttonPrevHTML: null
   		});
		
		function mycarousel_initCallback(carousel) {
			jQuery('.jcarousel-control a').bind('click', function() {
				carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('data-num')));
				return false;
			});
		 
			jQuery('#mycarousel-next').bind('click', function() {
				carousel.next();
				return false;
			});
		 
			jQuery('#mycarousel-prev').bind('click', function() {
				carousel.prev();
				return false;
			});
		};
		
		function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
			if (idx == 1) {
				jQuery("#mycarousel-prev").addClass('hidden');	
			} else {
				jQuery("#mycarousel-prev").removeClass('hidden');	
			}
			if (idx == 3) {
				jQuery('#mycarousel-next').addClass('hidden');
			} else {
				jQuery('#mycarousel-next').removeClass('hidden');					
			}
		};
		
		$(".jcarousel-control a").click(function(){
		
			if ($(this).hasClass("active")) {
				//Leave as is	
			} else {
				$(".jcarousel-control a").removeClass("active");
				$(".jcarousel-control a span").remove();
				$(this).addClass("active");
				$(this).append("<span></span>");
			}
		
    	});
			
	}
	
}

var Stockists = {
	
	initialize: function() {
		
		$('div.noscript').hide();
		//$('div.sidebar').show();

/*		
		//Set & update width for google maps window on browser resize
		$(window).bind("resize", resizeWindow);				  
		resizeWindow();
		
		function resizeWindow() {
			var fullWidth = $("#content div.stockists").width();
			var sidebarWidth = $("#content div.stockists div.sidebar").innerWidth();
			var mapDiv = $("#s-map");
		
			mapDiv.width(fullWidth - sidebarWidth);
		}*/

		// Define global markers and stockists array
		markersArray = [];
		stockistsObject = {};
		
		// Set up geocoder
		geocoder = new google.maps.Geocoder();
		
		var initialLocation = new google.maps.LatLng(-29.24469, 145.19531);
		
		// Set up map options
		var options = {
			zoom: 4,
			center: initialLocation,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			scrollwheel: false,
			mapTypeControl: false
		};
		
		// Initialize map
		map = new google.maps.Map(document.getElementById("s-map"), options);
		infowindow = new google.maps.InfoWindow({
			maxWidth: 400
		});
		
		google.maps.event.addListener(infowindow, 'closeclick', function() {
			$('div.stockist').removeClass('selected');
		});

		Stockists.setupSearchForm();
		Stockists.getStockists();
		
			// Handle Input field default text
			var input = $("form.search input.default");
			
			//Store previous text in data-text attribute
			if (input.hasClass("default")) {
				for (i=0; i < input.length; i++) {
					defVal = input.eq(i).attr("data-default");
					input.eq(i).val(defVal);
				}
			}
		
			input.focusin(function() {
				if (jQuery(this).hasClass('default')) {
					jQuery(this).removeClass('default').val("").addClass('custom');
				}
			});
			
			input.focusout(function() {
				var inputSize = jQuery(this).val().length;		
				var defVal = jQuery(this).attr("data-default");
				if (inputSize < 1) {
					jQuery(this).val(defVal).addClass('default').removeClass('custom');
				}
			});
	
	},
		
	setupSearchForm: function() {
		
		var countrybounds = new google.maps.LatLngBounds(new google.maps.LatLng('-50', '-168'), new google.maps.LatLng('-5', '108'));
		
		$("input#search").autocomplete({
			source: function(request, response) {
				geocoder.geocode({
					'bounds': countrybounds,
					'region': 'au',
					'address': request.term
				}, function(results, status) {
					
					$.each(results, function(index, value) {
						if(value) {
							var autopoint = new google.maps.LatLng(value.geometry.location.lat(), value.geometry.location.lng());
							if(countrybounds.contains(autopoint) == true) {
								results.splice(index, 1);
							}
						}
					});
					
					response($.map(results, function(item) {						
						return {
							label: item.formatted_address,
							value: item.formatted_address,
							latitude: item.geometry.location.lat(),
							longitude: item.geometry.location.lng(),
							bounds: item.geometry.bounds
						}
					}));
				})
			},
			
			//This bit is executed upon selection of an address
			select: function(event, ui) {
				var location = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
				map.setCenter(location);
				if(ui.item.bounds) {
					map.fitBounds(ui.item.bounds);
				} else {
					map.setZoom(14);
				}
				
			}
		});
		
		$('form.search').submit(function() {
			var search = $(this).find('input.search');
			
			switch(search.val()) {
				case STOCKISTS_CONFIGURATION['input']['message']:
				case "":
					search.focus();
					return false;
					break;
			}
			
			Stockists.searchStockists($(this).find('input').val());
			return false;
		});
		
	},
	
	searchStockists: function(search) {
		
		geocoder.geocode( {
			'address': search,
			'bounds': new google.maps.LatLngBounds(new google.maps.LatLng('-50', '-168'), new google.maps.LatLng('-5', '108')),
			'region': 'au'
			}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				map.setCenter(results[0].geometry.location);
				
				if(results[0].geometry.bounds) {
					map.fitBounds(results[0].geometry.bounds);
				} else {
					map.setZoom(14);
				}
			} else {
				
				var result  = '<div id="content">';
						
				switch(status) {
					case google.maps.GeocoderStatus.ZERO_RESULTS:
						result += '<h1>Location not found</h1>';
						result += '<p>Enter your suburb or postcode</p>';
						break;
					case google.maps.GeocoderStatus.OVER_QUERY_LIMIT:
						result += '<h1>Service temporarily unavailable.</h1>';
						result += '<p>Please wait before searching again.</p>';
						break;
					case google.maps.GeocoderStatus.REQUEST_DENIED:
						result += '<h1>Service temporarily unavailble.</h1>';
						result += '<p>Please contact us or try again later.</p>';
						break;
					case google.maps.GeocoderStatus.INVALID_REQUEST:
						result += '<h1>Location not found</h1>';
						result += '<p>Enter your suburb or postcode</p>';
						break;
				}
						
				result += '</div>';
				
				clemSite.displayModalWindow(result);
			}
		})
		
	},
	
	zoomToResults: function() {
		
		var latLng = [];
		$.each(markersArray, function(i, value) {
			if(markersArray[i].getVisible()) latLng.push(markersArray[i].getPosition());
		});
		
		var latLngBounds = new google.maps.LatLngBounds();
		$.each(latLng, function(i, value){
		   latLngBounds.extend(value);
		});
		
		map.setCenter(latLngBounds.getCenter());
		map.fitBounds(latLngBounds);
	},
	
	getStockists: function() {

		$.ajax({
			type: 'GET',
			url: location.href + Utilities.getDirectorySlash() + 'search/?is_ajax=true',
			dataType: 'json',
			success: function(data, textStatus){
				if($(data).length > 0)
				{
					Stockists.storeAllStockists(data);
				} else {
					var result  = '<div id="content">';
						result += '<h1>Stockists not found</h1>';
						result += '<p>Stockists not found - please try again later, or contact us.</p>';
					result += '</div>';

					clemSite.displayModalWindow(result);
				}
			},
			error: function(XMLHttpRequest){
				var result  = '<div id="content">';
					result += '<h1>Stockists not found</h1>';
					result += '<p>An error has occured while retrieving the stockists - please try again later, or contact us.</p>';
				result += '</div>';
				
				clemSite.displayModalWindow(result);	
			}
		});
		
	},
	
	storeAllStockists: function(data) {
		
		stockistsObject = data;

		$.each(stockistsObject, function(index, value){
			Stockists.addMarker(index, new google.maps.LatLng(value['Stockist']['latitude'], value['Stockist']['longitude']), value['Stockist']);
		});
		
		var clusterStyles = [{
			url: location.href + Utilities.getDirectorySlash() + '../img/stockists/map-cluster-small.png',
			height: 35,
			width: 35,
			textColor: '#ffffff',
			textSize: 11,
			textFont: '"RockwellRegular",serif'
		}, {
			url: location.href + Utilities.getDirectorySlash() + '../img/stockists/map-cluster-medium.png',
			height: 45,
			width: 45,
			textColor: '#ffffff',
			textSize: 12,
			textFont: '"RockwellRegular",serif'
		}, {
			url: location.href + Utilities.getDirectorySlash() + '../img/stockists/map-cluster-large.png',
			height: 55,
			width: 55,
			textColor: '#ffffff',
			textSize: 14,
			textFont: '"RockwellRegular",serif'
		}];
		
		var markerCluster = new MarkerClusterer(map, markersArray, {
			maxZoom: 9,
			styles: clusterStyles
		});
		
		Stockists.addStockistsToSidebar();
		
		var initialised = false;
		var boundsChanged = google.maps.event.addListener(map, 'bounds_changed', function() {
			if(!initialised) {
				google.maps.event.removeListener(boundsChanged);
			}
		})
		
		google.maps.event.addListener(map, 'dragend', Stockists.updateStockist);
		google.maps.event.addListener(map, 'zoom_changed', function() {
			setTimeout(Stockists.updateStockist, 500);
		});
		
		// Try W3C Geolocation (Preferred)
		if(navigator.geolocation) {
			navigator.geolocation.getCurrentPosition(function(position) {
				map.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
				map.setZoom(14);
			}, function() {});
		}
		
	},
	
	updateStockist: function() {
		
		$('div.stockist').hide();
		if(map.getZoom() >= 10) {
		
			$.each(markersArray, function(i, value){
			
				if(map.getBounds().contains(markersArray[i].getPosition())) {
					$('div#sid-' + $(markersArray[i]).data('id')).show();		
				}
			
			});
		
			Stockists.checkStock();
			$('div.results').scrollTop(0);
		
		}

	},
	
	checkStockistHasStock: function(checked, value) {
		
		var hasStock = false;
		
		$.each($(value).find('div.swatches img'), function(j, subvalue){
			if($.inArray($(subvalue).attr('id'), checked) != -1) {
				hasStock = true;
			}
		});
		return hasStock;

	},
	
	checkStock: function() {
		
		checked = [];
		p_checked = [];
		$.each($('div.ranges input:checkbox:checked'), function(i, value) {
			checked[i] = $(value).attr('name');
		});
		
		$.each($('div.fallback input:checkbox:checked'), function(i, value) {
			p_checked[i] = $(value).attr('name');
		});

		$.each($('div.stockist'), function(i, value) {
			if(Stockists.checkStockistHasStock(checked, value) &&  Stockists.checkStockistHasStock(p_checked, value) && map.getBounds().contains($(value).data('marker').getPosition()) && map.getZoom() >= 10) {
				$(value).show();
				$(value).data('marker').setVisible(true);
			} else {
				$(value).hide();
				$(value).data('marker').setVisible(false);
			}
		});
	},
	
	addStockistsToSidebar: function() {
		
		$('div#storeSort input:checkbox').attr('checked', true)
		$('div#storeSort input:checkbox').change(function(e) {
			$('div.stockist').removeClass('selected');
			infowindow.close();
			Stockists.updateStockist();
		});
		
		var stockists = "";
		
		$.each(markersArray, function(i, value){
			var marker = $(markersArray[i]).data('data');
			
			var stockist = "<div class='stockist clearfix' id='" + "sid-" + $(markersArray[i]).data('id') + "'>";
				stockist += "<span class='marker'>Marker</span>";
				stockist += "<h3><a class='anchor' href='javascript:;'>" + marker['title'] + "</a></h3>";
				stockist += "<div class='clearfix'></div>";
				stockist += "<ul>";
					if(marker['trading']) stockist += "<li>" + marker['trading'] + "</li>";
					if(marker['address']) stockist += "<li>" + marker['address'] + "</li>";
					if(marker['city']) stockist += "<li>" + marker['city'] + "</li>";
					if(marker['state']) stockist += "<li>" + marker['state']+ ", ";
					if(marker['country']) stockist +=  marker['country'];
					if(marker['postcode'] && marker['postcode'] != '0') stockist += ", " + marker['postcode'] + "</li>";
					if(marker['phone']) stockist += "<li class='phone'>" + marker['phone'] + "</li>";
					if(marker['fax']) stockist += "<li class='fax'>" + marker['fax'] + "</li>";
				stockist += "</ul>";
				var meta = "width='7' height='7' src='" + location.href + Utilities.getDirectorySlash() + "../img/stockists/swatch-";
				stockist += "<div class='colours' style=\"display:none\">";
					stockist += "<div class='swatches'>";
						if(marker['stockist_kids_school'] == true) stockist += "<img id='stockist_kids_school' alt='stockist_kids_school\'s' " + meta + "oc.gif' />";
						if(marker['stockist_kids_fashion'] == true) stockist += "<img id='stockist_kids_fashion' alt='stockist_kids_fashion\'s " + meta + "ss.gif' />";
						if(marker['stockist_premium'] == true) stockist += "<img id='stockist_premium' alt='stockist_premium\'s " + meta + "ss.gif' />";
						if(marker['stockist_general'] == true) stockist += "<img id='stockist_general' alt='stockist_general\'s " + meta + "ss.gif' />";
					stockist += "</div>";
					stockist += "<div class='clearfix'></div>";
					stockist += "<a href='javascript:;' class='colourchart' title=' '>What is this?</a>"
				stockist += "</div>";

			stockist += "</div>";			
			stockists += stockist;
		});
		
		$('div.results').html(stockists);
		
		$.each($('div.stockist'), function(i, value) {
			$(this).data('marker', markersArray[$(this).attr('id').split('-')[1]]);
		});
		
		$('div.stockist').hide();
		
		var tooltip = "<div><img src='" + location.href + Utilities.getDirectorySlash() + "../img/stockists/tooltip-colours.png' width='326' height='153' title='What do these colours mean?' /></div>";
		
		$('div.stockist a.colourchart').tooltip({
			layout:tooltip,
			predelay: 300,
			delay: 0,
			effect: 'slide',
			offset: [5, -85]
		}).dynamic();
		
		$('div.stockist').hover(function() {
			$(this).addClass('hover');
			$(this).data('marker').setAnimation(google.maps.Animation.BOUNCE);
			$(this).data('marker').setAnimation(null);
		}, function() {
			$(this).removeClass('hover');
			$(this).data('marker').setAnimation(null);
		});
		
		$('div.stockist a.anchor').click(function() {
			var marker = $(this).closest('div.stockist').data('marker');
			marker.setAnimation(google.maps.Animation.BOUNCE);
			Stockists.clickMarker(marker);
		});
		
	},
	
	clickMarker: function(marker) {
		
		map.setCenter(marker.getPosition());
		
		var contentString = '';
			contentString += '<div id="infowindow" style="height:150px;">';
		    	contentString += '<h4>' + $(marker).data('data')['title'] + '</h4>';
				contentString += '<ul>';
					if($(marker).data('data')['trading']) contentString += "<li>" + $(marker).data('data')['trading'] + "</li>";
					if($(marker).data('data')['address']) contentString += "<li>" + $(marker).data('data')['address'] + "</li>";
					if($(marker).data('data')['city']) contentString += "<li>" + $(marker).data('data')['city'] + "</li>";
					if($(marker).data('data')['state']) contentString += "<li>" + $(marker).data('data')['state'] + ", ";
					if($(marker).data('data')['country']) contentString += $(marker).data('data')['country'];
					if($(marker).data('data')['postcode'] && $(marker).data('data')['postcode'] != '0') contentString += ", " + $(marker).data('data')['postcode'] + "</li>";
					if($(marker).data('data')['phone']) contentString += "<li class='phone'>" + $(marker).data('data')['phone'] + "</li>";
					if($(marker).data('data')['fax']) contentString += "<li class='fax'>" + $(marker).data('data')['fax'] + "</li>";
				contentString += '</ul>';
		    contentString += '</div>';
		
		infowindow.setContent(contentString);
		infowindow.open(map, marker);
		if(map.getZoom() < 10) map.setZoom(10);
		
		$('div.stockist').removeClass('selected');
		$('div#sid-' + $(marker).data('id')).addClass('selected');
		
		$.each(markersArray, function(i, value) {
			markersArray[i].setAnimation(null);
		});
	},
	
	addMarker: function(id, loc, data) {
		marker = new google.maps.Marker({
			position: loc,
			map: map,
			icon: new google.maps.MarkerImage(location.href + Utilities.getDirectorySlash() + '../img/stockists/map-marker-icon.png', new google.maps.Size(16, 21), new google.maps.Point(0,0), new google.maps.Point(13, 21)),
			shadow: new google.maps.MarkerImage(location.href + Utilities.getDirectorySlash() + '../img/stockists/map-marker-shadow.png', new google.maps.Size(20, 15), new google.maps.Point(0,0), new google.maps.Point(8, 15)),
			visible: false
		});
		
		$(marker).data('id', id);
		$(marker).data('data', data);
		
		google.maps.event.addListener(marker, 'click', function(){
			Stockists.clickMarker(this);
		});
		
		markersArray.push(marker);
	}
	
}

Utilities = {
	
	getDirectorySlash:function () {
		return location.href.charAt(location.href.length - 1) == "/" ? "" : "/";
	}
	
}

$(document).ready(clemSite.initialize);

