 	/******************************************

	NORDWAYSTORE.SE
	- map javascript file
	
	Version: 0.2
	Author: Christopher
	Email: christopher@bai.se
	
******************************************/

$(document).ready(function() {

	var mapBox = $("#mapBox");
	var mapRegions = [$("#norrland"), $("#svealand"), $("#gotaland")];
	//var resellerLink = $("#resellerLink");
	var showStoreInfo = $("#showStoreInfo");
	var target = $("#regionSearchResult");
	var timestamp = new Date();
	var current_region = 0;
	
	// LOAD ALL STORES ON PAGE LOAD
	$.ajax({
		type: "GET",
		url: "/ajax.asp",
		data: "mode=show_stores",
		cache: false,
		beforeSend: function() {
			target.empty().addClass("ajax-loading");
		},
		success: function(response) {
			target.removeClass("ajax-loading").html(response);
		}
	});
	
	$("map area").mouseover(function() {
		$("#mapImage").css("background-image", "url(/img/shop/map/area_" + $(this).attr("rel") + ".gif)");
	}).mouseout(function() {
		$("#mapImage").css("background-image", "url(/img/shop/map/map.gif)");
	});

	$(".storeInfoLink").live("click", function() {		
		if($(this).next().css("display") == "block") {
			$(this).next().hide();
		}
		else {
			$(this).next().show();
		}
	});
	
	$("#norrland, #svealand, #gotaland").click(function(e) {
		e.preventDefault();
		region_id = $(this).attr("rel");
		
		if(current_region != region_id) {
			$.ajax({
				type: "GET",
				url: "/ajax.asp",
				data: "mode=change_map_region&region_id=" + region_id,
				cache: false,
				beforeSend: function() {
					target.empty().addClass("ajax-loading");
				},
				success: function(response) {
					target.removeClass("ajax-loading").html(response);
					current_region = region_id;
				}
			});
		}

	});

	$("#storeSearchForm").submit(function(e) {
		e.preventDefault();
		current_region = 0;
	
		$.ajax({
			type: "GET",
			url: "/ajax.asp",
			data: "mode=store_search&search=" + $("#reseller_search").val(),
			cache: false,
			beforeSend: function() {
				target.empty().addClass("ajax-loading");
			},
			success: function(response) {
				target.removeClass("ajax-loading").html(response);
			}
		});
	});
	
	/*
	resellerLink.addEvent("click", function() {
		if(mapBox.style.display != "block") {
			mapBox.style.display = "block";
		}
		else {
			mapBox.style.display = "none";
		}
	});*/
	
	/*function do(this)() {
		var nextSibling;
		nextSibling = current.next();
		nextSibling.setStyle("display", "block");
	}*/

});
