// JavaScript Document

var newsPageURL = "http://www.mcginley.co.uk/p/h/Home/McGinley_News/4/?lang=";
//var newsPageURL = "page.htm?cpi_id=4";

var initHomepage = function(local) {
	
	if(local == true)
	{
		var reader = new RSSReader({className: "rssWrapper", xmlPath: "rss.xml", scrollbar: true, thumbMaxHeight: 80, scrollbarWidth: 14, titleLength: 42, truncationDots: true});
		
		$("#searchButton").click(function(event){
			event.preventDefault();
			$("#searchText").val($("#keywordInput").val() + " " + $("#location").val() + " " + $("#sector").val());
			$('#searchform').submit();
		});
	}
	
	var slideScroll1 = new slideScroll({divID: "scroll1"});
	
	
	var mainGallery = new Gallery({wrapper: "galleryWrapper", xmlPath: "storage/xml/slideshow-1.xml", layout: "arrowsOnly", imagesClickable: false, transition: "fade", fadeButtons: true, pauseOnHover: true, slideInterval: 3500 });
	
	$(".scrollBtnLeft").click(function(event){
		event.preventDefault();
		$(".marketsMover").stop().animate(
				{marginLeft:  '0px'},
				{duration: 300,
				easing: 'easeOutExpo'});
	});
	
	$('.newsReportsContent').load(newsPageURL + ' #newsItems', function() {
		newsLoadComplete();
	});

}

var getMoreInfo = function(i) {
	
	$(".moreInfoBox").css({'display' : 'none'});
	$("#moreInfo"+i).css({'display' : 'inline'});
	
	$(".marketsMover").stop().animate(
			{marginLeft:  '-310px'},
			{duration: 300,
			easing: 'easeOutExpo'});
}

var newsLoadComplete = function()
{
	var html = $('.newsReportsContent').html();
	html = html.split(/\<hr\>/i);
	var newHTML = '<div id="newsItems">';
	var i = 0;
	for(i = 0; i < html.length; i++)
	{
		newHTML += '<p>';
		var newText = html[i];
		newText = newText.replace("<div id=\"newsItems\">", "");
		newText = newText.replace(/\<p\>/i, "");
		newText = newText.split(". ");
		newText = newText[0];
		newText = newText.split(".<");
		newText = newText[0];
		newText = newText.split(" <");
		newText = newText[0];
		newText += '...';
		newText += '<a href="'+newsPageURL+'#newsItem'+i+'">more</a>';
		newHTML += newText;
		newHTML += '</p>';
		newHTML += '<hr>';
	}
	
	newHTML += '</div>';
	
	$('.newsReportsContent').html(newHTML)
	
	var slideScroll2 = new slideScroll({divID: "scroll2"});
}
