/*-----------------------------------------------------------------------------+
| Funções Gerais JavaScript                                                    |
+-----------------------------------------------------------------------------*/

function popup(url,w,h){
	window.open(url,"","toobar=no,location=no,directories=no,maximize=no,menubar=no,scrollbars=yes,status=no,resizable=no,WIDTH="+w+",HEIGHT="+h+",top=0,left=50");
}

function roundNumber(preco) {
	var numberField = preco;
	var rlength = 2; // The number of decimal places to round to
	var newnumber = Math.round(numberField*Math.pow(10,rlength))/Math.pow(10,rlength);
	return newnumber;
}


function IsNumeric(sText)
{
   var ValidChars = "123456789 ";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

$(document).ready(function() {

	$('#tabsInterior a').click(function() {
		$('#tabsInterior a').removeClass('activo');
		$(this).addClass('activo');
		$('.janelaContent').load( $(this).attr('href') );
		return false;
	});

	$('#tabsInterior a:first').click();
	$('#slideshow li:last').css('padding-top', parseInt(((52 - $('#slideshow li:last').children().height()) / 2)));
	setInterval( "slideSwitch()", 5000 );
});

function slideSwitch() {
    var $active = $('#slideshow li.active');

    if ( $active.length == 0 ) $active = $('#slideshow li:last');

    var $next =  $active.next().length ? $active.next() : $('#slideshow li:first');

    $active.addClass('last-active');

	//Calcula a Margem a dar ao topo para o item seguinte
	margin_top = ((52 - $next.children().height()) / 2);
	margin_top = parseInt(margin_top);

	$next.next().css({'padding-top':margin_top});

    $next.css({'opacity': 0.0, 'padding-top':margin_top})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
