var d=document;
var w=window;
var ua=navigator.userAgent.toLowerCase();
var thm;

/* at cc_on - prevent flickering (disabled)
document.execCommand("BackgroundImageCache", false ,true);
at */

function getESrc(e){if (!e) e = w.event;return (e.originalTarget) ? e.originalTarget : e.srcElement;}

function redir() {
	if ( (ua.indexOf('windows ce') != -1 || ua.indexOf('avantgo') != -1 || ua.indexOf('symbian') != -1)
       && location.search != '?force') location.replace('/mobile/');
}

function preview() {
  w.open('/plug/preview.html', '_blank', 'scrollbars=no, width=260, height=370');
}

function spamArmor() {
	if ( (elo=d.getElementById('eml-lo')) && (ecy=d.getElementById('eml-cy')) )
	elo.onclick=ecy.onclick=function (e) {var t = getESrc(e);w.location=t.getAttribute('href').replace(/spam-kiss-my-/,'followthe');return false;}
}
function cssfix() {
	if (ua.indexOf('msie') == -1)
    d.getElementById('sss').style.backgroundColor = 'transparent';
}
function listbox() {
	var i,s;
	for (i=0; s=((d.getElementsByTagName) ? d.getElementsByTagName('select') : d.all.tags('select'))[i]; i++){
		s.onchange = listonchange;
	}
}
function listonchange(e) {
    var s = getESrc(e);
    var v = s.options[s.selectedIndex].value;
    if (v) {
	    if (v == "/series/" || v.indexOf('http://') != -1) w.location=v;//location.replace(v);
	    else w.location="/s/"+v;
    }
}

function p(b) {
var btn = d.getElementById(b);
var l = 'pop-'+b;
if (!l) return;
btn.onmouseover = function (){d.getElementById(l).style.display='block'};
btn.onmouseout = function (){d.getElementById(l).style.display='none'};
}
function initpad() {
p('pedia');
p('credits');
p('links');
p('bonus');
p('series');
p('forum');
if (ua.indexOf('msie') != -1) p('sss');
}

function attach(f) {
	var ol = w.onload;
	if (typeof w.onload != 'function') w.onload = f;
	else w.onload = function() {ol(); f();}
}

var biscotto = {
cn : 'rabbitstyle',
dys: 128,
rnd: false,
set : function (v,dy,p,dmn) {
  if (dy > 0) {
    var dt = new Date();
    dt.setTime(dt.getTime()+(dy*24*60*60*1000));
    ex = dt.toGMTString();
  } else { ex = 'Thu, 01-Jan-1970 00:00:01 GMT' }
  try {
	d.cookie = this.cn+"="+escape(v) +
		(ex ? ";expires="+ex : "") +
		(p ? ";path="+p : "") +
		(dmn ? ";domain="+dmn : "");
  } catch(e) {}
},
get : function () {
  var nameEQ = this.cn + '=';
  var ca = d.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return unescape( c.substring(nameEQ.length,c.length) );
  }
  return null;
},
del : function() { this.set('',0,"/","therabbit.it") }
}

// Ispirato da http://alistapart.com
function sas(t) {
  var chk = false;
	for (i=0; i<thm.length && (x=thm[i]); i++) {
		if ( x.getAttribute('rel').indexOf('style') != -1 && x.getAttribute('title') ) {
			x.disabled = true;
			if (x.getAttribute('title') == t) {
        x.disabled = false;
        chk = true;
      }
		}
	}
	if (!chk) thm[gpi()].disabled = false;
}
function srs() {
	var r = thm[Math.floor(Math.random()*thm.length)].getAttribute('title');
	if (r) {sas(r); biscotto.rnd = true;}
}
function gas() {
	for(i=0; (x=thm[i]); i++) {
		if ( x.getAttribute('rel').indexOf('style') != -1 && x.getAttribute('title') && !x.disabled ) 
			return x.getAttribute('title');
	}
	return null;
}
function gpi() {
  for (i=0; (x=thm[i]); i++) {
    if (x.getAttribute('rel').indexOf('style') != -1 && x.getAttribute('rel').indexOf('alt') == -1 && x.getAttribute('title') )
        return i;
  }
  return null;
}

function sss() {
	thm = ((d.getElementsByTagName) ? d.getElementsByTagName('link') : d.all.tags('link'));
	var cv = biscotto.get();
	if (cv) sas(cv);
}

function AA55() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	cssfix();
	listbox();
	redir();
	/*sss();
	initpad();*/
	spamArmor();
}

// Ispirato da http://dean.edwards.name
if (d.addEventListener) {d.addEventListener("DOMContentLoaded", AA55, null);w.onunload = function(){if (biscotto.rnd) biscotto.del(); else biscotto.set(gas(), biscotto.dys, '/', 'therabbit.it')}}
/*@cc_on @*/
/*@if (@_win32)
	d.write("<script defer>AA55();w.onunload = function(){if (biscotto.rnd) biscotto.del(); else biscotto.set(gas(), biscotto.dys, '/', 'therabbit.it')}<"+"/script>");
/*@end @*/


attach(AA55);attach(listbox);
//w.onunload = function(){if (biscotto.rnd) biscotto.del(); else biscotto.set(gas(), biscotto.dys, '/', 'therabbit.it')}
