function getHeaderDistance () {

	var header = document.getElementById('header')

	var content = document.getElementById('content-box-border')

	return content.offsetTop - ( header.offsetTop + header.offsetHeight )	


}

function setPosition () {

	var distance = getHeaderDistance()

	if ( document.body.className.indexOf('game') != -1  && distance <= 234 )  {

	document.body.style.backgroundPosition = '50% '+(-234+distance)+'px'

	}
	
}

window.onload = function(){

	return setPosition ()

}

function centerBox(box) {

	var themesBox = document.getElementById(box); 
	
	themesBox.style.display = 'block'; 
	
	if(document.all){
		var doc = document.documentElement ? document.documentElement : document;
		
		/*var doc;
		if(document.documentElement){
			doc = document.documentElement;
		}
		else {
			doc = document;
		}*/

		
		themesBox.style.left = ''+((document.body.offsetWidth-themesBox.offsetWidth)/2 + doc.scrollLeft)+'px'; 
		themesBox.style.top = ''+((doc.clientHeight-themesBox.offsetHeight)/2 + doc.scrollTop)+'px';
		
	}else {
	
		themesBox.style.left = ''+((document.body.offsetWidth-themesBox.offsetWidth)/2 + window.scrollX)+'px'; 
		themesBox.style.top = ''+((window.innerHeight-themesBox.offsetHeight)/2 + window.scrollY)+'px';
		
	}

}

function objectDebug(obj,val){
	var ctr = 0;
	for(var i in obj){
		if(!val || i.indexOf(val) != -1){
			ctr++;
			if(!confirm(i+" :: "+obj[i])) break;
		}
	}
	return ctr;
}

$(document).ready(function() {

    $('#themesBox li a').live('click', function(e) {
        e.preventDefault();
        $('#themesBox li').removeClass('active');
        $(this).parent().addClass('active');
        $('body').attr('class', $(this).attr('name'));
    });

    $('#themesBox a.save-theme').live('click', function(e) {
        e.preventDefault();
        var a = $('#themesBox li.active a');
        $.post('/ajax/set-profile-theme/', {theme: a.attr('name')},
            function(data){
                if (parseInt(data)) {
                    $('#themesBox').hide();
                    var new_theme = a.find('img').eq(0).clone();
                    $('#active-theme img').replaceWith(new_theme);
                    $('#active-theme span').text(new_theme.attr('alt'));
                }
        });
    });
});
