﻿$(document).ready(function(){
	$(document).pngFix();
	
	Shadowbox.init({skipSetup:true});
    Shadowbox.setup("area#sdbx",{
		width	:	"430px",
		height	:	"378px"
	});
	
	$(".scrollable1").jCarouselLite({
		start: 0,
		visible: 3,
		btnNext: ".next1",
		btnPrev: ".prev1",
		circular: true,
		speed: 500
	});
	$(".scrollable2").jCarouselLite({
		start: 0,
		visible: 3,
		btnNext: ".next2",
		btnPrev: ".prev2",
		circular: true,
		speed: 500
	});
	$(".prev1, .prev2")
		.mouseover(function(){
			$(this).animate({"left":"+=10px"},"fast").animate({"left":"-=10px"},"fast",arguments.callee);
		})
		.mouseout(function(){
			$(this).css("left","-2px").animate().stop();
		});
	$(".next1, .next2")
		.mouseover(function(){
			$(this).animate({"right":"+=10px"},"fast").animate({"right":"-=10px"},"fast",arguments.callee);
		})
		.mouseout(function(){
			$(this).css("right","10px").animate().stop();
		});
	
	$("#novos").show();
	$("#linknovos").addClass("ativo");
	$("#linknovos").click(function(){
		$("#tabs a").removeClass("ativo");
		$(this).addClass("ativo");
		$("ul.videos").slideUp();
		$("#novos").slideDown();
	});
	$("#linkvistos").click(function(){
		$("#tabs a").removeClass("ativo");
		$(this).addClass("ativo");
		$("ul.videos").slideUp();
		$("#vistos").slideDown();
	});
	$("#linkcoments").click(function(){
		$("#tabs a").removeClass("ativo");
		$(this).addClass("ativo");
		$("ul.videos").slideUp();
		$("#comentados").slideDown();
	});
	
	$("div.formcoment textarea[maxlength]").keypress(function(event){
		var key = event.which;
		if(key >= 33 || key == 13) {
			var maxLength = $(this).attr("maxlength");
			var length = this.value.length;
			if(length >= maxLength) {
				event.preventDefault();
			}
		}
	});
	
// Funcções AJAX de validação e envio de comentários
	$("#formcoment").validate({
		submitHandler: function(){ 
    		$("#formcoment").ajaxSubmit(function(){
    			$.post("comentar.php", {idvideo:$("#idvideo").val(), nome:$("#name").val(), email:$("#email").val(), postcoment:$("#postcoment").val()}, function(comenta){
					$("#loader").fadeOut("slow");
					$("#formcoment").hide("slow").delay(7000).show("slow");
					$("#coments").hide("slow").html(comenta).show("slow");
				});
			});
		},
		errorLabelContainer: $("#valida")
	});
	$("#comentar").click(function(){
		$("#loader").fadeIn("slow").delay(7000).fadeOut("slow");
		$("#valida").hide().show("slow");
	});

var y_fixo = $("#floatdiv").offset().top;
		
    $(window).scroll(function(){
        $("#floatdiv").animate({top: y_fixo+$(document).scrollTop()+"px"},{duration:1000,queue:false});
    });
	
	$(".img3")
		.mouseover(function(){
			$(this).css("border","#ff960C solid 2px").css("padding","3px");
		})
		.mouseout(function(){
			$(this).css("border","#ff960C solid 5px").css("padding","0");
		});
		
	$("#alxajaxaupair").load("aupair.html");
});