function $(id)
{
    return document.getElementById(id);
}

function turn_left()
{
	$('s_center').style.left = parseInt($('s_center').style.left) + 40 + 'px';
}
function turn_right()
{
	$('s_center').style.left = parseInt($('s_center').style.left) - 40 + 'px';
}
function getDreamScore()
{
	$('main_boker_div').style.display = 'none';
	$('text_boker_div').style.display = 'none';
	$('boker_footer').style.display = 'none';
	$('boker_score_div').style.display = 'block';
	get_results_dream();
	RefreshMenuButtonPressed('dream');
}

function getSantaScore()
{
	$('main_boker_div').style.display = 'none';
	$('text_boker_div').style.display = 'none';
	$('boker_footer').style.display = 'none';
	$('boker_score_div').style.display = 'block';
	get_results_santa();
	RefreshMenuButtonPressed('santa');
}

function getBokerScore()
{
	$('main_boker_div').style.display = 'none';
	$('text_boker_div').style.display = 'none';
	$('boker_footer').style.display = 'none';
	$('boker_score_div').style.display = 'block';
	get_results_boker();
	RefreshMenuButtonPressed('jom');
}

function getBokerMain()
{
	$('main_boker_div').style.display = 'Block';
	$('text_boker_div').style.display = 'Block';
	$('boker_footer').style.display = 'block';
	$('boker_score_div').style.display = 'none';
	RefreshMenuButtonPressed('jom');
}

/**
 * Get element absolute position
 */
function getElementPosition(obj)
{
    var x = 0, y = 0;
    while(obj)
    {
        x += obj.offsetLeft;
        y += obj.offsetTop;
        if (document.all)
        {
            obj = obj.offsetParent;
        }
        else
        {
            break;
        }
    }
    return {x:x, y:y};
}

function RefreshMenuButtonPressed(name)
{
	var obj = document.getElementById('btn_'+name);
	var pos = getElementPosition(obj);
	var hlt = document.getElementById('hlt_'+name);
	hlt.style.left = pos.x - 2;
    hlt.style.top  = pos.y - 1;
}

function CreateMenuButtonPressed(name)
{
    var obj = document.createElement('div');
    obj.className = 'btn';
    obj.id = 'btn_'+name;
    obj.style.backgroundImage = 'url(../img/btn/' + name + '.png)';
    $('s_center').appendChild(obj);

    var frame = document.createElement('div');
    frame.className = 'pframe';
    frame.id = 'hlt_'+name;
    var pos = getElementPosition(obj);
    frame.style.left = pos.x - 2;
    frame.style.top  = pos.y - 1;
    $('s_center').appendChild(frame);
}

function highLightBigIcon(icon)
{
	
var pos = getElementPosition(icon);
var frame = $('btn_frame_big');

frame.style.left = pos.x - 2;
frame.style.top = pos.y - 1;
frame.style.display = 'block'
}

function freeHighLight()
{
	var frame = $('btn_frame_big');
	
	frame.style.display = 'none';
}

function CreateMenuSeparator(name, f)
{
    obj = document.createElement('a');
    obj.className = 'sep';
    obj.style.backgroundImage = 'url(../img/i_' + name + '.png)';
    if (f)
    {
        obj.style.marginLeft = '30px';
    }
    $('s_center').appendChild(obj);
}

function CreateMenuButton(name, hint_text)
{
    var obj = document.createElement('a');
    obj.className = 'btn';
    obj.style.backgroundImage = 'url(../img/btn/' + name + '.png)';
    obj.href = name  + '.html'; //== 'about' ? 'index.html' : name

    var hint = document.getElementById('hint');
    obj.onmouseover = function()
    {
        var pos = getElementPosition(obj);
        var frame = $('btn_frame');
        frame.setStyle({'left': parseInt(pos.x - 2)+"px"});
        frame.setStyle({'top' : parseInt(pos.y - 1) + "px"});
        frame.style.display = 'block';
        frame.onclick = function()
        {
            location.href = obj.href;
        }
		var left = parseInt(pos.x + document.width/2 - 250 + parseInt($('s_center').style.left)) + "px";
        hint.setStyle({'left': left});
        hint.setStyle({'top' : parseInt(pos.y + obj.offsetHeight) + "px"});
        hint.style.display = 'block';
        if (document.all)
        {
            hint.style.width = '200px';
        }
        $('hint_body').innerHTML = hint_text;
    }


    $('s_center').appendChild(obj);
}

function print_f(id)
{
    var str = '';
   if(typeof(id) == "object"){
	id.setStyle({'marginLeft': '100px'});
   
   }

   alert(id.getStyle('margin-left'));
}


function getHint(event,id)
{
 	x = event.screenX;
 	
 	y = event.screenY;
 	var hint = $('hint');
 	hint.style.left = x;
    hint.style.top = y - 60;
    hint.style.display = 'block';
    
     var req = getXmlHttpRequest();
	 req.onreadystatechange = function()
	{
		 if (req.readyState != 4) return;
		dataAll = JSON.parse(req.responseText);
		data = dataAll.levels;
		text = "";
		for (i=0;i<data.length;i++)
		{
			text +=data[i].level+":  "+data[i].score+"<br>";
		}
		j=0;
		bad = dataAll.badges;
		if (bad.badge1 == '1')
		{
			text += "<img border=0 src=\"../img/boker/top10.png\"/>";
			j++;
		}
		if (bad.badge2 == '1')
		{
			text += "<img border=0 src=\"../img/boker/top50.png\"/>";
			j++;
		}
		if (bad.badge3 == '1')
		{
			text += "<img border=0 src=\"../img/boker/top100.png\" />";
			j++;
		}
		if (j>2)
		{
			text +="<br>";
			j=0;
		}
		if (bad.badge4 == '1')
		{
			text += "<img border=0 src=\"../img/boker/all_cleared.png\" />";
			j++;
		}
		if (j>2)
		{
			text +="<br>";
			j=0;
		}
		if (bad.badge5 == '1')
		{
			text += "<img border=0 src=\"../img/boker/10_min_survived.png\" />";
			j++;
		}
		if (j>2)
		{
			text +="<br>";
			j=0;
		}
		if (bad.badge6 == '1')
		{
			text += "<img border=0 src=\"../img/boker/3000_jumps.png\" />";
			j++;
		}
		if (j>2)
		{
			text +="<br>";
			j=0;
		}
		if (bad.badge7 == '1')
		{
			text += "<img border=0 src=\"../img/boker/1000_sec_stunts.png\" />";
			j++;
		}
		if (j>2)
		{
			text +="<br>";
			j=0;
		}
		if (bad.badge8 == '1')
		{
			text += "<img border=0 src=\"../img/boker/unlock_all.png\" />";
			j++;
		}
		if (j>2)
		{
			text +="<br>";
			j=0;
		}
		if (bad.badge9 == '1')
		{
			text += "<img border=0 src=\"../img/boker/1000_stunts.png\" />";
			j++;
		}
		if (j>2)
		{
			text +="<br>";
			j=0;
		}
		if (bad.badge10 == '1')
		{
			text += "<img border=0 src=\"../img/boker/50_falls.png\" />";
			j++;
		}
		if (j>2)
		{
			text +="<br>";
			j=0;
		}
		if (bad.badge11 == '1')
		{
			text += "<img border=0 src=\"../img/boker/100_falls.png\" />";
			j++;
		}
		if (j>2)
		{
			text +="<br>";
			j=0;
		}
		if (bad.badge12 == '1')
		{
			text += "<img border=0 src=\"../img/boker/100_min_action.png\" />";
			j++;
		}
		
		$('hint_body').innerHTML = text;
		 
	 }
	 req.open("GET", "../table_model.php?gamename=ibocker_1.0&action=level&pos="+id, true);
	 req.send(null);
}

function freeHint()
{
	 $('hint').style.display = 'none';
}

window.onload = function()
{
    var frame = $('btn_frame');
    frame.onmouseout = function()
    {
        frame.style.display = 'none';
        $('hint').style.display = 'none';
    }

    var link = $('dw_link');
    var hint = $('hint');

    link.onmouseover = function()
    {
        var pos = getElementPosition(link);
       
        hint.style.left = pos.x;
        hint.style.top = pos.y - 60;
        if (document.all)
        {
            hint.style.width = '300px';
        }
        hint.style.display = 'block';
        $('hint_body').innerHTML = DWLinkText;
    }

    link.onmouseout = function()
    {
        hint.style.display = 'none';
    }

    if (postLoad)
    {
        postLoad();
    }
}

