<!--
/* vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2 filetype=javascript: */
/* SVN: $Id:$ */
var AdInformation = [];
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);
}
-->

