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

PlayerSingleClass.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.statusTracking	= false;
		this.arrancarPagina	= false;
		this.uriTearPageL	= "pagarranc2.swf";
		this.uriTearPageR	= "pagarranc.swf";

	}, //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 = getQueryString("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(playerSinglePath+'swf/singleFlip.swf',1000, 1000);

    		this.flash.setFlashvars('lcId='+uid);
    		this.flash.setId("playerSingle");
    		this.flash.setWMode("transparent");
/*
            player = document.createElement("DIV");
            player.id = "displayPlayerSingle";
            newComponent(this.flash.toString(), "bottom", player);
            $("displayPlayer").appendChild(player);
/***/
            player  = "<div id='displayPlayerSingle'>"+this.flash.toString()+"</div><!-- displayPlayerSingle -->";
            newComponent(player, "top", $("displayPlayer"));

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

            this.setSize();
        }catch ( e ){
        }

	}, //Method initPlayer


	initFlash: function () {

        Player.flashProxy.call('flipInit',
    		{
                pathAreas:      playerSinglePath+"swf/",
    		    pagePath:       filePath+idPublicacao+"/"+idEdicaoXml+"/PAGINAS3D/",
    			uriXml:			xml,
    			idEdicao:		idEdicaoXml,
    			idCaderno:		idCaderno,
    			myPags:			0,
    			statusTracking:	false,
    			arrancarPagina:	false,
    			uriTearPageL:	"",//playerDoublePath+"swf/pagarranc2.swf",
    			uriTearPageR:	"",//playerDoublePath+"swf/pagarranc.swf",
    			mapAlpha:       50,
                mapColor:       0x006EAD,
    			page2go:        Player.autoRun()
    		}
    	);
//        Player.autoRun();

	},


	setSize: function () {

        $("displayPlayerSingle").style.width  = formatoCaderno.split("x")[0]+"px";
        $("displayPlayerSingle").style.height = formatoCaderno.split("x")[1]+"px";

        $("divSpacePlayer").style.marginLeft  = (parseInt(formatoCaderno.split("x")[0])+30)+"px";
        $("divSpacePlayer").style.marginTop   = -($("displayPlayerSingle").offsetHeight)+"px";
        $("divSpacePlayer").style.height      = formatoCaderno.split("x")[1]+"px";

	}, //Method setSize


	gotoPage: function () {

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

	}, //Method gotoPage

    gotoEditoria: function (page, ID_Edicao, ID_Caderno, ID_Materia, termo) {

		// var ID_Materia = DynamicAreas.getIdMateria();

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

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

			FlipAction.gotoPage(page);

		} else {

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

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

    },

	end: function () { } //Method end

};

if(typePlayer == "single"){
    Player = new PlayerSingleClass();
}