﻿// don't be so nosey!
//

var TimersCollection = new Object(); var TimerImageLookup = new Object(); var TimerInProgress = new Object();
var IE = document.all ? true : false; var gecko = (navigator.userAgent.indexOf("Gecko") > -1) && (navigator.userAgent.indexOf("KHTML") == -1);
var LoadedAlready = new Object(); var OtherVisibleDiv = new Object(); var TempLookup = []; var p = []; var c = false;
var DivsToRemove = []; var HitCount = [];var sos = true;
function r(min, max) { return (Math.round((max - min) * Math.random() + min)); }
function getDomainLink() { return "http://web0" + r(1, 4) + ".mugurdy.com"; }
function p(i) { px("assets/images/" + i); }
function px(i) { jQuery("<img>").attr("src", i); }
function findPos(obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent)
    {
        do
        {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
        return [curleft, curtop];
    }
}

function rI(o, id, x)
{
    if (x != 1)
    {
        if (!LoadedAlready[id])
        {
            createSwirl(o, id, x); HitCount[id] = 1;
            LoadedAlready[id] = true; TimerImageLookup[id] = o; TimerInProgress[id] = false;
            cFIT(id); TimersCollection[id] = setInterval("cFIT('" + id + "')", 350);
        }
        else
        {
            clearInterval(TimersCollection[id]);
            var od = document.getElementById('div' + id);
            if (od)
                od.innerHTML = '';
        }
    }
}

function cFIT(id)
{
    if (!TimerInProgress[id])
    {
        TimerInProgress[id] = true;
        if ($)
        {
            HitCount[id] = HitCount[id] + 1;
            $.ajax({
                type: "POST",
                url: "ia.asmx/a",
                data: "{'i':'" + id + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                error: function() { TimerInProgress[id] = false; },
                success: function(msg)
                {
                    if (msg.d)
                    {
                        clearInterval(TimersCollection[id]);
                        setTimeout("lI('" + id + "');", 350);
                    }
                    TimerInProgress[id] = false;
                }
            });
        }
    }
}

function lI(id)
{
    TimerImageLookup[id].src = 'Image.aspx?i=' + id + 'z';
}

function createSwirl(o, id, x)
{
    var pos = findPos(o); var d = document.createElement("div"); d.id = "div" + id;
    if (x == 0)
    {
        d.style.left = (pos[0] + 1) + 'px'; d.style.top = (pos[1] + 1) + 'px';
        d.style.width = 280 + 'px'; d.style.position = "absolute";
        d.setAttribute("align", "center"); d.style.zIndex = 1000;

        d.innerHTML = "<img src=\"http://www.mugurdy.com/assets/images/loading.gif\" style=\"padding-top: 53px;\" />";
    }
    document.getElementById('placeholder').appendChild(d);
}

var isFirst = true;
function sZD(o, id, address, m)
{
    if (isFirst && m != 1)
        isFirst = false;
    else
    {
        var showPopup = true;

        if (showPopup)
        {
            var fc = getFixedCords();
            var d2 = document.getElementById("zDiv" + id);
            if (d2)
            {
                d2.style.left = fc[0] + 'px';
                d2.style.top = fc[1] + 'px';
            }
            else
            {
//                cOZD();
//                var divTag = document.createElement("div");
//                var imgName = "35-" + r(0, 5) + ".gif";

//                divTag.id = "zDiv" + id;
//                divTag.style.left = fc[0] + 'px'; divTag.style.top = fc[1] + 'px';
//                divTag.style.width = 560 + 'px'; divTag.style.height = 426 + 'px';
//                divTag.style.position = 'absolute'; divTag.setAttribute("align", "center");
//                divTag.style.border = '1px solid #808080'; divTag.style.zIndex = 2000;                
//                
//                divTag.innerHTML = "<a href=\"" + address + "\" target=\"_blank\" border=0>" +
//            "<img id=\"zImg" + id + "\" src=\"" + getDomainLink() + "/Image.aspx?i=" + id + "z\" width=\"560\" height=\"426\" onclick=\"cOZD();\" border=\"0\" class=\"zdiv\" /></a>"
//                document.getElementById('placeholder').appendChild(divTag);
//
                //                OtherVisibleDiv = divTag; c = true;
                //cOZD();
                var iT = document.createElement("img");
                
                iT.id = "iT" + id;
                iT.style.left = fc[0] + 'px'; iT.style.top = fc[1] + 'px';
                iT.style.width = 560 + 'px'; iT.style.height = 426 + 'px';
                iT.style.position = 'absolute'; iT.style.border = '1px solid #808080';
                iT.style.zIndex = 2000; iT.setAttribute('class', 'zImg');
                iT.setAttribute('src', getDomainLink() + '/Image.aspx?i=' + id + 'z');

//                divTag.innerHTML = "<a href=\"" + address + "\" target=\"_blank\" border=0>" +
//            "<img id=\"zImg" + id + "\" src=\"" + getDomainLink() + "/Image.aspx?i=" + id + "z\" width=\"560\" height=\"426\" onclick=\"cOZD();\" border=\"0\" class=\"zdiv\" /></a>"
                document.getElementById('placeholder').appendChild(iT);

                OtherVisibleDiv = iT; c = true;
            }
        }

    }
}
var existingZoomed;
function nSZD(o, id, address, m)
{
    if (isFirst && m != 1)
        isFirst = false;
    else
    {
        var showPopup = true;

        if (showPopup)
        {
            var fc = getFixedCords();
            var d2 = document.getElementById("zDiv" + id);
            if (d2)
            {
                d2.style.left = fc[0] + 'px';
                d2.style.top = fc[1] + 'px';
            }
            else
            {
                nCOZD();
                var iT = document.getElementById('imgZ' + id);

                iT.style.left = fc[0] + 'px'; iT.style.top = fc[1] + 'px';
                iT.style.width = 560 + 'px'; iT.style.height = 426 + 'px';
                iT.style.position = 'absolute'; iT.style.border = '1px solid #808080';
                iT.style.zIndex = 2000; iT.setAttribute('class', 'zImg');

                OtherVisibleDiv = iT; c = true;
                existingZoomed = iT;
                $('#imgZ' + id).fadeIn('slow');
            }
        }

    }
}

function nCOZD()
{
    if (existingZoomed)
    {
        $('#' + existingZoomed.id).fadeOut('100');        
    }
}


function getFixedCords()
{
    var ret = p;
    if ((p[0] + 560) >= document.documentElement.clientWidth + document.body.offsetWidth)
        ret[0] = document.documentElement.clientWidth + document.documentElement.scrollLeft - 560;
    if ((p[1] + 426) >= document.documentElement.clientHeight + document.body.offsetHeight)
        ret[1] = document.documentElement.clientHeight + document.documentElement.scrollTop - 426;
    return ret;
}

function cOZD()
{
    if (c)
    {
        if (OtherVisibleDiv)
        {
            if (document.getElementById(OtherVisibleDiv.id) != null)
            {
                document.getElementById('placeholder').removeChild(OtherVisibleDiv);
                OtherVisibleDiv = null;
            }
        }
        c = false;
    }
}

function addToFavourites()
{
    if (IE)
        window.external.AddFavorite(location.href, document.title);
    else if (window.sidebar)
        window.sidebar.addPanel(document.title, location.href, '');
}

function popUp(url)
{
    var myWindow = window.open(url, 'popup' + url, 'height=400,width=550');
    if (window.focus)
        myWindow.focus();
    return false;
}

function s(o, i, m) { if (m == 0) { o.src = 'assets/images/' + i + '.gif' } else { o.src = 'assets/images/' + i + 'O.gif' } }