/*
 * IdeaValley Innovation
 * FlipSite
 * Maio 2006
 * Luiz Paulo dos Prazeres Júnior
 * 
 * Zoom Class
 */

var zoomPath  = toolsPath+"flipZoom/";
var ZoomClass = Class.create();

ZoomClass.prototype = {

    initialize: function () {

		FlipAction.register(this.openZoomBefore, "gotoZoom", "action");
		FlipAction.register(this.closeZoomAll, "gotoPage", "after");
		FlipAction.register(this.closeZoomAll, "gotoPage", "before");
        $('btnZoomMais').onclick = function (){ Zoom.clickZoom(); return false; };
        this.numPage             = 0;

    }, //Method initialize


    clickZoom: function (){
        this.initBoxZoom();
        //1(isUndefined(this.divZoom)){ this.initBoxZoom(); this.clickZoom(); return true; };
        if(typePlayer == "single"){
            Player.flashProxy.call('zoomInit');
        }else{
            if(StateMachine.getPageRight() == 1){
                Player.flashProxy.call('zoomInit', 'right');
                return false;
            }else if(StateMachine.getPageLeft() == maxPages){
                Player.flashProxy.call('zoomInit', 'left');
                return false;
            }

            if(isUndefined(this.divConsole)){ this.initConsole(); return true; };
            this.divConsole.style.display = "block";
        }

    }, // Method clickZoom


    initConsole: function (){

        div  = '<div id="displayZoomConsole">';
            div += '<div id="zoomConsoleTitle">';
                div += '<div> Selecione a Página para Ampliar </div>';
            div += '</div><!-- zoomConsoleTitle -->';
            div += '<div id="displayZoomLeft">';
                div += '<img onmouseover="Zoom.swapImageOn(this.parentNode);" class="pngTransparent" src="'+themePath+'imgs/iconsButtons/icon_zoom_off.png" width="123" height="165" border="0" />';
                div += '<img onmouseout="Zoom.swapImageOut(this.parentNode);" class="pngTransparent" src="'+themePath+'imgs/iconsButtons/icon_zoom_on.png" width="123" height="165" border="0" style="display:none;" />';
            div += '</div>';
            div += '<div id="displayZoomRight">';
                div += '<img onmouseover="Zoom.swapImageOn(this.parentNode);" class="pngTransparent" src="'+themePath+'imgs/iconsButtons/icon_zoom_off.png" width="123" height="165" border="0" />';
                div += '<img onmouseout="Zoom.swapImageOut(this.parentNode);" class="pngTransparent" src="'+themePath+'imgs/iconsButtons/icon_zoom_on.png" width="123" height="165" border="0" style="display:none;" />';
            div += '</div>';
        div += '</div><!-- displayZoomConsole -->';

        newComponent(div, 'before', $('flipConpoments'));
        this.divConsole = $('displayZoomConsole');

        // PROPRIEDADES DO CONSOLE
        obj = this.divConsole;

        centerY = ($('displayPlayerDouble').offsetHeight/2) - (obj.offsetHeight/2) - ($('displayPlayerDouble').offsetHeight / 7);
        centerX = ($('displayPlayerDouble').offsetWidth/2)  - (obj.offsetWidth/2);

        obj.style.left   = (findPosX($('displayPlayer'))+centerX)+"px";
        obj.style.top    = (findPosY($('displayPlayer'))+centerY)+60+"px";
        // PROPRIEDADES DO CONSOLE

        this.divConsole.onclick        = createMethodReference(this, "closeConsole");
        $('displayZoomLeft').onclick   = function (){ Player.flashProxy.call('zoomInit', 'left'); }
        $('displayZoomRight').onclick  = function (){ Player.flashProxy.call('zoomInit', 'right'); }

    }, // Method initConsole


    swapImageOn: function (div){
        div.childNodes[0].style.display = "none";
        div.childNodes[1].style.display = "block";
    },

    
    swapImageOut: function (div){
        div.childNodes[0].style.display = "block";
        div.childNodes[1].style.display = "none";
    },

    
    closeConsole: function (){
        this.divConsole.style.display = "none";
    },


    getZoom: function (pathPageZoom, numPage, widthZoom, heightZoom){
        //alert(pathPageZoom+", "+numPage+", "+widthZoom+", "+heightZoom);
        FlipAction.gotoZoom(pathPageZoom, numPage, widthZoom, heightZoom);
    }, // Method getZoom


    initBoxZoom: function (){
		try{ $('displayZoom').parentNode.removeChild($('displayZoom')); }catch(e){}
        div = '<div id="displayZoom"></div>';
        newComponent(div, 'before', $('flipConpoments'));
        this.divZoom = $('displayZoom');

        this.setPropriets("zoom");

        try{
            var uid         = new Date().getTime();
            this.flashProxy = new FlashProxy(uid, frameworkPath+'FlashJavascriptGateway/JavaScriptFlashGateway.swf');
            this.flash      = new FlashTag(themePath+'swf/zoom.swf','100%', '100%');
            this.flash.setFlashvars('lcId='+uid);
            this.flash.setId("zoomFlash");
            this.flash.setSalign("lt");
            this.flash.setWMode("opaque");
            this.flash.setWMode("transparent");

            newComponent(this.flash.toString(), "bottom", this.divZoom);

        }catch ( e ){
//            alert(e.message);
        }

    }, // Method initBoxZoom


    setPropriets: function () {

        if(!isUndefined(this.divZoom)){

            obj = this.divZoom;

            width     = parseInt(getUtilWindowSize(":").split(':')[0]);
            height    = parseInt(getUtilWindowSize(":").split(':')[1]);

            decrement = 10;

            //obj.style.width  = (width-decrement)+"px";
            obj.style.width  = 100+"%";
            obj.style.height = (height-$('header').offsetHeight-decrement)+"px";

            obj.style.left   = 0+"px";
            obj.style.top    = $('header').offsetHeight+"px";

            obj.style.display = "none";
        }

    }, //Method setPropriets


    openZoomBefore: function (pathPageZoom, numPage, widthZoom, heightZoom){
        if(pathPageZoom != "CLOSE")
            Zoom.openZoom(pathPageZoom, numPage, widthZoom, heightZoom);

    }, //Method openZoomBefore

    openZoom: function (pathPageZoom, numPage, widthZoom, heightZoom){
        this.initBoxZoom();
        //if(isUndefined(this.divZoom)){ this.initBoxZoom(); this.openZoom(pathPageZoom, numPage, widthZoom, heightZoom); return true; };

        StateMachine.isZoom                  = true;
        $("flipComponents").style.marginLeft = $("flipComponents").style.marginTop = -5000+"px";
        if(typePlayer == "single") $('menuAreaMateria').style.display   = "none";
        this.divZoom.style.display           = "block";
        $('baseboard').style.display         = "none";

        this.initFlash(pathPageZoom, numPage,  widthZoom, heightZoom);

	 try{ FlipPrint.divConsole.style.display     = "none"; }catch(e){}
        try{ FlipPrint.divConsoleOne.style.display  = "none"; }catch(e){}
        try{ FlipPrint.divConsoleMax.style.display  = "none"; }catch(e){}

    }, //Method openZoom


    initFlash: function (pathPageZoom, numPage,  widthZoom, heightZoom) {

        Zoom.numPage = numPage;
        str = "Zoom.flashProxy.call('zoomInit', { path: '"+pathPageZoom+"', numPage: "+numPage+", zwidth: "+widthZoom+", zheight: "+heightZoom+"});"
        setTimeout(str, 2000);
//        Zoom.flashProxy.call('zoomInit', { path: param });

    }, // Method initFlash


    closeZoom: function (){

        StateMachine.isZoom                  = false;
        $("flipComponents").style.marginLeft = $("flipComponents").style.marginTop = 0+"px";
        if(typePlayer == "single") $('menuAreaMateria').style.display   = "block";
        Zoom.divZoom.style.display           = "none";
        $('baseboard').style.display         = "block";

        FlipAction.gotoZoom("CLOSE", Zoom.numPage);
	 try{ FlipPrint.divConsoleZoom.style.display = "none"; }catch(e){}
    },

  closeZoomAll: function (){

      try{ $('displayZoomConsole').style.display = "none"; }catch(e){ };
      try{ $('displayZoom').style.display        = "none"; }catch(e){ };

  },

    end: function () {

        return false;

    } //Method end

};

Zoom = new ZoomClass();