var WindowObj=null;
function qwShowPJTPayouts(inctanceId)
{
    WindowObj = window.open("http://" + window.location.host + "/quiz/tournamentResults/giId/"+inctanceId,
    null,
    "resizable=no,scrollbars=yes,status=no, width=200, height=400");
}

if(!isWebsite) {
window.onload=function(){
if(!NiftyCheck())
    return;
	Rounded("div.rounded","all","#FFF","#f0f0e6","smooth");
	Rounded("div.bt_tournament","bl br","#fff321","#fff","smooth");
	Rounded("div.pjt_tournament","bl br","#14b6e7","#fff","smooth");
	Rounded("div.mp_tournament","bl br","#ffbf05","#fff","smooth");
	Rounded("div.it_tournament","bl br","#fd5e5b","#fff","smooth");
	Rounded("div.tournamentspanelfree","all","#dadad0","#fff","smooth");
};
}

function positionHPBlocks()
{return false;
    if($('lBlock') == null || $('rBlock') == null) {
        return;
    }
    var cntrHeight = $('lBlock').getHeight();
    var rghtHeight = $('rBlock').getHeight();
    if(cntrHeight >= rghtHeight) {
        var newHeight = cntrHeight -5;
        $('rBlock').setStyle({height: newHeight + 'px'});
    } else {
        var newHeight = rghtHeight - 5;
        $('lBlock').setStyle({height: newHeight + 'px'});
    }
}

document.observe( 'dom:loaded', function() {
    positionHPBlocks();
    resizeQuizBox();
});

function showProfile( playerId )
{
    if(isNaN(parseInt(playerId))) {
        return false;
    }
    blankWin = window.open('/player/view/id/' + playerId,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=yes,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
    return false;
}

/* set correct height to quiz boxes */
function resizeQuizBox()
{
    if(typeof(qcelltotal) == 'undefined') return;

    var origHeight = 0;
    for(var i = 1; i <= qcelltotal; i++) {
        if(i%2 != 0) {
            origHeight = $('qcell' + i).getHeight();
        }
        $('qcell' + i).setStyle(
            {
                height: origHeight + 'px'
            }
        );
    }
    // free projects
    if(null != $('qcellfree1') && null != $('qcellfree2')) {
        $('qcellfree1').setStyle({
            height: $('qcellfree1').getHeight() + 'px'
        });
        $('qcellfree2').setStyle({
            height: $('qcellfree1').getHeight() + 'px'
        });
    }
}

/* -------------------------------------------------- */
/**
 * Provides a simple interface for creating, retrieving and clearing cookies.
 */
CookieManager = Class.create();
CookieManager.prototype =
{
    BROWSER_IS_IE:
        (document.all
         && window.ActiveXObject
         && navigator.userAgent.toLowerCase().indexOf("msie") > -1
         && navigator.userAgent.toLowerCase().indexOf("opera") == -1),

    /**
     * I hate navigator string based browser detection too, but when Opera alone
     * chokes on cookies containing double quotes...
     */
    BROWSER_IS_OPERA:
        (navigator.userAgent.toLowerCase().indexOf("opera") != -1),

    initialize: function(options)
    {
        this.options =
        {
            shelfLife: 365,
            userData: false
        };//.extend(options || {});

        this.cookieShelfLife = this.options.shelfLife;
        this.userDataForIE = this.options.userData;

        // Internet Explorer has a cookie handling bug - if the *combined size*
        // of all cookies stored for a given domain is greater than 4096 bytes,
        // document.cookie will return an empty string. Until this is fixed, we
        // can fall back on IE's proprietary userData behaviour if necessary.
        if (this.BROWSER_IS_IE && this.userDataForIE)
        {
            this.IE_CACHE_NAME = "storage";
            if ($(this.IE_CACHE_NAME) == null)
            {
                var div = document.createElement("DIV");
                div.id = this.IE_CACHE_NAME;
                document.body.appendChild(div);
            }
            this.store = $(this.IE_CACHE_NAME);
            this.store.style.behavior = "url('#default#userData')";
        }
    },

    /**
     * Returns the value of a cookie with the given name, or <code>null</code>
     * if no such cookie exists.
     */
    getCookie: function(aCookieName)
    {
        var result = null;
        if (this.BROWSER_IS_IE && this.userDataForIE)
        {
            this.store.load(this.IE_CACHE_NAME);
            result = this.store.getAttribute(aCookieName);
        }
        else
        {
            for (var i = 0; i < document.cookie.split('; ').length; i++)
            {
                var crumb = document.cookie.split('; ')[i].split('=');
                if (crumb[0] == aCookieName && crumb[1] != null)
                {
                    result = crumb[1];
                    break;
                }
            }
        }

        if (this.BROWSER_IS_OPERA && result != null)
        {
            result = result.replace(/%22/g, '"');
        }
        return result;
    },

    /**
     * Sets a cookie with the given name and value.
     */
    setCookie: function(aCookieName, aCookieValue)
    {
        if (this.BROWSER_IS_IE && this.userDataForIE)
        {
            this.store.setAttribute(aCookieName, aCookieValue);
            this.store.save(this.IE_CACHE_NAME);
        }
        else
        {
            if (this.BROWSER_IS_OPERA)
            {
                aCookieValue = aCookieValue.replace(/"/g, "%22");
            }
            var date = new Date();
            date.setTime(date.getTime() + (this.cookieShelfLife * 24*60*60*1000));
            var expires = '; expires=' + date.toGMTString();
            document.cookie = aCookieName + '=' + aCookieValue + expires + '; path=/';
        }
    },

    /**
     * Clears the cookie with the given name.
     */
    clearCookie: function(aCookieName)
    {
        if (this.BROWSER_IS_IE && this.userDataForIE)
        {
            this.store.load(this.IE_CACHE_NAME);
            this.store.removeAttribute(aCookieName);
            this.store.save(this.IE_CACHE_NAME);
        }
        else
        {
            document.cookie =
                aCookieName + '=;expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
        }
    }
}
/* ----------------------------------------------- */

var objCookieMgr = new CookieManager({});




// sound controller
var Soundswitch = Class.create();
Soundswitch.prototype = {
	_cookieName: 'qwSndSwitch',
	_pictureNames: [ 'soundoff.png', 'soundon.png' ],
	_pictures: [],
	_currentState: 1,
	_container: null,

	_preloadPictures: function(picturesUrl)
	{
		for (var i = 0; i < this._pictureNames.length; i++) {
			var pictureName = this._pictureNames[i];

			var objImage = new Image();
			objImage.src = picturesUrl + '/' + pictureName;
			objImage.border = 0;
			objImage.width = 20;
			objImage.height = 19;
			objImage.onclick = this.toggleState.bind(this);

			this._pictures.push(objImage);

		};
	},

	initialize: function(divId, picturesUrl)
	{
		this._container = $( divId );
		if (this._container == null) {
			return;
		}

		this._preloadPictures(picturesUrl);

		// init current state
		//alert(objCookieMgr.getCookie(this._cookieName));
		//alert(objCookieMgr.getCookie("website"));
		if (objCookieMgr.getCookie(this._cookieName) == 0) {
			this._currentState = 0;
		}
		else {
			this._currentState = 1;
		}

		this.setState(this._currentState);
	},

	setState: function(newState)
	{
		this._currentState = newState;

		this._container.innerHTML = '';
		this._container.appendChild(this._pictures[newState]);

		// do not init cookie if default value - state=1 and no cookie is set now
		if (newState == 1 && objCookieMgr.getCookie(this._cookieName) == null) {
			return;
		}

		objCookieMgr.setCookie(this._cookieName, newState);
	},

	toggleState: function()
	{
		if (this._currentState == 0) {
			this.setState(1);
		}
		else {
			this.setState(0);
		}
	}
};




