$(function() {
    $("#home-page").easySlider({
		auto: true,
		continuous: true,
        controlsShow: true,
        speed: 		800,
        pause: 		8000,
	});
    
    if( $('.side-title').length > 0 ) {
        var sideTitleHeight = $('.side-title').height();
        var rigthHeight = $('.right-col').height();
        
        if( sideTitleHeight > rigthHeight ) {
            $('.right-col').height(sideTitleHeight);
            $('.right-col .submit').height(sideTitleHeight);
        } else {
            $('.side-title').height(rigthHeight);
            $('.right-col .submit').height(rigthHeight);
        }
        
    }
    
    if( $('form.pagseguro').length > 0 ) {
        $('form.pagseguro').each(function(){
            var total = $(this).children('.value_item_quant').val();
            var value = '';
            for( x=1; x<=total; x++ ) {
                value = value +
                    '<option value="'+x+'">'+x+'</option>' + "\n";
            }
            //alert(value);
            $(this).children('.item_quant').append(value);
        })
    }
	
	
	$("a.btn_comprar").live('click', function() {
		// ajusta descrições muito extensas
		var count = $(this).parent().parent().find(".pagseguro-form form input[name='item_descr']").val().length;
		var text = $(this).parent().parent().find(".pagseguro-form form input[name='item_descr']").val();
		if( count >= 90 ) {
			var item_descr = text.substr(0, 90);
			$(this).parent().parent().find(".pagseguro-form form input[name='item_descr']").val(item_descr);
		}
		
		// confere se a quantidade de itens foi selecionada
		/*if( $(".item_quant option:selected").val() != 0 ) {
			//submit do form
			var id = $(".pagseguro-form form").attr("id");
			$(id).submit();
			//return false;
		} else {
			alert("Escolha a quantidade de itens que deseja comprar.");
		}*/
		
		$(this).parent().parent().find(".pagseguro-form form").submit();
	});
    
	
    $('input[type=text]').autoClear();
	
	
	$("#lojistas .submit input").live(
		'click',
		function() {
			var email = $('input[name="fields[0][email]"]').val();
			var confirmar_email = $('input[name="fields[0][confirmar-email]"]').val();
			
			if( email != confirmar_email ) {
				if( $(".form").find(".erro") ) {
					$(".form .erro").remove();
					$('<div class="message erro" style="display: none;"><p>Os campos "Email" e "Confirmação de email" não conferem.</p></div>').insertBefore("#lojistas .inputs").fadeIn();
				}
				return false;
			}
		}
	);

});
