SEAT.PG.Lite = function(options) {
  var self = this;
  this.options = {clsContainer: 'container', clsSlow: 'lite', clsLite: 'litems'};
  $.extend(this.options, options);
  
  // Get the correct domain to use when writing the cookie - get the last 2 elements of the full domain
  var li,s,c = document.domain.split(".");
  this.cookieDomain = (c.length >= 3) ? c[c.length - 2] + "." + c[c.length - 1] : document.domain;
  
  // Display the appropriate link depending upon which version of the site we are displaying (default or lite)
  s = SEAT.COOKIE.getCookie(this.COOKIE_NAME) || "";
  li = (s === this.VAL_SLOW);
  this.setDesc(s);
  
  //minisiti code
  if(this.options.m){
    $.extend(this.options, {lite:li});
  }
  
  // Bind the onclick events
  $("#" + this.ID_SLOW).click(function() {
                                // Clicked on the "slow connection" link, so show the other link in case we don't change page
                                self.setCookie(self.VAL_SLOW);
                                self.setMRCookie(self.VAL_SLOW);
                                self.setDesc(self.VAL_SLOW);
                                $(this).siblings().add($(this)).toggleClass("none");
                                if(this.name === 'vv56kbps'){location.reload(true);}
                              });
  $("#" + this.ID_DEFAULT).click(function() {
                                // Clicked on the "veloce connection" link, so show the other link in case we don't change page
                                self.setCookie(self.VAL_DEFAULT);
                                self.setMRCookie(self.VAL_DEFAULT);
                                self.setDesc(self.VAL_DEFAULT);
                                $(this).siblings().add($(this)).toggleClass("none");
                                if(this.name === 'vvADSL'){location.reload(true);}
                              });
       
//for minisiti under squid                              
if(this.options.m){
    if(this.options.lite){
    	$("." + this.options.clsContainer).addClass(this.options.clsLite);
    	self.setMRCookie(self.VAL_SLOW);
        $("#" + this.ID_SLOW).addClass("none").removeClass("selected");
        $("span:.slow").removeClass("none").addClass("selected");
        $("#" + this.ID_DEFAULT).removeClass("none").removeClass("selected");
        $("span:.fast").addClass("none");
    }
    else {
        self.setMRCookie(self.VAL_DEFAULT);
        $("#" + this.ID_DEFAULT).addClass("none").removeClass("selected");
        $("span:.fast").removeClass("none").addClass("selected");
        $("#" + this.ID_SLOW).removeClass("none").removeClass("selected");
        $("span:.slow").addClass("none");
    }                             
}                              
	
};

SEAT.PG.Lite.prototype = {
  
  COOKIE_NAME:            "conspe",
  COOKIE_EXPIRY_DAYS:     1825,   // 5 years
  ID_DEFAULT:             "cSpeedDefault",
  ID_SLOW:                "cSpeedSlow",
  VAL_DEFAULT:            "",
  VAL_SLOW:               "s",
  
  setDesc: function(speed) {
    if (speed === this.VAL_SLOW) {
      $("#" + this.ID_SLOW).addClass("selected");
      $("#" + this.ID_DEFAULT).removeClass("selected");
    }
    else {
      $("#" + this.ID_DEFAULT).addClass("selected");
      $("#" + this.ID_SLOW).removeClass("selected");
    }
  },
  
  setCookie: function(speed) {
    // Cookie
    var expireDate = new Date();
  	expireDate.setTime(expireDate.getTime() + (this.COOKIE_EXPIRY_DAYS * 24 * 60 * 60 * 1000));
    SEAT.COOKIE.setCookie(this.COOKIE_NAME, speed, expireDate, this.cookieDomain, false);
  },
  
  setMRCookie: function(speed) {
    var expireDate;
    
    if (speed === this.VAL_SLOW) {
      // Clicked on the "slow" connection, so set a long term MR cookie to default the results
      // shown to 10
      expireDate = new Date();
    	expireDate.setTime(expireDate.getTime() + (this.COOKIE_EXPIRY_DAYS * 24 * 60 * 60 * 1000));
      SEAT.COOKIE.setCookie(SEAT.PG.COOKIE_MR, SEAT.PG.COOKIE_MR_LITE_DEFAULT, expireDate, false, false);
    }
    else {
      // Clicked on the "fast" connection, so reset the MR cookie to a session cookie with
      // 20 results
      SEAT.COOKIE.setCookie(SEAT.PG.COOKIE_MR, SEAT.PG.COOKIE_MR_DEFAULT, false, false, false);
    }
  }
}
