
var piwikSiteID = 35;
var popunder_url = 'http://cams.com/go/page/whos_online_landing?pid=g813820-pct.sub_playdude_pu_us';
var pu = new popUnder('popunder', popunder_url);


function GetRandom(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

function popUnder(ident, url) {
  this.ident = ident;
  this.url = url;
  this.window = null;
  this.windowProps = "toolbar=1,location=1,directories=0,status=1,menubar=1,width=980,height=600,scrollbars=1,resizable=1,top=0,left=0";
  this.cookies = new CookieManager(null, '/', 0);
  this.setup = function() {
    if(!this.cookies.get(this.ident)) {
      var that = this;
      document.onclick = function () {
        that.pop();
      }
    }
  }
  this.pop = function() {
    if(!this.window) {
      this.window = window.open(this.url, this.ident, "scrollbars=1,status=1,toolbar=1,resizable=1,menubar=1,location=1,top=0,left=0,width=" + screen.availWidth + ",height=" + screen.availHeight);
      if(this.window) {
        this.cookies.set(this.ident, 1);
        try {
          var piwikLinkTracker = Piwik.getTracker(pkBaseURL + "piwik.php", piwikSiteID);
          piwikLinkTracker.trackLink( this.url, 'link');
        } catch( err ) {}
      }
    }
    if(!this.window) {
      if(window.Event) {
        document.captureEvents(Event.CLICK);
      }
      var that = this;
      document.onclick = function () {that.pop();}
    }
    self.focus();
  }
  this.setup();
}

function CookieManager(domain, path, days) {
  this.settings = {
    domain: domain,
    path: path,
    days: days
  }
  this.set = function(name, value) {
    var date = new Date();
    date.setTime(date.getTime() + this.settings.days * 2 * 60 * 60 * 1000);
    var time = date.toGMTString();
    document.cookie = (
      name + '='
      + encodeURIComponent(value)
      + ( this.settings.domain ? '; domain=' + this.settings.domain : '' )
      + ( this.settings.path ? '; path=' + this.settings.path : '' )
      + ( this.settings.days ?'; expires=' + time : '' )
    );
  }
  this.get = function( name ) {
    var value = document.cookie.match('(?:^|;)\\s*' + name + '=([^;]*)');
    return value ? decodeURIComponent(value[1]) : false;
  }
}
