﻿$(function(){
	clearInterval(timer);
	var current = $('.imp-news li:first');
	var timer;
	$('.imp-news li:gt(0)').hide();
	$('.imp-news li:last').addClass('last');
	$('.imp-news li:first').addClass('first');
	
	timer=setInterval( function() {
						//current.slideUp("slow");
						current.fadeOut("slow");
						if (current.attr('class') == 'last')
							{
								current= $('.imp-news li:first');							
							}
						else
							{
								current= current.next();		
							}
							
						//current.show();
						current.fadeIn("slow");
						
					}, 4000);

////////////add star rating to each page of articles//////////////////
	$('#ratelinks li a').click(function(){
	var vote=$(this).text();
	var code=$(this).attr("id");
	$('#voteResult').empty();
	$('#voteResult').addClass("articleLoader");
			$.ajax({
				type: "POST",
				url: "call.set.inside.php",
				data: ({"voteAjax":vote,"papercode":code}),
				cache: false,
				success: function(data) {
				$('#voteResult').removeClass("articleLoader");					
				$('#voteResult').empty().append(data).fadeIn("slow");
					}
				});
	});
////////////////////////end of star rating///////////////////////////
///////////////////////search of news////////////////////
$('#news-search-extend').click(function(){
	$('#advance-search').slideToggle("slow");
});
/////////////////////////end of news search/////////////
});
////////////////////////////news each page submit user comments//////////////////////////////////////////
function commentSub(id) {
		var name=$('#userCommentName').val();
		var email=$('#userCommentEmail').val();
		var comment=$('#commentText').val();
		if (comment== '') {
			$('#warningComment').text('لطفا نظر خود را وارد نمایید!').css({'background-color':'#e65e3a'}).fadeIn("slow");
			setTimeout( function() {
				$('#warningComment').fadeOut("slow");
			}, 4000);

		} else {
			
			$('#warningComment').text('در حال ارسال ...').css({'background-color':'#6CB034'}).fadeIn("slow");
			$.ajax( {
				type :"POST",
				url :"call.set.php",
				data : ({"nameAjax":name,"emailAjax":email,"commentAjax":comment,"idAjax":id
					}),
				cache :false,
				success : function(data) {
				$('#userCommentName').attr("value","");
				$('#userCommentEmail').attr("value","");
				$('#commentText').attr("value","");
					$('#warningComment').text('نظر شما با موفقیت ثبت گردید!').css({'background-color':'#6CB034'}).fadeIn("slow");
					setTimeout( function() {
						$('#warningComment').fadeOut("slow");
					}, 4000);
				}

			});
		}
}
/////////////////////////////Article each page submit user comments//////////////////////////////
function commentSubArticle(articleId)
{
	   var name=$('#userNameArticle').val();
		var email=$('#userEmailArticle').val();
		var comment=$('#commentTextArticle').val();
		if (comment== '') {
			$('#warningComment').text('لطفا نظر خود را وارد نمایید!').css({'background-color':'#e65e3a'}).fadeIn("slow");
			setTimeout( function() {
				$('#warningComment').fadeOut("slow");
			}, 4000);

		} else {
			
			$('#warningComment').text('در حال ارسال ...').css({'background-color':'#6CB034'}).fadeIn("slow");
			$.ajax( {
				type :"POST",
				url :"call.set.inside.php",
				data : ({"nameAjaxArticle":name,"emailAjaxArticle":email,"commentAjaxArticle":comment,"idAjaxArticle":articleId
					}),
				cache :false,
				success : function(data) {
				$('#userNameArticle').attr("value","");
				$('#userEmailArticle').attr("value","");
				$('#commentTextArticle').attr("value","");
				$('#warningComment').text('نظر شما با موفقیت ثبت گردید!').css({'background-color':'#6CB034'}).fadeIn("slow");
					setTimeout( function() {
						$('#warningComment').fadeOut("slow");
					}, 4000);
				}

			});
		}
}
///////////////////////////news search validation////////////////////////
function checkValid()
{
		$('#newsSearchFrm').submit();
}
//////////////////////////////////////////////////////////////
