function ImagePreload(){
	$.loadImages(["sysimages/leftlinkmenu.png", "sysimages/rightlinkmenu.png"], '');
}

var local;

$(document).ready(function(){
  
  if(jQuery('.rightselect span.selectvalue').text() == ''){
      jQuery('span.selectvalue').each(function(i){
          jQuery(this).text(jQuery('select option:selected', jQuery(this).parent()).text());
      });
    }
    
    jQuery('.rightselect select').change(function(){
      jQuery('span.selectvalue', this.parentNode).text(jQuery('option:selected', this).text());
    });
    
    
     jQuery(".top_faq").click(function(){
      
      var faqsSels = jQuery(".uni_faq_sel");
      
      jQuery(".cnt_faq", faqsSels).hide(200, function(){
        jQuery(faqsSels).attr("class", "uni_faq");
        jQuery(faqsSels).attr("class", "uni_faq");
      });
      
      if(jQuery(this).parents('.uni_faq_sel').length == 0){
        jQuery(this).parent().attr("class", "uni_faq_sel");
        jQuery(".cnt_faq", jQuery(this).parent()).show(300, function(){
          
          jQuery(".suplementBottom").css("display", "none");
          //jQuery('#pane3').jScrollPane({scrollbarWidth:10, scrollbarMargin:10});
          //jQuery('.faqs').jScrollPane();
        });
      }
      
      
   });
   
   /*
   
    var a = $('div.bgwhite').height();
    alert(a);
    $('div.empresasidemenu').height(a);
    
    $('div.empresasidemenu2').height(a*1.07);
    if($.browser.msie && $.browser.version=='7.0'){
        $('div.empresasidemenu2').height(a*1.07);
        var b =-15*1.07;
        alert(b);
        $('div.empresasidemenu2').css("margin-bottom", b);

      }
     */
   
   $(".movie").click(function(){
        jQuery(".poplocation").height(jQuery(document).height());
        
        var idmovie = jQuery(this).attr("idmovie");
       
        var so = new SWFObject('flash/player.swf', 'Forever', '535', '312', '9', '#000000');             
        so.addParam("scale", "noScale");
        so.addParam("wmode", "transparent");
        so.addVariable("servidor",local+"/flash/not_"+idmovie+".flv");                                           
        so.write('forever');   
      
        jQuery('.poplocation').fadeIn(500);   
   });
   
   $(".btnfechar").click(function(){
       document.getElementById('forever').innerHTML="";
       jQuery('.poplocation').fadeOut(500); 
   });
  Highlights(); 
	ImagePreload();
	
	   var teste = false;
	//Slider da pagina da Historia
	$('#tabs').tabs({
	    fx: {opacity: 'toggle'},
			select: function( event, ui ) {
          $( ".slider" ).slider("value", ui.index );

			}
	});
	
	//console.log($('#tabs').children().length);
	//console.log($('#tabs').children('div[id^="tabs"]'));
	$(".slider").slider({
	  animate: true,
    min: 0,
    max: $('#tabs').children('div[id^="tabs"]').length - 1,
    slide: function( event, ui ) {
        
				$( "#tabs" ).tabs( "select", ui.value );			
    }
    
  });
  
  /*scroll*/
  
  //Get our elements for faster access and set overlay width
    var div = $('div.scroll'),
                 ul = $('ul.ulslider'),
                 // unordered list's left margin
                 ulPadding = 15;

    //Get menu width
    var divWidth = div.width();

    //Remove scrollbars
    div.css({overflow: 'hidden'});

    //Find last image container
    var lastLi = ul.find('li:last-child');

    //When user move mouse over menu
    div.mousemove(function(e){

      //As images are loaded ul width increases,
      //so we recalculate it each time
      var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;

      var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
      div.scrollLeft(left);
      //$('.bgscroll').css('left', 4+left+'px');
    });

  /*end scoll*/
  
  //Somar width da ulslider
  var soma = 0;
  $('.ulslider li').each(function(){
    soma += $(this).width();
  });
  //console.log(soma);
	$('.slider').width(soma);
	
	//Dar classe ao last-child da ul.slider
	$('ul.ulslider > li').last().attr('class', 'last');

  //Cycle das noticias
  
    

	
	
});

$(window).load(function(){
    var a = $('div.bgwhite').height();
    
    //console.log(a);
   
    $('div.empresasidemenu2').height(a+85);
    
    //$('div.empresasidemenu2').height(a);
    
    if($.browser.msie && $.browser.version=='7.0'){
        $('div.empresasidemenu2').height(a);
        var b =-15*1;
        $('div.empresasidemenu2').css("padding-bottom", b);

      }
    if($.browser.msie && $.browser.version=='8.0'){
      $('div.empresasidemenu2').height(a);
      var b =-15*1;
      $('div.empresasidemenu2').css("padding-bottom", b);

      }
      
      
    var alt1 = $('.sidemenubg').height()+100;
    var alt2 = $('.empresamainarea').height();
    if(alt1 > alt2)
      $('.random').height(alt1);
    else
      $('.random').height(alt2);
      
      
      
      //$('.zindex').height($('.sidemenubg').height()+120);
      
    //Acertar altura dos hovers da pagina das solas
    $('.redeye .hover').each(function(index){
      var alt = $(this).height()/2;
      //console.log($(this).height());
      $(this).css('top', 8-alt);  
    });
    
    //Efeito cinza
    $('.videopic > .movie1').pixastic('desaturate');
    $('.minMovie img').pixastic('desaturate');
    
    //Fazer crescer a parte lateral da pagina de produtos 
    //$('.produtossidemenu').height($('.bgwhite').height());
    
    //Tratar hover das materias primas
    //console.log($('ul.materiasprimas  > li.redeye').last().children('.hover').height());
    $('ul.materiasprimas').css('margin-bottom', $('ul.materiasprimas  > li.redeye').last().children('.hover').height()/3); 
    
  
});

function OpacityHome(){

	var active = $('ul.ulpaginator > li.active');
	active.removeAttr('style');

	switch(active.index()){
		case 0:
			active.next('li').css('background', 'url(sysimages/slide30.png) no-repeat left top');
			active.next('li').next('li').css('background', 'url(sysimages/slide20.png) no-repeat left top');
			active.next('li').next('li').next('li').css('background', 'url(sysimages/slide10.png) no-repeat left top');
			break;
		case 1:
			active.prev('li').css('background', 'url(sysimages/slide30.png) no-repeat left top');
			active.next('li').css('background', 'url(sysimages/slide30.png) no-repeat left top');
			active.next('li').next('li').css('background', 'url(sysimages/slide20.png) no-repeat left top');
			break;
		case 2:
			active.prev('li').css('background', 'url(sysimages/slide30.png) no-repeat left top');
			active.prev('li').prev('li').css('background', 'url(sysimages/slide20.png) no-repeat left top');
			active.next('li').css('background', 'url(sysimages/slide30.png) no-repeat left top');
			break;
		case 3:
			active.prev('li').css('background', 'url(sysimages/slide30.png) no-repeat left top');
			active.prev('li').prev('li').css('background', 'url(sysimages/slide20.png) no-repeat left top');
			active.prev('li').prev('li').prev('li').css('background', 'url(sysimages/slide10.png) no-repeat left top');
			break;
	}
	
}    

function FunctionsHome(){
  //Animar Noticias
  jQuery('.titlel').live('click', function(){
        /*
        $('.newstext').css('width', '444')-
        $('.botright').css('width', '212')-
        $('.newsdivider').css('width', '499')-
        $('.botleft').css('width', '499')-
        $('.bodyright').css('width', '213')-
        $('.boot').css('margin-right', '-72')-
        $('.botcenter').css('width', '212')-
        $('.bodycenter').css('width', '212')
        $('.videowrapper').css('width', '182')
        $(".videopic .movie1").css("width", "168px")
        $(".videopic .movie1").css("height", "167px")
        $(".btnplay").css("left", "64px")
        $('.vertdl').css('visibility', 'visible')
        $('.vertdm').css('visibility', 'hidden')
        $(".minMovie").css("display", "none")
        */
        
        //Slide do lado direito
        $('.botright').animate({
          width: '212px'
          }, 300, function(){
            $('.boot').animate({
              marginRight : '0px'
            }, 0); 
            $('.bodyright').animate({
              width : '213px'
            }, 0); 
        });
        $('titler').css('width', '212px')
        
        
        //Slide do meio
        $('.vertdm').css('display', 'none');
        $(".minMovie").css("display", "none");
        $('.botcenter').animate({
          width: '212px'
          }, 300, function(){
            $('.bodycenter').css('width', '212')
            $('.videowrapper').css('width', '182')
            $(".videopic .movie1").css("height", "167px")
            $('.vertdl').css('display', 'block')  
            
            $('.vertdm').css('margin-left', '85px')
        });        
         $(".btnplay").animate({
          left: '64px'}, 300);
        $(".videopic .movie1").animate({
          width: '168px'}, 300);
        /*$('.minimovie').animate({
          right: '20px'
          }, 300); */

        
        //Slide do lado esquerdo
        $('.botleft').animate({
          width: '499px'
          }, 300);
        $('.newstext').animate({
           width: '442px'
          }, 300);
        $('.newsdivider').animate({
           width: '499px'
          }, 300);
        $('.carousel').animate({
           width: '499px'
          }, 300);
        
          $('.titlem').animate({
         left: '510px'
         }, 300);
      $('.titler').animate({
         left: '728px'
         }, 300);  
      
      $('.titler').css('width', '212px')  
      $('.titlem').css('width', '212px')
      $('.titlel').css('width', '499px')
      $('.carousel').css('width', '494px')
      $('.cycle').css('width', '494px')  
      $('#titgr').css('display', 'none')
      $('#titpq').css('display', 'block')
      });
      
    
      
    //Animar Destaques  
    jQuery('.titler').live('click', function(){
      /*$('.newstext').css('width', '154')
      $('.botright').css('width', '499')
      $('.newsdivider').css('width', '212')
      $('.botleft').css('width', '212')
      $('.bodyright').css('width', '499')
      $('.boot').css('margin-right', '0')
      $('.botcenter').css('width', '212')
      $('.bodycenter').css('width', '212')
      $('.videowrapper').css('width', '182')
      $(".videopic .movie1").css("width", "168px")
      $(".videopic .movie1").css("height", "167px")
      $(".btnplay").css("left", "64px")
      $('.vertdl').css('visibility', 'hidden')
      $('.vertdm').css('visibility', 'hidden')
      $(".minMovie").css("display", "none")
      */
      
      //Slide do lado esquerdo
      $('.botleft').animate({
        width: '212px'
        }, 300);
      $('.newstext').animate({
         width: '154px'
         }, 0);
      $('.newsdivider').animate({
         width: '212px'
         }, 300);
      $('.carousel').animate({
         width: '212px'
         }, 300);
         
      //Slide do meio
      $('.vertdm').css('display', 'none');
      $('.vertdl').css('display', 'none');
      $(".minMovie").css("display", "none");
        $('.botcenter').animate({
          width: '212px'
          }, 200, function(){
            $('.bodycenter').css('width', '212')
            $('.videowrapper').css('width', '182')
            $(".videopic .movie1").css("height", "167px")
            $('.vertdl').css('display', 'none')
            $('.vertdm').css('margin-left', '85px')
        
        });
        $(".btnplay").animate({
          left: '64px'}, 300);
        $(".videopic .movie1").animate({
          width: '168px'}, 300);
        /*$(".minimovie").animate({
          right: '20px'}, 300);*/
        
         //Slide do lado direito
        $('.botright').animate({
          width: '499px'
          }, 300);
        $('.boot').animate({
            marginRight : '0px'
          }, 0); 
        $('.bodyright').animate({
            width : '499px'
          }, 0);
            
          
        //$('.titler').css('width', '494px')  
        $('.titlem').css('width', '212px')
        $('.titlel').css('width', '212px')
        $('.carousel').css('width', '212px')  
        $('.cycle').css('width', '212px')
       
        $('#titgr').css('display', 'block')
        $('#titpq').css('display', 'none')
        
         
       $('.titlem').animate({
         left: '223px'
         }, 300);
      $('.titler').animate({
         left: '441px'
         }, 300);             
         
        });        
      
         
                            
    //Animar Videos
    jQuery('.titlem').live('click', function(){
      
      /*
      $('.newstext').css('width', '154')
      $('.botright').css('width', '212')
      $('.newsdivider').css('width', '212')
      $('.botleft').css('width', '212')
      $('.bodyright').css('width', '213')
      $('.boot').css('margin-right', '72')
      $('.bodyright > h2').css('padding-left', '20')
      $('.bodyright > h3').css('padding-left', '20')
      $('.botcenter').css('width', '499')
      $('.bodycenter').css('width', '499')
      $('.videowrapper').css('width', '222')
      $(".videopic .movie1").css("width", "208px")
      $(".videopic .movie1").css("height", "167px")
      $(".btnplay").css("left", "84px")
      $('.vertdl').css('visibility', 'hidden')
      $('.vertdm').css('visibility', 'visible')
      $(".minMovie").css("display", "block")
      */
      
      //Slide do lado esquerdo
      $('.botleft').animate({
        width: '212px'
        }, 300);
      $('.newstext').animate({
         width: '154px'
         }, 0);
      $('.newsdivider').animate({
         width: '212px'
         }, 300);
      $('.carousel').animate({
         width: '212px'
         }, 300);
      $('.vertdl').css('display', 'none');   
      //Slide do lado direito
        $('.botright').animate({
          width: '212px'
          }, 300, function(){
            $('.boot').animate({
              marginRight : '0px'
            }, 0); 
            $('.bodyright').animate({
              width : '213px'
            }, 0);
        });
        $('titler').css('width', '212px')
        
        //Slide do meio
        $('.botcenter').animate({
          width: '499px'
          }, 300, function(){
            $(".minMovie").css("display", "block")
          });
        $('.bodycenter').animate({
          width: '499px'
          }, 300,function(){
            $('.vertdm').css('display', 'block')});
        /*$('.videowrapper').animate({
          width: '222px'
          }, 300);*/
        $('.videowrapper').css('width', '222px')  
        $('.videopic .movie1').animate({
          width: '208px',
          height: '167px'
          }, 300);
    
        $('.btnplay').animate({
          left: '84px'
          }, 300);
        /*$('.minimovie').animate({
          right: '20px'
          }, 300);*/    
      
        
        $('.vertdm').css('margin-left', '329px')
        //$(".minMovie").css("display", "block")
        
        $('.titlem').animate({
           left: '223px'
           }, 300);
        $('.titler').animate({
           left: '728px'
           }, 300);
        //$('.vertdm').css('display', 'block');
        $('.titler').css('width', '212px')  
        $('.titlem').css('width', '495px')
        $('.titlel').css('width', '212px')
        $('.carousel').css('width', '212px')
        $('.cycle').css('width', '212px')
      $('#titgr').css('display', 'none')
      $('#titpq').css('display', 'block')
      });
                          
};


function Highlights(){
  $('.titlel').hover(function() {
   
  		$('.dbarrow1').css('background','url(sysimages/dbarrowred.png) no-repeat left top');
  			}, function() {
  		  $('.dbarrow1').css('background','url(sysimages/dbarrow.png) no-repeat left top');
  });
  	
  $('.titler').hover(function() {

  		$('.dbarrow2').css('background','url(sysimages/dbarrowred.png) no-repeat left top');
  			}, function() {
  		$('.dbarrow2').css('background','url(sysimages/dbarrow.png) no-repeat left top');
  	});
  	
  $('.titlem').hover(function(){
      $('.dbarrow1').css('background','url(sysimages/dbarrowred.png) no-repeat left top');
      $('.dbarrow2').css('background','url(sysimages/dbarrowred.png) no-repeat left top');
  			}, function() {
  		  $('.dbarrow1').css('background','url(sysimages/dbarrow.png) no-repeat left top');
  		  $('.dbarrow2').css('background','url(sysimages/dbarrow.png) no-repeat left top');

  });
  	
};


function InputFileFunction(){

   $('#btncurriculum').file().choose(function(e, input) {
      var x = input.val();
      //alert(x);
      $('#txtcurriculo').val(x);
    //alert(input.val()); 
    //$('#txtcurriculo').val(jQuery(input.val()));
    //alerts the chosen filename. (jQuery('option:selected', this).text());
    });

};

function changeLink(that, link){
  location='index.php?'+link+'&limit='+that.value;
}

function changeLink2(that, link){
  location='index.php?'+link+'&order='+that.value;
}

function recpw(){

  document.getElementById('frmLogin').style.display='none';
  document.getElementById('linkRecpw').style.display='none';
  document.getElementById('frmRecpw').style.display='block';

}


function openquestion(){

  var popNatal = document.getElementById('popQuestionario');
  if(popNatal != null && popNatal != undefined) {
    popNatal.style.display='block';  
    var tamanho = getDocHeight();
    popNatal.style.height=tamanho+'px';
    setTimeout("closequestion()", 10000);
  }
}

function closequestion(){
  var popNatal = document.getElementById('popQuestionario');
  popNatal.style.display='none';  
}


function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function openMap(coords){
    var _html = '<iframe src="map_frame.php?coords='+coords+'" width="670" height="400" SCROLLING="no" frameborder="0" style="background-color:#FFF !important;margin:0px padding:0px;"></iframe>'; 
    document.getElementById('popQuestionario').style.display = "block";
    document.getElementById('frameholder').innerHTML = _html;

}

function sugerir(){
  var element = document.getElementById('psugerir');
  
  if(element.style.display=="none") element.style.display="block";
  else  element.style.display="none";
  
  
}


function addBookmarkForBrowser() {
  var title="Forever";
  var url = "http://www.forever.pt";

  if (window.sidebar) { // Mozilla Firefox Bookmark
  
    window.sidebar.addPanel(title, url,"");
    
  }else if( window.external ) { // IE Favorite

    window.external.AddFavorite( url, title); 
    
  }else if(window.opera && window.print) { // Opera Hotlist
    return true; 
  }
}

function showPics(that){
    var pop = jQuery("#popQuestionario");
    var imags = jQuery(that).attr("fgr");
    var arrImgs=imags.split("|"); 
    var _html = "";
  
    for(var i=0;i<arrImgs.length;i++){
      if(arrImgs[i]!="") _html+="<img src='"+arrImgs[i]+"' style='border:2px solid #FFFFFF;'>";
    }
    
    
    jQuery("#popImgsHolder").html(_html);
    
    var tamanho = getDocHeight();
    jQuery(pop).css("height",getDocHeight);
    pop.css("display", "block");
}



