var Label = {
    drawerInfoIsOpen : false,
    drawerToolsIsOpen : false,

    hideElementById : function(id) {
        document.getElementById(id).style.display="none";
    },
    showElementById : function(id) {
        document.getElementById(id).style.display="block";
    },
    getEventToElement :function(ev) {
	var is_ie = document.all ? true : false;
        if (is_ie) {
           return ev.toElement;
        } else {
           return ev.relatedTarget;
        }
    },
    drawerPhotoInit : function(id) {
	var pRegion = YAHOO.util.Dom.getRegion("box_" + id + "_photo");
	var attributes = { opacity: { to: 0.0 }, top: { to: (pRegion.bottom - pRegion.top)} };
	var anim = new YAHOO.util.Anim("box_" + id + "_drawer_info", attributes, 0.5, YAHOO.util.Easing.easeOut);
	anim.animate();
    },
    drawerPhotoOpen : function(ev, id) {
	var drawerId = "box_" + id + "_drawer_info";
	if (!Label.drawerInfoIsOpen) {
	    var dRegion = YAHOO.util.Dom.getRegion(drawerId);
	    var attributes = { opacity: { to: 0.8 }, top: { by: (dRegion.top - dRegion.bottom) } };
	    var anim = new YAHOO.util.Anim(drawerId, attributes, 0.5, YAHOO.util.Easing.easeOut);
	    anim.animate();
	    Label.drawerInfoIsOpen = true;
	}
        //Label.hideElementById("box_" + id + "_drawer_show");
        //Label.showElementById("box_" + id + "_drawer_hide");
    },
    drawerInfoOpen : function(ev, id) {
	var drawerId = "box_" + id + "_drawer_info";
	if (!Label.drawerInfoIsOpen && !Label.drawerToolsIsOpen) {
	    Label.drawerInfoIsOpen = true;
	    var pRegion = YAHOO.util.Dom.getRegion("box_" + id + "_photo");
	    var dRegion = YAHOO.util.Dom.getRegion(drawerId);
	    var attributes = { opacity: { from: 0, to:0.8 }, top: { to: ((pRegion.bottom - pRegion.top) - (dRegion.bottom - dRegion.top)) } };
	    var anim = new YAHOO.util.Anim(drawerId, attributes, 0.5, YAHOO.util.Easing.easeOut);
	    anim.animate();
	}
    },
    elementContainsElement : function(container, containee) {
        var isParent = false;
        if (containee != null){
        do {
                if (container == containee) {
                    isParent = true;
                    break;
                }
                containee = containee.parentNode;
            } while (containee != null);
        }
        return isParent;
    },
    drawerInfoInit : function(id) {
	var pRegion = YAHOO.util.Dom.getRegion("box_" + id + "_photo");
	var attributes = { opacity: { to: 0 }, top: { to: (pRegion.bottom - pRegion.top)} };
	var anim = new YAHOO.util.Anim("box_" + id + "_drawer_info", attributes, 0.5, YAHOO.util.Easing.easeOut);
    
	Label.drawerInfoIsOpen = false;
	anim.animate();
    
	YAHOO.util.Dom.setStyle("box_" + id + "_drawer_info", "cursor", "hand");
    },
    drawersClose : function(ev, id) {
	var tPhoto = "box_" + id + "_photo";	
        var toElement = Label.getEventToElement(ev);
        // check to make sure we really left the outer element ('this' is the element the event is attached to)
        if (Label.elementContainsElement(this, toElement)) {
            return;
        } else {
	    Label.drawersInit(ev, id);
        }
    },
    drawerToolsInit : function(id) {
	var pRegion = YAHOO.util.Dom.getRegion("box_" + id + "_photo");
	var attributes2 = { opacity: { to: 0 }, top: { to: (pRegion.bottom - pRegion.top)} };
	var anim2 = new YAHOO.util.Anim("box_" + id + "_drawer_tools", attributes2, 0.5, YAHOO.util.Easing.easeOut);
    
	Label.drawerToolsIsOpen = false;
	anim2.animate();
    
	YAHOO.util.Dom.setStyle("box_" + id + "_drawer_tools", "cursor", "hand");
    },
    drawersInit : function(ev, id) {
	Label.drawerToolsInit(id);
	Label.drawerInfoInit(id);
    },
    drawerPhotoClose : function(ev, id) {
	var tPhoto = "box_" + id + "_photo";	
        var toElement = Label.getEventToElement(ev);
        // check to makke sure we really left the outer element ('this' is the element the event is attached to)
	Label.drawerPhotoInit(id);
	Label.drawerInfoIsOpen = false;
	Label.drawerToolsIsOpen = false;
        //Label.hideElementById("box_" + id + "_drawer_hide");
        //Label.showElementById("box_" + id + "_drawer_show");
    }
}


