/******************************************
* DHTML Ad Box (By Matt Gabbert at http://www.nolag.com)
* Modified by Stephen Yabziz at http://yabsoft.com
* Visit http://www.dynamicdrive.com/ for full script
* This notice must stay intact for use
******************************************/

/***********************************
* setting for sponser ad
************************************/
var shakeTime=2000; // shake time for advertisement
var startShow=2000; //how long to begin to show advertisement
var AdTop = 200; //top of advertisement
var AdLeft = 500; // left of advertisement
var slideStep = 15; // 0 will dissble the slide down
var slideInternal = 10; //1000 = 1 seconds
/***********************************/

var adDiv;
var TO = null;
var Slide = null;
var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
var calunit=ns? "" : "px"
var curHeight = 0;
var shakePos = 5;

function initAd(){
        if(!ns && !ie && !w3) return;
        if(ie)                adDiv=eval('document.all.sponsorAdDiv.style');
        else if(ns)        adDiv=eval('document.layers["sponsorAdDiv"]');
        else if(w3)        adDiv=eval('document.getElementById("sponsorAdDiv").style');

    setTimeout("showAd();", startShow);
}
function shakeAd(object,speed)
{
    tmpobj = eval(object)

    if (shakePos == 5)
    {
        shakePos = -5;
    }
    else
    {
        shakePos = 5;
    }
    tmpobj.left = parseInt(tmpobj.left) + shakePos + calunit;
    tmpobj.top = parseInt(tmpobj.top) + shakePos + calunit;
    tmpobj = object;

    sp = speed;
    TO = setTimeout("shakeAd(tmpobj,sp)",speed);
}
function stopshake()
{
        clearTimeout(TO);
}
function slideAd()
{
    var stopSlide = 1;

    //detect the current postion
        if (ie){documentWidth  =AdLeft+truebody().scrollLeft-20;
        documentHeight = (slideStep>0 && curHeight<=AdTop+truebody().scrollTop-20) ? curHeight:AdTop+truebody().scrollTop;
    stopSlide = !(slideStep>0 && curHeight<=AdTop+truebody().scrollTop-20);}
        else if (ns){documentWidth=AdLeft+window.pageXOffset-20;
        documentHeight = (slideStep>0 && curHeight<=AdTop+window.pageYOffset-20) ? curHeight:AdTop+window.pageYOffset-20;
    stopSlide = !(slideStep>0 && curHeight<=AdTop+window.pageYOffset-20);}
        else if (w3){documentWidth=AdLeft+window.pageXOffset-20;
        documentHeight = (slideStep>0 && curHeight<=AdTop+window.pageYOffset-20) ? curHeight:AdTop+window.pageYOffset-20;
    stopSlide = !(slideStep>0 && curHeight<=AdTop+window.pageYOffset-20);}

    //assign to sponser box
    adDiv.left=documentWidth+calunit;
    adDiv.top =documentHeight+calunit;

    //increase curheight
    curHeight=curHeight+slideStep;

    //decide next action
    if(stopSlide)
    {
        clearTimeout(Slide);
        shakeAd(adDiv,75);
        setTimeout("stopshake()",shakeTime);
    }
    else
    {
        Slide = setTimeout("slideAd()",slideInternal);
    }

}
function showAd()
{
    //slide the ads,slideStep=0 can disbale slide
    slideAd();

    //show the ads
    if (ie||w3)
    adDiv.visibility="visible";
    else
    adDiv.visibility ="show";

    //bind to scroll event to the moveAd
    if (ie) window.onscroll = moveAd;
}
function moveAd()
{
    //detect the current postion
    if (ie){documentWidth  =AdLeft+truebody().scrollLeft-20;
        documentHeight =AdTop+truebody().scrollTop-20;}
        else if (ns){documentWidth=AdLeft+window.pageXOffset-20;
        documentHeight=AdTop+window.pageYOffset-20;}
        else if (w3){documentWidth=AdLeft+window.pageXOffset-20;
        documentHeight=AdTop+window.pageYOffset-20;}

    //assign to sponser box
    adDiv.left=documentWidth+calunit;
    adDiv.top =documentHeight+calunit;
}
function closeAd(){
        if (ie||w3)
        adDiv.display="none";
        else
        adDiv.visibility ="hide";

    if (ie) window.onscroll = null;
}

function truebody(){
        return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function screenSize() {
    var w, h; // Объявляем переменные, w - длина, h - высота
    w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
    h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
    return {w:w, h:h};
}
