jQuery(document).ready(function($){
	$("#cpf").mask("999.999.999-99");
	$("#nascimento").mask("99/99/9999"); 
	$("#telefone, #celular").mask("(99) 9999-9999"); 
	
	$("#frm_contato, #frm_login").validate();
	$("#slideshow").cycle(); 
	
	$("#assunto").change(function(){
		if ( $(this).val() == "Orçamentos" ){
				location.href = "orcamentos.php";
		} else if ( $(this).val() == "Trabalhe" ){
			location.href = "trabalhe.php";
		} else if ( $(this).val() == "Dúvidas" ){
			location.href = "contato.php?assunto=duvidas";
		} else if ( $(this).val() == "Críticas" ){
			location.href = "contato.php?assunto=criticas";
		} else if ( $(this).val() == "Sugestões" ){
			location.href = "contato.php?assunto=sugestoes";
		}
	});
	
	//detalhes do produto
	$(".proddescricao a").click(function(){
		$(".proddescricao li").removeClass("ative");
		$("#descricao, #descricao_tecnica").hide();
		
		$( $(this).attr("href") ).show();
		$(this).parent().addClass("ative");
		
		return false;
	});
	
	//orcamentos
	$("#tipo1, #orc_voltar").click(function(){
		$(".orcesconde, #aviso_servicos").hide();
		$(".field").show();
	});
	$("#tipo2").click(function(){
		//$(".orcesconde").show();
		$("#aviso_servicos").show();
		$(".field").hide();
	});
	
	 $('.banner_01').nivoSlider({
		effect:'fade',
		directionNav: false
	 });

	/*$('.slide ul').movingBoxes({
			startPanel   : 4,      // start with this panel
			width        : 740,    // overall width of movingBoxes (not including navigation arrows)
			wrap         : true,   // if true, the panel will "wrap" (it really rewinds/fast forwards) at the ends
			currentPanel : 'current',
			panelWidth 	 : 0.4
			//buildNav     : true,   // if true, navigation links will be added
		});	*/
	
	$('.slide ul').jcarousel({
	 	auto: 2,
		scroll: 1,
	 	wrap: 'circular',
	 	initCallback: mycarousel_initCallback,
	
		itemFirstInCallback:  mycarousel_itemFirstInCallback,
    itemFirstOutCallback: mycarousel_itemFirstOutCallback
  });
	
	$("#prodsidebar").cycle({
			fx:     'scrollLeft', 
	    speed:  'fast', 
	    timeout: 5000, 
	    next:   '#next2', 
	    prev:   '#prev2'
	});
			
});

function clearText(field){
	if (field.defaultValue == field.value) field.value =  '';
	else if (field.value == '') field.value = field.defaultValue;
}

function mycarousel_initCallback(carousel){
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}






/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 */
function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
		//jQuery('img', item).addClass('test');
		//alert(idx);
		var item_atual = idx + 1;
		jQuery(".jcarousel-item-"+ item_atual).find("img").animate({
			width: '115px'
		},300);
};

/**
 * This is the callback function which receives notification
 * when an item is no longer the first one in the visible range.
 */
function mycarousel_itemFirstOutCallback(carousel, item, idx, state) {
    //display('Item #' + idx + ' is no longer the first item');
		var item_atual = idx + 1;
		jQuery(".jcarousel-item-"+ item_atual).find("img").animate({
			width: '100px'
		},300);
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 */
function mycarousel_itemLastInCallback(carousel, item, idx, state) {
    //display('Item #' + idx + ' is now the last item');
		var item_atual = idx + 1;
		jQuery(".jcarousel-item-"+ item_atual).find("img").animate({
			width: '100px'
		},300);
};

/**
 * This is the callback function which receives notification
 * when an item is no longer the first one in the visible range.
 */
function mycarousel_itemLastOutCallback(carousel, item, idx, state) {
    //display('Item #' + idx + ' is no longer the last item');
		var item_atual = idx + 1;
		jQuery(".jcarousel-item-"+ item_atual).find("img").animate({
			width: '100px'
		},300);
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 * Triggered before animation.
 */
function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
    // No animation on first load of the carousel
    if (state == 'init')
        return;

    jQuery('img', item).fadeIn('slow');
		
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 * Triggered after animation.
 */
function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
    display('Item #' + idx + ' is now visible');
};

/**
 * This is the callback function which receives notification
 * when an item is no longer the first one in the visible range.
 * Triggered before animation.
 */
function mycarousel_itemVisibleOutCallbackBeforeAnimation(carousel, item, idx, state) {
    //jQuery('img', item).fadeOut('slow');
		jQuery('img', item).removeClass('test');
};

/**
 * This is the callback function which receives notification
 * when an item is no longer the first one in the visible range.
 * Triggered after animation.
 */
function mycarousel_itemVisibleOutCallbackAfterAnimation(carousel, item, idx, state) {
    display('Item #' + idx + ' is no longer visible');
};

/**
 * Helper function for printing out debug messages.
 * Not needed for jCarousel.
 */
var row = 1;
function display(s) {
    // Log to Firebug (getfirebug.com) if available
    //if (window.console != undefined && typeof window.console.log == 'function')
      //  console.log(s);

    if (row >= 1000)
        var r = row;
    else if (row >= 100)
        var r = '&nbsp;' + row;
    else if (row >= 10)
        var r = '&nbsp;&nbsp;' + row;
    else
        var r = '&nbsp;&nbsp;&nbsp;' + row;

    jQuery('#display').html(jQuery('#display').html() + r + ': ' + s + '<br />').get(0).scrollTop += 10000;

    row++;
};
