function NextFeed(){
	var do_next = $('#do_next').val();
	if(do_next=='1')
	{
		var current = $('#Activ');
		var next 	= current.next();
		$('div[class*="slider_feed_active"]').removeClass('slider_feed_active');		
		$('div[id="Activ"]').removeAttr('id');
		next.attr({"id":"Activ"})
		var img = (next.find('img').attr('src'))   ? next.find('img').attr('src')   : $('#slider_feeds div:eq(0)').find('img').attr('src');
		var alt = (next.find('img').attr('alt'))   ? next.find('img').attr('alt')   : $('#slider_feeds div:eq(0)').find('img').attr('alt');
		var name = (next.find('img').attr('name')) ? next.find('img').attr('name') : $('#slider_feeds div:eq(0)').find('img').attr('name');
		next.addClass('slider_feed_active');
		//$('#slideFader').fadeIn(100,function() { 
			$('#Slider').css({"background":"url("+img+") center top no-repeat"}); 
			$('#nakratko_text').html(name);
//			$('#nakratko_link').attr({"href":id});
//			alert(name);
			$('.Slide_text').html(alt);
		//}).fadeOut('fast');			
		if(!next.attr('class')) { $('#slider_feeds div:eq(0)').addClass('slider_feed_active').attr({"id":"Activ"}); }
		var d=setTimeout("NextFeed()",4000);
	}
	else
	{
		var d=setTimeout("NextFeed()",4000);
	}
}
$(document).ready(function() {
	$("#text").show().css({"text-shadow":"0px 1px #888"});
	$('.menu_link').mouseenter(function(){ $(this).animate({"padding-top":"10px"},200); }).
					mouseleave(function(){ $(this).animate({"padding-top":"7px"},200); });
	
//	$('.menu_link a').dropShadow({left: 1, top: 1, blur: 0, color: "#000", opacity:1, swap:false});
	$('.Slide_text').dropShadow({left: 1, top: 1, blur: 1, color: "#000", opacity:1, swap:false});
//	$('#nakratko_title').dropShadow({left: 1, top: 1, blur: 0, color: "#000", opacity:1, swap:false});
	
	var t=setTimeout("NextFeed()",4000);
//		NextFeed();
	
	$('.rounded_link').each(function() {
		var text = $(this).html();
		$(this).html('<div class="l_cor"></div><div class="c_cor">'+ text +'</div><div class="r_cor"></div>');
	});
});
$(function() {

		$("#kc").mouseenter(function() {
			$("#kc").css({"background-position":"center bottom"});
		}).mouseleave(function() {
			$("#kc").css({"background-position":"center top"});
		});


	$('.boxy').boxy();
	$('#Slider').mouseenter(function() { $('#nakratko1').fadeIn(200); }).mouseleave(function() { $('#nakratko1').fadeOut(200); });
	$('.menu_link').mouseenter(function() {
		$(this).parent().find(".menu_link_sides_l").css({"background":"url(http://sakarnews.info/images/menu_link_sides_l.png) bottom center no-repeat"}).animate({"height":"32px"},200);
		$(this).parent().find(".menu_link_sides_r").css({"background":"url(http://sakarnews.info/images/menu_link_sides_r.png) bottom center no-repeat"}).animate({"height":"32px"},200);

		$(this).css({"background":"#4e4e4e"});
/*
		$("<div>", {
			id: "foo",
			css: {
				height: "11px",
				background: "url(images/menu_arrow.png) center bottom no-repeat",
				clear: "both",
			}
		}).appendTo($(this).parent());
*/
	}).mouseleave(function() {
		$(this).parent().find(".menu_link_sides_l").css({"background":""}).animate({"height":"29px"},200);
		$(this).parent().find(".menu_link_sides_r").css({"background":""}).animate({"height":"29px"},200);

		$(this).parent().find("#foo").slideUp(0,
			function() { 
				$(this).remove(); 
		});	
		$(this).parent().find('div.menu_link').css({"background":""});
	});

// marquee

	$('#telegraph div.ScrollText').marquee('pointer').css({"height":"23px"}).mouseover(function () {
		$(this).trigger('stop');
		$(this).css({"cursor":"e-resize"})
	}).mouseout(function () {
		$(this).trigger('start');
	}).mousemove(function (event) {
		if ($(this).data('drag') == true) {
			this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
		}
	}).mousedown(function (event) {
		$(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
	}).mouseup(function () {
		$(this).data('drag', false);
	}).mouseenter(function() { $(this).css({"color":"black",'text-shadow':'0px 0px #000'}) 
	}).mouseleave(function() { $(this).css({"color":"white",'text-shadow':'0px 1px #888'}) });
	
	// slider
	
	$('.Slide_text').click(function() { var url = $(this).attr('id'); window.location=url; });
	
	$('#slider_feeds div').mouseenter(function() {
		
		$('div[class*="slider_feed_active"]').removeClass('slider_feed_active');
		
		$('div[id="Activ"]').removeAttr('id');
		$(this).attr({"id":"Activ"})
		
		var img = $(this).find('img').attr('src');
		var alt = $(this).find('img').attr('alt');
		var id  = $(this).find('img').attr('id');
		var name= $(this).find('img').attr('name');
		//alert(alt);
//		alert(img);
		$(this).addClass('slider_feed_active');
		//$('#slideFader').fadeIn(100,function() {
			$('#Slider').css({"background":"url("+img+") center top no-repeat"});
			$('.Slide_text').html(alt).attr({"id":id});
			$('#nakratko_text').html(name);
			$('#nakratko_link').attr({"href":id});
			//alert('dsa');
		//}).fadeOut('fast');	
	}).mouseleave(function() {
		$(this).removeClass('slider_feed_active');
	});
	$('#Slider').mouseenter(function() {
		$('#do_next').val('0');
	}).mouseleave(function() {
		$('#do_next').val('1');
	});
// red header
	$('#switch_city').mouseenter(function() {
		$('#other_cities').slideDown('fast',function() {
			$('#expand').val('1');
		});
	});
	$('#other_cities').mouseleave(function() {
		var expand = $('#expand').val();
		if(expand=='1')
		{
			$('#other_cities').slideUp('fast',function() {
				$('#expand').val('0');
			});
		}
	});
	$('.city').mouseenter(function() {
		$(this).css({'border-top':'1px solid #8b0e0e','border-bottom':'1px solid #8b0e0e','color':'#ffd3d3','background-color':'#780808','text-decoration':'underline'})
	}).mouseleave(function() {
		$(this).css({'border-top':'1px solid #5b0000','border-bottom':'1px solid #5b0000','color':'#ffd3d3','background-color':'','text-decoration':'none'})
	});
	
	$('#send').click(function() {
		
		var mail = $('#mail').val();

		 $.ajax({
		   type: "POST",
		   url: "index.php",
		   data: "mail="+mail,
		   success: function(msg){
			 $('#maillist').html('<div style="text-align:center; font-size:20px;">'+msg+'</div>');
		   }
		 });

	});

	$('.add_comment').click(function() {
		
		var comment_text = $('#comment_text').val();
		var comment_news_id = $('#comment_news_id').val();
		var comment_news_type = $('#comment_news_type').val();
		var comment_username = $('#comment_username').val();

		 $.ajax({
		   type: "POST",
		   url: "posting.php",
		   data: "mode="+comment_news_type+"&comment_text="+comment_text+"&comment_news_id="+comment_news_id+"&comment_username="+comment_username,
		   success: function(msg){
			$(msg).insertBefore('.comment:first').slideDown('slow');
			$("#comment_text").val('');
//			$("#comment_username").val('');
			Boxy.alert("Вашият коментар бе публикуван.", null, {title: 'Съобщение',closeText: '[ Затвори ]'});
		   }
		 });

	});
	
	$(".slides img").click(function() {
		var src = $(this).attr('src');
		new Boxy("<img src="+src+" style='margin:0; padding:0;'>", {title: "Снимка",fixed:false,modal:true,closeText:'[ Затвори ]'});
	});
	
	$('.vox_populi').mouseenter(function() {
		$(this).css({"background":"url(images/voice_item_h.png) top center no-repeat"});
		$(this).find('a').css({"color":"#485e0f","text-decoration":"underline"});
		$(this).find('img').css({"border":"1px solid #000"});
	}).mouseleave(function() {
		$(this).css({"background":"url(images/voice_item.png) top center no-repeat"});
		$(this).find('a').css({"color":"#485e0f","text-decoration":"none"});
		$(this).find('img').css({"border":"1px solid #7fa910"});
	});
	
	$('.rounded_link').mouseenter(function() {
		$(this).find('.l_cor').css({"background":"url(images/round_link_left_h.png) top center no-repeat"});									   
		$(this).find('.c_cor').css({"background":"#cbcbcb"});									   
		$(this).find('.r_cor').css({"background":"url(images/round_link_right_h.png) top center no-repeat"});									   
	}).mouseleave(function() {
		$(this).find('.l_cor').css({"background":"url(images/round_link_left.png) top center no-repeat"});									   
		$(this).find('.c_cor').css({"background":"#e1e1e1"});									   
		$(this).find('.r_cor').css({"background":"url(images/round_link_right.png) top center no-repeat"});									   
	});
	
	$('.poll_ans').mouseenter(function() {
		$(this).css({"color":"#62780d"});
	}).mouseleave(function() {
		$(this).css({"color":"#88a615"});
	});
	
	$('#poll_vote_button').mouseenter(function() {
		$(this).css({"background-position":"bottom"});
	}).mouseleave(function() {
		$(this).css({"background-position":"top"});
	}).click(function() {
		var checkedValue = $("#poll input[type='radio']:checked").val();
		if(!checkedValue)
		{
			alert('Изберете отговор.');
			return false;
		}
		else { 
			$.ajax({
				type: 'POST',
				url:'poll.php',
				data:'ans='+checkedValue,
				success: function(msg) {
					$("#poll_content").slideUp('slow',function() {
						$("#poll_content").html(msg).slideDown('slow');
					});
				}
			});
		}
	});
	
	
	$("#search_field").autocomplete({
		url: 'search.php',
		showResult: function(value, data) {
			return value;
		},
		useCache: false,
		sortFunction: function(a, b, filter) {
			var f = filter.toLowerCase();
			var fl = f.length;
			var a1 = a.value.toLowerCase().substring(0, fl) == f ? '0' : '1';
			var a1 = a1 + String(a.data[0]).toLowerCase();
			var b1 = b.value.toLowerCase().substring(0, fl) == f ? '0' : '1';
			var b1 = b1 + String(b.data[0]).toLowerCase();
			if (a1 < b1) {
				return 1;
			}
			if (a1 > b1) {
				return -1;
			}
			return 0;
		},
		minChars: 3,
		onItemSelect: function(item) {
			location.href=item.data;
//			alert(item.data);
//			var text = 'You selected <b>' + item.value + '</b>';
//			if (item.data.length) {
//				text += ' <i>' + item.data.join(', ') + '</i>';
//			}
//			$("#last_selected").html(text);
		}
	}).focus(function() {
		$("#search_field").val('').css({"color":"#333","font-style":"normal","font-weight":"normal","text-decoration":"none"});
	}).blur(function() {
		$("#search_field").val('търсиш ли новина?').css({"color":"#FF0000","font-style":"italic","font-weight":"bold","text-decoration":"underline"});
	});

	$(".reply_c").click(function(){
		this_id = $(this).attr('title');
		if(this_id==0) { alert('Само регистрираните потребители, могат да отговарят на коментари'); }
		else
		{
			$(this).css({"background":"url(images/reply_button_h.png) top center no-repeat"});
			$("#reply_div_"+this_id).slideDown('fast');
			$("#reply_name_"+this_id).slideDown('fast');
		}
	}).mouseenter(function() {
		$(this).css({"background-position":"bottom center"})
	}).mouseleave(function() {
		$(this).css({"background-position":"top center"})
	});
	
	$(".reply_submit").mouseover(function() {
		$(this).css({"background-position":"center bottom","cursor":"pointer"});
	}).mouseleave(function() {
		$(this).css({"background-position":"center top"});
	}).click(function() {
		this_id    = $(this).attr('title');
		this_reply = $("#cmnt_reply_text_"+this_id).val();
		this_user  = $("#cmnt_reply_name_"+this_id).val();
		
		if(this_user=='' || this_user.length<=5 || this_reply=='' || this_user.length<=6)
		{
			$("#reply_name_"+this_id).css({"background-position":"35px bottom","color":"#CC0000"});
			$("#cmnt_reply_name_error_"+this_id).fadeIn('fast');
		}
		else
		{
			if($("#table_replies_"+this_id).css('display')=='none')
			{
				$.ajax({
					url: 'posting.php',
					data: 'mode=sakar_news_reply&reply_id='+this_id+'&reply_user='+this_user+'&reply_text='+this_reply+"&is_first=true",
					type: 'POST',
					success: function(msg) 
						{
							$('div[title="'+this_id+'"]').css({"background":"url(images/reply_button.png) top center no-repeat"});
							$("#reply_div_"+this_id).slideUp('fast');
							$("#reply_name_"+this_id).slideUp('fast');
		
							$("#table_replies_"+this_id).slideDown('fast');
		
							splitted = msg.split("|");
//							alert(msg);
		
							$("#freply_avatar_"+this_id).html(splitted[0]);
							$("#freply_user_"+this_id).html(splitted[1]);
							$("#freply_date_"+this_id).html(splitted[2]);
							$("#freply_cmnt_"+this_id).html(splitted[3]);
						}
				});
			}
			else
			{
				$.ajax({
					url: 'posting.php',
					data: 'mode=sakar_news_reply&reply_id='+this_id+'&reply_user='+this_user+'&reply_text='+this_reply+"&is_first=false",
					type: 'POST',
					success: function(msg) 
						{
//							alert(msg);
							$('div[title="'+this_id+'"]').css({"background":"url(images/reply_button.png) top center no-repeat"});
							$("#reply_div_"+this_id).slideUp('fast');
							$("#reply_name_"+this_id).slideUp('fast');
		
							$(".tr_comment_"+this_id+":first").before(msg).slideDown('slow');
		
						}
				});
			}
		}
	});
	
	$("#nakratko1").click(function() {
		var the_link = $("#nakratko_link").attr("href");
		location.href = the_link;
	});
});

