﻿var browser=document.all?"IE":"OTHER";
var globalVars= new Array();

/*** class GetDOMElement *******/
function GetDOMElement()
{
    this.ID="";
    this.getTopposition=GetYPosition;
    this.getLeftposition=GetXPosition;;
    this.getWidth=GetWidth;
    this.getHeight=GetHeight;
}
// for generating the Y position
function GetYPosition()
{
    var elementObject=document.getElementById(this.ID);
    var elemntPosition = getParentPosition(elementObject);
    return parseFloat(elementObject.offsetTop)+parseFloat(elemntPosition[1]);
}
// for generating the parent XY position
function getParentPosition(ElementObj)
{
    try{
    var parentElementObj=ElementObj.offsetParent;
    var intXPosition=0;
    var intYPosition=0;
    var elemntPosition = new Array();
    intXPosition=parseFloat(parentElementObj.offsetLeft);
    intYPosition=parseFloat(parentElementObj.offsetTop);
       
    while(parentElementObj.tagName!="BODY")
    {
        try{
            parentElementObj=parentElementObj.offsetParent;
            intXPosition+=parseFloat(parentElementObj.offsetLeft);
            intYPosition+=parseFloat(parentElementObj.offsetTop);
        }
        catch(err)
        {
            break;
        }            
    }
    elemntPosition[0]=intXPosition;
    elemntPosition[1]=intYPosition;
    }
    catch(err){
        elemntPosition[0]=intXPosition;
        elemntPosition[1]=intYPosition;
    }    
    return elemntPosition;
}
// for generating the X position
function GetXPosition()
{
    var elementObject=document.getElementById(this.ID);
    var elemntPosition = getParentPosition(elementObject);
    return parseFloat(elementObject.offsetLeft)+parseFloat(elemntPosition[0]);
}
function GetWidth()
{
    var elementObject=document.getElementById(this.ID);
    return parseFloat(elementObject.offsetWidth);
}
function GetHeight()
{
    var elementObject=document.getElementById(this.ID);
    return parseFloat(elementObject.offsetHeight);
}
/***************************************************************/


/*** class Browser details *******/
function BrowserDomDetails()
{
    this.width;
    this.height;
    
    this.isBrowserTypeIE=checkIsBrowserTypeIE;
    this.getBrowserSize=generateBrowserSize;
}
function checkIsBrowserTypeIE()
{
    if(browser=="IE")
        return true;
    else    
        return false;
}
function generateBrowserSize()
{
    if(typeof(window.innerWidth)=='number'){
        this.width=window.innerWidth;
        this.height=window.innerHeight;
    }
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
        this.width=document.documentElement.clientWidth;
        this.height=document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)){
        this.width=document.body.clientWidth;
        this.height=document.body.clientHeight;
    }

    var scrollY = 0;
    var scrollX = 0;
       
    if(document.documentElement && document.documentElement.scrollTop){
        scrollY = document.documentElement.scrollTop;
        scrollX = document.documentElement.scrollLeft;
    }
    else if(document.body && document.body.scrollTop){
        scrollY = document.body.scrollTop;
        scrollX = document.body.scrollLeft;
    }
    else if(window.pageYOffset){
        scrollY = window.pageYOffset;
        scrollX = window.pageXOffset;
    }
    else if(window.scrollY){
        scrollY = window.scrollY;
        scrollX = window.scrollX;
    }
    
    this.width=parseFloat(this.width)+parseFloat(scrollX);
    this.height=parseFloat(this.height)+parseFloat(scrollY);
}
/***************************************************************/


/*** class ElementAnimations inherrited from GetDOMElement *******/
ElementAnimations.prototype = new GetDOMElement();
ElementAnimations.prototype.constructor=ElementAnimations;  
function ElementAnimations(ElementID)
{
    //properties for enableing the animation
    this.ID=ElementID;
    this.AnimFromCurrentPosition;
    this.toCenter;
    this.CurrentXposition;
    this.CurrentYposition;
    this.newXposition;
    this.newYposition;
    
    //properties for starting and stopping animations
    this.timeLimit=220;
    this.actualTimeHit=10;
    this.intervalStopper;
    this.xMovepix;
    this.yMovepix;
    this.currentTimeHit;
    this.CurrentDummyXposition;
    this.CurrentDummyYposition;
    this.AbortAnimation=false;

    //different animation methods.
    this.dropFromTopStyle;//LEFT/CENTER/RIGHT
    this.dropFromTop=FromTopAnimtaion;
    
    // method to set all properties to start and stop animations and to raise animation event.
    this.AnimateDialogueNewPosition=startAnimation;
    
    // method to animated the layer
    this.Animate=startRealAnimation;
    
    // method raised after the animation
    this.abortAnimate=abortPresertAnimation;
    this.postAnimate=TEST;
}
function TEST(){
}
function startRealAnimation()
{
    if(this.currentTimeHit < this.timeLimit && this.AbortAnimation==false){
        var tempXposition=parseFloat(this.CurrentDummyXposition)+parseFloat(this.xMovepix);
        var tempYposition=parseFloat(this.CurrentDummyYposition)+parseFloat(this.yMovepix);

        document.getElementById(this.ID).style.position="absolute";
        document.getElementById(this.ID).style.top=tempYposition+"px";
        document.getElementById(this.ID).style.left=tempXposition+"px";

        this.CurrentDummyXposition=tempXposition;
        this.CurrentDummyYposition=tempYposition;

        this.currentTimeHit=(this.currentTimeHit)+(this.actualTimeHit);
    }
    else{
        this.intervalStopper=window.clearInterval(this.intervalStopper);
        this.postAnimate();
    }
}
function abortPresertAnimation()
{
    this.AbortAnimation=true;
}
function startAnimation()
{
    var Difference;
    var time=220;
    var timeSpan=10;
    var xDifference=(parseFloat(this.newXposition)-parseFloat(this.CurrentXposition));
    var yDifference=(parseFloat(this.newYposition)-parseFloat(this.CurrentYposition));
    
    this.xMovepix=(xDifference/this.timeLimit)*this.actualTimeHit;
    this.yMovepix=(yDifference/this.timeLimit)*this.actualTimeHit;
    
    this.currentTimeHit=0;
    //this.intervalStopper=setInterval("this.Animate()",timeSpan);
    if(browser=="IE")
    {
        globalVars[this.uniqueId]=this;
        this.intervalStopper=setInterval('IEAnimator("' + this.uniqueId + '","Animate")',timeSpan);
    }
    else
        this.intervalStopper=setInterval( function(that){ that.Animate(); },timeSpan,this);
}
function IEAnimator(id,strFunc)
{
    var scope = globalVars[id];
    eval("scope."+strFunc+"()");
}
// all functions for animation
function FromTopAnimtaion()
{
    var oBrowserDomDetails = new BrowserDomDetails();
    oBrowserDomDetails.getBrowserSize();
    
    if(this.AnimFromCurrentPosition==false){
        if(this.dropFromTopStyle=="TOPLEFTCORNER"){
            this.CurrentXposition=0-this.getWidth();
            this.CurrentYposition=0-this.getHeight();
        }
        else if(this.dropFromTopStyle=="TOPRIGHTCORNER"){
            this.CurrentXposition=oBrowserDomDetails.width;
            this.CurrentYposition=0-this.getHeight();
        }
        else if(this.dropFromTopStyle=="TOPCENTER"){
            this.CurrentXposition=(oBrowserDomDetails.width/2)-(this.getWidth()/2);
            this.CurrentYposition=0-this.getHeight();
        }
        else if(this.dropFromTopStyle=="LEFTMIDDLE"){
            this.CurrentXposition=0-this.getWidth();
            this.CurrentYposition=(oBrowserDomDetails.height/2)-(this.getHeight()/2);
        }
        else if(this.dropFromTopStyle=="RIGHTMIDDLE"){
            this.CurrentXposition=oBrowserDomDetails.width;
            this.CurrentYposition=(oBrowserDomDetails.height/2)-(this.getHeight()/2);
        }
        else if(this.dropFromTopStyle=="BOTTOMLEFTCORNER"){
            this.CurrentXposition=0-this.getWidth();
            this.CurrentYposition=oBrowserDomDetails.height;
        }
        else if(this.dropFromTopStyle=="BOTTOMCENTER"){
            this.CurrentXposition=(oBrowserDomDetails.width/2)-(this.getWidth()/2);
            this.CurrentYposition=oBrowserDomDetails.height;
        }
        else if(this.dropFromTopStyle=="BOTTOMRIGHTCORNER"){
            this.CurrentXposition=oBrowserDomDetails.width;
            this.CurrentYposition=oBrowserDomDetails.height;
        }
    }
    else{
        this.CurrentXposition=this.getTopposition();
        this.CurrentYposition=this.getLeftposition();
    }
    
    if(this.toCenter==true){
        this.newXposition=(oBrowserDomDetails.width/2)-(this.getWidth()/2);
        this.newYposition=(oBrowserDomDetails.height/2)-(this.getHeight()/2);
    }
    
    this.CurrentDummyXposition=this.CurrentXposition;
    this.CurrentDummyYposition=this.CurrentYposition;

    oBrowserDomDetails="";
    this.AnimateDialogueNewPosition();
}
/******************************************************************/

zaggAnimations.prototype = new GetDOMElement();
function zaggAnimations()
{
}
