﻿divForPopUpImage = null;


var DeltaXAxle = 40;
var DeltaYAxle = 20;

function TracePositionOfCursor(e) {
    x1 = (document.all) ? window.event.clientX + truebody().scrollLeft : e.pageX;
    y1 = (document.all) ? window.event.clientY + truebody().scrollTop : e.pageY;
    if (divForPopUpImage != null && divForPopUpImage.style.display != "none") {
        divForPopUpImage.style.left = (x1 + DeltaXAxle) + "px";
        divForPopUpImage.style.top = (y1 + DeltaYAxle) + "px";
    }
}
function TracePositionOfCursorWithCorrection(e) {
    x = (document.all) ? window.event.clientX + truebody().scrollLeft : e.pageX;
    y = (document.all) ? window.event.clientY : e.pageY - getOffsetTop();
    x1 = x;
    y1 = y;
    var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
    var docheight = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

    //alert(x+'|'+y+' window='+docwidth+'|'+docheight);
    /*if (docwidth - x1 < Pop_UpDivWidth){
    x1 = x1 - DeltaXAxle - Pop_UpDivWidth;
    } else {
    x1 += DeltaXAxle;
    }*/
    if (x1 - docwidth / 2 > 5) {
        x1 = x1 - DeltaXAxle - Pop_UpDivWidth - 20;
    }
    else
        x1 += DeltaXAxle;

    //		if (docheight - y1 <Pop_UpDivHeight ){
    //			y1 = docheight -Pop_UpDivHeight+truebody().scrollTop;
    //		} else {
    //			y1 += DeltaYAxle+truebody().scrollTop;
    //		}
    if (docheight - y1 < Pop_UpDivHeight) {
        y1 = docheight - Pop_UpDivHeight + getOffsetTop();
    } else {
        y1 += DeltaYAxle + getOffsetTop();
    }




    if (y1 < 0) { y1 = y; }
    if (divForPopUpImage != null && divForPopUpImage.style.display != "none") {
        divForPopUpImage.style.left = x1 + "px";
        divForPopUpImage.style.top = y1 + "px";
    }

}
function ShowPopUpDiv(id, logofile, transparency) {
    document.onmousemove = TracePositionOfCursor;
    var TransparencyValue = 90;
    if (transparency)
        TransparencyValue = transparency;
    var AbsoluteTransparencyValue = (TransparencyValue / 100);
    if (divForPopUpImage == null) {
        divForPopUpImage = document.getElementById(id);
    }
    if (logofile)
        divForPopUpImage.innerHTML = '<img src="' + logofile + '" style="-moz-opacity: ' + AbsoluteTransparencyValue + ';filter: alpha(Opacity=' + TransparencyValue + ');">';
    divForPopUpImage.style.position = "absolute";
    divForPopUpImage.style.display = "block";
    divForPopUpImage.style.visibility = "visible";

}
function truebody() {
    return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}
var Pop_UpDivHeight = 0, Pop_UpDivWidth = 0;

function ShowPopUpDivWithComment(id, logofile, transparency, imgDivID, commentDivID, comment, width, height) {
    if (width > 0 && height > 0) {
        document.onmousemove = TracePositionOfCursorWithCorrection;
        Pop_UpDivHeight = height;
        Pop_UpDivWidth = width;
    }
    else
        document.onmousemove = TracePositionOfCursor;

    var TransparencyValue = 90;
    if (transparency)
        TransparencyValue = transparency;
    var AbsoluteTransparencyValue = (TransparencyValue / 100);
    if (divForPopUpImage == null) {
        divForPopUpImage = document.getElementById(id);

    }

    if (logofile) {
        var imgDiv = document.getElementById(imgDivID);
        imgDiv.innerHTML = '<img src="' + logofile + '" style="-moz-opacity: ' + AbsoluteTransparencyValue + ';filter: alpha(Opacity=' + TransparencyValue + ');">';
        if (commentDivID) {
            var commentDiv = document.getElementById(commentDivID);
            if (comment) {
                commentDiv.style.display = "block";
                commentDiv.innerHTML = comment;
            }
            else
                commentDiv.style.display = "none";
        }

    }
    divForPopUpImage.style.position = "absolute";
    divForPopUpImage.style.display = "block";
    divForPopUpImage.style.visibility = "visible";
}
// Функция предназначена для показа всплывающей картинки с параметрами по-умолчанию
function ShowPopUpImg(img, comment, alt) {
    var mainDiv = document.getElementById('divForDefaultPopUpImage');
    if (!mainDiv) {
        var body = truebody();
        mainDiv = document.createElement('div');
        mainDiv.id = 'divForDefaultPopUpImage';
        mainDiv.className = 'popup_wrap';
        mainDiv.style.display = 'none';
        mainDiv.style.zIndex = 100;
        mainDiv.width = 500;
        mainDiv.height = 400;
        var divTbl = document.createElement('div');
        try
		{ divTbl.style.display = 'table'; } catch (e) { }
        mainDiv.appendChild(divTbl);

        var divPop = document.createElement('div');
        divPop.className = 'PopUpImage';
        mainDiv.appendChild(divPop);

        var divImg = document.createElement('div');
        divImg.id = 'divForDefaultImage';
        divPop.appendChild(divImg);

        var pComm = document.createElement('p');
        pComm.id = 'divForDefaultComment';
        divPop.appendChild(pComm);

        //		var imgSh=document.createElement('img');
        //		imgSh.src='/i/shadow_popup.png'; 
        //		imgSh.height=13; 
        //		if(window.navigator.userAgent.toLowerCase())
        //		{
        //		    var posl=window.navigator.userAgent.toLowerCase().indexOf('msie');
        //		    var posr=window.navigator.userAgent.toLowerCase().indexOf('6.0',posl);
        //		    if(posl>0&&posl<posr)
        //		    {
        //		    alert('sdfsdf');
        //		    		    imgSh.style.display='none'; 
        //	           }
        //		}
        //		mainDiv.appendChild(divImg);
        //		
        //		var divSh=document.createElement('div');
        //		divSh.className='shadow_popup_wrap'; 
        //		mainDiv.appendChild(divSh);
        document.forms[0].appendChild(mainDiv);
    }
    if (alt == 1)
        ShowPopUpDivWithComment('divForDefaultPopUpImage', '/handlers/imgalt.ashx?width=500&height=400&Img=' + img, 100, 'divForDefaultImage', 'divForDefaultComment', comment, 550, 450);
    else
        ShowPopUpDivWithComment('divForDefaultPopUpImage', '/img.ashx?width=500&height=400&Img=' + img, 100, 'divForDefaultImage', 'divForDefaultComment', comment, 550, 450);
}
function HidePopUpDiv() {
    if (divForPopUpImage) {
        divForPopUpImage.style.display = "none";
        divForPopUpImage.style.left = 0;
        var divForComment = document.getElementById('divForComment');
        if (divForComment)
        { divForComment.innerHTML = ''; divForComment.style.display = "none"; }
        divForPopUpImage.style.top = -500;
        divForPopUpImage = null;

        document.onmousemove = null;
    }

}





