jQuery(document).ready(function(){

inside_tabContent_items = jQuery('#inside .tabContent > div');
jQuery('div#inside ul.tabControls a:first').addClass('selected');

jQuery('div#inside ul.tabControls > li > a').click(function(event) {
	event.preventDefault();
	targetDiv = jQuery(this).attr('href');
	jQuery('div#inside ul.tabControls a').removeClass('selected');
	inside_tabContent_items.hide();
	jQuery(targetDiv).show(150);
	jQuery(this).addClass('selected');
});

financials_tabContents = jQuery('#financials .content > div');

jQuery('div#financials ul.controls > li > a').click(function(event) {
	event.preventDefault();
	targetDiv = jQuery(this).attr('href');
	jQuery('div#financials ul.controls a').removeClass('selected');
	financials_tabContents.hide(100);
	jQuery(targetDiv).show(150);
	jQuery(this).addClass('selected');
});



/* Top Story Magic*/
		var top_stories = jQuery("ul#top_stories > li");
		var storyItem = 0;
		
		function storyChange( index ) {
			jQuery("#headline_wrapper").fadeOut(150, function(){
				//jQuery("#top_stories > li").removeClass("currentStory");
				jQuery("#top_story_"+storyItem).removeClass("currentStory");
				jQuery("#panel_link_"+storyItem).removeClass("selected");
			});
			jQuery("#headline_wrapper").fadeIn(150, function(){
				jQuery("#top_story_"+index).addClass("currentStory");
				jQuery("#panel_link_"+index).addClass("selected");
				storyItem = index;
			});
		}
		function storyNext() {
			var index = (storyItem+1 < top_stories.length) ? storyItem+1 : 0;
			storyChange( index );
		}
		function storyPrev() {
			var index = (storyItem-1 >= 0) ? storyItem-1 : top_stories.length-1;
			storyChange( index );
		}
		jQuery("#prevStory").click( function(event) {
			event.preventDefault();
			storyPrev();
			return false;
		});
		jQuery("#nextStory").click( function(event) {
			event.preventDefault();
			storyNext();
			return false;
		});
		jQuery(".headline_pane_link").click( function(event) {
			event.preventDefault();
			var value = jQuery(this).text();
			index = value-1;
			storyChange(index);
			return false;
		});
		
		var other_top_stories = jQuery("ul#other_top_stories_list > li");
		var otherStoryItem = 0;
		
		function otherStoryChange( otherIndex ) {
			jQuery("#other_headline_wrapper").fadeOut(150, function(){
				jQuery("#other_top_story_"+otherStoryItem).removeClass("currentStory");
				jQuery("#other_top_story_link_"+otherStoryItem).removeClass("selected");
			});
			jQuery("#other_headline_wrapper").fadeIn(150, function(){
				jQuery("#other_top_story_"+otherIndex).addClass("currentStory");
				jQuery("#other_top_story_link_"+otherIndex).addClass("selected");
				otherStoryItem = otherIndex;
			});
		};
		function otherStoryPrev() {
			var otherIndex = (otherStoryItem-1 >= 0) ? otherStoryItem-1 : other_top_stories.length-1;
			otherStoryChange( otherIndex );
		};
		
		jQuery(".other_top_stories_control").click( function(event) {
			event.preventDefault();
			var value = jQuery(this).attr('id').replace(/(other_top_story_link_)([0-9]+)/i,'$2');
			otherStoryChange( value );
			return false;
		});
/* End Top Story Magic */


/* RSS Feed Function for Weather feeds from Yahoo */
	function get_weather_feed($location) {
	var fadetime = 1000;
		//clear the content in the div for the next feed.
		jQuery("#wDetails").fadeOut(fadetime/2);
		jQuery("#wDetails").empty();
		var locationURL = 'http://www.theghanaianjournal.com/data/proxy.php?url=http://www.theghanaianjournal.com/data/weather_' + $location +'.xml';
		//use the JQuery get to grab the URL from the selected item, put the results in 
		//to an argument for parsing in the inline function called when the feed retrieval 
		//is complete $.get('proxy.php?url='+jQuery('#diffFeeds').val(), function(d) {
		jQuery.get(locationURL, function(d) {
			//find each 'item' in the file and parse it
			jQuery(d).find('item').each(function() {
				//name the current found item this for this particular loop run
				var $item = jQuery(this);
				var utitle = $item.find('title').text();
				var link = $item.find('link').text();
				var forecast = $item.find('yweather\\:condition').attr('text');
				var temp = $item.find('yweather\\:condition').attr('temp');
				var code = $item.find('yweather\\:condition').attr('code');
				var regexp = /^(Conditions for )(.*)(\,.*GMT$)/i;
				var title = utitle.replace(regexp,'$2');
				// now create a var 'html' to store the markup we're using to output the feed to the browser window
				var html = "<span><img class=\'weathericon\' height=\'48\' width=\'48\'src=\'http://www.theghanaianjournal.com/data/icons/" + code + ".gif\'><\/span><span class=\"weatherforecast\">" + temp + "&deg;C \(" + forecast + "\)<\/span><br \/><span class=\'weathertitle\'>" + title + " <small style=\"margin-left: 5px;font-size:0.9em;\"><a href=\"http://weather.yahoo.com/Ghana/GHXX/regional.html\">&raquo; More...<\/a><\/small><\/span>";
				//put that feed content on the screen!
				jQuery('#wDetails').append(html);
				jQuery("#wDetails").fadeIn(fadetime);
			});
				
		});
	};
	//Call the function
	get_weather_feed('accra');

	jQuery("li.wLocation > a").click(function(event){
		event.preventDefault();
		var linktext = jQuery(this).text().toLowerCase();
		jQuery("li.wLocation").find("a").removeClass('bold');
		jQuery(this).addClass('bold');
		get_weather_feed(linktext);
	   });

/* END RSS Feed Function */


//Don't show border when hovering over links enclosing images
	jQuery("a:has(img)").hover( function (){
		jQuery(this).css("border", "none");
	},
	function(){
		jQuery(this).css("border", "none");
	});
// End


// Nav menu magic
$(" #nav-menu li").hover(function(){
    $(this).find('ul:first').css({visibility: "visible",display:"none"}).show(150);
	},function(){
    $(this).find('ul:first').css({visibility: "hidden"});
	});


// End

});
