MaxIndex = 1;
function browsers() {
this.ie = (navigator.userAgent.indexOf("MSIE") != -1) ? 1 : 0;
this.nn = (navigator.userAgent.indexOf("Netscape") != -1) ? 1 : 0;
this.opera = (navigator.userAgent.indexOf("Opera") != -1) ? 1 : 0;
}
var bw = new browsers();
function $(obj) {
if(document.all) {
if(typeof obj == "string") {
return document.all(obj);
return false;
}
}
if(document.getElementById) {
if(typeof obj == "string") {
return document.getElementById(obj);
return false;
}
}
}
window.onload = function() {
init();
document.onmousedown = take;
document.onmousemove = move;
document.onmouseup = release;
}
function init() {
for(var i=1; i<10; i++) {
var opener = $("opener" + i);
var closer = $("closer" + i);
var smaller = $("small" + i);
if(opener && closer && smaller) {
opener.onclick = function() {
var num = this.id;
num = num.substr(num.length - 1, 1);
$("parentparag" + num).style.display = "block";
magick($("parentparag" + num), 99);
}
closer.onclick = function() {
var num = this.id;
num = num.substr(num.length - 1, 1);
$("parentparag" + num).style.display = "none";
$("parentparag" + num).style.opacity = 0;
if(bw.ie) { $("parentparag" + num).filters["alpha"].opacity = 0};
}
smaller.onclick = function() {
var num = this.id;
num = num.substr(num.length - 1, 1);
if($("parentparag" + num).offsetHeight > 270) {
resize($("parentparag" + num), 10, true);
} else if($("parentparag" + num).offsetHeight < 30) {
resize($("parentparag" + num), 20, false);
}
}
}
}
}
function resize(whatElem, speed, bool) {
var elemHeight = whatElem.offsetHeight;
var step = (bool) ? --elemHeight : elemHeight++;
if(step) {
if(bool) {
whatElem.style.height = parseInt(step - speed) + "px";
if(step < 40) {
whatElem.style.height = 29 + "px";
return false;
}
} else {
whatElem.style.height = parseInt(step + speed) + "px";
if(step > 250) {
whatElem.style.height = 280 + "px";
return false;
}
}
}
timerID = setTimeout(function() {resize(whatElem, speed, bool)}, 1);
}
function magick(obj, maxOpacity) {
var cont = (bw.ie) ? obj.filters["alpha"].opacity : obj.style.opacity;
cont++;
obj.style.display = "block";
if(bw.ie) {
if(obj.filters["alpha"].opacity < maxOpacity) {
obj.style.filter = "alpha(opacity = "+parseInt(cont + 1, 10) +")";
timerID = setTimeout(function(){ magick(obj, maxOpacity) }, 1);
}
} else {
if(obj.style.opacity < maxOpacity / 100) {
if(bw.opera) {
obj.style.opacity = cont - 0.95;
} else {
obj.style.opacity = cont - 0.98;
}
timerID = setTimeout(function(){ magick(obj, maxOpacity) }, 1);
}
}
}
var offsetX = 0;
var offsetY = 0;
var targetEl;
function take(e) {
e = e || window.event;
var target = (e.target) ? e.target : e.srcElement;
var num = target.id;
if(num != "" && document.getElementById("parent" + num) != null) {
if(document.all) {
targetEl = document.all("parent" + num);
} else if(document.getElementById) {
targetEl = document.getElementById("parent" + num);
}
document.getElementById("parent" + num).style.zIndex = MaxIndex++; // закрепил zIndex на первое место
}
if(targetEl) {
if(e.pageX) {
offsetX = e.pageX - target.parentNode.parentNode.offsetLeft;
offsetY = e.pageY - target.parentNode.parentNode.offsetTop;
} else if(e.offsetX) {
offsetX = e.offsetX;
offsetY = e.offsetY;
}
return false;
}
}
function move(e) {
e = e || window.event;
if(targetEl) {
var targetW = targetEl.offsetWidth;
var windowW = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
if (e.pageX && window.innerWidth) {
var posRight = e.pageX - offsetX + targetW;
var diff = posRight - windowW;
if(posRight > windowW) {
targetEl.style.width = parseInt(targetW - diff, 10) + "px";
} else if(posRight < windowW && targetW < 500) {
targetEl.style.width = parseInt(targetW - diff, 10) + "px";
}
targetEl.style.left = parseInt(e.pageX - offsetX, 10) + "px";
targetEl.style.top = parseInt(e.pageY - offsetY, 10) + "px";
} else if(e.clientX) {
var posRight = e.clientX - offsetX + targetW;
var diff = posRight - windowW;
if(posRight > windowW) {
targetEl.style.width = parseInt(targetW - diff, 10) + "px";
} else if(posRight < windowW && targetW < 500) {
targetEl.style.width = parseInt(targetW - diff, 10) + "px";
}
targetEl.style.left = parseInt(e.clientX - offsetX, 10) + "px";
targetEl.style.top = parseInt(e.clientY - offsetY, 10) + "px";
}
if(targetEl.offsetLeft < 0) {targetEl.style.left = 0 + "px"}
if(targetEl.offsetTop < 0) {targetEl.style.top = 0 + "px"}
return false
}
}
function release(e) {
e = e || window.event;
var target = (e.target) ? e.target : e.srcElement;
var num = target.id;
if(num != "" && document.getElementById("parent" + num) != null) {
targetEl = null;
//document.getElementById("parent" + num).style.zIndex = 0; // тут нужно условие
}
}