$(document).ready(function(){
	$('a.anchor').click(function() {
		var target = $('a[name=' + this.hash.split('#')[1] + ']');
		if(target.length){
			var targetOffset = target.offset().top - 2;
			$('html,body').animate({scrollTop: targetOffset}, 'slow');
			return false;
		}
	});
	$('.destaqueScroll').nivoSlider({
        effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
        slices:15, // For slice animations
        boxCols: 10, // For box animations
        boxRows: 10, // For box animations
        animSpeed:500, // Slide transition speed
        pauseTime:5000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:false, // Next & Prev navigation
        directionNavHide:true, // Only show on hover
        controlNav:true, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0.8, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
    });
    $total = $('.nivo-controlNav a.nivo-control').length;
    $('.nivo-controlNav a.nivo-control').each(function(){
    	$(this).addClass('nav'+$total);
    	$total--;
    });
    /* */
    // Menu - Inicio
    $('#menu .submenu').parent().hover(function(){
   		$(this).find('div.submenu:eq(0)').show();
   		$(this).find('a:eq(0)').addClass('atual');
   	}, function(){
   		$(this).find('div.submenu:eq(0)').hide();
   		$(this).find('a:eq(0)').removeClass('atual');
    });
    $('#menu a[href=#]').click(function(){ return false; });
    // Menu - Fim
    // Home - Inicio
/*
    $balt = 0;
    $('.blocoSuperior .blocoHome').each(function(){
    	if($(this).height() > $balt){ $balt = $(this).height(); }
    });
    $('.blocoSuperior .blocoHome').css({'height':$balt+'px'});
/* */
    $balt = 0;
    $('.blocoMeio .blocoHome').each(function(){
    	if($(this).height() > $balt){ $balt = $(this).height(); }
    });
    $('.blocoMeio .blocoHome').css({'height':$balt+'px'});
    $balt = 0;
    $('.blocoInferior .blocoHome').each(function(){
    	if($(this).height() > $balt){ $balt = $(this).height(); }
    });
    $('.blocoInferior .blocoHome').css({'height':$balt+'px'});
    // Home - Fim
    $('.formulario input.text').blur(function(){
    	$(this).removeClass('hover');
    }).focus(function(){
    	$(this).addClass('hover');
    });
    // Where to Buy
		$('#sel_state').bind('change', function(){
			$.get('/ajax/where-to-buy', { state: $('#sel_state').val() }, function(data) { $('#sel_city').html(data); });
		}).parent().submit(function(){
			if($('#sel_state').val() < 1){
				alert('Select one State!');
			} else if ($('#sel_city').val() < 1){
				alert('Select one City!');
			} else {
				$state = $city = '';
				$('#sel_state option').each(function(){
					if($(this).val() == $('#sel_state').val()){
						$state = $(this).attr('label');
					}
				});
				$('#sel_city option').each(function(){
					if($(this).val() == $('#sel_city').val()){
						$city = $(this).attr('label');
					}
				});
				document.location.href = '/where-to-buy/'+$state+'/'+$city;
			}
			return false;
		});
});
