var toonpool = {};
//user-config
toonpool.c = {};
//iframe
toonpool.i = {};
toonpool.i.src = 'http://www.toonpool.com/misc/plugins/toonpool_gadget.php';
toonpool.i.id = 'toonpoolIframe';
toonpool.i.height = 190;
toonpool.i.width = 120;
toonpool.i['border-width'] = '0';
toonpool.i['border-color'] = '#46415c';
toonpool.i['border-style'] = 'none';

toonpool.i.write = function() {
  var d = "";
  d += "<iframe ";
  d += "frameborder='0' ";//IE sucks
  d += "allowtransparency='true' ";//IE sucks
  d += "framespacing='0'";//IE6 sucks
  d += "id="+toonpool.i.id+" ";
  d += "style='height:"+toonpool.i.height+"px; width:"+toonpool.i.width+"px;border-width:"+toonpool.i['border-width']+"px;border-color:"+toonpool.i['border-color']+";border-style:"+toonpool.i['border-style']+";' ";
  d += "src='"+toonpool.i.src+toonpool.i.createQuery()+"'";
  d += "</iframe>";
  return d;
};

toonpool.i.createQuery = function() {
  var q = [];
  for (var v in toonpool.c) {
    q.push(v+'='+encodeURIComponent(toonpool.c[v]));
  }
  return q.length == 0 ? '' : '?'+q.join('&');
};

//Slideshow
toonpool.s = {};
toonpool.s.timer = null;
toonpool.s.speed = 8000;
toonpool.s.slide = true;
toonpool.s.preloaded = null;
toonpool.s.pics = [];
toonpool.s.h = 130;
toonpool.s.w = 100;
toonpool.s.fullsize = false;

toonpool.s.printLogo = function() {
  var t = Math.floor((toonpool.s.h - 90) / 2 + 10)+'px';
  var l = Math.floor((toonpool.s.w - 74) / 2 + 10)+'px';
  document.getElementById('imageHolder').innerHTML = "<a class='a_img' href='http://www.toonpool.com/' onclick='window.open(this.href); return false;'><img style='position:relative; border:none; top:"+t+"; left:"+l+";' src='http://www.toonpool.com/misc/pics/general/gadgetloader.gif' alt='toonpool.com' /></a>";
};

toonpool.s.preload = function() {
  var tp = toonpool;
  if (tp.s.pics.length == 0) {
    tp.s.preloaded = null;
    return;
  }
  var p = tp.s.pics.shift();
  var nA = document.createElement('a');
  nA.setAttribute('href',p.href);
  nA.setAttribute('class','a_img');
  nA.setAttribute('onclick','window.open(this.href); return false;');
  var nIMG = document.createElement('img');
  var r = 1;
  if (toonpool.s.fullsize) {
    r = Math.max(Math.max(p.height/500,p.width/500),1);
  }
  var t = Math.floor((toonpool.s.h - p.height/r) / 2 + 10)+'px';
  var l = Math.floor((toonpool.s.w - p.width/r) / 2 + 10)+'px';
  nIMG.setAttribute('style','position:relative; border:none; top:'+t+'; left:'+l);
  if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {//IE sucks
    nA.setAttribute('className','a_img');
    nA.onclick = function() {window.open(this.href); return false;};
    nIMG.style.setAttribute('cssText', 'position:relative; border:none; top:'+t+'; left:'+l);
  }
  nIMG.setAttribute('src',p.src);
  nIMG.setAttribute('title',p.title);
  nIMG.setAttribute('alt',p.title);
  nA.appendChild(nIMG);
  tp.s.preloaded = nA;
};

toonpool.s.init = function() {
  toonpool.s.printLogo();
  toonpool.s.preload();
  if (!toonpool.s.slide) {
    toonpool.s.timer = window.setTimeout(function(){document.getElementById('imageHolder').innerHTML = '';document.getElementById('imageHolder').appendChild(toonpool.s.preloaded);},(toonpool.s.speed / 2 ));
    return;
  }
  toonpool.s.timer = window.setTimeout(toonpool.s.showThumb,(toonpool.s.speed / 2 ));
};

toonpool.s.showThumb = function() {
  if (toonpool.s.preloaded == null) {
    return;
  }
  document.getElementById('imageHolder').innerHTML = '';
  document.getElementById('imageHolder').appendChild(toonpool.s.preloaded);
  toonpool.s.preload();
  if (toonpool.s.preloaded != null) {
    toonpool.s.timer = window.setTimeout(toonpool.s.showThumb,toonpool.s.speed);
  } else {
    toonpool.s.timer = window.setTimeout(function(){window.location.reload();},toonpool.s.speed);
  }
};