var Fishker = {
init : function() {
if (document.location.href.indexOf('.fishker.') == -1 && document.body.clientWidth > 1024 &&
window.parent == window
) {
if (navigator.userAgent.indexOf('MSIE') == -1) {
var css = document.createElement('link');
css.rel = 'stylesheet';
css.type = 'text/css';
css.href = 'http://www.' + Fishker.frontEnd + '/css2/toolbar.css?ver=21062010.1744';
document.getElementsByTagName("head")[0].appendChild(css);
} else {
document.createStyleSheet('http://www.' + Fishker.frontEnd + '/css2/toolbar.css?ver=21062010.1744');
}	var s = document.createElement('script');
s.src = "http://www." + Fishker.frontEnd + "/toolbar_html.js?session-id=e101c0fb-b7fe1c7d-94897848";
s.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(s);
}
},	start: function() {
Fishker.writeToolbar();
if (Fishker.isAuth) {
Fishker.ownId = document.getElementById('user-id').value;
Fishker.refresh();
}

},

startTimeout : function() {
Fishker.timeout = window.setTimeout(Fishker.refresh, 2 * 60 * 1000);
},
refresh : function() {
Fishker.update();
Fishker.startTimeout();
},
update : function() {
var e = ge('fishker_data_loader');
if (e) {
e.parentNode.removeChild(e);
}
var s = document.createElement('script');
s.src = "http://www." + Fishker.frontEnd + "/api?method=getFriendsOnline&format=JS&session-id=e101c0fb-b7fe1c7d-94897848";
s.type = "text/javascript";
s.id = "fishker_data_loader";
document.getElementsByTagName("body")[0].appendChild(s);
},
_update : function() {
var l = ge('fishker_loading');
l.style.display = 'none';
var p = l.parentNode;
var i = 0;
while (i < p.childNodes.length) {
if (p.childNodes[i].className == 'fTBimg') {
p.removeChild(p.childNodes[i]);
} else {
i++;
}
}
for ( var i = 0; i < Fishker.users.length; i++) {
var name = Fishker.users[i].firstName + ' ' + Fishker.users[i].secondName;
var img = document.createElement('img');
img.alt = name;
img.title = name;
img.src = Fishker.users[i].avatar;
img.id = Fishker.users[i].id;
// img.style.position = 'absolute';
// img.style.top = '-2px';
img.style.height = '25px';
img.style.width = '25px';
// img.style.left = '0px';
addEvent(img, 'click', function() {
window.location.href = 'http://www.' + Fishker.frontEnd + '/' + this.id;
});
var d = document.createElement('div');
d.className = 'fTBimg';
d.style.marginLeft = '5px';
d.style.position = 'relative';
d.style.display = 'inline-block';
d.style.height = '15px';
d.style.width = '25px';
d.style.float = 'left';
d.appendChild(img);
p.insertBefore(d, l);
}
ge('fishker_total_online').innerHTML = "Сейчас на сайте: " + Fishker.online;
addEvent(ge('fishker_total_online'), 'click', function(e) {
window.location.href = 'http://www.' + Fishker.frontEnd + '/' + Fishker.ownId + '/online';
return false;	});
if (Fishker.users.length > 0) {
ge('fishker_friends_online').innerHTML = "Друзья онлайн ";
ge('fishker_f_count').innerHTML = "&nbsp;(" + Fishker.frndsOnlineCount + "): ";
addEvent(ge('fishker_friends_online'), 'click', function(e) {
window.location.href = 'http://www.' + Fishker.frontEnd + '/' + Fishker.ownId + '/friendsOnline';
return false;
});
} else {
ge('fishker_friends_online_div').hide();
}
},
openMenu : function(node) {
var menu;
for (var i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].tagName && node.childNodes[i].tagName.toLowerCase().match('div')) {
menu = node.childNodes[i];
break;
}
}
menu.style.display = 'block';
var he = function(e) {
menu.style.display = 'none';
removeEvent(document, 'click', he);
node.onclick = function() {
Fishker.openMenu(node);
return false;
};
return false;
}
addEvent(node, 'click', function() {return false;});
window.setTimeout(function(){
addEvent(document, 'click', he);
}, 10);
},
writeToolbar : function() {
var d = document.createElement('div');
d.id = "fishker-toolbar";
d.innerHTML = Fishker.toolbarHtml;
if (navigator.userAgent.indexOf('MSIE') != -1) {
d.style.textAlign = 'left';
}
document.getElementsByTagName("body")[0].appendChild(d);
document.getElementsByTagName('body')[0].style.padding='0 0 2em';
var li = document.createElement('img');
li.src = "http://counter.yadro.ru/hit;fishker?t26.6;r" + escape(document.referrer) + ((typeof(screen) == "undefined") ? "" : ";s" + screen.width + "*" + screen.height + "*" + (screen.colorDepth ? screen.colorDepth : screen.pixelDepth)) + ";u" + escape(document.URL) + ";" + Math.random();
li.width = 1;
li.height = 1;
document.getElementsByTagName("body")[0].appendChild(li);
},
share : function() {
var msg = document.title + " · " + document.location.href;
out = Base64.encode(msg);
document.location.href = "http://www." + Fishker.frontEnd + "/" + Fishker.ownId + "?bmsg=" + out;
},
hide : function() {
ge("fishker-toolbar").style.display = "none";
var s = document.createElement('script');
s.src = "http://www." + Fishker.frontEnd + "/toolbar_hide.js";
s.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(s);
}
};
function addEvent(obj, evType, fn) {
if (obj.addEventListener) {
obj.addEventListener(evType, fn, false);
return true;
} else if (obj.attachEvent) {
var r = obj.attachEvent("on" + evType, fn);
return r;
} else {
//	alert("Handler could not be attached");
}
}
function removeEvent(obj, evType, fn) {
if (obj.removeEventListener) {
obj.removeEventListener(evType, fn, false);
return true;
} else if (obj.detachEvent) {
var r = obj.detachEvent("on" + evType, fn);
return r;
} else {
//	alert("Handler could not be removed");
}
}
function ge(id) {
return document.getElementById(id);
}
function getCookie(name) {
var cookie = " " + document.cookie;
var search = " " + name + "=";
var setStr = null;
var offset = 0;
var end = 0;
if (cookie.length > 0) {
offset = cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = cookie.indexOf(";", offset)
if (end == -1) {
end = cookie.length;
}
setStr = unescape(cookie.substring(offset, end));
}
}
return(setStr);
}
Fishker.users = [];
Fishker.online = 0;
Fishker.frontEnd = "fishker.ru";
Fishker.isAuth = false;
Fishker.init();
var Base64 = {
// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for encoding
encode : function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = Base64._utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 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;
}
output = output +
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
}
return output;
},
// private method for UTF-8 encoding
_utf8_encode : function (string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
}
