/*
 * IdeaValley Innovation
 * FlipSite
 * Maio 2006
 * Luiz Paulo dos Prazeres J?nior
 * 
 * Indice Class
 */
 
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 () {
	try{
	
		if(StateMachine.isIndice){ return false}
        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;
	}catch(e)
	{
		//alert("q porra"+e);
	}


	}, //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 () {
		//alert(StateMachine.isIndice )
		try{
        obj                   = this.divIndice.style;
        if(StateMachine.isIndice){  
   		    //obj.display           =  "none";
			//this.closeIndice();
		}else{
			StateMachine.isIndice =  true ;	
			obj.display           =  "block";			
		}
        /*
        StateMachine.isIndice = (obj.display == "block" ) ?  false : true ;
		obj.display           = (obj.display == "block" ) ? "none" : "block";
		*/
		//alert(this.divIndice.style.display+"  "+obj.display+"  "+StateMachine.isIndice); 
		}catch(e){
			//alert("Viadinhos"+e);
		}
		
		
	}, //Method openIndice


	closeIndice: function (){
		try{
			$('displayIndice').style.display = "none";
			//alert("Fecha porra");
			document.getElementById("displayIndice").style.display = "none";		
			StateMachine.isIndice            = false;
		}catch(e){
			//alert("a"+e);
		}finally{ //alert("Finally close");$('displayIndice').style.display = "none";
		//alert(document.getElementById("displayIndice").style.display);
		}
	},


	returnIndice: function (returnString, status) {

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

	}, //Method returnIndice


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

Indice = new IndiceClass();