$(document).ready(function()	{

	
	//functions for showing/hiding mask
	function showMask(){
		$('#market_news_sidebar').expose({
			color : "#EEEBEB",
			onClose: 	function(event) {
								newsClose();
							}
		});
	};
	function hideMask(){
		$.mask.close();
	};
	

	
	
	
	//global var to store ID of opened article
	var opened_article;
	var is_opened = false;
		
	//dimensions for the articles
	var articleCSS = {
		'width': '720px',
		'margin-left': '-735px'
	};
	
	var market_article_close = {
		'width': '0px',
		'margin-left': '-15px',
		'border-style': 'none'
	}


	
	//Opens the clicked article
	function newsOpen(market_article){
		if(opened_article == market_article){
			newsClose();
		}else if(is_opened == true){
			
			$('.market_news_article').hide();
			$(market_article).fadeIn(); 
			showMask();
			opened_article = market_article;
			
		}else{
				$('.market_news_article').hide();
				$('#market_news_slide_out').animate(articleCSS, 400);
				$('#market_news_slide_out').css('border-style','solid');
				setTimeout(function() { 
					$(market_article).fadeIn(); 
				},400);
				showMask();
				opened_article = market_article;
				is_opened = true;
				
				setTimeout(function() { 
					$('#market_news_slide_out').css('border-style','solid');
				},400);
		}
	}
	
	function newsClose(){
			if($('#market_news_slide_out').css('width')!= '0px'){
				$('.market_news_article').hide();
				
				//different actions based on user agent (browser)
				if ($.browser.msie){
					$('#market_news_slide_out').css(market_article_close);
				}else {
					$('#market_news_slide_out').animate(market_article_close, 400);
				}
				
				setTimeout(function() { 
					$('#market_news_slide_out').css('border-style','none'); 
				},400);
				opened_article = "";
				is_opened = "false";
				hideMask();
				
				//repeat hide to make sure double articles aren't shown, and masking remnants aren't shown
				setTimeout(function() { 
					$('.market_news_article').hide();
				},400);
			}
			
			

	}
	
	
	$('#market_article_link_01').click(function()	{
		newsOpen('#market_article_01');
		
	});
	
	$('#market_article_link_02').click(function()	{
		newsOpen('#market_article_02');	
	});
	
	$('#market_article_link_03').click(function()	{
		newsOpen('#market_article_03');	
	});
	
	
	

	
});
