jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

            

(function ($) {
    var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        s = {
            'array': function (x) {
                var a = ['['], b, f, i, l = x.length, v;
                for (i = 0; i < l; i += 1) {
                    v = x[i];
                    f = s[typeof v];
                    if (f) {
                        v = f(v);
                        if (typeof v == 'string') {
                            if (b) {
                                a[a.length] = ',';
                            }
                            a[a.length] = v;
                            b = true;
                        }
                    }
                }
                a[a.length] = ']';
                return a.join('');
            },
            'boolean': function (x) {
                return String(x);
            },
            'null': function (x) {
                return "null";
            },
            'number': function (x) {
                return isFinite(x) ? String(x) : 'null';
            },
            'object': function (x) {
                if (x) {
                    if (x instanceof Array) {
                        return s.array(x);
                    }
                    var a = ['{'], b, f, i, v;
                    for (i in x) {
                        v = x[i];
                        f = s[typeof v];
                        if (f) {
                            v = f(v);
                            if (typeof v == 'string') {
                                if (b) {
                                    a[a.length] = ',';
                                }
                                a.push(s.string(i), ':', v);
                                b = true;
                            }
                        }
                    }
                    a[a.length] = '}';
                    return a.join('');
                }
                return 'null';
            },
            'string': function (x) {
                if (/["\\\x00-\x1f]/.test(x)) {
                    x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                        var c = m[b];
                        if (c) {
                            return c;
                        }
                        c = b.charCodeAt();
                        return '\\u00' +
                            Math.floor(c / 16).toString(16) +
                            (c % 16).toString(16);
                    });
                }
                return '"' + x + '"';
            }
        };


	$.toJSON = function(v) {
		var f = isNaN(v) ? s[typeof v] : s['number'];
		if (f) return f(v);
	};
	
	$.parseJSON = function(v, safe) {
		if (safe === undefined) safe = $.parseJSON.safe;
		if (safe && !/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))
			return undefined;
		return eval('('+v+')');
	};
	$.parseJSON.safe = false;
    })(jQuery);


        var blankSrc = "/content/images/blank.gif";
        var realSrc = null;

        function fixImage(element) {
           var src = element.src;
           if (src == realSrc) {
              element.src = blankSrc;
              return;
           }
           if ( ! new RegExp(blankSrc).test(src)) {
              realSrc = src;
           }
           if ( /\.png$/.test( realSrc.toLowerCase())) {
              element.src = blankSrc;
              element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
                                             src + "',sizingMethod='scale')";
           } else {
              element.runtimeStyle.filter = "";
           }
        }

        var image = new Image();
        var dump = "";
        image.src = "/content/images/nq/logo.gif";
        if(image.width == 0) {
            
        }
      function SetValAc(data, text) {jQuery('#accepted_'+data.game_id).html(data.data).css("display","");jQuery('#link_accepted_'+data.game_id).hide();}
      function SetValAs(data, text) {jQuery('#assigned_'+data.game_id).html(data.data).css("display","");jQuery('#link_assigned_'+data.game_id).hide();}


	var CGame = function(id)
	{
		this.gstatElement = document.getElementById('gstat_' + id);
		this.gstElement = document.getElementById('gst_' + id);
		this.sttimeElement = document.getElementById('st_time_' + id);
		this.remasElement = document.getElementById('rem_as_' + id);
		this.hoursElement = document.getElementById('hours_' + id);
		this.minutesElement = document.getElementById('min_' + id);
		this.secondsElement = document.getElementById('sec_' + id);
		this.hours = 0;
		this.minutes = 0;
		this.seconds = 0;
	};
	CGame.prototype = {
		lastDigit: function(digit)
		{
			var strDigit = digit + "";
			return strDigit.substr(strDigit.length-1,strDigit.length);
		},
	
		formatTimePart: function(val, variants)
		{
			var strRet = "";
			if(val > 0)
			{
				strRet += val + " ";
				var lastDig = this.lastDigit(val);
				if(val > 9 && val < 20)
				{
					strRet += variants[0];
				}
				else if(lastDig == 0 && (val > 19 || val == 10))
				{
					strRet += variants[0];
				}
				else if(lastDig == 1)
				{
					strRet += variants[1];
				}
				else if(lastDig > 1 && lastDig < 4)
				{
					strRet += variants[2];
				}
				else
				{
					strRet += variants[0];
				}
			}
		
			return strRet;
		},
	
		checkTime: function()
		{
			if (this.hoursElement)
			{
				this.hoursElement.innerHTML = this.formatTimePart(this.hours,this.hourVariants);
			}
			if (this.minutesElement)
			{
				this.minutesElement.innerHTML = this.formatTimePart(this.minutes,this.minuteVariants);
			}
			if (this.secondsElement)
			{
				var strSeconds = this.formatTimePart(this.seconds,this.secondsVariants);
				if ("" == strSeconds)
				{
					strSeconds = "ровно";
				}
				this.secondsElement.innerHTML = strSeconds;
			}
		},
	
		displayTime: function()
		{
			if (this.seconds <= 0 && this.minutes == 0 && this.hours == 0)
			{
				if (this.gstatElement)	this.gstatElement.style.display = '';
				if (this.gstElement)	this.gstElement.style.display = '';
				if (this.sttimeElement)	this.sttimeElement.style.display = 'none';
				if (this.remasElement)	this.remasElement.style.display = '';
			}
			else
			{
				if(this.seconds > 0)
				{
					this.seconds--;
				}
				else if (this.minutes > 0)
				{
					this.minutes--; this.seconds = 59;
				}
				else if(this.hours > -1)
				{
					this.hours--; this.minutes = 59; this.seconds = 59;
				}
				else
				{
					this.minutes = 0; this.seconds = 59;
				}
				this.checkTime();
			}
		},
	
		hourVariants: new Array("часов","час","часа"),
		minuteVariants: new Array("минут","минута","минуты"),
		secondsVariants: new Array("секунд","секунда","секунды")
	};

	var CGames = function(){};
	CGames.prototype = {
		addGame: function(id)
		{
			this.m_games[id] = new CGame(id);
			return this.m_games[id];
		},
	
		displayTime: function()
		{
			for (var gameid in this.m_games)
			{
				var game = this.m_games[gameid];
				game.displayTime();
			}
			setTimeout(g_displayTime,1000);
		},
	
		m_games: new Array()
	};

	var g_gameTimes = new CGames();

	function g_displayTime()
	{
		g_gameTimes.displayTime();
	}

$.fn.ToolTipDemo = function(bgcolour, fgcolour){
	this.mouseover(
		function(e)
		{
			if((!this.title && !this.alt) && !this.tooltipset) return;
			var mouseX = e.pageX || (e.clientX ? e.clientX + document.body.scrollLeft : 0);
			var mouseY = e.pageY || (e.clientY ? e.clientY + document.body.scrollTop : 0);
			mouseX += 10;
			mouseY += 10;
			bgcolour = bgcolour || "#eee";
			fgcolour = fgcolour || "#000";
			if(!this.tooltipdiv)
			{
				var div = document.createElement("div");
				this.tooltipdiv = div;
				$(div).css(
				{
					border: "1px solid #333",
					backgroundColor: "#000",
					padding: "0px 2px",
					color: "#eee",
					fontFamily: "Verdana",
					fontSize: "10px",
					position: "absolute"
				})
				.html((this.title || this.alt));
				this.title = "";
				this.alt = "";
				$("body").append(div);
				this.tooltipset = true;
			}
			$(this.tooltipdiv).show().css({left: mouseX + "px", top: mouseY + 3 + "px"});
		}
	).mouseout(
		function()
		{
			if(this.tooltipdiv)
			{
				$(this.tooltipdiv).hide();
			}
		}
	);
	return this;
};

function fix(){
    var obj=document.getElementById('container');
    obj.style.width='';
    cWidth="";
    var cWidth=obj.clientWidth;
    if(cWidth<=990) obj.style.width="990px";// else obj.style.width="70%";
}

function opentab(num){
    var objopen = document.getElementById('taber_'+num+'_open');
    var objclose = document.getElementById('taber_'+num+'_close');
    var objtab = document.getElementById('tab_'+num);
    objopen.className='hidden';
    objclose.className='visible';
    objtab.className='tab_content_visible';
}


function closetab(num){
    var objopen = document.getElementById('taber_'+num+'_open');
    var objclose = document.getElementById('taber_'+num+'_close');
    var objtab = document.getElementById('tab_'+num);

    objopen.className='visible';
    objclose.className='hidden';
    objtab.className='tab_content_hidden';
}

var times;

function showCities(){
    clearInterval(times);
    var obj=document.getElementById('cities');
    obj.className='cities_visible';
}

function closeCities(){
    clearInterval(times);
}

function slowCloseCities(){
    times=setInterval("closeCities()",2000);
}


var flag=0;

function doCities(){
    if(flag==0) {document.getElementById('cities').className='cities_visible';flag=1;} else {document.getElementById('cities').className='cities_hidden';flag=0;}
}

function newImage(arg) 
{
	rslt = new Image();
	rslt.src = arg;
	return rslt;
}


function swapON(id){
document.getElementById(id).src=eval(id+'_on').src;
}

function swapOFF(id){
document.getElementById(id).src=eval(id).src;
}

function replaceclass(id,name){
document.getElementById(id).className=name;
}

function go(url){document.location.href=url;}

function rollon(obj){var cc=obj.className; obj.className=cc+'_on';closeallopen();}
function rolloff(id){
         var cc = document.getElementById('menu_'+id);
         if(id == 1 || id == 9) {
            cc.className="menu_bg_"+id;
         } else {
            cc.className="menu_bg_common";
         }
    }

function showpopup(id){
	clearInterval(times);
	var obj = document.getElementById('sub_'+id);

	var mnu=document.getElementById('menudiv');
	var start=mnu.offsetLeft;
	var coordY=mnu.offsetTop;
	obj.className='submenu_visible_'+id;

	switch(id){
		case 1: var offset=5; break;
		case 2: var offset=114; break;
		case 3: var offset=222; break;
		case 4: var offset=330; break;
		case 5: var offset=440; break;
		case 6: var offset=550; break;
		case 7: var offset=660; break;
		case 8: var offset=763; break;
		case 9: var offset=873; break;

	}

	var result=start+offset;
	obj.style.left=result+"px";
	obj.style.top=coordY+42+"px";
}

function closeallopen(){
//document.getElementById('cities').className='cities_hidden';flag=0;
if(document.getElementById("sub_1")) closepopup(1);
if(document.getElementById("sub_2")) closepopup(2);
if(document.getElementById("sub_3")) closepopup(3);
if(document.getElementById("sub_4")) closepopup(4);
if(document.getElementById("sub_5")) closepopup(5);
if(document.getElementById("sub_6")) closepopup(6);
if(document.getElementById("sub_7")) closepopup(7);
if(document.getElementById("sub_8")) closepopup(8);
if(document.getElementById("sub_9")) closepopup(9);

}


function slowclosepopup(id){
times=setInterval("closepopup("+id+")",1000);
}

function closepopup(id){
var obj=document.getElementById("sub_"+id);
if(obj) obj.className="hidden";
}

function go(url){document.location.href=url;}

      var VisibleBlocks;

      jQuery(document).ready(function(){
        $('a[rel*=facebox]').facebox();
        if(jQuery.browser.msie) {jQuery(".png").each(function (id) {fixImage(this);})}

        if(!$.cookie('VisibleBlocks')) {
          VisibleBlocks = new Array(1, 1, 1, 1, 1, 1, 1);
          $.cookie("VisibleBlocks", $.toJSON(VisibleBlocks), { expires: 31 });
        } else {
          VisibleBlocks = $.parseJSON($.cookie('VisibleBlocks'));
        }
        if(!jQuery.browser.msie) {
            $(".close_box img").ToolTipDemo();
            $(".close_box_right img").ToolTipDemo();
        }
    });

        
        changeTheme = function(theme) {
            if(theme == "light") {
                $.cookie("Theme", "dark", { expires: 31 });
            } else {
                $.cookie("Theme", "light", { expires: 31 });
            }
            document.location.reload();
        }
