var casinoAff = function() {

  var clientUrl = 'http://banner.grosvenorcasinos.com/cgi-bin/SetupCasino.exe';
  var affId = $.query.get('AFF_ID') || $.cookie('AFF_ID');
  var subId = $.query.get('SUB_ID') || $.cookie('SUB_ID');
  var affDays = 15;
  var affCookieSet = false;

  return {
    onload: function() {

      if (affId) {
        this.affiseAnchors();
      }

    },

    affiseAnchors: function() {

      $('a[href*=' + clientUrl +']').each(function() {
        var href = $(this).attr('href');
        if(href.search(/\?/) != -1) {

           if(subId){
            $(this).attr('href', href + '&creferer=AFFID:' + affId + ';SUBID:' + subId);
          } else {
             $(this).attr('href', href + '&creferer=AFFID:' + affId);
          }

        } else {

        if(subId){
            $(this).attr('href', href + '?creferer=AFFID:' + affId + ';SUBID:' + subId);
          } else {
             $(this).attr('href', href + '?creferer=AFFID:' + affId);
          }
        }
      });
    },

     affiseRedirect: function(){
        if (affId) {

        if(subId){
            setTimeout("window.location.href='" + clientUrl + "?creferer=AFFID:" + affId + ';SUBID:' + subId +"'", 2000);
          } else {
             setTimeout("window.location.href='" + clientUrl + "?creferer=AFFID:" + affId + "'", 2000);
          }

        } else {
         setTimeout("window.location.href='" + clientUrl + "'", 2000);
        }
    }
  };
}();

$(function() {
  casinoAff.onload();
});
