String.prototype.trim=function(){
    return this.replace(/^\s*|\s*$/g,'');
};
YAHOO.namespace("mastop");
YAHOO.mastop.Dialog = function(){
    var yud = YAHOO.util.Dom;
    var yue = YAHOO.util.Event;
    var yw = YAHOO.widget;
    var yum = YAHOO.util.Motion;
    return {
        init: function(){
            yue.onDOMReady(this.createDialogs, this, true);
        },
        getImages: function(){
            return yud.getElementsByClassName("mstpFoto");
        },
        getVideos: function(){
            return yud.getElementsByClassName("mstpVideo");
        },
        createDialogs: function(){
            yue.on(YAHOO.mastop.Dialog.getImages(), 'click', this.loadImages);
            yue.on(YAHOO.mastop.Dialog.getVideos(), 'click', this.loadVideos);
            YAHOO.mastop.wait = new YAHOO.widget.Panel("wait",
            { width: "240px",
            fixedcenter: true,
            effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25},
            close: false,
            draggable: false,
            zindex:4,
            modal: true,
            visible: false
            }
            );
            YAHOO.mastop.wait.setHeader("Carregando...");
            YAHOO.mastop.wait.setBody("<img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/>");
            YAHOO.mastop.wait.render(document.body);
        },
        loadImages: function(e){
            YAHOO.mastop.wait.show();
            yue.stopEvent(e);
            yue.removeListener(document, 'keypress');
            var label = yud.getElementsByClassName("DMFotosLabel", "div", this);
            var Foto = new Image();
            Foto.onload = function() {
                var imgScale = YAHOO.mastop.Dialog.scaleImage(Foto);
                var imgWidth = imgScale[0]+20;
                yud.setStyle(Foto, "width", "100%");
                var imgDialog = new YAHOO.widget.Panel("mstpImg",
                {
                    width: imgWidth,
                    fixedcenter : true,
                    modal : true,
                    visible : false,
                    draggable: true,
                    close: true,
                    constraintoviewport : true,
                    underlay: "shadow",
                    effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25},
                    zindex:1000
                } );
                imgDialog.setHeader(label[0].innerHTML);
                imgDialog.setBody(Foto);
                imgDialog.render(document.body);
                var imgCloseHandler = function(e, o){
                    o.hide();
                };
                yue.on(imgDialog.body, 'click', imgCloseHandler, imgDialog);
                yud.setStyle(imgDialog.body, 'cursor', 'pointer');
                YAHOO.mastop.wait.hide();
                imgDialog.show();
            }
            Foto.src = this.href;
        },
        loadVideos: function(e){
            YAHOO.mastop.wait.show();
            yue.stopEvent(e);
            yue.removeListener(document, 'keypress');
            var label = yud.getElementsByClassName("DMVideosLabel", "div", this);
            var vidDialog = new YAHOO.widget.Panel("mstpVid",
            {
                fixedcenter : true,
                modal : true,
                width: "450px",
                visible : false,
                draggable: true,
                close: true,
                constraintoviewport : true,
                effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25},
                zindex:1000
            } );
            var so = new SWFObject(this.href, "sotester", "425", "353", "9", "#000000");
            vidDialog.setHeader(label[0].innerHTML);
            vidDialog.setBody('<div id="mstpVidBody">Carregando Vídeo '+label[0].innerHTML+'<br /> <img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/></div>');
            vidDialog.render(document.body);
            so.write('mstpVidBody');
            YAHOO.mastop.wait.hide();
            vidDialog.show();
        },
        scaleImage : function(aImage) {
            var sHeight = aImage.height;
            var sWidth = aImage.width;
            if(aImage.width > yud.getViewportWidth()) {
                sWidth = yud.getViewportWidth()-20;
                sHeight = aImage.height * (sWidth / aImage.width);
                if(sHeight+100 > (yud.getViewportHeight()-20)) {
                    sHeight = yud.getViewportHeight()-120;
                    sWidth = aImage.width * (sHeight / aImage.height);
                }
            } else if(aImage.height+100 > yud.getViewportHeight()) {
                sWidth = aImage.width * ((yud.getViewportHeight()-120) / aImage.height);
                sHeight = yud.getViewportHeight()-120;
                if(sWidth > (yud.getViewportWidth()-20)) {
                    sWidth = aImage.width * (sHeight / aImage.height);
                    sHeight = aImage.height * (sWidth / aImage.width);
                }
            }
            var scaleAtts = new Array(Math.floor(sWidth), Math.floor(sHeight));
            return scaleAtts;
        }
    }
}();
YAHOO.mastop.Dialog.init();