function write_text(text, id)
{
	var value = $("#"+id).val();
	if(value == "")
		$("#"+id).val(text);
}

function clear_text(text, id)
{
	var value = $("#"+id).val();
	if(value == text)
		$("#"+id).val("");
}

function mySlideToggle(id){
	$("#"+id).slideToggle();
	
	
}
function mySlideToggleMenu(id, idm, cl, selected_class){
	$("#"+id).slideToggle('slow',function() {
		if($("#"+id).css("display") == "block")
		{
			$("#"+idm).removeClass();
			$("#"+idm).addClass(selected_class);		
		}
		else
		{
			$("#"+idm).removeClass();
			$("#"+idm).addClass(cl);		
		}	
	 });
}

function show_hide(id){	
	if(document.getElementById(id).style.display=='none') {
		document.getElementById(id).style.display='block';			
	} else {
		document.getElementById(id).style.display='none';
	}				
}


var timer;
function ajax_pic(id, clicking, lng)
{
	var count_pic = $("#count_pic").val();
	if(count_pic == 0)
		return;
	if(clicking == 1)
		clearTimeout(timer);
	
	var str = "id="+id+"&lng="+lng;
	$.getJSON("./ajax/ajax_pic.php", str, function(json){		
		if (json.error != "ERROR") {
				var name 		= json.news_pic;
				var title_news  = json.news_title;
				var news_id  	= json.news_id;
				var a_title     = '<a href="'+lng+'/'+news_id+'/1/news.more.html" class="news_a_tej">'+title_news+'</a>';
				var text = "./up/news/hot/"+name;
				
				$("#curent_pic").animate({ opacity: 'hide'}, "fast","", function(){
						$("#curent_pic").attr("src", text);
						$("#news_tej_title").html(a_title);
						$("#curent_pic").animate({ opacity: 'show'}, "fast","", function(){
								if(count_pic == 1)
									return;
								var number = $("#a_pic_"+id).attr("number");
								if(count_pic == number)
									number = 1;
								else
									number++;
								var obj_a = $('a[number="'+number+'"]');
								
								var id_next = obj_a[0].id;
								var mas = id_next.split('a_pic_');
								id_next = mas[1];
								timer = setTimeout("ajax_pic('"+id_next+"', '0', '"+lng+"')",10000);
						});
				});
				
				var a_pic = $('a[id^="a_pic_"]');
				for(i=0; i<a_pic.length; i++)
				{
					curent_id = a_pic[i].id;
					var a_obj = $("#"+curent_id);
					if(a_obj.hasClass("round_news_selected"))
					{
						a_obj.removeClass("round_news_selected");
						a_obj.addClass("round_news");
					}
				}
				$("#a_pic_"+id).removeClass("paging_a");
				$("#a_pic_"+id).addClass("round_news_selected");
			}
	});	
	
	/*
	$.ajax({
		url: "./ajax/ajax_pic.php",
		data: "id="+id,
		type: "POST",
		cache: false,
		success: function(result){
			if (result != "ERROR") {
				var name = result;
				var text = "./up/news/hot/"+name;
				
				$("#curent_pic").animate({ opacity: 'hide'}, "fast","", function(){
						$("#curent_pic").attr("src", text);
						$("#curent_pic").animate({ opacity: 'show'}, "fast","", function(){
								if(count_pic == 1)
									return;
								var number = $("#a_pic_"+id).attr("number");
								if(count_pic == number)
									number = 1;
								else
									number++;
								var obj_a = $('a[number="'+number+'"]');
								
								var id_next = obj_a[0].id;
								var mas = id_next.split('a_pic_');
								id_next = mas[1];
								timer = setTimeout("ajax_pic('"+id_next+"', '0', '"+lng+"')",10000);
						});
				});
				
				var a_pic = $('a[id^="a_pic_"]');
				for(i=0; i<a_pic.length; i++)
				{
					curent_id = a_pic[i].id;
					var a_obj = $("#"+curent_id);
					if(a_obj.hasClass("round_news_selected"))
					{
						a_obj.removeClass("round_news_selected");
						a_obj.addClass("round_news");
					}
				}
				$("#a_pic_"+id).removeClass("paging_a");
				$("#a_pic_"+id).addClass("round_news_selected");
			}
		}
	});
	*/
}

$("document").ready(function(){
	var lng = $("#tej_news_lng").val();
	var obj_a = $('a[number="1"]');
	if(obj_a.length > 0)
	{
		var id_next = obj_a[0].id;
		var mas = id_next.split('a_pic_');
		id_next = mas[1];
		ajax_pic(id_next, '0', lng);
	}
});

