(function()
{
  var $ = null;
  
  var Proxishop = function() 
  {  
    this.widgetType = "proxishop";
    this.widgetId = window[this.widgetType + "_widget"];
    this.host = Proxishop.getHost();    
    this.version = Proxishop.getVersion();
    
    this.rootUrl = "http://" + this.host + "/proxishop_v" + this.version + "/";
      
    this.adsUrl = null;
    this.shopSheetInfoUrl = null;
    this.scriptsLoaded = 0;
    
    this.localisationInfosLoaded = false;
    
    this.ready = false;
     
    this.proxishopUrl = null;
    this.proxishopLocalisationUrl = null;
    this.localisationViewUrl = null;
      
    this.localisationDisplayed = false;
  
    this.viewPosition = window["proxishop_view_position"];
    
    if (this.viewPosition == "none")
    {
      this.createViewContainer();
    }
  
    if (window["proxishop_localisation_position"] == "inline")
    {    
      this.createLocalisationViewContainer();
    }
    
    if (window["proxishop_sheet_info_position"] == "inline")
    {
      this.createShopSheetInfoViewContainer();
    }
    
    var me = this;
    
    //Proxishop.onDOMReady(function(){me.init()});
    
    Proxishop.addLoadListener(function(){me.init()});
  }
  
  
  Proxishop.prototype.init = function()
  { 
    var scriptsToLoad = ["http://" + this.host + "/js_v" + this.version + "/jquery-1.4.1.min.js",
                          "http://" + this.host + "/js_v" + this.version + "/proximis_tool.js",
                          "http://maps.google.com/maps?file=api&v=2&async=2&key=" + window["proxishop_google_maps_api_key"]
                         ];
   
    if (typeof(eval(window)["proxishop_localisation_display_type"]) != 'undefined' && window["proxishop_localisation_display_type"] == "extended")
    {
      scriptsToLoad.push("http://" + this.host + "/js_v" + this.version + "/mapiconmaker.js");
      scriptsToLoad.push("http://" + this.host + "/js_v" + this.version + "/jquery.mousewheel.js");
      scriptsToLoad.push("http://" + this.host + "/js_v" + this.version + "/jscrollpane.js");
    }
                          
    var me = this;
      
    var proxishopLoader = new ProxishopLoader(scriptsToLoad, function(){me.onInitJsLoaded()});
  }
  
  Proxishop.prototype.onReady = function()
  {
    Proxishop.noConflict();

    this.ready = true;
        
    if (window["onProximisEvent"])
      window["onProximisEvent"]("jscriptsLoaded");

    this.jquery = $;
    
    this.getCookiesInfos();
    this.initUI();
  }
  
  Proxishop.prototype.initUI = function()
  {
    this.defaultLightLocalisationPromptWidth = 292;
    this.defaultLightLocalisationPromptHeight = 266;
    
    this.defaultCompactLocalisationPromptWidth = 350;
    this.defaultCompactLocalisationPromptHeight = 340;
    
    this.defaultExtendedLocalisationPromptWidth = 580;
    this.defaultExtendedLocalisationPromptHeight = 370;
    
    if (ProximisTool.isDefined(window, "proxishop_localisation_display_type") && window["proxishop_localisation_display_type"] == "light")
    {
      this.defaultLocalisationPromptWidth = this.defaultLightLocalisationPromptWidth;
      this.defaultLocalisationPromptHeight = this.defaultLightLocalisationPromptHeight;
    }
    else if (ProximisTool.isDefined(window, "proxishop_localisation_display_type") && window["proxishop_localisation_display_type"] == "compact")
    {
      this.defaultLocalisationPromptWidth = this.defaultCompactLocalisationPromptWidth;
      this.defaultLocalisationPromptHeight = this.defaultCompactLocalisationPromptHeight;
    }
    else
    {
      this.defaultLocalisationPromptWidth = this.defaultExtendedLocalisationPromptWidth;
      this.defaultLocalisationPromptHeight = this.defaultExtendedLocalisationPromptHeight;    
    }

    this.defaultCompactShopSheetViewWidth = 375;
    this.defaultCompactShopSheetViewHeight = 480;
    
    this.defaultExtendedShopSheetViewWidth = 505;
    this.defaultExtendedShopSheetViewHeight = 650;
    
    if (ProximisTool.isDefined(window, "proxishop_sheet_info_display_type") && window["proxishop_sheet_info_display_type"] == "compact")
    {
      this.defaultShopSheetViewWidth = this.defaultCompactShopSheetViewWidth;
      this.defaultShopSheetViewHeight = this.defaultCompactShopSheetViewHeight;
    }
    else
    {
      this.defaultShopSheetViewWidth = this.defaultExtendedShopSheetViewWidth;
      this.defaultShopSheetViewHeight = this.defaultExtendedShopSheetViewHeight;    
    }
  
    this.showView();
  
    if ((!this.localisationInfosLoaded && window["proxishop_localisation_show_mode"] == "auto") || window["proxishop_localisation_show_mode"] == "always")
    {
      this.showLocalisationView();
    }
    
    if (!this.localisationDisplayed)
    {
      if (ProximisTool.isDefined(window, "proxishop_sheet_info_show_mode") && window["proxishop_sheet_info_show_mode"] == "always")
      {
        this.showShopSheetInfo("store");
      }
    }
  }
  
  Proxishop.prototype.getCookiesInfos = function()
  {
    var estimated = ProximisTool.getCookie("proximis_localisation_estimated");
  
    var street = ProximisTool.getCookie("proximis_localisation_street");
    var zip = ProximisTool.getCookie("proximis_localisation_zip");
    var city = ProximisTool.getCookie("proximis_localisation_city");
    var country = ProximisTool.getCookie("proximis_localisation_country");
    var store_id = ProximisTool.getCookie("proximis_localisation_store_id");
    var radius = ProximisTool.getCookie("proximis_localisation_radius");
    var lat = ProximisTool.getCookie("proximis_localisation_lat");
    var lng = ProximisTool.getCookie("proximis_localisation_lng");
    
    if (estimated && estimated != "null")
    {
      window["proximis_localisation_estimated"] = estimated;
    }
    
    if (street)
    {
      window["proximis_localisation_street"] = street;
    }
    
    if (zip && zip != "null")
    {
      window["proximis_localisation_zip"] = zip;
      window["proximis_localisation_city"] = null; 
      this.localisationInfosLoaded = true;     
    }
    else if (city && city != "null")
    {
      window["proximis_localisation_city"] = city;
      window["proximis_localisation_zip"] = null;
      this.localisationInfosLoaded = true;
    }
    
    if (country && country != "null")
    {
      window["proximis_localisation_country"] = country;
    }
    
    if (store_id && store_id != "null")
    {
      window["proximis_localisation_store_id"] = store_id;
      this.localisationInfosLoaded = true;
    }
    
    if (radius && radius != "null")
    {
      window["proximis_localisation_radius"] = radius;
    }
    
    if (lat && lat != "null")
    {
      window["proximis_localisation_lat"] = lat;
    }
    
    if (lng && lng != "null")
    {
      window["proximis_localisation_lng"] = lng;
    }
  }

  Proxishop.prototype.createViewContainer = function()
  {
    if (document.getElementById("proxishop_view_container") == null)
    {
      var html = '<div id="proxishop_view_container" style="display:none;background:none;"></div>';
      document.write(html);
    }
  }
  
  Proxishop.prototype.createShopSheetInfoViewContainer = function()
  {  
    if (document.getElementById("proxishop_sheet_info_view_container") == null)
    {
      var html = '<div id="proxishop_sheet_info_view_container" style="display:none;';
      
      if (window["proxishop_sheet_info_position"] != "inline")
        html += 'position:absolute;';
      
      if (window['proxishop_sheet_info_left'])
        html += 'left:' +  window['proxishop_sheet_info_left'] + 'px;';
      if (window['proxishop_sheet_info_top'])
        html += 'top:' +  window['proxishop_sheet_info_top'] + 'px;';
        
      html += 'width:' + this.defaultShopSheetViewWidth + 'px;height:' + this.defaultShopSheetViewHeight + 'px;z-index:32000;background:none"></div>';
      
      if (window["proxishop_sheet_info_position"] == "inline")
        document.write(html);
      else
        $("body").append(html);
      
      var style = '<style type="text/css">.proxishop_sheet_view { display:none; }</style>';
      
      if (window["proxishop_sheet_info_position"] == "inline")
        document.write(style);
      else
        $("body").append(style);
    }
  }
  
  Proxishop.prototype.createLocalisationViewContainer = function()
  {   
    if (!document.getElementById("proxishop_localisation_view_container"))
    {
      var html = '<div id="proxishop_localisation_view_container" style="display:none;';
      
      if (window["proxishop_localisation_position"] != "inline")
        html += 'position:absolute;z-index:32000;';
      
      if (window['proxishop_localisation_left'])
        html += 'left:' + window['proxishop_localisation_left'] + 'px;';
  
      if (window['proxishop_localisation_top'])      
        html += 'top:' + window['proxishop_localisation_top'] + 'px;';
      
      if (window["proxishop_localisation_width"])   
        html += 'width:' +  window["proxishop_localisation_width"] + 'px;';
      
      if (window["proxishop_localisation_height"])
        html += 'height:' +  window["proxishop_localisation_height"] + 'px;';
        
      html += 'background:none"></div>';
      
      if (window["proxishop_localisation_position"] == "inline")    
        document.write(html);
      else
        $("body").append(html);
      
      var style = '<style type="text/css">.proxishop_localisation { display:none; }</style>';
      if (window["proxishop_localisation_position"] == "inline")
        document.write(style);
      else
        $("body").append(style);
    }
  }
  
  Proxishop.prototype.processGetProxishopUrl = function()
  {
    this.proxishopUrl = this.rootUrl + "getProxishopView";
    this.addUrl("widget", "proxishopUrl");
    this.addUrl("affiliate", "proxishopUrl");
    this.addUrl("key", "proxishopUrl");
    this.proxishopUrl += "&href=" + encodeURIComponent(window.location.href);
    this.proxishopUrl += "&referrer=" + encodeURIComponent(document.referrer);
    this.addUrl("localisation", "proxishopUrl");
    if (window["proximis_localisation_radius"])
      this.proxishopUrl += "&localisation_radius=" + window["proximis_localisation_radius"];
    else
      this.addUrl("localisation_radius", "proxishopUrl");
    this.addUrl("background", "proxishopUrl");
    this.addUrl("view_position", "proxishopUrl");
    this.addUrl("view_top", "proxishopUrl");
    this.addUrl("view_left", "proxishopUrl");
    this.addUrl("view_label", "proxishopUrl");
    this.addUrl("view_label_color", "proxishopUrl");
    this.addUrl("view_label_font", "proxishopUrl");
    this.addUrl("view_label_font_size", "proxishopUrl");
    this.addUrl("view_border_color", "proxishopUrl");
    this.addUrl("view_outer_color", "proxishopUrl");
    this.addUrl("view_outer_size", "proxishopUrl");
    this.addUrl("view_inner_background", "proxishopUrl");
    this.addUrl("custom_css", "proxishopUrl");
  }
  
  Proxishop.prototype.processGetProxishopLocalisationUrl = function()
  {
    this.localisationViewUrl = this.rootUrl + "getProxishopLocalisation";
    this.addUrl("widget", "localisationViewUrl");
    this.addUrl("affiliate", "localisationViewUrl");
    this.addUrl("key", "localisationViewUrl");
    this.localisationViewUrl += "&href=" + encodeURIComponent(window.location.href);
    this.localisationViewUrl += "&referrer=" + encodeURIComponent(document.referrer);
    this.addUrl("localisation_estimation", "localisationViewUrl");
    this.addUrl("localisation_display_type", "localisationViewUrl");
    this.addUrl("localisation_position", "localisationViewUrl");
    this.addUrl("localisation_input", "localisationViewUrl");
        
    if (window["proximis_localisation_street"])  
      this.localisationViewUrl += "&street=" + encodeURIComponent(window["proximis_localisation_street"]);
         
    if (window["proximis_localisation_city"])  
      this.localisationViewUrl += "&city=" + encodeURIComponent(window["proximis_localisation_city"]);
      
    if (window["proximis_localisation_zip"])  
      this.localisationViewUrl += "&zip=" + encodeURIComponent(window["proximis_localisation_zip"]);

    if (window["proximis_localisation_country"])  
      this.localisationViewUrl += "&country=" + encodeURIComponent(window["proximis_localisation_country"]);
      
    if (window["proximis_localisation_lat"])  
      this.localisationViewUrl += "&lat=" + encodeURIComponent(window["proximis_localisation_lat"]);
      
    if (window["proximis_localisation_lng"])  
      this.localisationViewUrl += "&lng=" + encodeURIComponent(window["proximis_localisation_lng"]);
      
    if (window["proximis_localisation_radius"])
      this.localisationViewUrl += "&localisation_radius=" + encodeURIComponent(window["proximis_localisation_radius"]);
    else
      this.addUrl("localisation_radius", "localisationViewUrl");
      
    if (window["proximis_localisation_estimated"])
      this.localisationViewUrl += "&localisation_estimated=" + window["proximis_localisation_estimated"];

    this.addUrl("localisation_max_stores", "localisationViewUrl");
    this.addUrl("localisation_offset_stores", "localisationViewUrl");
    this.addUrl("localisation_store_groups", "localisationViewUrl");
    this.addUrl("localisation_width", "localisationViewUrl");
    this.addUrl("localisation_height", "localisationViewUrl");
    this.addUrl("localisation_scale", "localisationViewUrl");
    this.addUrl("localisation_title", "localisationViewUrl");
    this.addUrl("localisation_title_color", "localisationViewUrl");
    this.addUrl("localisation_custom_css", "localisationViewUrl");
  }
  
  Proxishop.prototype.processShopSheetInfoUrl = function(infoType, addOnUrl)
  {
    this.shopSheetInfoUrl = this.rootUrl + "getShopSheetInfo";
    this.addUrl("widget", "shopSheetInfoUrl");
    this.addUrl("affiliate", "shopSheetInfoUrl");
    this.addUrl("key", "shopSheetInfoUrl");
    
    this.shopSheetInfoUrl += "&href=" + encodeURIComponent(window.location.href);
    this.shopSheetInfoUrl += "&referrer=" + encodeURIComponent(document.referrer);
 
    this.addUrl("localisation_estimation", "shopSheetInfoUrl");
    this.addUrl("sheet_info_position", "shopSheetInfoUrl");
    this.addUrl("sheet_info_display_type", "shopSheetInfoUrl");
    
    if (window["proximis_localisation_store_id"])
      this.shopSheetInfoUrl += "&id=" + window["proximis_localisation_store_id"];
    
    if (window["proximis_localisation_street"])
      this.shopSheetInfoUrl += "&street=" +  encodeURIComponent(window["proximis_localisation_street"]);
      
    if (window["proximis_localisation_city"])
      this.shopSheetInfoUrl += "&city=" +  encodeURIComponent(window["proximis_localisation_city"]);
      
    if (window["proximis_localisation_zip"])
      this.shopSheetInfoUrl += "&zip=" + encodeURIComponent(window["proximis_localisation_zip"]);

    if (window["proximis_localisation_country"])
      this.shopSheetInfoUrl += "&country=" + encodeURIComponent(window["proximis_localisation_country"]);
    
    if (window["proximis_localisation_lat"])  
      this.shopSheetInfoUrl += "&lat=" + encodeURIComponent(window["proximis_localisation_lat"]);
      
    if (window["proximis_localisation_lng"])  
      this.shopSheetInfoUrl += "&lng=" + encodeURIComponent(window["proximis_localisation_lng"]);
  
    if (window["proximis_localisation_estimated"])
      this.shopSheetInfoUrl += "&localisation_estimated=" + window["proximis_localisation_estimated"];
      
    this.shopSheetInfoUrl += "&info_type=" + infoType;		
    this.shopSheetInfoUrl += "&show_change_store=true";		
    
    if (window["proxishop_sheet_info_custom_css"])
    {
       this.shopSheetInfoUrl += "&sheet_info_custom_css=" + window["proxishop_sheet_info_custom_css"];
    }
    
    if (addOnUrl)
      this.shopSheetInfoUrl += "&" + addOnUrl;
  }
  
  Proxishop.prototype.addUrl = function(name, variable)
  {
    if (name && window["proxishop_" + name])
    {
      if ( this[variable].indexOf("?") == -1)
        this[variable] += "?" + name + "=" + encodeURIComponent(window["proxishop_" + name]) ;
      else
        this[variable] += "&" + name + "=" + encodeURIComponent(window["proxishop_" + name]) ;
    }
  }
  
  Proxishop.prototype.showView = function(urlSrc)
  {
    this.processGetProxishopUrl();
        
    if (!urlSrc)
      urlSrc = this.proxishopUrl;
    
    var me = this;
    
    $.getJSON(urlSrc + "&jsoncallback=?", function(result) 
    {
      if (result["error"])
      {
        var event = new Array();
        event["name"] = "proxishop_view_error";
        event["type"] = "error";
        event["object"] = "proxishop";
        event["reason"] = result["error"];
        
        ProximisTool.sendStats(me, event);
        
        alert(result["error"]);
      }
        
      ProximisTool.includeCssList(result["css"]);
      
      if (me.viewPosition == "none")
      {
        $("#proxishop_view_container").html(result["html"]);
        $("#proxishop_view_container").show();
      }
      else
      {       
        $("body").append(result["html"]);
      }
      
      if (result["html"] && result["html"].length > 0)
      {
        var event = new Array();
        event["name"] = "proxishop_display";
        event["type"] = "display";
        event["object"] = "proxishop";
        
        ProximisTool.sendStats(me, event);
      }
      else
      {
        var event = new Array();
        event["name"] = "proxishop_view_error";
        event["type"] = "error";
        event["object"] = "proxishop";
        event["reason"] = "empty html";
        
        ProximisTool.sendStats(me, event);
      }
    });
    
    var event = new Array();
    event["name"] = "proxishop_view_request";
    event["type"] = "server_request";
    event["object"] = "proxishop";
    event["url"] = urlSrc;
    
    ProximisTool.sendStats(this, event);
  }
  
  Proxishop.prototype.showShopSheetInfo = function(infoType, addOnUrl)
  {
    this.processShopSheetInfoUrl(infoType, addOnUrl);
    
    this.createShopSheetInfoViewContainer();
    
    var me = this;
    
    var urlReq = this.shopSheetInfoUrl;
    
    $.getJSON(urlReq + "&jsoncallback=?", function(result) 
    {
      if (result["error"])
      {
        var event = new Array();
        event["name"] = "proxishop_shop_sheet_info_view_error";
        event["type"] = "error";
        event["object"] = "proxishop";
        event["reason"] = result["error"];
        
        ProximisTool.sendStats(me, event);
 
        alert(result["error"]);
      }

      var windowSize = ProximisTool.getWindowSize();
  
      var shopSheetLeft = 0;
      var shopSheetTop = 0;
      
      if (ProximisTool.isDefined(window, "proxishop_sheet_info_left"))
      {
        shopSheetLeft = window['proxishop_sheet_info_left'];
      }
      else
      {
        shopSheetLeft = (windowSize[0] - me.defaultShopSheetViewWidth) / 2;
        if (shopSheetLeft < 0)
          shopSheetLeft = 0
      }
      
      if (ProximisTool.isDefined(window, "proxishop_sheet_info_top"))
      {
        shopSheetTop = window['proxishop_sheet_info_top'];
      }
      else
      {
        shopSheetTop = (windowSize[1] - me.defaultShopSheetViewHeight) / 2;
        if (shopSheetTop < 0)
          shopSheetTop = 0;
      }
  
      shopSheetTop += $(window).scrollTop();
      
      $("#proxishop_sheet_info_view_container").css("left", shopSheetLeft);
      $("#proxishop_sheet_info_view_container").css("top", shopSheetTop);
      
      window["proximis_shop_sheet_info_parent_object"] = me;
      
      ProximisTool.includeCssList(result["css"]);
      
      $("#proxishop_sheet_info_view_container").html(result["html"]);
      $("#proxishop_sheet_info_view_container").fadeIn("fast", function() { $("#proxishop_sheet_info_view_container").show() });
      
      if (result["html"] && result["html"].length > 0)
      {
        var infoType = $("#proxishop_sheet_view").attr("info_type");
        var storeId = $("#proxishop_sheet_view").attr("store_id");

        var event = new Array();
        event["name"] = "proxishop_shop_sheet_info_display";
        event["type"] = "display";
        event["object"] = "proxishop";
        event["data"] = new Array(); event["data"]["info_type"] = infoType; event["data"]["store_id"] = storeId;
        
        ProximisTool.sendStats(me, event);
      }
      else      
      {
        var event = new Array();
        event["name"] = "proxishop_shop_sheet_info_view_error";
        event["type"] = "error";
        event["object"] = "proxishop";
        event["reason"] = "empty html";
        
        ProximisTool.sendStats(me, event);
      }
    });
    
    var event = new Array();
    event["name"] = "proxishop_shop_sheet_info_view_request";
    event["type"] = "server_request";
    event["object"] = "proxishop";
    event["url"] = urlReq;
    
    ProximisTool.sendStats(this, event);
  }
  
  Proxishop.prototype.onClickProxishopView = function()
  {
    if (!this.ready)    // if the function onClickProxishopView is programmatically called
    {
      setTimeout("proxishop.onClickProxishopView()", 200);
      return;
    }
    
    var event = new Array();
    event["name"] = "proxishop_view_click";
    event["type"] = "visitor_action";
    event["object"] = "proxishop";
      
    ProximisTool.sendStats(this, event);
        
    if (!this.localisationDisplayed)
    {
      if (!this.localisationInfosLoaded && window["proxishop_localisation_show_mode"] == "ondemand")
      {
        this.showLocalisationView();
      }
      else
      {  
        this.showShopSheetInfo("store");
      }
    }
  }
  
  Proxishop.prototype.showLocalisationView = function(addOnUrl)
  { 
    this.processGetProxishopLocalisationUrl();
    
    var me = this;
    var urlReq = this.localisationViewUrl;
    
    if (addOnUrl)
     urlReq += "&" + addOnUrl;
    
    this.createLocalisationViewContainer();
    
    $.getJSON(urlReq + "&jsoncallback=?", function(result) 
    {     
      if (result["error"])
      {
        var event = new Array();
        event["name"] = "proxishop_localisation_view_error";
        event["type"] = "error";
        event["object"] = "proxishop";
        event["reason"] = result["error"]; 

        ProximisTool.sendStats(me, event);

        alert(result["error"]);
      }

      if (window["proxishop_localisation_position"] != "inline")
      {
        var windowSize = ProximisTool.getWindowSize();
      
        var localisationLeft = 0;
        var localisationTop = 0;
        var localisationWidth = me.defaultLocalisationPromptWidth;
        var localisationHeight = me.defaultLocalisationPromptHeight;

        if (ProximisTool.isDefined(window, "proxishop_localisation_width"))
        {
          localisationWidth = window['proxishop_localisation_width'];
        }
        
        if (ProximisTool.isDefined(window, "proxishop_localisation_height"))
        {
          localisationHeight = window['proxishop_localisation_height'];
        }
        
        if (ProximisTool.isDefined(window, "proxishop_localisation_left"))
        {
          localisationLeft = window['proxishop_localisation_left'];
        }
        else
        {
          localisationLeft = (windowSize[0] - localisationWidth) / 2;
          if (localisationLeft < 0)
            localisationLeft = 0
        }
        
        if (ProximisTool.isDefined(window, "proxishop_localisation_top"))
        {
          localisationTop = window['proxishop_localisation_top'];
        }
        else
        {
          localisationTop = (windowSize[1] - localisationHeight) / 2;
          if (localisationTop < 0)
            localisationTop = 0;
        }
      
        localisationTop += $(window).scrollTop();
        
        $("#proxishop_localisation_view_container").css("left", localisationLeft);
        $("#proxishop_localisation_view_container").css("top", localisationTop);
      }
              
      ProximisTool.includeCssList(result["css"]);
              
      window["proximis_localisation_parent_object"] = me;

      $("#proxishop_localisation_view_container").html(result["html"]);

/*      if (window["proxishop_debug"])
      {
        $("#proxishop_localisation_view_container").html('<script type="text/javascript" src="http://widget.proximis.fr/js_v1/proxishop_localisation_light.js" /><div id="proxishop_localisation" store_id="2-4409" user_city="Moidieu-détourbe" user_zip="" user_lat="45.516701" user_lng="5.016700" user_country="FR" max_stores="2" offset_stores="0">	<div id="proxishop_localisation_view" class="proxishop_localisation_view" style="overflow:hidden;">			<div class="proxishop_localisation_popup_frame" rel="popup_frame" style="">   			<div class="content" rel="popup_frame">    			<div class="t" rel="popup_frame"></div>         				<div class="proxishop_localisation_view_inner">									<div class="proxishop_localisation_stores">						<div class="proxishop_localisation_title" style="">							<span class="proxishop_localisation_title_top">NOS MAGASINS</span><br/>pr&egrave;s de chez vous						</div>						<div class="proxishop_localisation_stores_view">															<div class="proxishop_localisation_store_view" store_id="2-4409" store_url="">									<div class="proxishop_localisation_store_label"> VIENNE</div>									<div class="proxishop_localisation_store_distance">&agrave; 11,2  km</div>									<div class="proxishop_localisation_store_phone">04 74 31 62 51</div>									<div class="proxishop_localisation_clear_both"></div>								</div>															<div class="proxishop_localisation_store_view" store_id="2-4394" store_url="">									<div class="proxishop_localisation_store_label"> ST FONS</div>									<div class="proxishop_localisation_store_distance">&agrave; 24,8  km</div>									<div class="proxishop_localisation_store_phone">04 78 70 95 42 </div>									<div class="proxishop_localisation_clear_both"></div>								</div>													</div>					</div>					<div class="proxishop_localisation_stores_paging">																<div id="proxishop_localisation_stores_page_next_link" class="proxishop_localisation_stores_page_next_btn"><a class="proxishop_localisation_stores_page_next_link" href="http://lynx.dev-pimentddb.com/magasins">+ d\'adresses</a></div>										</div>					<form id="proxishop_localisation_form" class="proxishop_localisation_form" method="post">						<input id="proxishop_localisation_form_zip_city_input" class="proxishop_localisation_form_zip_city_input proxishop_localisation_png" type="text" value="Moidieu-détourbe"/>						<input id="proxishop_localisation_form_zip_city_submit_btn" class="proxishop_localisation_form_zip_city_submit_btn" type="submit" value=""/>					</form>								</div>			</div>           	<div class="b" rel="popup_frame"><div></div><div class="proxishop_localisation_powered_by"><a href="http://www.proximis.fr" target="_blank">Powered by Proximis&copy;</a></div></div>		</div>	</div></div>');    
      }
*/        
      $("#proxishop_localisation_view_container").fadeIn("fast", function() { $("#proxishop_localisation_view_container").show();});
    
      me.localisationDisplayed = true;
      
      if (result["html"] && result["html"].length > 0)
      {
        var event = new Array();
        event["name"] = "proxishop_localisation_display";
        event["type"] = "display";
        event["object"] = "proxishop";
       
        ProximisTool.sendStats(me, event);
      }
      else
      {
        var event = new Array();
        event["name"] = "proxishop_localisation_view_error";
        event["type"] = "error";
        event["object"] = "proxishop";
        event["reason"] = "empty html";
       
        ProximisTool.sendStats(me, event);
      }
    }
    );
    
    var event = new Array();
    event["name"] = "request_proxishop_localisation_view_request";
    event["type"] = "server_request";
    event["object"] = "proxishop";
    event["url"] = urlReq;
    
    ProximisTool.sendStats(me, event);
  }
  
  Proxishop.prototype.onValidLocalisation = function()
  {
    this.localisationInfosLoaded = true;
    
    if (!(ProximisTool.isDefined(window, "proxishop_localisation_position") && window["proxishop_localisation_position"] == "inline"))       
      $("#proxishop_localisation_view_container").fadeOut("fast", function() { $("#proxishop_localisation_view_container").hide() });
      
    this.localisationDisplayed = false;
    
    if (ProximisTool.isDefined(window, "proxipub"))
    {
      proxipub.showView();
    }
    
    if (ProximisTool.isDefined(window, "proxishop_localisation_select_store_target") && window["proxishop_localisation_select_store_target"] == "url" 
      && window["proximis_localisation_store_url"] && window["proximis_localisation_store_url"].length > 0)
      window.location.href = window["proximis_localisation_store_url"];
    else 
      this.showShopSheetInfo("store");
  }
  
  Proxishop.prototype.onClickChangeStore = function()
  {
    var addonUrl = "";
    if (window["proxishop_localisation_display_type"] == "compact")
      addonUrl = "step=1";
      
    this.showLocalisationView(addonUrl);
    $("#proxishop_sheet_info_view_container").fadeOut("fast", function() { $("#proxishop_sheet_info_view_container").hide() });
  }
  
  Proxishop.prototype.onInitJsLoaded = function()
  {
    var me = this;
    Proxishop.synchronize(function(){me.onReady()});
  }
  
  Proxishop.getHost = function()
  {
    var scripts = document.getElementsByTagName("script");
    
    var httpPrefix = "http://";
    
    for (var index = 0; index < scripts.length; index++)
    {
      var script = scripts[index];
      
      if (script.src.indexOf("proxishop.js") != -1)
      {
        var host = script.src;
        host = host.replace(httpPrefix, "");
        host = host.substr(0, host.indexOf('/'));
        return host;
      }
    }
  }
  
  Proxishop.synchronize = function(onReadyHandler)
  {
    if (!window["jQueryProximis"])
    {        
      setTimeout(function(){Proxishop.synchronize(onReadyHandler)}, 13);
      return;
    }
      
    if (!window["ProximisTool"])
    {    
      setTimeout(function(){Proxishop.synchronize(onReadyHandler)}, 13);
      return;
    }
  
    document.body.onunload = function(){GUnload()};       // free resources to avoid memory leaks
    onReadyHandler();
  }
  
  Proxishop.noConflict = function()
  {
    $ =  window.jQueryProximis;
  }

  Proxishop.onDOMReady = function(handler)
  {
    if (!document.body)
    {
      setTimeout(function(){Proxishop.onDOMReady(handler)}, 13);
      return;
    }
          
    handler();
  }
    
  Proxishop.getVersion = function()
  {
    var scripts = document.getElementsByTagName("script");
    
    var jsPrefix = "js_v";
       
    for (var index = 0; index < scripts.length; index++)
    {
      var script = scripts[index];
      
      if (script.src.indexOf("proxishop.js") != -1)
      {
        var src = script.src;
        var right = src.lastIndexOf('/');
        var left = src.lastIndexOf('/', right - 1);
        var version = src.substr(left + 1, right - left - 1);
        version = version.replace(jsPrefix, "");
        
        return parseInt(version, 10);
      }
    }
  }
  
  Proxishop.addLoadListener = function(func) 
  {
     if (window.addEventListener) 
        window.addEventListener("load", func, false);
     else if (document.addEventListener) 
        document.addEventListener("load", func, false);
     else if (window.attachEvent) 
        window.attachEvent("onload", func);
     else if (typeof window.onload != "function") 
        window.onload = func;
     else 
     {
        var oldonload = window.onload;
        window.onload = function() {
           oldonload();
           func();
        };
     }
  }
  
  var ProxishopLoader = function(urls, onLoadHandler)
  {
    this.urls = urls;
    this.onLoadHandler = onLoadHandler;
     
    if (!window["proximisScriptsLoaded"])
      window["proximisScriptsLoaded"] = new Array();
    
    this.getJsList(urls);
  }
  
  ProxishopLoader.prototype.getJsList = function(urls)
  {
    this.jsToLoad = 0;
    
    for (var index = 0; index < urls.length; index++)
    {
      if (!window["proximisScriptsLoaded"][urls[index]])
      {
        this.jsToLoad++;
      }
    }
    
    for (var index = 0; index < urls.length; index++)
    {
      if (!window["proximisScriptsLoaded"][urls[index]])
      {
        this.getJs(urls[index]);
      }
    }
  }
  
  ProxishopLoader.prototype.onJsLoaded = function(script)
  {
    if (!window["proximisScriptsLoaded"][script.src])
    {        
      window["proximisScriptsLoaded"][script.src] = true;
      
      this.jsToLoad--;
      if (this.jsToLoad == 0)
      {
        if (this.onLoadHandler)
          this.onLoadHandler();
      }
    }  
  }
  
  ProxishopLoader.prototype.getJs = function(url)
  {
    var me = this;
    var heads = document.getElementsByTagName("head");
    if (heads && heads.length > 0) 
    {
      var head = heads[0];
      
    	if (document.getElementsByTagName && !window["proximisScriptsLoaded"][url]) 
    	{
    	  var scriptsTag = document
    		var script = document.createElement("script");
    		script.type = "text/javascript";
    		script.src = url;
    		//script.defer = true;
    		    		
  		  if ( script.addEventListener )
          script.addEventListener( 'load', function() 
          { 
            me.onJsLoaded(this); 
          }, false );
        else
          script.onreadystatechange = function() {if (this.readyState == 'complete' || this.readyState == 'loaded') { me.onJsLoaded(this);}};
    		
    	  head.appendChild(script);
    	 
    	//document.write('<script type="text/javascript" src="' + url + '"></script>');
    	}
    }
  }

  window.proxishop = new Proxishop();
})();