//--------------------------------------------------------------------------------------
// JQUERY
var top_id_tmp;
var bot_id_tmp;

$(document).ready(function() {

	loadNews('one_hl','pages/home/top_headline_1.php','pages/home/bottom_headlines.php');
	top_id_tmp ="";
	bot_id_tmp="";
	
});

function activateMenu(menu_id){
	var str_menu_id = "#" + menu_id;
	$("div.a_menu_item").css({backgroundImage:"none"});
	$(str_menu_id).css({backgroundImage:"url(images/menu_highlight.png)"});
	
}

function loadAll(menu_id, top_id, bot_id){
	activateMenu(menu_id);
	loadTop(top_id);
	loadBottom(bot_id);
	top_id_tmp = "";
	bot_id_tmp = "";
}

function activateStory (story_id, top_id){
	loadTop(top_id);
	var str_story_id = "#" + story_id;
	$("div.a_story_link").css({color:''});
	$(str_story_id).css({color:"#FFFFFF"});
	top_id_tmp = str_story_id;
	setImgLow();
	bot_id_tmp = str_story_id + "_img";
	setImgHigh();
}

//change img src value to low
function setImgLow(){
	try{
		var low = $(bot_id_tmp).attr("src").replace(/_high.jpg/,".jpg");
		$(bot_id_tmp).attr("src",low);
	}
	catch(e){}

}

//change img src value to high
function setImgHigh(){
	try{
		if ($(bot_id_tmp).attr("src").indexOf("_high.jpg") == -1) {
			var high = $(bot_id_tmp).attr("src").replace(/.jpg/,"_high.jpg");
			$(bot_id_tmp).attr("src",high);
		}
	}
	catch(e){}
}

//rollover img to high
function swapHigh(img_id){
	var str_img_id = "#" + img_id;
	if (str_img_id != bot_id_tmp){
		//set high img
		var high = $(str_img_id).attr("src").replace(/.jpg/,"_high.jpg");
		$(str_img_id).attr("src",high);
	}

}

//rollover img to low
function swapLow(img_id){
	var str_img_id = "#" + img_id;
	if (str_img_id != bot_id_tmp){
		var low = $(str_img_id).attr("src").replace(/_high.jpg/,".jpg");
		$(str_img_id).attr("src",low);
	}
}


//--------------------------------------------------------------------------------------
// Ajax 
var xmlhttptop;
var xmlhttpbot;


function loadTop(url){
	var RandUrl;
	RandUrl = url + "?&id=" + Math.floor(Math.random()*10000);
	xmlhttptop=null;

	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttptop=new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		// code for IE6, IE5
		xmlhttptop=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttptop!=null){
		xmlhttptop.onreadystatechange = function(){
			if (xmlhttptop.readyState==4){	
				if (xmlhttptop.status==200){
					document.getElementById('ajax_top').innerHTML=xmlhttptop.responseText;
				}
				else{
					//alert("Problem retrieving data:" + xmlhttptop.statusText);
				}
			}	  
		};
		xmlhttptop.open("GET",RandUrl,true);
		xmlhttptop.send(null);
	}
	else{
		//alert("Your browser does not support XMLHTTP!");
	}
}

function loadBottom(url){
	var RandUrl;
	RandUrl = url + "?&id=" + Math.floor(Math.random()*10000);
	xmlhttpbot=null;

	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttpbot=new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		// code for IE6, IE5
		xmlhttpbot=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttpbot!=null){
		xmlhttpbot.onreadystatechange = function(){
			if (xmlhttpbot.readyState==4){	
				if (xmlhttpbot.status==200){
					document.getElementById('ajax_bottom').innerHTML=xmlhttpbot.responseText;
					$(top_id_tmp).css({color:"#FFFFFF"});
				}
				else{
					//alert("Problem retrieving data:" + xmlhttpbot.statusText);
				}
			}	  
		};
		xmlhttpbot.open("GET",RandUrl,true);
		xmlhttpbot.send(null);
	}
	else{
		//alert("Your browser does not support XMLHTTP!");
	}
}

function loadNews(story_id, top_id, bot_id){
	var RandUrl;
	RandUrl = bot_id + "?&id=" + Math.floor(Math.random()*10000);
	xmlhttpbot=null;

	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttpbot=new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		// code for IE6, IE5
		xmlhttpbot=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttpbot!=null){
		xmlhttpbot.onreadystatechange = function(){
			if (xmlhttpbot.readyState==4){	
				if (xmlhttpbot.status==200){
					document.getElementById('ajax_bottom').innerHTML=xmlhttpbot.responseText;
					activateStory(story_id, top_id);
				}
				else{
					//alert("Problem retrieving data:" + xmlhttpbot.statusText);
				}
			}	  
		};
		xmlhttpbot.open("GET",RandUrl,true);
		xmlhttpbot.send(null);
	}
	else{
		//alert("Your browser does not support XMLHTTP!");
	}
}