/*
 * $Date: 2010/01/12 05:52:11 $
 * $Revision: 1.8 $
 */

/* base 64 */
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",decode:function(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(i<input.length){enc1=this._keyStr.indexOf(input.charAt(i++));enc2=this._keyStr.indexOf(input.charAt(i++));enc3=this._keyStr.indexOf(input.charAt(i++));enc4=this._keyStr.indexOf(input.charAt(i++));chr1=(enc1 << 2)|(enc2 >> 4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if (enc3 != 64){output=output+String.fromCharCode(chr2);}if (enc4!=64){output=output+String.fromCharCode(chr3);}}output=Base64._utf8_decode(output);return output;},_utf8_decode:function (utftext){var string = "";var i=0;var c=c1=c2=0;while ( i < utftext.length ){c=utftext.charCodeAt(i);if (c < 128) {string += String.fromCharCode(c);i++;}else if((c > 191) && (c < 224)){c2=utftext.charCodeAt(i+1);string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));i+=2;}else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}return string;}}

$('.link_to_tracker').live('click',function()
{
    name = this.id;
    name = name.replace(/(^\s+)|(\s+$)/g, "");
    rel  = $(this).attr('rel');
    type = '';

    attr_class = $(this).attr('class');

    if((/buy-button/).test(attr_class)){type='buy';}
    else if((/preview-button/).test(attr_class)){type='preview';}
    else{type='exe';}

    pageTracker._trackPageview(type+'/'+dgLanguage+'/'+name);

    if (rel != '' && rel != 'nofollow')
    {
        link = decode_link(rel);
        $(this).attr('target','_blank').attr('href', link);
    }
});

$('.link_to_encode').live('click',function(){
	
	rel=$(this).attr('rel');
	if (rel != '' && rel != 'nofollow'){
		link = decode_link(rel);
		$(this).attr('target','_blank').attr('href', link);
	}
});

function decode_link(link){link=link.replace(/-_-/g, "=");link=link.replace(/-/g, "+");link=link.replace(/_/g, "/");return Base64.decode(link);}

/*
 * login js
 */

function login()
{
    $.post('/user/login', { login: $('#loginform_login').val(),
                            password: $('#loginform_password').val(),
                            remember_me: $('#remember_me').attr('checked')},
                            login_response);
    return false;
}

function login_response(data)
{
    if (data == 'true')
    {
        var str = document.location.toString();
        if (str.search(/user\/recovery/) == -1)
            location.reload(true);
        else
            document.location = '/';
    }
    else
        if (data == 'ipblock')
            $('#loginform_error').html(ipblock);
        else
            if (data == 'block')
                $('#loginform_error').html(accblock);
            else if (data == 'false')
                $('#loginform_error').html(loginfail);
            else
                document.location = data;
}

function start_login_animate(){$('#user_area').animate({top : 0}, 1000, "swing");}
function logout(){return true;}
function facebook_logout(){if (dgLanguage == 'en') FB.logout(function(response) {}); return true;}
function vk_logout(){VK.Auth.logout();return true;}
function facebook_login(){window.location.href = '/facebook_login';}
function vk_login(){VK.Auth.login(null, VK.access.FRIENDS | VK.access.WIKI);}

function update_user_box()
{
    if (!dg_current_user) return 0;

    var user_box = document.getElementById('user_box');
    user_box.innerHTML =
          "<h4 class='header'>FaceBook profile</h4>"
        + "<div class='right-column-block'><center>"
        + "<div id='fb_img'><fb:profile-pic uid='loggedinuser' size='square' facebook-logo='true'></fb:profile-pic></div>"
        + "<div id='fb_text'>Welcome, <fb:name uid='loggedinuser' useyou='false'></fb:name></div>"
        + "<div class='breaker'></div>";
        + "</span></center></div>";

    FB.XFBML.Host.parseDomTree();
}
/*
 * end login js
 */

/*
 * favorites js
 */

inArray = function (arr, value)
{
    for (var i in arr)
    {
        // Matches identical (===), not just similar (==).

        if (arr[i] === value)
        {
            return i;
	}
    }

    return false;
};

var in_progress = new Array;

$('.fav_star, .fav_star_sel').live('click', send_fav_req);

function send_fav_req()
{
    if (inArray(in_progress, $(this).attr('rev')) === false)
    {
        in_progress.push($(this).attr('rev'));
	$.post('/user/favorites', {gameid:$(this).attr('rev')}, change_fav, "json");
    }

    return false;
}

function showMessage(text, m_class)
{
    if (!m_class) m_class = 'simple-message';
    $('.jpopup').remove();
    $('body').prepend('<div class="jpopup '+m_class+'" id="jpopup-message">'+text+'</div>');
    setTimeout("$('.jpopup').remove();", 3000);
}

function change_fav(data)
{
    if (data.status == 'on')
    {
        showMessage(addedtofav, 'simple-message');
        $('.fav_star[rev="'+data.gameid+'"]').attr('class', 'fav_star_sel').attr('title', delfromfav);
    }
    else
    {
        showMessage(removedfromfav, 'simple-message');
        $('.fav_star_sel[rev="'+data.gameid+'"]').attr('class', 'fav_star').attr('title', addtofav);
    }

    in_progress.splice(inArray(in_progress, data.gameid), 1);
}

/*
 * end favorites js
 */

/*
 * rating js
 */

function rating_init()
{
    $('.rate-link').hover(function(){
        id  = $(this).attr('id');
        id  = id.split('-');
        num = parseInt(id[1]);

        for (i = 1; i <= num; i++)
        {
            $('#rate-'+i).find('img').attr('src', '/images/view/rate/2-0.png');
        }

        if (num != 5)
	{
          for(i = (num+1); i <= 5; i++)
          {
            $('#rate-'+i).find('img').attr('src', '/images/view/rate/2-1.png');
          }
        }
    }, function(){
        for(i = 1; i <= 5; i++)
        {
            $('#rate-'+i).find('img').attr('src', '/images/view/rate/2-1.png');
        }
    }).click(function(){
        $.post($(this).attr('href'), {}, function(data){
            eval("param = "+data);

            if (param['status'] == 'rated')
            {
                alert('You have already rated this game.');
                return false;
            }

	    $.cookie(param['game_id'], param['user_rate'], { expires: 'httponly', path: '/' });

            var width = (114 / 5 * param['game_rate']);
            var rate  = param['game_rate'];
            var num   = param['user_rate'];

            $('#game-rate').css('width', width+'px');
            $('#game-rate-number').text( rate.toFixed(2) );
            $('#game-voices').text(param['voices']);
            $('.rate-link').unbind();

            for(i = 1; i <= num; i++)
            {
                $('#rate-'+i).find('img')
                             .attr('src', '/images/view/rate/2-0.png');
            }

            if (num != 5)
                for(i = (num+1); i <= 5; i++)
                {
                    $('#rate-'+i).find('img')
                                 .attr('src', '/images/view/rate/2-1.png');
                }
                for(i = 1; i <= 5; i++)
                {
                    $('#rate-'+i).replaceWith($('#rate-'+i).html());
                }

                $('.game-rating p').text(yourrate);
        });

        return false;
    });
}

/*
 * end rating js
 */

$(document).ready(set_actions);

function get_banner()
{
    $.post('/mainpage/right_banner', {action: 'view'},
	   function(jtext)
	   {
	    jtext = jtext.replace(/\]/,'');
	    jtext = jtext.replace(/\[/,'');

            var obj = $.parseJSON(jtext);
	    if (!obj) return 0;
            if (typeof(obj) != 'object') return 0;

	    html  = '<noindex><a href="/nojs/' +obj.href_encode;
	    html += '" rel="'+obj.href_encode+'" target="_blank" class="link_to_encode">';
	    html += '<img src="/images/banners/' + obj.src;
	    html += '" /></a></noindex>';
	    $('#right_banner').html(html);
		$('#right_banner a').live('click', function() {
		    $.post('/mainpage/right_banner',
			   {action: 'click', name: obj.name});
		});
	  }
    );
}

function get_design()
{
    $.post('/design/'+dgLanguage+'/view', {},
	function(jtext)
	{
	    jtext = jtext.replace(/\]/,'');
	    jtext = jtext.replace(/\[/,'');

	    var html = '';
	    var obj  = $.parseJSON(jtext);

	    if (!obj) return 0;
	    if (typeof(obj) != 'object') return 0;

	    $.cookie('DG_DESIGN', obj.cookie, { expires: 'httponly', path: '/' });

	    if (obj.bg_color) $('body').css('background-color', obj.bg_color);
	    if (obj.bottom)   $('body').css(
		{'background-image'   : 'url(/images/bg_design/'+obj.bottom+')',
	    	 'background-position': 'center bottom',
		 'background-repeat'  : 'no-repeat'});
	    if (obj.top) $('#background-bottom').css(
		'background', 'url(/images/bg_design/'+obj.top+') no-repeat center top');

	    if (obj.banner)
	    {
		var src = dg_current_domain + '/swf/' + obj.banner;
		
		if (obj.src) src += '?bannerLink=' + obj.src;

		var flashvars = '';

		if (obj.flashvars)
		{
		    flashvars = (/^http:\/\//).test(obj.flashvars) || (/^http%3A%2F%2F/).test(obj.flashvars) ? obj.flashvars : dgDomain + obj.flashvars;
		    flashvars = 'gameinfo=' + flashvars;
		}
		else flashvars = obj.clicktag ? 'clicktag=' + dgDomain + obj.clicktag : '';

		var wh = 'width="' +obj.width+'" height="'+ obj.height+'"';

		html  = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
		html += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
		html += wh + ' id="header_banner_swf" align="middle">';
		html += '<param name="allowScriptAccess" value="always" />';
		html += '<param name="movie" value="' +src+ '" />';
		html += '<param name="quality" value="high" />';

		if (flashvars) html += '<param name="flashvars" value="' +flashvars+ '" />';

		html += '<param name="wmode" value="transparent">';
		html += '<param name="base" value="' +src+ '" />';
		html += '<embed base="' +src+ '"';
		html += 'src="' +src+ '"';

		if (flashvars) html += 'flashvars="' +flashvars+ '"';

		html += 'wmode="transparent" quality="high" ' + wh;
		html += ' name="header_banner_swf" align="middle"';
		html += 'allowScriptAccess="always"';
		html += 'type="application/x-shockwave-flash"';
		html += 'pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		html += '</object>';

		$('#header_banner').html(html);

		$('#header_banner').live('click', function() {
		    $.post('/design/' + dgLanguage + '/click/' + obj.name, {});
		});
	    }
	}
    );
}
function set_actions()
{
    // if (dgLanguage == 'en') {window.setTimeout(show_dreamfarm, 3000)};
    if (document.getElementById('bb_at')) set_bookmark();
    if (document.getElementById('blogmap_showmore'))
    {
	$('#blogmap_showmore').click(function(){
	    $('#blogmap_showmore span').toggle();
	    $('.noshow').toggle();
	});
    }
    $('#dg_social a').live('click', function() {
        id = $(this).parent().attr('id');
	pageTracker._trackPageview(dgLanguage + '/' + id);
    });
	$('.in_left').live('click',function(){
		var soctype = new Array();
		var obj = $(this);
		
		soctype = obj.attr('class').split(' ');
		
		if (soctype[2] != null){
			pageTracker._trackPageview(dgLanguage + '/' + soctype[2]);
		}
	});

    $('.category_buttons').each(function() {
	$(this).hover(
	    function() { $(this).find('.subcategory_buttons').show(); },
	    function() { $(this).find('.subcategory_buttons').hide(); }
	);
    });

    $('#login_link').click(function() {
		$('#user_links').animate({top : '-30px'}, 1000, "swing");
		setTimeout(start_login_animate, 1000);
		
		return false;
    });

    $('#loginform_close a').click(function(){
	$('#user_area').animate({top : '-130px'}, 1000, "swing");
	setTimeout($('#user_links').animate({top : 0}, 1000, "swing"), 1000);
	return false;
    });

    $('#login_form').submit(login);

    //get_banner();
    get_design();

    $('.top-tab').click(function(){
      $('.top-tab').toggleClass('active');
      $('.top-tab a').toggleClass('top-tab-a').toggleClass('top-tab-a-active');
      $('.top-games-list').toggle();
    });

    $('.preview-button-old').each(function(){
	this.onclick =
            function() {
		id = this.id;

                $.post($(this).attr('href'), {}, function(data) {
		    if (data == 'ok')
		    {
			$('#alert_me_text').text(alert_me_text);
			$('#' +id).remove();
		    }
		    else if (data == 'not_logged')
			window.location.href = '/user/login';
		});

                return false;
            }
    });
}

function show_dreamfarm()
{
    if ($.cookie('dg_promo_dream-farm')) return 0;

    $('#popup_dream-farm_overlay').css({
	opacity: '0.6',
	backgroundColor: '#000000'
    }).show();

    $('#popup_dream-farm_window').css({
	width:  '800',
	height: '600'
    }).show();

    $('#popup_dream-farm_closeWindow').show();
    $('#popup_dream-farm_no-thanks').show();

    $.cookie('dg_promo_dream-farm', 1, { expires: 1, path: '/' });

    $('#popup_dream-farm_window a').click(hide_dreamfarm);
    $('#popup_dream-farm_overlay').click(hide_dreamfarm);
    $('#popup_dream-farm_no-thanks').click(hide_dreamfarm);
}

function hide_dreamfarm()
{
    $('#popup_dream-farm_overlay').remove();
    $('#popup_dream-farm_window').remove();
    $('#popup_dream-farm_no-thanks').remove();
}

/* http://keith-wood.name/countdown.html
   Countdown for jQuery v1.5.7.
   Written by Keith Wood (kbwood{at}iinet.com.au) January 2008.
   Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and 
   MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. 
   Please attribute the author if you use it. */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(A($){A 1j(){8.1C=[];8.1C[\'\']={1k:[\'2A\',\'2B\',\'2C\',\'2D\',\'2E\',\'2F\',\'2G\'],2H:[\'2I\',\'2J\',\'2K\',\'2L\',\'2M\',\'2N\',\'2O\'],1l:[\'y\',\'m\',\'w\',\'d\'],1D:\':\',1S:1f};8.1g={1T:E,1U:E,1V:E,1W:E,1X:\'2P\',1m:\'\',1Y:1f,1E:\'\',1Z:\'\',20:\'\',21:1f,22:E,23:E,25:1};$.1n(8.1g,8.1C[\'\']);8.1o=[]}x w=\'G\';x Y=0;x O=1;x W=2;x D=3;x H=4;x M=5;x S=6;$.1n(1j.26,{1p:\'2Q\',2R:2S(A(){$.G.27()},2T),19:[],2U:A(a){8.1F(8.1g,a);1G(8.1g,a||{})},1H:A(a,b,c,e,f,g,h,i){B(1q b==\'2V\'&&b.2W==P){i=b.1I();h=b.1J();g=b.1K();f=b.1L();e=b.R();c=b.16();b=b.17()}x d=K P();d.2X(b);d.28(1);d.2Y(c||0);d.28(e||1);d.2Z(f||0);d.31((g||0)-(T.33(a)<30?a*1a:a));d.34(h||0);d.35(i||0);C d},29:A(a){C a[0]*36+a[1]*37+a[2]*2a+a[3]*2b+a[4]*2c+a[5]*1a+a[6]},38:A(a,b){B(!b){C $.G.1g}x c=$.U(a,w);C(b==\'39\'?c.V:c.V[b])},2d:A(a,b){x c=$(a);B(c.2e(8.1p)){C}c.3a(8.1p);x d={V:$.1n({},b),z:[0,0,0,0,0,0,0]};$.U(a,w,d);8.2f(a)},1M:A(a){B(!8.1N(a)){8.19.2g(a)}},1N:A(a){C($.3b(a,8.19)>-1)},1w:A(b){8.19=$.3c(8.19,A(a){C(a==b?E:a)})},27:A(){18(x i=8.19.1r-1;i>=0;i--){8.1s(8.19[i])}},1s:A(a,b){x c=$(a);b=b||$.U(a,w);B(!b){C}c.3d(8.2h(b));c[(8.F(b,\'1S\')?\'3e\':\'3f\')+\'3g\'](\'3h\');x d=8.F(b,\'23\');B(d){x e=b.Q!=\'2i\'?b.z:8.1x(b,b.X,K P());x f=8.F(b,\'25\');B(f==1||8.29(e)%f==0){d.1t(a,[e])}}x g=b.Q!=\'1u\'&&(b.I?b.1b.L()<b.I.L():b.1b.L()>=b.Z.L());B(g&&!b.1O){b.1O=2j;B(8.1N(a)||8.F(b,\'21\')){8.1w(a);x h=8.F(b,\'22\');B(h){h.1t(a,[])}x i=8.F(b,\'20\');B(i){x j=8.F(b,\'1m\');b.V.1m=i;8.1s(a,b);b.V.1m=j}x k=8.F(b,\'1Z\');B(k){3i.3j=k}}b.1O=1f}1h B(b.Q==\'1u\'){8.1w(a)}$.U(a,w,b)},2f:A(a,b,c){b=b||{};B(1q b==\'1P\'){x d=b;b={};b[d]=c}x e=$.U(a,w);B(e){8.1F(e.V,b);1G(e.V,b);8.2k(a,e);$.U(a,w,e);x f=K P();B((e.I&&e.I<f)||(e.Z&&e.Z>f)){8.1M(a)}8.1s(a,e)}},1F:A(a,b){x c=1f;18(x n 1Q b){B(n.N(/[2l]2m/)){c=2j;11}}B(c){18(x n 1Q a){B(n.N(/[2l]2m[0-9]/)){a[n]=E}}}},2k:A(a,b){x c;x d=8.F(b,\'1W\');x e=0;x f=E;18(x i=0;i<8.1o.1r;i++){B(8.1o[i][0]==d){f=8.1o[i][1];11}}B(f!=E){e=(d?f:0);c=K P()}1h{x g=(d?d.1t(a,[]):E);c=K P();e=(g?c.L()-g.L():0);8.1o.2g([d,e])}x h=8.F(b,\'1V\');h=(h==E?-c.3k():h);b.I=8.F(b,\'1U\');B(b.I!=E){b.I=8.1H(h,8.1y(b.I,E));B(b.I&&e){b.I.1z(b.I.1I()+e)}}b.Z=8.1H(h,8.1y(8.F(b,\'1T\'),c));B(e){b.Z.1z(b.Z.1I()+e)}b.X=8.2n(b)},3l:A(a){x b=$(a);B(!b.2e(8.1p)){C}8.1w(a);b.3m(8.1p).3n();$.3o(a,w)},3p:A(a){8.Q(a,\'1u\')},3q:A(a){8.Q(a,\'2i\')},3r:A(a){8.Q(a,E)},Q:A(a,b){x c=$.U(a,w);B(c){B(c.Q==\'1u\'&&!b){c.z=c.2o;x d=(c.I?\'-\':\'+\');c[c.I?\'I\':\'Z\']=8.1y(d+c.z[0]+\'y\'+d+c.z[1]+\'o\'+d+c.z[2]+\'w\'+d+c.z[3]+\'d\'+d+c.z[4]+\'h\'+d+c.z[5]+\'m\'+d+c.z[6]+\'s\');8.1M(a)}c.Q=b;c.2o=(b==\'1u\'?c.z:E);$.U(a,w,c);8.1s(a,c)}},3s:A(a){x b=$.U(a,w);C(!b?E:(!b.Q?b.z:8.1x(b,b.X,K P())))},F:A(a,b){C(a.V[b]!=E?a.V[b]:$.G.1g[b])},1y:A(k,l){x m=A(a){x b=K P();b.2p(b.L()+a*13);C b};x n=A(a){a=a.3t();x b=K P();x c=b.17();x d=b.16();x e=b.R();x f=b.1L();x g=b.1K();x h=b.1J();x i=/([+-]?[0-9]+)\\s*(s|m|h|d|w|o|y)?/g;x j=i.2q(a);3u(j){3v(j[2]||\'s\'){1c\'s\':h+=1d(j[1],10);11;1c\'m\':g+=1d(j[1],10);11;1c\'h\':f+=1d(j[1],10);11;1c\'d\':e+=1d(j[1],10);11;1c\'w\':e+=1d(j[1],10)*7;11;1c\'o\':d+=1d(j[1],10);e=T.1A(e,$.G.1i(c,d));11;1c\'y\':c+=1d(j[1],10);e=T.1A(e,$.G.1i(c,d));11}j=i.2q(a)}C K P(c,d,e,f,g,h,0)};x o=(k==E?l:(1q k==\'1P\'?n(k):(1q k==\'3w\'?m(k):k)));B(o)o.1z(0);C o},1i:A(a,b){C 32-K P(a,b,32).R()},2h:A(c){c.z=14=(c.Q?c.z:8.1x(c,c.X,K P()));x d=1f;x e=0;x f=$.1n({},c.X);18(x g=0;g<c.X.1r;g++){d|=(c.X[g]==\'?\'&&14[g]>0);f[g]=(c.X[g]==\'?\'&&!d?E:c.X[g]);e+=(f[g]?1:0)}x h=8.F(c,\'1Y\');x i=8.F(c,\'1m\');x j=(h?8.F(c,\'1l\'):8.F(c,\'1k\'));x k=8.F(c,\'1D\');x l=8.F(c,\'1E\')||\'\';x m=A(a){x b=$.G.F(c,\'1l\'+14[a]);C(f[a]?14[a]+(b?b[a]:j[a])+\' \':\'\')};x n=A(a){x b=$.G.F(c,\'1k\'+14[a]);C(f[a]?\'<15 1v="3x"><15 1v="2r">\'+14[a]+\'</15><3y/>\'+(b?b[a]:j[a])+\'</15>\':\'\')};C(i?8.2s(c,f,i,h):((h?\'<15 1v="1R 2r\'+(c.Q?\' 2t\':\'\')+\'">\'+m(Y)+m(O)+m(W)+m(D)+(f[H]?8.J(14[H],2):\'\')+(f[M]?(f[H]?k:\'\')+8.J(14[M],2):\'\')+(f[S]?(f[H]||f[M]?k:\'\')+8.J(14[S],2):\'\'):\'<15 1v="1R 3z\'+e+(c.Q?\' 2t\':\'\')+\'">\'+n(Y)+n(O)+n(W)+n(D)+n(H)+n(M)+n(S))+\'</15>\'+(l?\'<15 1v="1R 3A">\'+l+\'</15>\':\'\')))},2s:A(c,d,e,f){x g=8.F(c,(f?\'1l\':\'1k\'));x h=A(a){C($.G.F(c,(f?\'1l\':\'1k\')+c.z[a])||g)[a]};x j=A(a,b){C T.1B(a/b)%10};x k={3B:8.F(c,\'1E\'),3C:8.F(c,\'1D\'),3D:h(Y),3E:c.z[Y],3F:8.J(c.z[Y],2),3G:8.J(c.z[Y],3),3H:j(c.z[Y],1),3I:j(c.z[Y],10),3J:j(c.z[Y],1e),3K:j(c.z[Y],13),3L:h(O),3M:c.z[O],3N:8.J(c.z[O],2),3O:8.J(c.z[O],3),3P:j(c.z[O],1),3Q:j(c.z[O],10),3R:j(c.z[O],1e),3S:j(c.z[O],13),3T:h(W),3U:c.z[W],3V:8.J(c.z[W],2),3W:8.J(c.z[W],3),3X:j(c.z[W],1),3Y:j(c.z[W],10),3Z:j(c.z[W],1e),40:j(c.z[W],13),41:h(D),42:c.z[D],43:8.J(c.z[D],2),44:8.J(c.z[D],3),45:j(c.z[D],1),46:j(c.z[D],10),47:j(c.z[D],1e),48:j(c.z[D],13),49:h(H),4a:c.z[H],4b:8.J(c.z[H],2),4c:8.J(c.z[H],3),4d:j(c.z[H],1),4e:j(c.z[H],10),4f:j(c.z[H],1e),4g:j(c.z[H],13),4h:h(M),4i:c.z[M],4j:8.J(c.z[M],2),4k:8.J(c.z[M],3),4l:j(c.z[M],1),4m:j(c.z[M],10),4n:j(c.z[M],1e),4o:j(c.z[M],13),4p:h(S),4q:c.z[S],4r:8.J(c.z[S],2),4s:8.J(c.z[S],3),4t:j(c.z[S],1),4u:j(c.z[S],10),4v:j(c.z[S],1e),4w:j(c.z[S],13)};x l=e;18(x i=0;i<7;i++){x m=\'4x\'.4y(i);x o=K 2u(\'\\\\{\'+m+\'<\\\\}(.*)\\\\{\'+m+\'>\\\\}\',\'g\');l=l.2v(o,(d[i]?\'$1\':\'\'))}$.2w(k,A(n,v){x a=K 2u(\'\\\\{\'+n+\'\\\\}\',\'g\');l=l.2v(a,v)});C l},J:A(a,b){a=\'\'+a;B(a.1r>=b){C a}a=\'4z\'+a;C a.4A(a.1r-b)},2n:A(a){x b=8.F(a,\'1X\');x c=[];c[Y]=(b.N(\'y\')?\'?\':(b.N(\'Y\')?\'!\':E));c[O]=(b.N(\'o\')?\'?\':(b.N(\'O\')?\'!\':E));c[W]=(b.N(\'w\')?\'?\':(b.N(\'W\')?\'!\':E));c[D]=(b.N(\'d\')?\'?\':(b.N(\'D\')?\'!\':E));c[H]=(b.N(\'h\')?\'?\':(b.N(\'H\')?\'!\':E));c[M]=(b.N(\'m\')?\'?\':(b.N(\'M\')?\'!\':E));c[S]=(b.N(\'s\')?\'?\':(b.N(\'S\')?\'!\':E));C c},1x:A(f,g,h){f.1b=h;f.1b.1z(0);x i=K P(f.1b.L());B(f.I){B(h.L()<f.I.L()){f.1b=h=i}1h{h=f.I}}1h{i.2p(f.Z.L());B(h.L()>f.Z.L()){f.1b=h=i}}x j=[0,0,0,0,0,0,0];B(g[Y]||g[O]){x k=$.G.1i(h.17(),h.16());x l=$.G.1i(i.17(),i.16());x m=(i.R()==h.R()||(i.R()>=T.1A(k,l)&&h.R()>=T.1A(k,l)));x n=A(a){C(a.1L()*1a+a.1K())*1a+a.1J()};x o=T.4B(0,(i.17()-h.17())*12+i.16()-h.16()+((i.R()<h.R()&&!m)||(m&&n(i)<n(h))?-1:0));j[Y]=(g[Y]?T.1B(o/12):0);j[O]=(g[O]?o-j[Y]*12:0);x p=A(a,b,c){x d=(a.R()==c);x e=$.G.1i(a.17()+b*j[Y],a.16()+b*j[O]);B(a.R()>e){a.2x(e)}a.4C(a.17()+b*j[Y]);a.4D(a.16()+b*j[O]);B(d){a.2x(e)}C a};B(f.I){i=p(i,-1,l)}1h{h=p(K P(h.L()),+1,k)}}x q=T.1B((i.L()-h.L())/13);x r=A(a,b){j[a]=(g[a]?T.1B(q/b):0);q-=j[a]*b};r(W,2a);r(D,2b);r(H,2c);r(M,1a);r(S,1);B(q>0&&!f.I){x s=[1,12,4.4E,7,24,1a,1a];x t=S;x u=1;18(x v=S;v>=Y;v--){B(g[v]){B(j[t]>=u){j[t]=0;q=1}B(q>0){j[v]++;q=0;t=v;u=1}}u*=s[v]}}C j}});A 1G(a,b){$.1n(a,b);18(x c 1Q b){B(b[c]==E){a[c]=E}}C a}$.4F.G=A(a){x b=4G.26.4H.4I(4J,1);B(a==\'4K\'||a==\'4L\'){C $.G[\'2y\'+a+\'1j\'].1t($.G,[8[0]].2z(b))}C 8.2w(A(){B(1q a==\'1P\'){$.G[\'2y\'+a+\'1j\'].1t($.G,[8].2z(b))}1h{$.G.2d(8,a)}})};$.G=K 1j()})(4M);',62,297,'||||||||this|||||||||||||||||||||||||var||_periods|function|if|return||null|_get|countdown||_since|_minDigits|new|getTime||match||Date|_hold|getDate||Math|data|options||_show||_until||break||1000|periods|span|getMonth|getFullYear|for|_timerTargets|60|_now|case|parseInt|100|false|_defaults|else|_getDaysInMonth|Countdown|labels|compactLabels|layout|extend|_serverSyncs|markerClassName|typeof|length|_updateCountdown|apply|pause|class|_removeTarget|_calculatePeriods|_determineTime|setMilliseconds|min|floor|regional|timeSeparator|description|_resetExtraLabels|extendRemove|UTCDate|getMilliseconds|getSeconds|getMinutes|getHours|_addTarget|_hasTarget|_expiring|string|in|countdown_row|isRTL|until|since|timezone|serverSync|format|compact|expiryUrl|expiryText|alwaysExpire|onExpiry|onTick||tickInterval|prototype|_updateTargets|setUTCDate|periodsToSeconds|604800|86400|3600|_attachCountdown|hasClass|_changeCountdown|push|_generateHTML|lap|true|_adjustSettings|Ll|abels|_determineShow|_savePeriods|setTime|exec|countdown_amount|_buildLayout|countdown_holding|RegExp|replace|each|setDate|_|concat|Years|Months|Weeks|Days|Hours|Minutes|Seconds|labels1|Year|Month|Week|Day|Hour|Minute|Second|dHMS|hasCountdown|_timer|setInterval|980|setDefaults|object|constructor|setUTCFullYear|setUTCMonth|setUTCHours||setUTCMinutes||abs|setUTCSeconds|setUTCMilliseconds|31557600|2629800|_settingsCountdown|all|addClass|inArray|map|html|add|remove|Class|countdown_rtl|window|location|getTimezoneOffset|_destroyCountdown|removeClass|empty|removeData|_pauseCountdown|_lapCountdown|_resumeCountdown|_getTimesCountdown|toLowerCase|while|switch|number|countdown_section|br|countdown_show|countdown_descr|desc|sep|yl|yn|ynn|ynnn|y1|y10|y100|y1000|ol|on|onn|onnn|o1|o10|o100|o1000|wl|wn|wnn|wnnn|w1|w10|w100|w1000|dl|dn|dnn|dnnn|d1|d10|d100|d1000|hl|hn|hnn|hnnn|h1|h10|h100|h1000|ml|mn|mnn|mnnn|m1|m10|m100|m1000|sl|sn|snn|snnn|s1|s10|s100|s1000|yowdhms|charAt|0000000000|substr|max|setFullYear|setMonth|3482|fn|Array|slice|call|arguments|getTimes|settings|jQuery'.split('|'),0,{}))

/*
 * addthis buttons
 */

function set_bookmark(){var bm_index=0;var bm_array=new Array();var bm_value=$.cookie('dg_bookmark');if (bm_value){bm_array=bm_value.split(';');if ((bm_array.length)==15){bm_array=new Array();bm_value='';}else{bm_value=';'+bm_value+';';}}else{bm_value='';}do{bm_index=Math.floor(Math.random()*15);}while(bm_value.search(';'+bm_index+';')!= -1)bm_array.push(bm_index);var date=new Date(0);var expires=date.getUTCSeconds()+15552000;$.cookie('dg_bookmark', bm_array.join(';'), { expires: expires, path: '/' });get_bookmark(bm_index);}
function get_bookmark(index){switch(parseInt(index)){case 0:img='aim.png';cls='aim';break;case 1:img='blogger.png';cls='blogger'; break;case 2:img='delicious.png';cls='delicious'; break;case 3:img='digg.png';cls='digg';break;case 4:img='facebook.png';cls='facebook';break;case 5:img='google.png';cls='google';break;case 6:img='mixx.png';cls='mixx';break;case 7:img='myspace.png';cls='myspace';break;case 8:img='reddit.png';cls='reddit';break;case 9:img='stumbleupon.png';cls='stumbleupon';break;case 10:img='twitter.png';cls='twitter';break;case 11:img='yahoo.png';cls='yahoobkm';break;case 12:img='friendfeed.png';cls='friendfeed';break;case 13:img='bebo.png';cls='bebo';break;case 14:img='linkedin.png';cls='linkedin';break;}$('#bb_at').attr('class', 'addthis_button_' + cls).append('<img src="/images/view2/bmk/'+img+'" alt="Bookmark with '+cls+'" width="140" height="80" />');}

/*
 * screenshots
 */
var preview_zoomed = false;

function browserVersion()
{
    var version = "";
    var name    = "";
    var ua      = navigator.userAgent;

    var offset  = ua.indexOf("Firefox");

    if (ua.indexOf("Firefox") > -1)
    {
        name    = "Firefox";
        version = ua.substring(offset+8, ua.indexOf("(", offset));
    }

    offset = ua.indexOf("MSIE ");

    if (offset > -1)
    {
        name    = "MSIE";
        version = parseFloat(ua.substring(offset+5, ua.indexOf(";", offset)));
    }

    offset = ua.indexOf("Opera");

    if (offset > -1)
    {
        name    = "Opera";
        version = ua.substring(offset+6, ua.indexOf("(", offset));
    }

    navname = navigator.appName;

    return {type:navname, version:version, name:name};
}

function update_page(id)
{	
	
    id  = (/^(.*)_(\d)$/).exec(id);

    var cur_shot  = parseInt(id[2]);
    var file_name = id[1];

    if (cur_shot > 1)
    {
        $('#shots_prev').removeClass('shots_disabled').css('visibility','visible');

        document.getElementById('shots_prev').onclick =
            function() {
                ch_shot(file_name+"_"+(cur_shot - 1));
                return false;
            }
    }
    else
    {
        $('#shots_prev').addClass('shots_disabled').css('visibility','hidden');
    }
    if (cur_shot < 3)
    {
        $('#shots_next').removeClass('shots_disabled').css('visibility','visible');

        document.getElementById('shots_next').onclick =
            function() {
                ch_shot(file_name+"_"+(cur_shot + 1));
                return false;
            }
    }
    else
    {
        $('#shots_next').addClass('shots_disabled').css('visibility','hidden');
    }
}

function hide_shots()
{
    if (browserVersion().name != "MSIE") hide_id('shots_div', 50);
    else $('#shots_div').hide();

    $('#s_shots_bg').hide();
}
$('.vidlnk').live('click', load_vpreview);
$('#vid_close').live('click',function(e){

	$('#videoblock').hide();
	$('#s_vid_bg').hide();
});
function load_vpreview()
{
    var id = this.id;
	
    var x  = 0;
    var y  = 0;
    var bg = document.getElementById('s_vid_bg');

    var page_size    = getPageSize();
   // var file_name    = '/images/screenshots/' + id + '_big.jpg';
    var browser_name = browserVersion().name;

   // $('#shots_pic').html('<img src="'+file_name+'" width="640" height="480" border="0">');

    if (browser_name == "MSIE")
    {
        x = document.documentElement.offsetWidth*0.5 - 340 + document.documentElement.scrollLeft + document.body.scrollLeft;
        y = document.documentElement.offsetHeight*0.5 - 302 + document.documentElement.scrollTop + document.body.scrollTop;
        if (y<0)y = document.documentElement.scrollTop + document.body.scrollTop;
        if (x<0)x = document.documentElement.scrollLeft + document.body.scrollLeft;
    }
    else if (browser_name == "Firefox")
    {
        x = window.innerWidth*0.5 - 340 + window.scrollX;
        y = window.innerHeight*0.5 - 302 + window.scrollY;
    }
    else if(browser_name == "Opera")
    {
        x = window.innerWidth*0.5 - 340 + document.documentElement.scrollLeft + document.body.scrollLeft;
        y = window.innerHeight*0.5 - 302 + document.documentElement.scrollTop + document.body.scrollTop;
    }

    if (x==0)
    {
        x = window.innerWidth*0.5 - 340 + window.scrollX;
        y = window.innerHeight*0.5 - 302 + window.scrollY;
    }

    bg.style.width   = page_size[0]+"px";
    bg.style.height  = page_size[1]+"px";
    bg.style.display = 'block';
	
    if (y<0) y=1;
    var load = document.getElementById('videoblock');
    load.style.left = x+"px";
    load.style.top  = y+"px";
    if ((x > 0)&&(y > 0)) load.style.display = 'block';
    //update_page(id);

    if (browser_name != "MSIE") show_id('videoblock',30,98);

    return false;
}
function ch_shot(id)
{
    var file_name = '/images/screenshots/' + id + '_big.jpg';
    $('#shots_pic').html('<img src="'+file_name+'" width="640" height="480" border="0">');
    update_page(id);
}

function  getPageSize()
{
    var xScroll, yScroll;
    var windowWidth, windowHeight;

    if (window.innerHeight && window.scrollMaxY)
    {
	xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight)
    {
	// all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    }
    else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight)
    {
	// Explorer 6 strict mode
        xScroll = document.documentElement.scrollWidth;
        yScroll = document.documentElement.scrollHeight;
    }
    else
    {
	// Explorer Mac...would also work in Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    if (self.innerHeight)
    {
	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
	// Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    }
    else if (document.body)
    {
	// other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height|width less then height|width of the viewport
    pageHeight = yScroll < windowHeight ? windowHeight : yScroll;
    pageWidth  = xScroll < windowWidth  ? windowWidth  : xScroll;

    pageWidth -= 20;

    return [pageWidth, pageHeight, windowWidth, windowHeight];
}


function load_preview()
{
    var id = this.id;

    $('a.thumbnail-image').removeClass('thumbnail-image-active');
    $(this).addClass('thumbnail-image-active');

    var x  = 0;
    var y  = 0;
    var bg = document.getElementById('s_shots_bg');

    var page_size    = getPageSize();
    var file_name    = '/images/screenshots/' + id + '_big.jpg';
    var browser_name = browserVersion().name;

    $('#shots_pic').html('<img src="'+file_name+'" width="640" height="480" border="0">');

    if (browser_name == "MSIE")
    {
        x = document.documentElement.offsetWidth*0.5 - 340 + document.documentElement.scrollLeft + document.body.scrollLeft;
        y = document.documentElement.offsetHeight*0.5 - 302 + document.documentElement.scrollTop + document.body.scrollTop;
        if (y<0)y = document.documentElement.scrollTop + document.body.scrollTop;
        if (x<0)x = document.documentElement.scrollLeft + document.body.scrollLeft;
    }
    else if (browser_name == "Firefox")
    {
        x = window.innerWidth*0.5 - 340 + window.scrollX;
        y = window.innerHeight*0.5 - 302 + window.scrollY;
    }
    else if(browser_name == "Opera")
    {
        x = window.innerWidth*0.5 - 340 + document.documentElement.scrollLeft + document.body.scrollLeft;
        y = window.innerHeight*0.5 - 302 + document.documentElement.scrollTop + document.body.scrollTop;
    }

    if (x==0)
    {
        x = window.innerWidth*0.5 - 340 + window.scrollX;
        y = window.innerHeight*0.5 - 302 + window.scrollY;
    }

    bg.style.width   = page_size[0]+"px";
    bg.style.height  = page_size[1]+"px";
    bg.style.display = 'block';

    if (y<0) y=1;
    var load = document.getElementById('shots_div');
    load.style.left = x+"px";
    load.style.top  = y+"px";
    if ((x > 0)&&(y > 0)) load.style.display = 'block';
    update_page(id);

    if (browser_name != "MSIE") show_id('shots_div',30,98);

    return false;
}

function show_id(elem_id, begin, end)
{
    begin = begin + 3;

    document.getElementById(elem_id).style.filter="alpha(opacity="+begin+")";
    document.getElementById(elem_id).style.opacity = begin/100;

    t = setTimeout("show_id(\""+elem_id+"\","+begin+","+end+")",1);

    if (begin>=end) clearTimeout(t);
}

function hide_id(elem_id, begin)
{
    begin = begin - 5;

    document.getElementById(elem_id).style.filter  = "alpha(opacity="+begin+")";
    document.getElementById(elem_id).style.opacity = begin/100;

    t = setTimeout("hide_id(\""+elem_id+"\","+begin+")",1);
    if (begin<=0)
    {
        clearTimeout(t);

        $('#'+elem_id).hide();
    }
}

function dg_logged_share(type, lang, game){$.post("/mainpage/shared_logged", {type:type,lang:lang,game:game});}

