function strtr (str, from, to) {
    var fr = '',
        i = 0,
        j = 0,
        lenStr = 0,
        lenFrom = 0,
        tmpStrictForIn = false,
        fromTypeStr = '',
        toTypeStr = '',
        istr = '';
    var tmpFrom = [];
    var tmpTo = [];
    var ret = '';
    var match = false;

    if (typeof from === 'object') {
        tmpStrictForIn = this.ini_set('phpjs.strictForIn', false);
        from = this.krsort(from);
        this.ini_set('phpjs.strictForIn', tmpStrictForIn);
 
        for (fr in from) {
            if (from.hasOwnProperty(fr)) {
                tmpFrom.push(fr);
                tmpTo.push(from[fr]);
            }
        }
 
        from = tmpFrom;
        to = tmpTo;
    }
 
    lenStr = str.length;
    lenFrom = from.length;
    fromTypeStr = typeof from === 'string';
    toTypeStr = typeof to === 'string';
 
    for (i = 0; i < lenStr; i++) {
        match = false;
        if (fromTypeStr) {
            istr = str.charAt(i);
            for (j = 0; j < lenFrom; j++) {
                if (istr == from.charAt(j)) {
                    match = true;
                    break;
                }
            }
        } else {
            for (j = 0; j < lenFrom; j++) {
                if (str.substr(i, from[j].length) == from[j]) {
                    match = true;
                    i = (i + from[j].length) - 1;
                    break;
                }
            }
        }
        if (match) {
            ret += toTypeStr ? to.charAt(j) : to[j];
        } else {
            ret += str.charAt(i);
        }
    }
 
    return ret;
}

function base64_url_encode(input){
    return strtr(e(input), '+/=', '-_,');
}

function base64_url_decode(input){
    return w(strtr(input, '-_,', '+/=')); 
}

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function e(a){
    a = escape(a);
    var b = "";
    var c, chr2, chr3 = "";
    var d, enc2, enc3, enc4 = "";
    var i = 0;
    do {
        c = a.charCodeAt(i++);
        chr2 = a.charCodeAt(i++);
        chr3 = a.charCodeAt(i++);
        d = c >> 2;
        enc2 = ((c & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;
        if (isNaN(chr2)) {
            enc3 = enc4 = 64;
        } else if (isNaN(chr3)) {
            enc4 = 64;
        }
        b = b + keyStr.charAt(d) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
        c = chr2 = chr3 = "";
        d = enc2 = enc3 = enc4 = "";
    } while (i < a.length);
    return b
}

function w(a) {
    var b = "";
    var c, chr2, chr3 = "";
    var d, enc2, enc3, enc4 = "";
    var i = 0;
    do {
        d = keyStr.indexOf(a.charAt(i++));
        enc2 = keyStr.indexOf(a.charAt(i++));
        enc3 = keyStr.indexOf(a.charAt(i++));
        enc4 = keyStr.indexOf(a.charAt(i++));
        c = (d << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;
        b = b + String.fromCharCode(c);
        if (enc3 != 64) {
            b = b + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
            b = b + String.fromCharCode(chr3);
        }
        c = chr2 = chr3 = "";
        d = enc2 = enc3 = enc4 = "";
    } while (i < a.length);
    return unescape(b);
}

function zx_isset(){
    var a = arguments, l = a.length, i = 0, undef;
    
    if (l === 0) {
        throw new Error('Empty isset'); 
    }
    
    while (i !== l) {
        if (a[i] === undef || a[i] === null) {
            return false; 
        }
        i++; 
    }
    return true;
}

function _zx_overlay(html, header, width, clasa, onclose){

    $('body').append('<div class="zx-overlay"><div class="zx-window"><div class="zx-inner" style="'+(width > 0 ? 'width:'+width+'px;' : '')+'"><div class="box"><div class="top"><div class="left">'+header+'</div><div class="right" onclick="$(\'.zx-overlay, #zx-overlay-ov\').remove();'+onclose+'"></div></div><div class="bottom"><div class="content">'+html+'</div></div></div></div></div></div>');

}

var window_focus = true;

$(function(){

    $(window).focus(function(){
        window_focus = true;
    }).blur(function(){
        window_focus = false;
    });
    
    $('img').error(function(){
        
    });
    
    setInterval(function(){
        if(window_focus){
            $('#zx-news .zx-news-content').fadeOut(1000, function(){
                $(this).fadeIn(1000);
            });
        }
    }, 2000);
     
    $('#zx-news .slide').bind('click', function(){
        var $T = $(this), $O = $('#zx-news .zx-news-content'), $O_P = $O.position();
        
        if($T.is('.slide-left')){
            if($O_P.left <= 0){
                $O.animate({'right':'0px'}, { duration: 500, queue: false });
                return false;
            }
            $O.animate({'right':'+=120px'}, { duration: 500, queue: false });
        } else {
            $O.animate({'right':'-=120px'}, { duration: 500, queue: false });
        }
    });
    
    
    $('#zx-tip').remove();
    $('.zx-tip').live('click mouseover mouseout', function(e){
        if(e.type == 'mouseover'){
            $('<div/>').attr('id', 'zx-tip').addClass('zx-css-tip'+($(this).is('.zx-tip-wrap') ? ' zx-tip-wrap' : '')).html(($(this).attr('zx-tip-crypt') == '1' ? w($(this).attr('zx-tip')) : $(this).attr('zx-tip'))+'<div class="zx-css-tip-pointer-down"><div class="zx-css-tip-pointer-down-inner"></div></div>').appendTo('.zx-hidden-ob-box').position({
                my:'top bottom',
                at:'top',
                of:this,
                offset:'0 '+($.browser.msie ? '0' : '-10')
            });
        } else {
            $('#zx-tip').remove();
        }
    });
    
    $('.zx-tip-bottom').live('click mouseover mouseout', function(e){
        if(e.type == 'mouseover'){
            $('<div/>').attr('id', 'zx-tip').addClass('zx-css-tip-bottom'+($(this).is('.zx-tip-wrap') ? ' zx-tip-wrap' : '')).html('<div class="zx-css-tip-pointer-top"><div class="zx-css-tip-pointer-top-inner"></div></div>'+($(this).attr('zx-tip-crypt') == '1' ? w($(this).attr('zx-tip')) : $(this).attr('zx-tip'))).appendTo('.zx-hidden-ob-box').position({
                my:'bottom top',
                at:'bottom',
                of:this,
                offset:'0 '+($.browser.webkit || $.browser.msie ? '25' : '10')
            });
        } else {
            $('#zx-tip').remove();
        }
    });
    
    $('.fadeIn').each(function(){
        $(this).fadeTo(0, $(this).attr('fadeIn') == '' ? 0.5 : $(this).attr('fadeIn'));
    }).hover(function(){
		$(this).animate({opacity:1}, {duration:500,queue:false});
	}, function(){
		$(this).animate({opacity:$(this).attr('fadeIn') == '' ? 0.5 : $(this).attr('fadeIn')}, {duration:500,queue:false});
	});
    
});
