

// Author: Kris Purdy
// Date: 03/04/2007

//======================================================================
function getAbsLeft(a_Element) {
//pre: any HTML object in a page.
//pst: the absolute left position relative to the top left of the page.
	var l_Left = 0;
	var l_Ele = a_Element;
  while (l_Ele) {
  	l_Left += l_Ele.offsetLeft;
  	l_Ele = l_Ele.offsetParent;
  }
	return l_Left;
}

//======================================================================
function getAbsTop(a_Element) {
//pre: any HTML object in a page.
//pst: the absolute top position relative to the top left of the page.
	var l_Top = 0;
	var l_El = null;
	for (l_El = a_Element; l_El; l_El = l_El.offsetParent) {
	  l_Top += l_El.offsetTop;
	}
	for (l_El = a_Element.parentNode; l_El && 
	    l_El != document.body; l_El = l_El.parentNode) {
	  if (l_El.scrollTop) {
	    l_Top -= l_El.scrollTop;
	  }
	}
	return l_Top;
}

//======================================================================
function selectTextOnClick(a_Elem) {
//pre: any HTML input DOM object in a page.
//pst: the text selected in the DOM object.
    a_Elem.select();
}



function assignHoverEvents () {
  $(".hoverLink").hover(
    function(e) {
      var l_LinkHeight = $(this).children("A").get(0).scrollHeight;
      $(this).children(".hoverTip").get(0).style.left = getAbsLeft(this) 
        + "px";
      $(this).children(".hoverTip").get(0).style.top = (getAbsTop(this)
        + l_LinkHeight) + "px";
      $(this).children(".hoverTip").fadeIn("medium");
    }, 
    function(e) {
      $(this).children(".hoverTip").fadeOut("fast");
    }
  ); 
}




	

var eek;

function ticknews() {
    $("#ticker li:eq("+curritem+")").fadeOut("slow",function() {
    	$("#ticker li:eq("+curritem+")").css({marginLeft: 500});
  		curritem = ++curritem%newsitems;
    	$("#ticker li:eq("+curritem+")").animate({ opacity: 0.99, marginLeft: 0 }, 1000);  
    });
   

}



function loadFeed() {
    $.ajax({
        type: "GET",
        url: "/en/1/rssfeeder.qxml?feed=http://www.thisislondon.co.uk/newsheadlines/rss-clean/",
        dataType: "xml",
        success: function(rss) {
eek=rss;
            strRSS = "<ul id='ticker'>";
            $("/channel/item/title",rss).each(function(i) {
                strRSS += "<li ><a href='";
                strRSS += $("/channel/item/link:eq(" + i + ")",rss).text().substring(0,200);
                strRSS += "'>";
                strRSS += $(this).text();
                strRSS += "</a></li>";
            });
            strRSS+="</ul>";
            $("#news_feed").html(strRSS);


			//$("#feed_me ul li").hide();
			newsitems = $("#ticker li").hide().size();

   			ticknews();
   			setInterval(ticknews,5000); //time in milliseconds

        }
    });
}

