﻿$(document).ready(function() {
//START SHOPFINDER (Scope):

//Step 1: Hent fylker
$(".ToggleShopScopeSelector").livequery("click",function(){
    $("#scope").toggle();
    $("#scope_select").toggle();
    var status = $("#scope_select").css("display");
    if(status.indexOf("block") >= 0) {
        var url = $(this).attr("href");
          $("#scope_select .facets").empty();
          $("#scope_select").load(url);
    }
    return false;
});

//step 1 (from navpath inside the shopFinder)
$(".ToggleShopScopeSelectorInside").livequery("click",function(){
       var url = $(this).attr("href");
       $("#scope_select .facets").empty();
       $("#scope_select").load(url);
    return false;
});

//step 2: Hent kommunuer i fylke
$(".getKommuner a , #getKommuner").livequery("click",function(){
    var url = $(this).attr("href");
    $("#scope_select .facets").empty();
   $("#scope_select").load(url);
   return false;
});

//step 3: Hent butikker i kommune
$(".getButikker a , #getButikker, #getButikk").livequery("click",function(){
    var url = $(this).attr("href");
    $("#scope_select .facets").empty();
    $("#scope_select").load(url, function(){
        $("#scope").hide();
        $("#scope_select").show();
    });
   return false;
});

//Butikkpaginering : 
$("#scope_select .shops a.nextShops, #scope_select .shops a.prevShops").livequery("click",function(){
    var url = $(this).attr("href");
    //$("#scope_select .shops").empty();
    $("#scope_select").load(url , function(){
        $("#scope_select .shops").fadeIn();
    });
    //scroll(0,0);
    return false;
});

//START: SHOPFINDER (map) :

$("#shopfinder .getFylkerFinder").click(function(){
    var url = $(this).attr("href");
    $("#mapContainer").hide();
    $("#shopFinderContainer").show();
    $("#shopFinderContainer").load(url);
    return false;
});

$("#getFylkerFinder").livequery("click",function(){
    var url = $(this).attr("href");
    $("#shopFinderContainer").load(url);
    return false;
});

//step 2: Hent kommunuer i fylke
$("#shopFinderContainer .getKommunerFinder a , #getKommunerFinder, #getKommunerFinderFromMap").livequery("click",function(){
    var url = $(this).attr("href");
     $("#mapContainer").hide();
    $("#shopFinderContainer .facets").empty();
    $("#shopFinderContainer").show();
   $("#shopFinderContainer").load(url);
   return false;
});

//step 3: Hent butikker i kommune
$("#shopFinderContainer .getButikkerFinder a , #getButikkerFinder, #getButikkerFinderFromMap").livequery("click",function(){
    var url = $(this).attr("href");
    $("#mapContainer").hide();
    $("#shopFinderContainer .facets").empty();
     $("#shopFinderContainer").show();
    $("#shopFinderContainer").load(url);
   return false;
});

//Butikkpaginering : 
$("#shopFinderContainer .shops a.nextShops, #shopFinderContainer .shops a.prevShops").livequery("click",function(){

    var url = $(this).attr("href");
   
    $("#shopFinderContainer").load(url);
    return false;
});

//for some reason the page is not reloaded if u select the same shop twise. Then just show the mapContainer as its just hidden at the moment.
$("#shopFinderContainer .showMap").livequery("click",function() {
    $("#mapContainer").show();
    $("#shopFinderContainer").hide();
    //if u select another shop: then the link will work:
    return true;
});

});
