/*
Script developed by Eugene Krivorucho (c) 2008
Only for 2smi.ru use =)
*/
var iPB = 112 + 1;
var time = 1;
var numPic = 0;
var padHeight = 100;
var oblako = 0;
var info = false;
var description = false;
var l_Block = false;
var ie=document.all;
var nn6=document.getElementById&&!document.all;
var isdrag=false;
var x,y;
var dobj;
// var he = '';
// var be = new Object;
var hs = {
opacity : 0.6,
descriptionCounter : 1,
ie : (document.all && !window.opera),
safari : navigator.userAgent.indexOf("Safari") != -1,
createElement : function (tag, attribs, styles, parent, nopad) {
var el = document.createElement(tag);
if (attribs) hs.setAttribs(el, attribs);
if (nopad) hs.setStyles(el, {padding: 0, border: 'none', margin: 0});
if (styles) hs.setStyles(el, styles);
if (parent) parent.appendChild(el);
return el;
},
setAttribs : function (el, attribs) {
for (var x in attribs) {
el[x] = attribs[x];
}
},
setStyles : function (el, styles) {
for (var x in styles) {
try {
if (hs.ie && x == 'opacity') {
el.style.filter = styles[x] == 1 ? 'none' : 'alpha(opacity='+ (styles[x] * 100) +')';
}
else el.style[x] = styles[x];
}
catch (e) {}
}
},
position : function(el) {
var p = { x: el.offsetLeft, y: el.offsetTop };
while (el.offsetParent) {
el = el.offsetParent;
p.x += el.offsetLeft;
p.y += el.offsetTop;
if (el != document.body && el != document.documentElement) {
p.x -= el.scrollLeft;
p.y -= el.scrollTop;
}
}
return p;
},
genContainer : function () {
/*
if (!hs.container) {
hs.container = hs.createElement('div',
null,
{ position: 'absolute', left: 0, top: 0, width: '100%' },
document.getElementById('description'),
true
);
}
*/
if (!hs.container)
hs.container = document.getElementById('desc');
}
}
function pP() {
numPic++;
var eNumPic = document.getElementById('numPic');
var eNumPercent = document.getElementById('Percent');
numPercent = Math.round(100 / 112 * numPic);
if (numPercent > 100)
numPercent = 100;
eNumPercent.style.width = (380 / 100) * numPercent+'px';
eNumPic.innerHTML = numPercent+'%';
}
function sD(e, o, t) {
if (t == 's') {
if (description == true)
closeDescription();
description = true;
}
else {
if (description == true)
closeDescription();
background(2);
}
if (e.tagName != 'DIV')
e = document.getElementById(e);
el = e.getElementsByTagName('IMG')[0];
this.thumb = el;
var key = this.key = hs.descriptionCounter++;
var pos = hs.position(el);
// store properties of thumbnail
this.thumbWidth = el.width ? el.width : el.offsetWidth;
this.thumbHeight = el.height ? el.height : el.offsetHeight;
this.thumbLeft = pos.x;
this.thumbTop = pos.y;
// thumb borders
this.thumbOffsetBorderW = (this.thumb.offsetWidth - this.thumbWidth) / 2;
this.thumbOffsetBorderH = (this.thumb.offsetHeight - this.thumbHeight) / 2;
// get the wrapper
hs.genContainer();
//if (!hs.loading) {
hs.loading = hs.createElement('div',
{
id: 'description_' + this.key,
innerHTML: showText(e, o, t),
className: 'descnews'
},
{
position: 'absolute',
opacity: '1'
}, hs.container
);
//}
oblako = this.key;
this.loading = hs.loading;
//this.loading.href = 'closeDescription('+ this.key +')';
this.loading.visibility = 'visible';
this.loading.style.left = (this.thumbLeft + this.thumbOffsetBorderW)
+'px';
//+ (this.thumbWidth - this.loading.offsetWidth) / 2)
this.loading.style.top = (this.thumbTop)
+'px';
//+ (this.thumbHeight - this.loading.offsetHeight) / 2)
if (o > 1) {
if (!document.getElementById('oblako'))
obl = document.getElementById('oblako2');
else
obl = document.getElementById('oblako');
h = 0 - obl.clientHeight;
if (o == 2)
w = '-20px';
else
w = '-308px';
obl.style.margin = h+'px 0 0 '+w;
}
}
function showText(e, o, t) {
text = news[e.id];
el = e.getElementsByTagName('IMG')[0];
if (t == 's')
html = '
';
else {
html = '';
}
return html;
}
function removeElementById(remele) {
remele = document.getElementById(remele);
remele.parentNode.removeChild(remele)
}
function closeOblako() {
if (l_Block == false) {
if (info == true) {
e = document.getElementById('info');
e.style.display = 'none';
description = false;
}
if (oblako > 0)
removeElementById('description_'+oblako);
oblako = 0;
}
}
function closeDescription() {
if (info == true) {
e = document.getElementById('info');
e.style.display = 'none';
description = false;
}
if (oblako > 0)
removeElementById('description_'+oblako);
oblako = 0;
e = document.getElementById('transperent');
e.style.height = 0;
e.style.visibility = 'hidden';
}
function showNews() {
showPic(1, iPB);
}
function hideNews(u) {
document.getElementById('loading').style.visibility = 'visible';
hidePic(iPB - 1, u);
}
function hidePic(id, u) {
if (id > 0) {
e = document.getElementById('n_'+id).style.visibility = 'hidden';
setTimeout("hidePic("+(id - 1)+", '" + u + "')", time);
}
else {
OptionRequest(u);
closeOblako();
return true;
}
}
function showPic(id, maxid) {
if (id < maxid) {
e = document.getElementById('n_'+id).style.visibility = 'visible';
setTimeout("showPic("+(id + 1)+", "+maxid+")", time);
}
else {
document.getElementById('loading').style.visibility = 'hidden';
return true;
}
}
function background(t) {
if (!t)
t = 1;
e = document.getElementById('main_block');
height = e.clientHeight + 12;
if (this.size().height > height)
height = this.size().height;
e = document.getElementById('transperent');
if (hs.ie)
e.style.filter = hs.opacity == 1 ? 'none' : 'alpha(opacity='+ (hs.opacity * 100) +')';
else
e.style.opacity = hs.opacity;
e.style.visibility = 'visible';
if (t == 1) {
scrollBG(e, 0, height);
l_Block = true;
}
else
e.style.height = height;
}
function scrollBG(e, s, h) {
if (s < h) {
b = s + padHeight;
if (b > h)
b = h;
e.style.height = b;
setTimeout("scrollBG(e, b, "+h+")", time);
}
else {
l_Block = false;
if (info == true) {
width = this.size().width;
e = document.getElementById('info');
e.style.top = '148';
e.style.left = width / 2 - 200;
e.style.display = 'block';
}
return true;
}
}
window.size = function() {
var w = 0;
var h = 0;
//IE
if(!window.innerWidth) {
//strict mode
if(!(document.documentElement.clientWidth == 0)) {
w = document.documentElement.clientWidth;
h = document.documentElement.clientHeight;
}
else
{
//quirks mode
w = document.body.clientWidth;
h = document.body.clientHeight;
}
}
else
{
//w3c
w = window.innerWidth;
h = window.innerHeight;
}
return {width:w,height:h};
}
function showHtml(html) {
url = 'http://2smi.ru/'+html;
e = document.getElementById('info_block');
e.innerHTML = '
';
background(1);
info = true;
OptionRequest(url);
}
function OptionRequest(URL) {
try {
var requester = new XMLHttpRequest();
}
catch (error) {
try {
var requester = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (error) {}
}
if(requester&&requester.readyState!=0) {
requester.abort()
}
requester.open("GET", URL, true);
requester.onreadystatechange=function() {
if(requester.readyState==4 && requester.responseText) {
if(requester.responseText.charAt(0) == "<"){
alert('Повторите попытку позже, сервер временно не доступен!');
} else {
eval(requester.responseText);
}
}
}
requester.send("null");
}
function showThemes(name) {
numPic = -1;
pP();
url = 'view.themes.'+name;
//url = '/main.page.php?themes='+name+'&type=ajax';
hideNews(url);
}
Array.prototype.clear = function() {
var obj = this
this.length.times(function(index) {
delete obj[index]
})
this.length = 0
}
Number.prototype.times = function(block) {
for (var i = 0; i < this; i++) block(i)
}
function selectAll(e) {
e.focus()
e.select()
}
function showPicture(r) {
n = document.getElementById('news');
n.innerHTML = '';
if (!html)
var html = '';
if (!m)
var m = 1;
if (!k)
var k = 1;
for (var i = 1; i < 113; i++) {
if (!p)
var p = '0';
p = '0';
if (m > 14) {
m = 1;
k++;
}
if (m > 14 - 5)
p = '1';
if (k > 8 - 3 && p == '0')
p = '2';
if (k > 8 - 3 && p == '1')
p = '3';
if (news[blocks[i]][3] > 0)
html += '';
else
html += '';
m++;
}
html += '';
n.innerHTML = html;
}
function movemouse(e) {
if (isdrag) {
dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
dobj.style.top = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
return false;
}
}
function selectmouse(e) {
var fobj = nn6 ? e.target : event.srcElement;
var topelement = nn6 ? "HTML" : "BODY";
while (fobj.tagName != topelement && fobj.className != "dragme") {
fobj = nn6 ? fobj.parentNode : fobj.parentElement;
}
if (fobj.className=="dragme") {
isdrag = true;
dobj = fobj;
tx = parseInt(dobj.style.left+0);
ty = parseInt(dobj.style.top+0);
x = nn6 ? e.clientX : event.clientX;
y = nn6 ? e.clientY : event.clientY;
document.onmousemove=movemouse;
return false;
}
}
document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");
function CreateBookmarkLink() {
var title = '2smi.ru | отбираем лучшие новости';
var url = "http://2smi.ru/";
if (window.sidebar) {
window.sidebar.addPanel(title, url,"");
}
else
if( window.external ) {
window.external.AddFavorite( url, title);
}
else
if(window.opera && window.print) {
return true;
}
}
function setHomepage(f) {
f.style.behavior='url(#default#homepage)';
f.setHomePage('http://2smi.ru/')
}