function $(id) {
  return document.getElementById(id);
}

function base64_decode( data ) {   
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = ac = 0, dec = "", tmp_arr = [];

    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));

        bits = h1<<18 | h2<<12 | h3<<6 | h4;

        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;

        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);
    
    dec = tmp_arr.join('');  
    return dec;
}

function do_open(s) {
    res = base64_decode(s);
    w = 800;
    h = 600;
    l = (screen.availWidth-10 - w) / 2;
    t = (screen.availHeight-20 - h) / 2;
    window.open(res,'','left='+l+' ,top='+t+' ,width=' + w + ',height=' + h + ', scrollbars=no, toolbar=no, menubar=no');
}


function hide_more_adsense() {
 conts = document.getElementsByTagName('div');
 adsense_count = 0;
 for (i=0; i<conts.length; ++i) {
   if (conts[i].id == 'adsense_container') {
     ++adsense_count;
     if (adsense_count>3) conts[i].style.display = 'none';
   }
 }
}

function handleErrorFn() { 
	//top.location=window.location.href; 
}
window.onerror = handleErrorFn;
if (top.location.href != window.location.href) {
	top.location = window.location.href;
}

function show_trailer(u) {
	url = base64_decode(u);
	var s1 = new SWFObject("http://wowheaded.com/sb/vid/mediaplayer.swf","mediaplayer","300","224","7");  
	s1.addParam("allowfullscreen","false");  
	s1.addVariable("width","300");  
	s1.addVariable("height","224");  
	s1.addVariable("file",url);  
	s1.addVariable("image","http://www.wowheaded.com/sb/i/game-trailer.png");  
	s1.write("my_video_container"); 
}


//**** splash ***//
var splashw_delta;
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if (version == 6) {
	splashw_delta = 20;
} else {
	splashw_delta = 15; 	
}
 
var timer_id = 0;
var splash_h = 0;

function set_pos() {
	win_height = 0;
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	var dsoctop=document.all? iebody.scrollTop : pageYOffset;
	if (typeof window.innerWidth != 'undefined') {
		win_height = window.innerHeight;
	} else {
		win_height = document.documentElement.clientHeight;
	}		
	mytop = Math.round((win_height-splash_h)/2+dsoctop);
	$('splash_contents').style.top = mytop+'px';		
}

function pos_splash(w,h) {		
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	var dsoctop=document.all? iebody.scrollTop : pageYOffset;
	win_height = 0;
	w = w + splashw_delta;
  $('splash_contents').style.width = w+'px';
  $('splash_contents').style.height = h+'px';  

	
  if (typeof window.innerWidth != 'undefined') {
		win_height = window.innerHeight;
	} else {
		win_height = document.documentElement.clientHeight;
	}		
		viewportheight = win_height;
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}		
	$("splash").style.height = blanket_height+'px';
	mytop = Math.round((win_height-h)/2+dsoctop);
  $('splash_contents').style.top = mytop+'px';

	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}	  	
	myleft = Math.round((window_width-w)/2);
  $('splash_contents').style.left = myleft+'px';
  splash_h = h;
  
}
	
	
function close_splash() {
  clearInterval(timer_id);
  $("splash").style.display = "none";
  $("splash_contents").style.display = "none";
 	$('splash_head2').style.backgroundImage = 'url()';
  
  var c = document.getElementById('splash_body');
  c.childNodes[0].style.display = 'none';
	$('splash_keeper').appendChild(c.childNodes[0]);
}

function show_splash(div_id, w, h) {
 if ($(div_id+'_title') != undefined) {
 	$('splash_head2').style.backgroundImage = 'url('+$(div_id+'_title').src+')';
 }
 $(div_id).style.width = w+'px';  
 $(div_id).style.height = h+'px';  
 $('splash_body').appendChild($(div_id));
  
  pos_splash(w,h);
  $('splash_contents').style.display = 'block';
  $('splash').style.display = 'block';
  $(div_id).style.display = 'block';
  
  timer_id = setInterval('set_pos()', 100);
}  
/** shots **/
var scr_url = '';
function show_screen(url_screen) {
	$('loading_gif').style.display = 'block';
	$('screen_place').style.display = 'none';
	$('err_report').style.display = 'none';
	show_splash('splash_loading', 640, 480);
	
	scr_url = url_screen;
	scrImage = new Image(); 
	scrImage.onload = screen_loaded;
	scrImage.onerror = loadFailure;
	scrImage.src = url_screen;
}

function screen_loaded() {
	$('loading_gif').style.display = 'none';
	$('err_report').style.display = 'none';
	$('screen_place').src = scr_url;
	$('screen_place').style.display = 'block';	
}
function loadFailure() {
	$('loading_gif').style.display = 'none';
	$('err_report').style.display = 'block';
}
/** video**/
function watch_trailer(u) {
	url = base64_decode(u);
	var s1 = new SWFObject("http://wowheaded.com/sb/vid/mediaplayer.swf","mediaplayer","300","224","7");  
	s1.addParam("allowfullscreen","false");  
	s1.addVariable("width","300");  
	s1.addVariable("height","224");  
	s1.addVariable("file",url);  
	s1.addVariable("image","http://www.wowheaded.com/sb/i/game-trailer.png");
	s1.write("trailer_video_container");
	show_splash('splash_video', 300, 220);
}