/*
 * IdeaValley Innovation
 * FlipSite
 * Maio 2006
 * Luiz Paulo dos Prazeres Júnior
 * 
 * Skip Class
 */
 
var flipSkipPath 	= toolsPath+"flipSkip/";
var FlipSkipClass 	= Class.create();

FlipSkipClass.prototype = {

	/*
	 *	REQUISIÇÃO AJAX PARA O FORM DE BUSCA
	 *	REQUISIÇÃO AJAX PARA INCLUSÃO DO BOX PARA BUSCA
	 */
    initialize: function () {

		document.onkeydown = this.eventKey;
		FlipAction.register(this.setSkip, "gotoPage", "after");
        this.lastSkip = 1;

        this.initActions();

	}, //Method initialize


    initActions: function () {

        $('btnCouver').onclick       = function (){ FlipAction.gotoPage(1);                              return false; }
        $('skipPrevious').onclick    = function (){ FlipAction.prevPage();                               return false; }
        $('skipNext').onclick        = function (){ FlipAction.nextPage();                               return false; }
        $('btnLast').onclick         = function (){ FlipAction.gotoPage(maxPages);                       return false; }
        $('skiptoPage').onclick      = function (){ $('skiptoPage').value = ""; $('skiptoPage').focus(); return false; }
        $('skiptoPage').onblur       = function (){ FlipSkip.setSkip();                                  return false; }
        $('imgSkip').onclick         = function (){ FlipSkip.skipPageNow(FlipSkip.lastSkip);             return false; }

        this.setSkip();
    }, //Method initActions


    eventKey: function (e) {

    	if (!e) e = window.event;
//        alert(e['keyCode']);

        if(StateMachine.getIsFlip()){
        	if(e['keyCode'] == 38){ // SETA CIMA = CAPA
        		FlipAction.gotoPage(1);
        	}else if(e['keyCode'] == 39){ // SETA DIREITA  = NEXTPAGE
        		FlipAction.nextPage();
        	}else if(e['keyCode'] == 40){ // SETA BAIXO    = LASTPAGE
        		FlipAction.gotoPage(maxPages);
        	}else if(e['keyCode'] == 37){ // SETA ESQUERDA = PREVPAGE
        		FlipAction.prevPage();
        	}
        }

    }, //Method eventKey

	initSkip: function (returnString, status) { /* INCLUSÃO DO SKIP NO MENU DE FERRAMENTAS */

		if(status == "sucess"){
			newComponent(returnString, 'bottom', $('flipToolBarList'));
			FlipSkip.setSkip();
		}

	}, //Method initSkip

    nextPage: function () {
        FlipAction.gotoPage(StateMachine.pageRight+1);
    }, //Method nextPage

    prevPage: function () {
        FlipAction.gotoPage(1);
    }, //Method prevPage

    skipPage: function(key){

        if(((key=='13') || (key == '9')) && ($F('skiptoPage') != "")){

		    valor = parseInt($F('skiptoPage'));

            this.skipPageNow(valor);

        }
    },


	skipPageNow: function (valor) { /* MUDA O VISOR DO SKIP */

            valor = (valor > maxPages) ? maxPages : valor;
            if(valor != ""){
                if(typePlayer == "single")
                    valor = parseInt(valor);
                else if((parseInt(valor) > 5) && (parseInt(valor) % 2 == 0) && (parseInt(valor) != maxPages))
                   valor = parseInt(valor)+1;
            }

            FlipAction.gotoPage(valor);
            this.setSkip();

	}, //Method skipPageNow



	setSkip: function () { /* MUDA O VISOR DO SKIP */
        this.lastSkip = $F("skiptoPage");

        if(StateMachine.getPlayerType() == "double"){
            if(StateMachine.getPageLeft() == ""){
                skipValue =  StateMachine.getPageRight();
            }else{
                
                    skipValue = (StateMachine.getPageLeft() == maxPages) ? StateMachine.getPageLeft() : (StateMachine.getPageLeft()+" | "+StateMachine.getPageRight());
            }
        }else{
            skipValue = StateMachine.getPage();
        }

		$("skiptoPage").value = skipValue;

	} //Method setSkip
}; //Class FlipSkipClass

FlipSkip = new FlipSkipClass();