function MX_BookPreview(partner_id, isbn, output_id, target_id, target_div_id)
  {
  this.partner_id = partner_id;
  this.isbn = isbn;
  this.output_id = output_id;
  this.target_id = target_id;
  this.target_div_id = target_div_id;
  this.include_div = false;
  this.button_id = false;
  this.flash_id = false;
  this.traffic_id = false;
  this.lang = false;
  this.cnt_id = false;
  this.fill_parent = false;
  
  this.setIncludeDiv = function(include_div)
    {
    this.include_div = include_div;
    }
  
  this.setButtonId = function(button_id)
    {
    this.button_id = button_id;
    }
  
  this.setTrafficId = function(traffic_id)
    {
    this.traffic_id = traffic_id;
    }
  
  this.setFlashLang = function(lang)
    {
    this.lang = lang;
    }

  this.setFlashId = function(flash_id)
    {
    this.flash_id = flash_id;
    }
  
  this.setCntId = function(cnt_id)
    {
    this.cnt_id = cnt_id;
    }

  this.replaceParent = function(p)
    {
    this.fill_parent = p;
    }

  this.show = function()
    {
    var d = new Date();
    if (!this.include_div)
      {
      this.include_div = "MX_"+d.getTime()+Math.round(Math.random()*65536);
      document.writeln('<div id="'+this.include_div+'"></div>');
      }
    var rnd = "MX_"+d.getTime()+Math.round(Math.random()*65536);
    var par = "partner_id="+this.partner_id+"&isbn="+this.isbn+"&output_id="+this.output_id+"&target_id="+this.target_id+"&include_div="+this.include_div+
      "&rnd="+rnd+"&loc="+escape(window.location.href);
    if (this.target_id == 1) par+= "&target_div_id="+this.target_div_id;
    if (this.button_id) par += "&button_id="+this.button_id;
    if (this.flash_id) par += "&flash_id="+this.flash_id;
    if (this.traffic_id) par += "&traffic_id="+this.traffic_id;
    if (this.lang) par += "&lang="+this.lang;
    if (this.cnt_id) par += "&cnt_id="+this.cnt_id;
    if (this.fill_parent) par += "&fill_parent="+this.fill_parent;

    var ov = document.createElement('script');
    ov.id = rnd;
    ov.type = "text/javascript";
    ov.src = "//www.blickinsbuch.de/gateway/check.php?"+par;
    document.getElementsByTagName('head')[0].appendChild(ov);
    setTimeout("MX_Remove('"+rnd+"')", 4000);
    }
  }
  
function MX_getInternetExplorerVersion()
  {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
        rv = parseFloat( RegExp.$1 );
    }
    return rv;
  }

function MX_Remove(id)
  {
  document.getElementsByTagName("head")[0].removeChild(document.getElementById(id));
  }

function MX_BookInDiv(target, url)
  {
  document.getElementById(target).innerHTML = '<iframe frameborder="0" style="height:100%;width:100%;border: 0 none" src="'+url+'"></iframe>';
  document.getElementById(target).style.visibility = "visible";
  document.getElementById(target).style.display = "block";
  }

function MX_BookInOverlay(url)
  {
  var theWidth, theHeight;
  // Window dimensions:
  if (window.innerWidth) {
  theWidth=window.innerWidth;
  }
  else if (document.documentElement && document.documentElement.clientWidth) {
  theWidth=document.documentElement.clientWidth;
  }
  else if (document.body) {
  theWidth=document.body.clientWidth;
  }
  if (window.innerHeight) {
  theHeight=window.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight) {
  theHeight=document.documentElement.clientHeight;
  }
  else if (document.body) {
  theHeight=document.body.clientHeight;
  }
  
  
  var ov = document.createElement('div');
  ov.id = 'mx_book_overlay';
  ov.style.position = 'fixed';
  ov.style.top = '0px';
  ov.style.left = '0px';
  ov.style.width = '100%';
  ov.style.height = '100%';
  ov.style.zoom = 1;
  ov.style.background = 'url(\'//www.blickinsbuch.de/gateway/img/alpha_black_50.png\')'
  ov.innerHTML = '<div style="height:100%; width:100%;"><div style="margin:'+theHeight*0.05+'px auto;width:'+theWidth*0.8+'px;height:'+theHeight*0.9+'px;background:#ccc;"><a style="display:block;float:right;height:30px;width:50px;background:url(\'//www.blickinsbuch.de/gateway/img/close.png\') no-repeat" href="javascript:MX_BookInOverlayClose()"></a><iframe id="mx_book_overlay_frame" frameborder="0" scrolling="auto" style="height:100%;width:100%;border: 0 none" src="'+url+'"></iframe></div></div>';
  document.getElementsByTagName('body')[0].appendChild(ov);
  }

function MX_BookInOverlayClose()
  {
  document.getElementById('mx_book_overlay_frame').src = 'about:blank';
  document.getElementsByTagName("body")[0].removeChild(document.getElementById('mx_book_overlay'));
  }

function MX_BookSlide(id, cnt_url, pages)
  {
  this.CheckDisplayedRange = function()
    {
    var ver=MX_getInternetExplorerVersion();
    if (document.documentMode<8) var compatMode=true;
    var end = this.activePage + 4;
    if (end > this.totalPages) end = this.totalPages;
    while (end > this.displayedTo)
      {
      var img = document.createElement('img');
      img.src = this.pages[this.displayedTo];
      img.style.border = '0 none';
      img.style.boxShadow = '0 -2px 4px 2px #ccc';
      img.style.cssFloat = 'none';
      img.style.MozOpacity = '1';
      img.style.margin = '0';
      img.style.padding='0';
      img.style.verticalAlign='top';
      var add = document.createElement('div');
      add.style.width = '220px';
      add.style.padding = '10px 0';
      add.style.textAlign = 'center';   
      add.style.display = 'inline-block';
      add.style.verticalAlign='top';
      if ( ver > -1 )
      {
        if ( ver<8.0 || compatMode ) 
        {
          add.style.display = 'inline';
          add.style.zoom='1';
        }
      }          
      add.appendChild(img);
      document.getElementById('MX_slider'+this.id).appendChild(add);
      this.displayedTo++;
      }
    }
  
  this.updatePageInfo = function()
    {
    document.getElementById('MX_display'+this.id).innerHTML = 'Seite '+(this.activePage+1)+' von '+this.totalPages;
    }
  
  this.leftClick = function()
    {
    if (this.inAnimation) return;
    if (this.activePage <= 0) return;
    this.activePage--;
    this.animeScroll(this.activePage*220);
    if (this.activePage <= 0) document.getElementById('MX_btn_left'+this.id).style.backgroundPosition='0px 0px';
    document.getElementById('MX_btn_right'+this.id).style.backgroundPosition='-58px -26px';
    this.updatePageInfo();
    }

  this.rightClick = function()
    {
    if (this.inAnimation) return;
    if (this.activePage >= this.totalPages-1) return;
    this.activePage++;
    this.animeScroll(this.activePage*220);
    if (this.activePage >= this.totalPages-1) document.getElementById('MX_btn_right'+this.id).style.backgroundPosition='-58px 0px';
    document.getElementById('MX_btn_left'+this.id).style.backgroundPosition='0px -26px';
    this.updatePageInfo();
    this.CheckDisplayedRange();
    if (!this.firstCount)
      {
      this.count('Next');
      this.firstCount = 1;
      }
    }
  
  this.animeScroll = function(dst)
    {
    var ofs = document.getElementById('MX_container'+this.id).scrollLeft;
    if (Math.abs(ofs - dst) < 25)
      {
      this.inAnimation = 0;
      document.getElementById('MX_container'+this.id).scrollLeft = dst;
      }
    else
      {
      this.inAnimation = 1;
      document.getElementById('MX_container'+this.id).scrollLeft += dst > ofs ? 50 : -50;
      var self = this;
      setTimeout(function() {self.animeScroll(dst)}, 75);
      }
    }
  
  this.count = function(type)
    {
    //var img = document.createElement('img');
    //img.src = this.cnt_url+type+"&l="+escape(window.location.href);
    }
  
  this.finalize = function()
    {
    if (!document.getElementById('MX_slider'+this.id))
      {
      var self = this;
      setTimeout(function() {self.finalize()}, 100);
      }
    else
      {
      this.CheckDisplayedRange();  
      document.getElementById('MX_container'+id).scrollLeft = 0;
      this.updatePageInfo();
      this.count('Load');
      }
    }

  this.id = id;
  this.cnt_url = cnt_url;
  this.pages = pages;
  this.totalPages = pages.length;
  this.activePage = 0;
  this.displayedTo = 0;
  this.inAnimation = 0;
  this.firstCount = 0;
  this.finalize();
  }
