$(document).ready(function() {
/*--------------*/  
  $(".video-post").hover(function() {
        $(this).find("span.play-video").animate({ opacity: "0.6" }, 400);
        $(this).find(".video-thumb-large img").animate({ opacity: "0.5" }, 400);
    },function(){
        $(this).find("span.play-video").animate({ opacity: "0" }, 400);
        $(this).find(".video-thumb-large img").animate({ opacity: "1" }, 400);

	}); 

/*--------------*/
  $(".video-thumb img").hover(function() {
  		$(this).animate({opacity: "1"},300);
	},function(){
	  	$(this).animate({opacity: "0.5"},300);
	}); 
/*--------------*/
	$(".tab_content").hide();
	$("ul.tabs li:first").addClass("active").show();
	$(".tab_content:first").show(); 
	$("li.tabs").click(function() {
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn();
		return false;
	});
	
	//$("#loopedSlider").css("display", "none");
	/*setTimeout(function(){
		$("#Slider-loading").fadeOut(000,function(){
			$("#loopedSlider").slideDown(400);	
		});
	},3000);*/
/*--------------*/
	var timer, imgsrc, cnt = 0;
	$('.video-thumb img').bind('mouseover', function() {
		if (!timer) {
			var $t = $(this);
			imgsrc = $t.attr('src').replace('1.jpg','');
			timer = setInterval(function() {
				$t.attr('src', imgsrc + (cnt+1) + ".jpg");
				cnt = ( cnt + 1 ) % 3; // 0, 1, 2
			}, 800);
		}
	}).bind('mouseout',function() {
	if (timer) {
		clearInterval(timer);
		timer = null;
	}
		$(this).attr('src', imgsrc + '1.jpg');
	});

/*--------------*/
	$("#buttons li").each(function(){	
		var $sublist = $(this).find('ul:first');		
		$(this).hover(function(){	
			$sublist.stop().css({overflow:"hidden", height:"auto", display:"none"}).slideDown(300, function(){
				$(this).css({overflow:"visible", height:"auto"});
			});	
		},
		function(){	
			$sublist.stop().slideUp(300, function()	{	
				$(this).css({overflow:"hidden", display:"none"});
			});
		});	
	});
	
/*--------------*/	
	$(function(){
		 $('a[href*=#top]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
			&& location.hostname == this.hostname) {
				 var $target = $(this.hash);
				 $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
				 if ($target.length) {
					 var targetOffset = $target.offset().top;
					 $('html,body').animate({scrollTop: targetOffset}, 700);
					 return false;
				 }
			 }
		 });
	 });	




	var jval2 = {
		
		'title' : function() {
			var ele = $('#author');
			if(ele.val().length < 3 || ele.val() == 'الإسم (مطلوب)'  ) {
				ele.removeClass('normal').addClass('error');
			} else {
				ele.removeClass('error').addClass('normal');
			}
		},
		'email' : function() {
			var ele = $('#email');
			var patt = /^.+@.+[.].{2,}$/i;

			if(!patt.test(ele.val())) {
				ele.removeClass('normal').addClass('error');
			} else {
				ele.removeClass('error').addClass('normal');
			}
		},
		'details' : function() {
			var ele = $('#comment');
			if(ele.val().length < 10 ) {
				ele.removeClass('normal').addClass('error');
			} else {
				ele.removeClass('error').addClass('normal');
			}
		}

	};


	$('#author').keyup(jval2.title);
	$('#email').keyup(jval2.email);
	$('#comment').keyup(jval2.details);

	$('#author').blur(jval2.title);
	$('#email').blur(jval2.email);
	$('#comment').blur(jval2.details);

	
});
