/* needs: JQuery + Cookie-Plugin */
var adsize = {w:850, h:437};
var adsource = '/img/layerad-2010-08-29.jpg';
//var adtarget = 'http://www.xylexpo.com';
var adtarget = '#';

var date = new Date();
date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));

if ($.browser.msie) {
  var closedx = 421;
} else {
  var closedx = adsize.w - 15;
}

$(document).ready(function() {
   if (!$.cookie('adclosed')) {
     $('body').append('<div id="adl"></div>');
     if (adtarget != '#') {
       $('div#adl').append('<a href="#" id="adclose">x</a>');
       $('a#adclose').css({
         'position': 'absolute',
         'color': '#aaa',
         'font': 'bold 14px Arial, Helvetica, sans-serif',
         'display': 'block',
         'width' : '16px',
         'height' : '16px',
         'z-index': '10001',
         'background': 'white',
         'text-decoration': 'none',
         'border': '1px solid #ccc',
         'border-style': 'none none solid solid',
         'margin-left': closedx+'px'
       }).click(function() {
          $('div#adl').remove();
           $.cookie('adclosed', 1, { path: '/', expires: date });
          return false;
       })
     }
     $('div#adl')
     .append('<a id="layerlink" href="'+adtarget+'"><img width="'+adsize.w+
              '" height="'+adsize.h+'" src="'+adsource+'" alt="" /></a>')
     .css({
       'position': 'absolute',
       'display':'none',
       'top': '50%',
       'left': '50%',
       'margin-left': '-'+((adsize.w+20)/2)+'px',
       'margin-top': '-'+((adsize.h+20)/2)+'px',
       'z-index': '10000',
       'width': (adsize.w+2)+'px',
       'height': (adsize.h+2)+'px',
       'padding': '10px',
       'border': '1px solid #ccc',
       'background': 'white'
     });
     $('div#adl a').css({'display':'block'});
     if (adtarget == '#') {
       $('div#adl a').click(function() {
          $('div#adl').remove();
           $.cookie('adclosed', 1, { path: '/', expires: date });
          return false;
       });
     }
     $('a#layerlink').click(function() {
       if ($(this).attr('href') != '#') {
         $('div#adl').remove();
         $.cookie('adclosed', 1, { path: '/', expires: date });
         window.open($(this).attr('href'));
         return false;
       }
     });
     $('div#adl img').css({'display':'block', 'border': '1px solid #ccc'});
     $('div#adl').fadeIn(1000); 
   }
});