/*
 * IdeaValley Innovation
 * FlipSite
 * Maio 2006
 * Luiz Paulo dos Prazeres Júnior
 * 
 * Player Class
 */
 
var playerDoublePath	 = playerPath+"flipPlayerDouble/";
var PlayerDoubleClass		= Class.create();

PlayerDoubleClass.prototype = {


	initialize: function () {

		this.initVars();
		this.initPlayer();
		this.initFunctions();

	}, //Method initialize


	initFunctions: function () {

		FlipAction.register(this.gotoPage, "gotoPage", "action");
		FlipAction.register(this.gotoEditoria, "gotoEditoria", "action");
		FlipAction.register(FlipAction.gotoEditoria, "gotoMateria", "action");
		FlipAction.register(FlipAction.gotoEditoria, "gotoAnuncio", "action");

	}, //Method initFunctions


	initVars: function (){

		this.myPags	   = 0;
		this.offsetX   = 2;
        this.offsetY   = 2;
        shadowStrength = 40;

	}, //Method initVars


    autoRun: function () {

        page2go = 1;
        if(getQueryString("autoFlip") != ""){
            /*
             * Ativando o autoFlip via endereço ( queryString ) automaticamente o flip vai para a segunda página e ativará o modo automático
             * Este processo está sendo criado neste ponto, pois, o javascript não tem controle sobre o carregamento das páginas FLASH, ficando a obrigação do FLASH em ir para a segunda página no carregamento inicial
             * 
             */
            page2go = 2;
        }

        if(getQueryString("page2go") != ""){

            page2go = parseInt(getQueryString("page2go"));
            /*
             * Procedimento criado para evitar BUG do playerDuplo
             * Esse BUG aparece um NAN quando tentamos ir para uma página PAR maior que 5
             * Com esse filtro, o gotoPage do autoRun irá sempre para a página impar do flip aberto
             */
            if((page2go > 5) && (page2go % 2 == 0) && (page2go != maxPages))
                page2go = page2go+1;

            // Verifica se a página passada como parametro é maior que o máximo de páginas
            page2go = (page2go > maxPages) ? maxPages : page2go;
        }
        return page2go;

    }, //Method autoRun


	initPlayer: function () {

        try{
            var uid         = new Date().getTime();
            this.flashProxy = new FlashProxy(uid, frameworkPath+'FlashJavascriptGateway/JavaScriptFlashGateway.swf');
    		this.flash	    = new FlashTag(playerDoublePath+'swf/flip.swf',1000, 1000);
    		this.flash.setFlashvars('lcId='+uid);
    		this.flash.setId("playerDouble");
            this.flash.setSalign("lt");
    		this.flash.setWMode("transparent");
/*
            player = document.createElement("DIV");
            player.id = "displayPlayerDouble";

            newComponent(this.flash.toString(), "bottom", player);
            $("displayPlayer").appendChild(player);
*/
            player  = "<div id='displayPlayerDouble'>"+this.flash.toString()+"</div><!-- displayPlayerDouble -->";
            newComponent(player, "top", $("displayPlayer"));

    		$('displayPlayerDouble').onscroll = function () { $('displayPlayerDouble').scrollTop = 0; $('displayPlayerDouble').scrollLeft = 0; };

            this.setSize();
        }catch ( e ){
//            alert(e.message);
        }

	}, //Method initPlayer


	initFlash: function () {

        Player.flashProxy.call('flipInit',
    		{
    			uriTearPageL:	"",//themePath+"swf/pagarranc2.swf",
    			uriTearPageR:	"",//themePath+"swf/pagarranc.swf"
    			preloaderURI:	themePath+"swf/travamento_loading_"+formatoCaderno+".swf",
    			cursorURI:	    themePath+"swf/cursor.swf",
    			click4zoomURI:  themePath+"swf/click4zoom.swf",

    		    pagePath:       filePath+idPublicacao+"/"+idEdicaoXml+"/PAGINAS3D/",
    			uriXml:			xml,
    			idEdicao:		idEdicaoXml,
    			idCaderno:		idCaderno,
    			myPags:			0,
    			statusTracking:	false,
    			arrancarPagina:	false,
    			smoothness:	    3,
    			shadowStrength:	Player.shadowStrength,
    			shadowOffsetX:	Player.offsetX,
    			shadowOffsetY:	Player.offsetY,
    			page2go:        Player.autoRun(),
    			wellcome:       themePath+"swf/wellcome.swf"
    		}
    	);

	},


	setSize: function () {

        $("displayPlayerDouble").style.width  = ((parseInt(formatoCaderno.split("x")[0])*2)+(this.offsetX*2))+"px";
        $("displayPlayerDouble").style.height = (parseInt(formatoCaderno.split("x")[1])+(parseInt(formatoCaderno.split("x")[0])/3)-20)+"px";
        $("divSpacePlayer").style.marginLeft  =  ($("displayPlayerDouble").offsetWidth+20)+"px";
        $("divSpacePlayer").style.marginTop   = -($("displayPlayerDouble").offsetHeight)+"px";
        $("divSpacePlayer").style.height      = formatoCaderno.split("x")[1]+"px";
        
        $("divBemVindo").style.marginTop       = -($("displayPlayerDouble").offsetHeight-20)+"px";

	}, //Method setSize



	gotoPage: function () {

   		Player.flashProxy.call('gotoPage', arguments[0]); // arguments[0] = numPage

	}, //Method gotoPage


    gotoEditoria: function (page, ID_Edicao, ID_Caderno, origem) {
//        alert(page+", "+ID_Edicao+", "+ID_Caderno+", "+origem);
        ID_Edicao  = (!isNull(ID_Edicao))  ? ID_Edicao  : "";
        ID_Caderno = (!isNull(ID_Caderno)) ? ID_Caderno : "";
        page       = (!isNull(page))       ? page       : 1;

		arquivoFlip = (demo)? '?preview=1&' : '?';

		if ((ID_Caderno == idCaderno) && (ID_Edicao == idEdicaoXml)) {

			FlipAction.gotoPage(page);

		} else {

			origemView = (origem == undefined) ? '' : '&origem='+origem;
			url = arquivoFlip+"idEdicao="+ID_Edicao+"&idCaderno="+ ID_Caderno + "&page2go=" + page + origemView;
		    document.location.href = url;

		}
//        eval('FlipAction.flipActions["gotoEditoria"].run('+args+');');
        return true;

    },

	end: function () { } //Method end

};

if(typePlayer == "double"){
    Player = new PlayerDoubleClass();
}