﻿/*
summary:be used to create an overlay on an element.
Note:require("YgYuz_ElementDimension.js") (The function will require the dependency-YgYuz_ElementDimension.js)
*/
var Overlay = (function(){

    function Overlay(){
    
    }// constructor
    
    Overlay.prototype = {
    /*
    summary:initialize the Overlay that will cover an element(object) entirely.
    parameters:ele-- the object(element) the Overlay will cover.
                id-- the id of an overlay.
                bgcolor -- the backgroundColor of an overlay.
                isTransparent -- whether the overlay is transparent or not.
                opacity -- the value of opacity which must be less than 1 and greater than 0.
    return : null;
    */
        OverlayEntirelyOn:function(ele,id,bgcolor,isTransparent,opacity){
        
            this.parentElement = ele;
            
            this.overlayWidth = ElementDimension.getElementSize(ele).width;
            this.overlayHeight = ElementDimension.getElementSize(ele).height;
            this.overlayTop = ElementDimension.getElementCoordinate(ele).top;
            this.overlayLeft = ElementDimension.getElementCoordinate(ele).left;
            
            this.overlayId = id;
            this.overlayBgColor = bgcolor;
            this.zIndex = ele.style.zIndex+100;
    
            
            if(isTransparent){
                this.filter = "progid:DXImageTransform.Microsoft.Alpha(style=5,opacity="+100*opacity+",finishOpacity="+100*(1-opacity)+")";
                this.opacity = opacity;
            }else{
                this.filter = "progid:DXImageTransform.Microsoft.Alpha(style=5,opacity=100,finishOpacity=0)";
                this.opacity = "1";

            }
            
            
        },
    /*
    summary:create the overlay initialized by calling OverlayOn and will cover the element parameterized by OverlayOn.
    parameters: null
    return: the created overlay.
    */    
        CreateOverlay:function(){
        var objBgDiv=document.createElement("div");
        objBgDiv.setAttribute('id',this.overlayId);
        objBgDiv.style.position="absolute";
        objBgDiv.style.top=this.overlayTop+"px";
        objBgDiv.style.left=this.overlayLeft+"px";    
        objBgDiv.style.width=this.overlayWidth + "px";
        objBgDiv.style.height=this.overlayHeight + "px";
        objBgDiv.style.background= this.overlayBgColor;
        
        objBgDiv.style.filter=this.filter;
        objBgDiv.style.opacity=this.opacity;
        
        objBgDiv.style.zIndex = this.zIndex;
        //var objDivOverlay = document.body.appendChild(objBgDiv);   
        var objDivOverlay = this.parentElement.appendChild(objBgDiv);
        return objDivOverlay;    

        },
        
        
          /*
            summary:create the overlay initialized by calling OverlayOn and will cover the element parameterized by OverlayOn.
   parameters:ele-- the object(element) the Overlay will cover.
                id-- the id of an overlay.
                bgcolor -- the backgroundColor of an overlay.
                width -- width of an overlay.
                height- height of an overlay.
                top -- the top position of an overlay.
                left-- the left position of an overlay.
                isTransparent -- whether the overlay is transparent or not.
                opacity -- the value of opacity which must be less than 1 and greater than 0.
    return: the created overlay.
    */    
        
        OverlayPartiallyOn : function(ele,id,width,height,top,lef,bgcolor,isTransparent,opacity){
            this.parentElement = ele;
            this.overlayWidth = width;
            this.overlayHeight = height;
            this.overlayTop = top;
            this.overlayLeft = lef;
            
            this.overlayId = id;
            this.overlayBgColor = bgcolor;
            this.zIndex = ele.style.zIndex+100;
            
            if(isTransparent){
                this.filter = "progid:DXImageTransform.Microsoft.Alpha(style=5,opacity="+100*opacity+",finishOpacity="+100*(1-opacity)+")";
                this.opacity = opacity;
            }else{
                this.filter = "progid:DXImageTransform.Microsoft.Alpha(style=5,opacity=100,finishOpacity=0)";
                this.opacity = "1";
            }
        },
        
        RemoveOverlay : function(ele){
            if(typeof(ele.parentNode)!="undefined")
                ele.parentNode.removeChild(ele);
        }
        
    }
    
    /*
        Note: i'm confusing why doesn't the first 'new' sometimes implements successfully.so i will call 'new' repeatedly if the first time is unsuccessful.
    */
    var ol = new Overlay();
    if(typeof ol =="undefined" || ol==null)
        ol = new Overlay();
    return ol;
    
}
)();
