function MM_jumpMenu(targ,selObj,restore){ //v3.0
 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
 if (restore) selObj.selectedIndex=0;
}

function MM_reloadPage(init) {  
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function envia1(f)
{
var chosen;
escolhido=f.go1.options[f.go1.selectedIndex].value;
self.location=escolhido;
return false;
}

function opcao(URL) {
aWindow=window.open(URL,"Large","toolbar=no,width=910,height=540, status=no,scrollbars=yes,resize=no,menubars=no,location=no,directories=no");
}

function arruma(src, mask) 
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida) 
  {
	src.value += texto.substring(0,1);
  }
}

		var tabAtual = 1
 
		mudarTab = function(numeroTab) {
			$("#tab_"+tabAtual).toggle()
			$("#tab_"+numeroTab).toggle()
			tabAtual = numeroTab
		}

function enquete(URL) {
aWindow=window.open(URL,"Large","toolbar=no,width=350,height=300, status=no,scrollbars=yes,resize=no,menubars=no");
}

function mostra(num)
{
    for(i=1;i<=4;i++)
    {
        document.getElementById('aba_'+i).style.display = 'none';
    }
    document.getElementById('aba_'+num).style.display = 'block';
}

$(document).ready(function() {
    $('#centralimagens').show();
    $('#centralimagens').cycle({
        fx:'scrollHorz',
        timeout: 0,
        next: '#centralimgprox',
        prev: '#centralimgant'
    });
    
    $('#duvidasfrq').cycle({
        fx:'scrollHorz',
        timeout: 0,
        next: '#c_22',
        prev: '#c_21'
    });

    $('#c_30').cycle({
        fx:'scrollHorz',
        timeout: 0,
        next: '#c_31',
        prev: '#c_29'
    });

    $('#mini_2').show();
    $('#mini_2').cycle({
        fx: 'fade',
        timeout: 6000,
        next:'#mini_3',
        prev:'#mini_1'
    });

    $('#parceiros').cycle({
        fx: 'fade',
        timeout: 6000,
        next:'#1',
        prev:'#2'
    });

    $('#banner_1').show();
    $('#banner_1').cycle({
        fx: 'fade',
        timeout: 4000,
        next:'',
        prev:''
    });

    $("#upload_pic").css("display", "none");

    $("#alterar_foto").click(function() {
            $("#upload_pic").fadeIn('slow');
    })

    $("#close").click(function() {
            $("#upload_pic").fadeOut('slow');
    })

    $('#crop_img').imgAreaSelect({maxWidth: 130, maxHeight: 130, handles: true});

    $('#crop_img').imgAreaSelect({
        onSelectEnd: function (img, selection) {
            $('input[name=x1]').val(selection.x1);
            $('input[name=y1]').val(selection.y1);
            $('input[name=x2]').val(selection.x2);
            $('input[name=y2]').val(selection.y2);
        }
    });

    $("#corpo2_2_2").CloudCarousel(
		{
			xPos: 100,
			yPos: 20,
			buttonLeft: $(""),
			buttonRight: $(""),
			altBox: $("#alt-text"),
                        xRadius: 100,
                        yRadius: -20,
                        reflHeight: 0,
                        reflGap: 0,
                        reflOpacity: 0.4,
                        speed: 0.3,
                        autoRotate: 'right',
                        autoRotateDelay: 3000,
                        FPS: 30,
			titleBox: $("#title-text")
		}
    );

    // Show menu when #myDiv is clicked
        $(".panel").find('a').each(function(){
            //alert($(this).attr("id"));

            $(this).contextMenu({
                menu: 'myMenu'
        },
                function(action, el, pos) {
                if(window.confirm("Tem certeza que deseja excluir o arquivo?")){
                window.location='excluir.php?id='+$(el).attr('id');
                }
                /*alert(
                        'Action: ' + action + '\n\n' +
                        'Element ID: ' + $(el).attr('id') + '\n\n' +
                        'X: ' + pos.x + '  Y: ' + pos.y + ' (relative to element)\n\n' +
                        'X: ' + pos.docX + '  Y: ' + pos.docY+ ' (relative to document)'
                        );
                */
        });
    });
    $(".trigger").click(function(){
	$(".panel").slideToggle("slow");
	});

    $('.invest').fancybox();

});

$(function() {
				//current thumb's index being viewed
				var current			= -1;
				//cache some elements
				var $btn_thumbs = $('#fp_thumbtoggle');
				var $loader		= $('#fp_loading');
				var $btn_next		= $('#fp_next');
				var $btn_prev		= $('#fp_prev');
				var $thumbScroller	= $('#thumbScroller');

				//total number of thumbs
				var nmb_thumbs		= $thumbScroller.find('.content').length;

				//preload thumbs
				var cnt_thumbs 		= 0;
				for(var i=0;i<nmb_thumbs;++i){
					var $thumb = $thumbScroller.find('.content:nth-child('+parseInt(i+1)+')');
					$('<img>').load(function(){
						++cnt_thumbs;
						if(cnt_thumbs == nmb_thumbs)
				//display the thumbs on the bottom of the page
				showThumbs(2000);
					}).attr('src',$thumb.find('img').attr('src'));
				}


				//make the document scrollable
				//when the the mouse is moved up/down
				//the user will be able to see the full image
				//makeScrollable();

				//clicking on a thumb...
				$thumbScroller.find('.content').bind('click',function(e){
					var $content= $(this);
					var $elem 	= $content.find('img');
					//keep track of the current clicked thumb
					//it will be used for the navigation arrows
					current 	= $content.index()+1;
					//get the positions of the clicked thumb
					var pos_left 	= $elem.offset().left;
					var pos_top 	= $elem.offset().top;
					//clone the thumb and place
					//the clone on the top of it
					var $clone 	= $elem.clone()
					.addClass('clone')
					.css({
						'position':'fixed',
						'left': pos_left + 'px',
						'top': pos_top + 'px'
					}).insertAfter($('BODY'));

					var windowW = $(window).width();
					var windowH = $(window).height();

					//animate the clone to the center of the page
					$clone.stop()
					.animate({
						'left': windowW/2 + 'px',
						'top': windowH/2 + 'px',
						'margin-left' :-$clone.width()/2 -5 + 'px',
						'margin-top': -$clone.height()/2 -5 + 'px'
					},500,
					function(){
						var $theClone 	= $(this);
						var ratio		= $clone.width()/120;
						var final_w		= 400*ratio;

						$loader.show();

						//expand the clone when large image is loaded
						$('<img class="fp_preview"/>').load(function(){
							var $newimg 		= $(this);
							var $currImage 	= $('#fp_gallery').children('img:first');
							$newimg.insertBefore($currImage);
							$loader.hide();
							//expand clone
							$theClone.animate({
								'opacity'		: 0,
								'top'			: windowH/2 + 'px',
								'left'			: windowW/2 + 'px',
								'margin-top'	: '-200px',
								'margin-left'	: -final_w/2 + 'px',
								'width'			: final_w + 'px',
								'height'		: '400px'
							},1000,function(){$(this).remove();});
							//now we have two large images on the page
							//fadeOut the old one so that the new one gets shown
							$currImage.fadeOut(2000,function(){
								$(this).remove();
							});
							//show the navigation arrows
							showNav();
						}).attr('src',$elem.attr('alt'));
					});
					//hide the thumbs container
					hideThumbs();
					e.preventDefault();
				});

				//clicking on the "show thumbs"
				//displays the thumbs container and hides
				//the navigation arrows
				$btn_thumbs.bind('click',function(){
					showThumbs(500);
					hideNav();
				});

				function hideThumbs(){
					$('#outer_container').stop().animate({'bottom':'-160px'},500);
					showThumbsBtn();
				}

				function showThumbs(speed){
					$('#outer_container').stop().animate({'bottom':'0px'},speed);
					hideThumbsBtn();
				}

				function hideThumbsBtn(){
					$btn_thumbs.stop().animate({'bottom':'-50px'},500);
				}

				function showThumbsBtn(){
					$btn_thumbs.stop().animate({'bottom':'0px'},500);
				}

				function hideNav(){
					$btn_next.stop().animate({'right':'-50px'},500);
					$btn_prev.stop().animate({'left':'-50px'},500);
				}

				function showNav(){
					$btn_next.stop().animate({'right':'0px'},500);
					$btn_prev.stop().animate({'left':'0px'},500);
				}

				//events for navigating through the set of images
				$btn_next.bind('click',showNext);
				$btn_prev.bind('click',showPrev);

				//the aim is to load the new image,
				//place it before the old one and fadeOut the old one
				//we use the current variable to keep track which
				//image comes next / before
				function showNext(){
					++current;
					var $e_next	= $thumbScroller.find('.content:nth-child('+current+')');
					if($e_next.length == 0){
						current = 1;
						$e_next	= $thumbScroller.find('.content:nth-child('+current+')');
					}
					$loader.show();
					$('<img class="fp_preview"/>').load(function(){
						var $newimg 		= $(this);
						var $currImage 		= $('#fp_gallery').children('img:first');
						$newimg.insertBefore($currImage);
						$loader.hide();
						$currImage.fadeOut(2000,function(){$(this).remove();});
					}).attr('src',$e_next.find('img').attr('alt'));
				}

				function showPrev(){
					--current;
					var $e_next	= $thumbScroller.find('.content:nth-child('+current+')');
					if($e_next.length == 0){
						current = nmb_thumbs;
						$e_next	= $thumbScroller.find('.content:nth-child('+current+')');
					}
					$loader.show();
					$('<img class="fp_preview"/>').load(function(){
						var $newimg 		= $(this);
						var $currImage 		= $('#fp_gallery').children('img:first');
						$newimg.insertBefore($currImage);
						$loader.hide();
						$currImage.fadeOut(2000,function(){$(this).remove();});
					}).attr('src',$e_next.find('img').attr('alt'));
				}

                function makeScrollable(){
					$(document).bind('mousemove',function(e){
						var top = (e.pageY - $(document).scrollTop()/2) ;
						$(document).scrollTop(top);
                    });
				}
            });

function abas(x,y){
    $('.abas'+y).hide();
    $('.abas'+x).show();
}

function setOnde(value)
{
    document.getElementById('onde1').value = value;
    document.getElementById('n_09').innerHTML = (value==1)?'Conteúdo':'Notícias';
}

try
{
    var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
    var yr = 2010;
    var m = 06;
    var d= 21;
}
catch(ExceptionCode)
{

}
   function countdown(){
        try
        {
            theyear=yr;
            themonth=m;
            theday=d;
            var today=new Date()
            var todayy=today.getYear();
            if (todayy < 1000)
                todayy+=1900;
            var todaym=today.getMonth();
            var todayd=today.getDate();
            var todayh=today.getHours();
            var todaymin=today.getMinutes();
            var todaysec=today.getSeconds();
            var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
            futurestring=montharray[m-1]+" "+d+", "+yr;
            dd=Date.parse(futurestring)-Date.parse(todaystring);
            dday=Math.floor(dd/(60*60*1000*24)*1);
            dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
            dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
            dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
            //if(dday==0&&dhour==0&&dmin==0&&dsec==1){
            if(dmin==0 || dmin<0){
              document.getElementById(alvo).innerHTML = "00";
              return;
            }
            else
            {
                    dday = (dday.toString().length==1)?"0"+dday:dday;
                    document.getElementById('c_04').innerHTML = dday;
           }
           //setTimeout("countdown()",1000);
        }catch(ExceptionCode)
        {

        }
    }

    $(document).ready(function()
    {
        try
        {
            countdown();
        }
        catch(ExceptionCode)
        {

        }
    }
);
function getProdutos(area){
    //alert("area: "+area+", marca: "+marca+", subcategoria: "+sub);
    $("#lista_produtos").text('carregando produtos..');
    $("#lista_produtos").load("produtos.php?area="+area);
}
/* ------------------------------------- Mural --------------------------------- */
function limitChars(limit){

var text = $('#message').val();
var textlength = text.length;

$('#count').html(textlength);

if(textlength > limit){
return false;
}else{
return true;
}

}

function isValidEmail(str) {
return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
}

function refreshCaptcha(){
document.getElementById('captcha').src = 'captcha/securimage_show.php?' + Math.random();
//return false;
}

function postData(){

var name = $('#name').val();
var id_user_rec = $('#id_user_rec').val();
var email = $('#email').val();
var website = $('#website').val();
var message = $('#message').val();
var captcha_code = $('#captcha_code').val();

 var dataString = 'name='+ name + '&id_user_rec='+ id_user_rec + '&email=' + email + '&website=' + website + '&message=' + message + '&captcha_code=' + captcha_code;
 $("#error").html("Processando...");
 $.ajax({
   type: "POST",
   url: "post.php",
   data: dataString,
   error: function(){
     //alert('Error loading document');
	 return false;
   },
   success: function() {
     //place something here
   }
 });
return true;
}

function loadMessages(offset){
$("#messages").html("Carregando...").hide().fadeIn("slow");
$('#messages').load('messages.php?offset='+offset).hide().fadeIn("slow");
return false;
}

function loadMessages_user(offset){
$("#messages_user").html("Carregando...").hide().fadeIn("slow");
$('#messages_user').load('messages_user.php?offset='+offset).hide().fadeIn("slow");
return false;
}

$(document).ready(function(){
  loadMessages(0);
  loadMessages_user(0);
  $("#cap").html("<img id=captcha src=captcha/securimage_show.php alt=CAPTCHA Image />");
//$("#cap").html("<img src=CaptchaSecurityImages.php?width=100&amp;height=26&amp;characters=5>");


  $("#message").keyup(function() {
     limitChars(20);
  });

  $(".refresh").click(function() {
  loadMessages(0);
  loadMessages_user(0);
  //alert('refresh!');
  return false;
  });

  //$("form").submit(function() {
  $(".button").click(function() {

var sec_code = $.ajax({
  url: "get_session.php",
  async: false
 }).responseText;


     if($('#message').val()==''||$('#name').val()==''){
        $('#error').html("Nome e mensagem n&atilde;o pode estar vazio").addClass('error').hide().fadeIn("slow");
        return false;
	 };
	 if($('#email').val()!=''){
	   if(isValidEmail($('#email').val())==false){
	   $('#error').html("Email inv&aacute;lido").addClass('error').hide().fadeIn("slow");
	   return false;
	   };
	 };
	 if($('#website').val()!='' && $('#website').val()!='http://'){
	   if(isValidURL($('#website').val())==false){
	   $('#error').html("URL Inv&aacute;lida").addClass('error').hide().fadeIn("slow");
	   return false;
	   };
	 };
	 if($('#message').val().length>300){
	 $('#error').html("Mensagem n&atilde;o deve exceder 300 caracteres.").addClass('error').hide().fadeIn("slow");
	 return false;
	 };
	 if(sec_code!=$('#captcha_code').val()){
	 $('#error').html("C&oacute;digo de seguran&ccedil;a inv&aacute;lido").addClass('error').hide().fadeIn("slow");
	 refreshCaptcha();
	 return false;
	 }
	 if(postData()){
	 $('#error').html("Processando.....").removeClass('error').hide().fadeIn("slow");
	 $.timer(3000,function(){
	 $('#error').html("Mensagem inserida!").addClass('success').hide().fadeIn("slow");
	 loadMessages(0);
         loadMessages_user(0);
         refreshCaptcha();
	 //$('input[@type="text"]').val("");
	 $('#name').val("");
         $('#id_user_rec').val("");
	 $('#email').val("");
	 $('#website').val("");
	 $('#message').val("");
	 $('#captcha_code').val("");
	 });
	 }else{
	 $('#error').html("Erro no banco de dados.").fadeIn("slow");
	 return false;
	 }
	 return false;

  });


});
/* ----------------------------------- Fim Mural -------------------------------- */
/* ----------------------------------- Album -------------------------------- */

			$(window).load(function() {
				sliderLeft=$('#thumbScroller .container').position().left;
				padding=$('#outer_container').css('paddingRight').replace("px", "");
				sliderWidth=$(window).width()-padding;
				$('#thumbScroller').css('width',sliderWidth);
				var totalContent=0;
				$('#thumbScroller .content').each(function () {
					totalContent+=$(this).innerWidth();
					$('#thumbScroller .container').css('width',totalContent);
				});
				$('#thumbScroller').mousemove(function(e){
					if($('#thumbScroller  .container').width()>sliderWidth){
						var mouseCoords=(e.pageX - this.offsetLeft);
						var mousePercentX=mouseCoords/sliderWidth;
						var destX=-(((totalContent-(sliderWidth))-sliderWidth)*(mousePercentX));
						var thePosA=mouseCoords-destX;
						var thePosB=destX-mouseCoords;
						var animSpeed=600; //ease amount
						var easeType='easeOutCirc';
						if(mouseCoords==destX){
							$('#thumbScroller .container').stop();
						}
						else if(mouseCoords>destX){
							//$('#thumbScroller .container').css('left',-thePosA); //without easing
							$('#thumbScroller .container').stop().animate({left: -thePosA}, animSpeed,easeType); //with easing
						}
						else if(mouseCoords<destX){
							//$('#thumbScroller .container').css('left',thePosB); //without easing
							$('#thumbScroller .container').stop().animate({left: thePosB}, animSpeed,easeType); //with easing
						}
					}
				});
				$('#thumbScroller  .thumb').each(function () {
					$(this).fadeTo(fadeSpeed, 0.6);
				});
				var fadeSpeed=200;
				$('#thumbScroller .thumb').hover(
				function(){ //mouse over
					$(this).fadeTo(fadeSpeed, 1);
				},
				function(){ //mouse out
					$(this).fadeTo(fadeSpeed, 0.6);
				}
			);
			});
			$(window).resize(function() {
				//$('#thumbScroller .container').css('left',sliderLeft); //without easing
				$('#thumbScroller .container').stop().animate({left: sliderLeft}, 400,'easeOutCirc'); //with easing
				$('#thumbScroller').css('width',$(window).width()-padding);
				sliderWidth=$(window).width()-padding;
			});
/* ----------------------------------- Fim Album -------------------------------- */

