var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline=0;
var headlines = new Array(); // an array of jQuery objects
npDivIndex =0;
function slideMeUp(what, bywhat){
		npDivIndex++;
		if(npDivIndex > 3){
			$nDiv = $("#"+bywhat+"1").html()
			npDivIndex = 1;
		}else{
			$nDiv = $("#"+bywhat+npDivIndex).html();
		}
		$("#"+what).html($nDiv);
		return false;
}

function slideMeDown(what, bywhat){
		npDivIndex--;
		if(npDivIndex <= 0){
			$pDiv = $("#"+bywhat+"3").html()
			npDivIndex = 3;
		}else{
			$pDiv = $("#"+bywhat+npDivIndex).html();
		}
		$("#"+what).html($pDiv);
		return false;
}

$(document).ready(function(){
	// more
	$(".more").bind('mouseover', function(){
	try{
		clearTimeout(showTime);
	}catch (e){
	}
		$("#menu").show();
	});

	$(".more").bind('mouseout', function(){
		showTime = setTimeout('$("#menu").hide();',500);
	});

	$("#menu").bind('mouseover', function(){
		clearTimeout(showTime);
		$("#menu").fadeIn();
	});

	$("#menu").bind('mouseout', function(){
		showTime = setTimeout('$("#menu").hide();',500);
	});


	// control news
	index = 0;

	x = setInterval(swapNews, 8500);

	$(".nLink").bind('click', function(){
		$(".news-post").html($(".n" + this.id).html());
		clearInterval(x);
		return false;
	});


	// control headlines


	headline_count = $("div.headline").size();

	for (var i = 0; i < headline_count; i++) {
	 headlines[i] = $("div.headline:eq("+i+")");
	}

	headlines[current_headline].css('top', '5px');

	headline_interval = setInterval(headline_rotate,4000);
	$('#scrollup').hover(function() {
	 clearInterval(headline_interval);
	}, function() {
	 headline_interval = setInterval(headline_rotate,4000);
	 headline_rotate();
	});


	$("#upNews").click(function() {
									 clearInterval(headline_interval);
									 slideUpNews();
									 return false;
								 });
	$("#downNews").click(function() {
									 clearInterval(headline_interval);
									 slideDownNews();
									 return false;
								 });


}); // EO $()

function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count;
  headlines[old_headline].animate({top: -33},"slow", function() {
    $(this).css('top', '38px');
    });
  headlines[current_headline].show().animate({top: 5},"slow");
  old_headline = current_headline;
}

function slideUpNews(){
	headline_rotate();
}

function slideDownNews(){
	if (old_headline == 0) {
		current_headline = headline_count - 1;
	} else {
		current_headline = (old_headline - 1) % headline_count;
	}
  headlines[old_headline].animate({top: 33},"slow", function() {
    $(this).css('top', '38px');
    });
  headlines[current_headline].css('top', '-33px');
  headlines[current_headline].show().animate({top: 5},"slow");
  old_headline = current_headline;
}

function switchTab(container, id){
	$("#"+container).html($("#b"+id).html());
	return false;
}

function swapNews(){
	index++;
	if(index <= 5){
		$(".news-post").html($(".n"+index).html());
	}else{
		index = 1;
		$(".news-post").html($(".n"+index).html());
	}

}

<!-- Begin
 
function OpenVoteUrl(url, type)
{
 
	if (type == 0)
	{
		if (document.all.Answer.value > 0) 	// Anser is run time control
		{
		
			url = url + "&voteSelect=" + document.all.Answer.value;
			var coll = document.all.item("voteSelect");
			if (coll)
			{
				for (var i=0; i<coll.length; i++)
				{
					coll(i).checked = false;
					coll(i).disabled = true;
				}
			}
			//var votePartLink = document.all.item("votePart");
			//if (votePartLink)
			//	votePartLink.removeAttribute("href");
			document.all.Answer.value = 0;
			window.open(url,"","height=401,width=500,left=200,top=2,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");	
		
		}
	}
	else
		window.open(url,"","height=401,width=500,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");	
}
 
// End -->
function voted()
{
    
        alert("لقد قمت بالتصويت علي هذا الموضوع من قبل"); 
        
        return false;
    }

function SearchValidation()
{
Search1=document.form2.Search1.value;
if((Search1==null || Search1=="" || Search1=="بحث"))
{
	alert("ادخل كلمة للبحث");
	document.form2.Search1.focus();
	return false;
}
 
return true;
 
}
