<!--
/* vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2 filetype=javascript: */
/* SVN: $Id:$ */
var AdInformation = {"TXT":[{"SpacePath_id":"349","prefix":"<div class=\"prBlock\"><ul>","suffix":"<\/ul><\/div>","pos":"TXT","height":"0","width":"0","start":"1270652400","end":"1281106800","priority":"0","comment":"\u597d\u8a55\u306b\u3064\u304d\u91cd\u7248\uff01\u66f8\u5f0f\u3068\u5224\u4f8b\u306e\u8c4a\u5bcc\u306a\u907a\u8a00\u57f7\u884c\u306e\u300c\u624b\u5f15\u66f8\u300d\u3002\u5fc5\u8981\u306a\u77e5\u8b58\u3068\u5b9f\u52d9\u3092\u7db2\u7f85\u3002","url":"http:\/\/www.kajo.co.jp\/book\/40386000001.html","AdEntity_id":"1659","extension":"","AdPosition_id":"193","AdSchedule_id":"1952"}]};
var AdsRedirect = '/redirect/id/';
var AdsServer = 'http://ads.authense.co.jp';

// fake link
function FixFakeLink()
{
  this.href = this.ad.url;
}

function FakeLink()
{
  this.href = AdsServer + AdsRedirect + this.ad.AdSchedule_id;
  if (this.callback) {
    this.callback(this.ad.url);
  }
  this.onmouseout = FixFakeLink;
}

function SetFakeLink(ad, callback, id)
{
  var obj = document.getElementById('authense_ad_system_'+ id);
  obj.ad = ad;
  obj.callback = callback;
  obj.onclick = FakeLink;
}

/**
 * ad insert function.
 *
 * @param pos position name
 * @param callback callback function; you can call your own process
 * @param delim image ad delimter
 * @return void
 */
function adInsert(pos, callback, delim)
{
  // body
  var ad = eval("AdInformation."+ pos);

  if (!ad) {
    return;
  }

  document.write(ad[0].prefix);
  //--------------------------------------
  //
  // Image Advertisement
  //
  //--------------------------------------
  if (ad[0].height >0 && ad[0].width>0) {
    for (var i=0; i<ad.length; i++) {
      //--------------------------------------
      //
      // FLASH Advertisement
      //
      //--------------------------------------
      if (ad[i].extension == 'swf' || ad[i].extension == 'swc') {
        document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ ad[i].width +'" height="'+ ad[i].height +'">');
        document.write('<param name="movie" value="/admedia/'+ ad[i].SpacePath_id +'/'+ ad[i].AdPosition_id +'/'+ ad[i].AdEntity_id +'/'+ ad[i].AdSchedule_id +'.'+ ad[i].extension +'" />');
        document.write('<param name="FlashVars" value="clickTAG='+ AdsServer + AdsRedirect + ad[i].AdSchedule_id +'" />');
        document.write('<!--[if !IE]>-->');
        document.write('<object type="application/x-shockwave-flash" data="/admedia/'+ ad[i].SpacePath_id +'/'+ ad[i].AdPosition_id +'/'+ ad[i].AdEntity_id +'/'+ ad[i].AdSchedule_id +'.'+ ad[i].extension +'" width="'+ ad[i].width +'" height="'+ ad[i].height +'">');
        document.write('<!--<![endif]-->');
        document.write('<param name="FlashVars" value="clickTAG='+ AdsServer + AdsRedirect + ad[i].AdSchedule_id +'" />');
        document.write('<!--[if !IE]>-->');
        document.write('</object>');
        document.write('<!--<![endif]-->');
        document.write('</object>');
      //--------------------------------------
      //
      // Advertisement with Title 
      //
      //--------------------------------------
      } else if (ad[0].pos == 'TAD') {
        document.write('<div class="ad-item">');

        // image
        document.write('<a class="ad-thumb" id="authense_ad_system_'+ ad[i].AdSchedule_id +'_image" href="'+ ad[i].url + '" target="_blank">');
        document.write('<img border="0" height="'+ ad[i].height +'" width="'+ ad[i].width +'" src="/admedia/'+ ad[i].SpacePath_id +'/'+ ad[i].AdPosition_id +'/'+ ad[i].AdEntity_id +'/'+ ad[i].AdSchedule_id +'.'+ ad[i].extension +'">');
        document.write('</a>');
        SetFakeLink(ad[i], callback, ad[i].AdSchedule_id +'_image');

        // title
        title = ad[i].comment.split('\r\n');
        if (title[0] != '') {
          document.write('<a class="ad-title" id="authense_ad_system_'+ ad[i].AdSchedule_id +'_title" href="'+ ad[i].url + '" target="_blank">');
          document.write(title[0]);
          document.write('</a>');
          SetFakeLink(ad[i], callback, ad[i].AdSchedule_id +'_title');
        }
        
        // body
        body = ad[i].comment.split('\r\n');
        if (body[1] != '') {
          document.write('<a class="ad-note" id="authense_ad_system_'+ ad[i].AdSchedule_id +'_body" href="'+ ad[i].url + '" target="_blank">');
          document.write(body[1]);
          document.write('</a>');
          SetFakeLink(ad[i], callback, ad[i].AdSchedule_id +'_body');
        }

        document.write('</div>');
      //--------------------------------------
      //
      // Advertisement
      //
      //--------------------------------------
      } else {
        if (ad[i].url) {
          // if fake link causes trouble, use bellow code. it's simple.
          //document.write('<a id="authense_ad_system_'+ ad[i].AdSchedule_id +'" href="'+ AdsServer + AdsRedirect + ad[i].AdSchedule_id + '" target="_blank">');
          document.write('<a id="authense_ad_system_'+ ad[i].AdSchedule_id +'" href="'+ ad[i].url + '" target="_blank">');
        }

        document.write('<img border="0" height="'+ ad[i].height +'" width="'+ ad[i].width +'" src="/admedia/'+ ad[i].SpacePath_id +'/'+ ad[i].AdPosition_id +'/'+ ad[i].AdEntity_id +'/'+ ad[i].AdSchedule_id +'.'+ ad[i].extension +'">');
        if (ad[i].comment) {
          document.write('<br>');
          document.write(ad[i].comment);
        }

        if (ad[i].url) {
          document.write('</a>');
          SetFakeLink(ad[i], callback, ad[i].AdSchedule_id);
        }
      }
      if (delim) document.write(delim);
    }
  } else {
    //--------------------------------------
    //
    // TEXT Advertisement
    //
    //--------------------------------------
    for (var i=0; i<ad.length; i++) {
      document.write('<li>');

      if (ad[i].url) {
        // if fake link causes trouble, use bellow code. it's simple.
        //document.write('<a id=":uthense_ad_system_'+ ad[i].AdSchedule_id +'" href="'+ AdsServer + AdsRedirect + ad[i].AdSchedule_id + '" target="_blank">');
        document.write('<a id="authense_ad_system_'+ ad[i].AdSchedule_id +'" href="'+ ad[i].url + '" target="_blank">');
      }

      document.write(ad[i].comment);

      if (ad[i].url) {
        document.write('</a>');
        SetFakeLink(ad[i], callback, ad[i].AdSchedule_id);
      }
      document.write('</li>');
    }
  }
  document.write(ad[0].suffix);
}
-->
