var adPopped = false;
var sid = "store";
if ( typeof(theStore) != 'undefined' ) {
  sid = theStore;
} else {
  var theStore = '';
}

if (contextPath == '/ca') {
	sid = 'ca';
	theStore = 'ca';
} else if (contextPath == '/au') {
	sid = 'au';
	theStore = 'au';
} else if (contextPath == '/nz') {
	sid = 'nz';
	theStore = 'nz';
} else if (contextPath == '/uk') {
	sid = 'nz';
	theStore = 'uk';
} else if (contextPath == '/organized') {
	sid = 'organized';
	theStore = 'organized';
}  else if (contextPath == '/bargain') {
	sid = 'bargain';
	theStore = 'bargain';
}  	

 var thisSite = getSiteCookie();

  $(document).ready( function() {
   if (( thisSite == 'store' ) || (theStore =='organized')) {
      $.get('/' + thisSite + '/popup/ajaxPopover.jsp', function(data) {
         if ( !data.match(/^\s*---EMPTY---\s*$/) ) {
             adPopped = true;
             positionPopover();
             $('#popAd').html(data);
             $('#popAd').show();
         }
     });
   }
  });
  

  function getSiteCookie() {
        var allCookies = document.cookie.split(';');
        for ( i=0; i<allCookies.length; i++ ) {
                var thisCookie = allCookies[i].split('=');
                var pattern = /^\s*siteId\s*$/;
                if ( thisCookie[0].match(pattern) ) {
                        return thisCookie[1];
			break;
                }
        }
  }
  
  function positionPopover() {
     if ( adPopped ) {
         //var wi = $(window).width(); 
         var posLeft = $('#main').position().left;
         if ( $(window).width() > 1140 ) {
             posLeft -= 135;
         }
     }
     $('#popAd').css({'left':posLeft + 'px'}); 
  }
  $(window).resize( function() { positionPopover(); } );


