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');

    pageTracker._trackPageview('exe/' + 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);}
function change_featured(){$('div.videoshot-tab').css('background-image', 'url(/images/view/videoshot-tab-bg.png)');$(this).parent().css('background-image', 'url(/images/view/videoshot-tab-bg-wide.png)');$('#featured-videoshot1 param[name="movie"]').attr('value', $(this).attr('rel'));$('#featured-videoshot1 param[name="FlashVars"]').attr('value', $(this).attr('ref'));$('#featured-videoshot1 embed').attr('src', $(this).attr('rel'));$('#featured-videoshot1 embed').attr('flashvars', $(this).attr('ref'));return false;}
function langDropDown(){$('#header-languages-list').show();$('#header-languages-list').mouseleave(function(){$('#header-languages-list').hide();});return false;}

/*
 * 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)==16){bm_array=new Array();bm_value='';}else{bm_value=';'+bm_value+';';}}else{bm_value='';}do{bm_index=Math.floor(Math.random()*16);}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='technorati.png';cls='technorati';break;case 11:img='twitter.png';cls='twitter';break;case 12:img='yahoo.png';cls='yahoobkm';break;case 13:img='friendfeed.png';cls='friendfeed';break;case 14:img='bebo.png';cls='bebo';break;case 15:img='linkedin.png';cls='linkedin';break;}$('#bb_at').attr('class', 'addthis_button_' + cls).append('<img src="/images/bmk/'+img+'" alt="Bookmark with '+cls+'" width="140" height="80" />');}

$(document).ready(function(){
    if (document.getElementById('bb_at')) set_bookmark();
    $('#header-languages, #language-selector').click(langDropDown);
    $('div.videoshot-tab a').live('click', change_featured);
    $('.desc-switcher').live('click', function(){$('.game-list-description').toggle(); return false;});
});

