
var indicePath 	= toolsPath+"flipIndice/";
var IndiceClass = Class.create();

IndiceClass.prototype = {

	/*
	 *	REQUISI??O AJAX PARA O BOT?O DE INDICE
	 *	REQUISI??O AJAX PARA INCLUS?O DO BOX PARA BUSCA
	 */
    initialize: function () {
        this.origemView = "1"; // idOrigemView
        this.loading   = "";
        if(!isUndefined($('btnIndice')))
            $('btnIndice').onclick = function (){
            	if(tipoPublicacao == "1" && !StateMachine.isIndice){
            	    StateMachine.isIndice = true;
            		Indice.getIndice(); return false; 
            	}else{ 
            		FlipAction.gotoEditoria(paginaIndice, idEdicao, "", this.origemView);
            	}			
            };

	}, //Method initialize


    reposition: function () {

        widthDiference   = ( ( formatoCaderno.split("x")[0] * 2) - this.divIndice.offsetWidth  )/2;
        heighthDiference = ( ( formatoCaderno.split("x")[1]    ) - this.divIndice.offsetHeight )/2;

        this.divIndice.style.left = ( findPosX($("displayPlayer")) + widthDiference   )+"px";
        this.divIndice.style.top  = ( findPosY($("displayPlayer")) + heighthDiference )+"px";

    }, //Method reposition


	getIndice: function () {

		//if(isUndefined(this.divIndice)){ Indice.initBoxIndice(); return true; };
        if(tipoPublicacao == "1"){
			if(isUndefined(this.divIndice)){ Indice.initBoxIndice(); return true; };
		}
		else{
			FlipAction.gotoEditoria(paginaIndice, idEdicaoXml, "", this.origemView);
			return false;
		}
        
		if(this.loading == ""){ this.loading = new Loading(this.divIndice); };

		this.openIndice();
		flipAjax.request(indicePath+"flipListIndice.php", "themePath="+themePath, "post", this.returnIndice);
        return false;

	}, //Method getIndice


	initBoxIndice: function (){

        if(arguments.length == 2){

    		if(arguments[1] == "sucess"){
    			newComponent(arguments[0], 'before', $('flipComponents'));
                Indice.divIndice = $('displayIndice');
    			Indice.initActions();
        		Indice.reposition();
    			Indice.getIndice();
    		}
   		    return true;
        }
		 flipAjax.request(indicePath+"flipResultIndice.php", "themePath="+themePath+"&dataPublicacao="+dataPublicacao, "post", this.initBoxIndice);

	}, // Method initBoxIndice


	initActions: function () {
	
		DragObj.init($('indiceTitle'), $('displayIndice'), $('displayMenu').offsetWidth, null, findPosY($('displayPlayer')));
		$('indiceClose').onclick = this.closeIndice;
	
	}, //Method initActions
	
    run: function (page, idEdicao, idCaderno, idMateria) {
	
        this.closeIndice();
        //FlipAction.gotoMateria(page, idEdicao, idCaderno, idMateria, this.origemView);
		FlipAction.gotoMateria(page, idEdicao, idCaderno, this.origemView, idMateria);
	
    }, //Method run
	
    gotoEditoria: function (nrPagina2, idEdicao2, idCaderno2, origemView2) {
									
        this.closeIndice();
        FlipAction.gotoEditoria(nrPagina2, idEdicao2, idCaderno2, origemView2);

    }, //Method gotoEditoria

	openIndice: function () {

        obj                   = this.divIndice.style;
        StateMachine.isIndice = (obj.display == "block") ? false : true;
		obj.display           = (obj.display == "block") ? "none" : "block";

	}, //Method openIndice


	closeIndice: function (){
		$('displayIndice').style.display = "none";
		StateMachine.isIndice            = false;
	},


	returnIndice: function (returnString, status) {

       Indice.loading.display("none");
       document.getElementById('resultsIndice').innerHTML = returnString;

	}, //Method returnIndice


    end: function () { } //Method end
};

Indice = new IndiceClass();