
var win           = null;
var eve_event     = null;
var filename      = null;
var linktofile    = '/content/files/';
var url           = '';
var _id           = '';
var _ii           = '';
var _i            = '';
var absolute_link = '';

function lightboxRegister() {
    $.colorbox({href:"/lightboxregister/?file="+filename, speed:1000, width:500, height: 320});
}

function startLoading() {
    $('.botao').css('display', 'none'); 
    $('.loading').css('display', 'block');
}

function stopLoading() {
    $('.botao').css('display', 'block'); 
    $('.loading').css('display', 'none'); 
}


//Submit Registation
function submitRegistation(f){
      
    f = $(f).serialize();
    
    if($('#v_erro') != null)
        $('#v_erro').hide();
    
    startLoading();
    
    $.ajax({
            url: '/lightboxregister',
            data: 'ajax=AJAX&'+f,
            type: 'POST',
            dataType: 'json',
            success: function(transport) {
                            
                            json = transport;
                           
                                
                            stopLoading(); 
                            if(json.status == 1) {
                                $('#v_erro').html(json.msg);
                                $('#v_erro').show();
                            
                                $('#name').value = '';   
                                $('#email').value = '';
                                
                                $('#registrationForm').hide();
                                
                                $('#file-link').html('<a href="'+linktofile+'/'+json.filename+'" target="_blank">'+ json.click +'</a> '+ json.msg_click +'.');
                                $('#file-link').show();
                                
                                
                            } else { 
                                 $('#v_erro').html(json.msg);
                                 $('#v_erro').show();
                                /*  if($('#v_erro') != null){
                                     if($('#v_erro').html()){
                                         //$('#v_erro').fadeOut();
                                         $('#v_erro').html(json.msg);
                                         //$('#v_erro').fadeIn("slow");
                                     }else{
                                         $('#v_erro').html(json.msg);
                                         $('#v_erro').show();
                                     }
                                } */ 
                            }
            }
        });
    return false;
}

function movSlider(){
    var a = $('#next')[0];
    
   /*  var e = document.createEvent('MouseEvents');
    
    e.initEvent( 'click', true, true );
    a.dispatchEvent(e); */
    /*         $('#slider-stage2').mouseover(function() {
            return;
        });
        
        var e1 = document.createEvent('MouseEvents');
        e1.initEvent( 'click', true, true );
        a1.dispatchEvent(e1); */
    
    var a1 = $('#next22')[0];
    if(a1){
        $('#next22').simulate('click', {
                              cancelable: true
                              });
    }
}

function addAttrNext(){
     $('.spcNext').css('display', 'Block');  
     $('.spcAuxSl').css('display', 'none');
      _ii = window.clearInterval(_ii);
}

function addAttrPrev(){
     $('.spcPrev').css('display', 'Block');  
     $('.spcAuxSlP').css('display', 'none');
     _i = window.clearInterval(_i);
}

$(document).ready(function(){
	
	/*$("#login label").inFieldLabels({ fadeOpacity:0.2 });
	$("#search label").inFieldLabels({ fadeOpacity:0.2 });
	$("#searchleft label").inFieldLabels({ fadeOpacity:0.2 });*/
	
	$("#nav .submenu>ul>li:not(.selected)").hover(
	                                              
		function () {
		                                     
            $('#nav .submenu>ul>li.selected').find('.submenu2, .active-item').hide();
            
			$(this).addClass('showMenu');
			
			if($.browser.msie){
			    if( $.browser.version > 7.0){
			        $(this).find('.active-item').css('display','block');
			    }else{
    			    $(this).find('.active-item').css('*display','inline-block !important ');
    			}
			}else{
			    $(this).find('.active-item').css('display','block');
			}
			
			//$(this).addClass('.active-item-spc-ff');
			//$(this).addClass('.active-item-spc-ie');
			
			//$(this).find('.active-item').css('display','block');
			
			//$('.showMenu').css('*width','100%');
		}, 
		function () {
		    
		    $('#nav .submenu>ul>li.selected').find('.submenu2, .active-item').show();
		    
			$(this).removeClass('showMenu');
			$(this).find('.active-item').css('display','none');
		}
	);
	
	if($('.private-file')){
	    $(this).bind("contextmenu", function(e) {
                e.preventDefault();
            }); 
	}
             
	//Onclick private FIle
	$('.private-file').click(function(evt) {
	                         
        evt.preventDefault();  
                         
        url = window.location;                 
      
        if(evt.target.nodeName != 'A'){
                aux = $(evt.target).parents('a:first');
                
                //console.log(aux);
                if(!aux.length)
                    return false;
                
                var str = new String(aux.data('_href'));
            
        }else{
            
            if(this.tagName == 'SPAN'){
                _aa_child = $(this).find('a:first-child');
                if(_aa_child.attr('href')){
                   var str = _aa_child.data('_href');
                }else
                    return;
                    
            }else
                var str = new String($(this).data('_href'));
        }
            
        if(!str.length)
            return false;
             
        
        var pairs = str.split('/');
        
        filename  = pairs[pairs.length-1];
        
        lightboxRegister();
        //evt.preventDefault();  
        
        eve_event = evt;
    });
    
    
     $('.private-file').each(function(i){
         _tag =  this.tagName;
         
         switch(_tag){
            case 'SPAN':
                
                _aa_parent = $(this).parents('a:first');
                if(_aa_parent.attr('href')){
                    _aa_parent.data('_href', _aa_parent.attr('href'));
                    _aa_parent.attr('href', '#');
                }
                
                _aa_child = $(this).find('a:first-child');
                if(_aa_child.attr('href')){
                    _aa_child.data('_href', _aa_child.attr('href'));
                    _aa_child.attr('href', '#');
                }
                break;
                
           case 'A':
                $(this).data('_href', $(this).attr('href'));
                $(this).attr('href', '#');
                break;   
                
          case 'IMG':
                _aa_parent = $(this).parents('a:first');
                _aa_parent.data('_href', _aa_parent.attr('href'));
                _aa_parent.attr('href', '#');
                break;        
        }
     }
     );
     
     //Simulate Click
      _id = setInterval('movSlider()', 5000);   
     $('#sliderBloc2').mouseenter(function(){
         window.clearInterval(_id);
     });
     
     $('#sliderBloc2').mouseleave(function(){
         _id = setInterval('movSlider()', 5000);
     });
      
     $('#previous22').mouseenter(function(){
         window.clearInterval(_id);
     }); 
     
     $('#next22').mouseenter(function(){
         window.clearInterval(_id);
     }); 
     
     $('.spcNext').click(function(evt) {
	     $('.spcNext').css('display', 'none');  
	     _ii = setInterval('addAttrNext()', 500);  
	     $('.spcAuxSl').css('display', 'Block');
     });
     
     $('.spcPrev').click(function(evt) {
         $('.spcPrev').css('display', 'none');  
         _i = setInterval('addAttrPrev()', 500);   
         $('.spcAuxSlP').css('display', 'Block');
     });
     
     
});

