jQuery(document).ready(function(){

	if(jQuery.browser.msie){
		jQuery('#dropDownMenu li.headlink').hover(
			function() {
				jQuery(this).find('ul').css('display', 'block');
	//			jQuery('#searchUniverse').css('display', 'none');
			},
			function() {
				jQuery(this).find('ul').css('display', 'none');
//				jQuery('#searchUniverse').css('display', 'block');
			}
		);
        
        jQuery('#dropDownMenu li').hover(
			function() {
				jQuery('#searchUniverse').css('visibility', 'hidden');
			},
			function() {
				jQuery('#searchUniverse').css('visibility', 'visible');
			}
		);
	}

	//escondendo menuloader
	jQuery("#menuloader").fadeOut(1300);

    jQuery('#close').click(function() {
        jQuery('#postFeedback').fadeOut();
    });
	
	/////////////////////// PAGINADOR //////////////////////
    
    // classe paginador
    
    /* 
     * Espera receber como id o ID do elemento DOM criado a partir da função PHP eletro_pagination()
     * 
	*/
	
    eletroPagination = function(id, items_per_page, type, author, template, target) {
      this.init(id, items_per_page, type, author, template, target);
    }

    jQuery.extend(eletroPagination.prototype, {
        // object variables
        id: '',
        items_per_page: '', 
        type: '', 
        author: '', 
        template: '',
        cur_page: 1,
        target: '',
        pages: 0,
        chamada: 0,
        canal: 0,

        init: function(id, items_per_page, type, author, template, target) {
            // do initialization here
            this.id = id;
            this.items_per_page = jQuery('#' + this.id + '_items_per_page').val();
            this.type = jQuery('#' + this.id + '_type').val();
            this.author = jQuery('#' + this.id + '_author').val();
            this.template = jQuery('#' + this.id + '_template').val();
            this.target = jQuery('#' + this.id + '_target').val();
            this.chamada = jQuery('#' + this.id + '_chamada').val();
            this.canal = jQuery('#' + this.id + '_canal').val();
            this.pages = jQuery('#' + this.id + ' .pagenumber').length;
            var th = this;
            
            jQuery('#' + this.id + ' .pageMinus').click(function() { th.prev(); });
            jQuery('#' + this.id + ' .pagePlus').click(function() { th.next(); });
            jQuery('#' + this.id + ' .pagenumber').click(function() { th.gotoPage(jQuery(this).html()); });
            
            this._updateButtons();
            this._loadContent();
            
        },
        
        next: function() {
            if (this.cur_page < this.pages) {
            	
                this.cur_page ++;
                this._updateButtons();
                this._loadContent();
            }
        },
        
        prev: function() {
            if (this.cur_page > 1) {
                this.cur_page --;
                this._updateButtons();
                this._loadContent();
            }
        },
        
        gotoPage: function(page) {
            this.cur_page = page;
            this._updateButtons();
            this._loadContent();
        },
        
        _updateButtons: function() {
            var th = this;
            var page = 0;
            var lastSeen = 0;
            jQuery('#' + this.id +' .pagenumbers .etc').remove();
            jQuery('#' + this.id + ' .pagenumber').each(function() {
                page++;
                if ((page < 3) || (Math.abs(page - th.cur_page) <= 1) || (th.pages - page < 2)) {
                    jQuery(this).show();
                    if (lastSeen != page-1) {
                        jQuery(this).before('<span class="etc"> ... </span>');
                    }
                    lastSeen = page;
                    if (jQuery(this).html() == th.cur_page) {
                        jQuery(this).addClass('curpage');
                    } else {
                        jQuery(this).removeClass('curpage');
                    }
                } else {
                    jQuery(this).hide();
                }
            });
        },
        
        _loadContent: function() {
        	var th = this;
        	this._showLoader();
        	
        	var data = {
        	            type: th.type,
        	            items_per_page: th.items_per_page,
        	            template: th.template,
        	            author: th.author,
        	            paged: th.cur_page,
        	            canal: th.canal,
        	            chamada: th.chamada
        	           }
        	
        	jQuery('#' + this.target).load(base_url + 'ajax_get_media.php', data, function() {   
        		th._hideLoader();
        		if (typeof(myLightbox) != 'undefined') myLightbox.updateImageList();        		
        		th._onRequestComplete();
        	 });
        },
        
        _onRequestComplete: function() {
        	// extenda a classe e sobreescreve esse metodo. Veja eletro_perfil_edit.js
        },
        
        _showLoader: function() {
        	jQuery('#' + this.id + ' .paginationLoader').fadeIn();
        	        	
        },
        
        _hideLoader: function() {
        	jQuery('#' + this.id + ' .paginationLoader').fadeOut();
        }
        
        
    });
	
	// Inicia a paginação em todos os elementos pagináveis
	jQuery('.eletroPagination').each(function() {
        new eletroPagination(this.id);
    });
    
    jQuery('#user_login').focus(function() {
        if (jQuery(this).val() == wp_vars.login_input)
            jQuery(this).val('');
    });
    
    jQuery('#user_login').blur(function() {
        if (jQuery(this).val() == '')
            jQuery(this).val(wp_vars.login_input);
    });
    
    jQuery('#user_pass').focus(function() {
        if (jQuery(this).val() == 'Senha')
            jQuery(this).val('');
    });
    
    jQuery('#user_pass').blur(function() {
        if (jQuery(this).val() == '')
            jQuery(this).val('Senha');
    });
    
    
});
