$(document).ready(function(){
    //--------------------------------------------------------//
    //Scroll down news button
    //--------------------------------------------------------//
    if ($('.boundingbox')){
        $('#scrolldownNews').mousedown(function(){
//        	$('.boundingbox').scrollTop($('.boundingbox').scrollTop()+100);
        	$('.boundingbox').animate({scrollTop:$('.boundingbox').scrollTop()+200},700);
        	$('.news_cell').stop().animate({ backgroundColor: '#fff' },300);
        	newsOpen=false;
        	$('.news_cell').css('border-top','0');
        	$('.bigNewsBox').fadeOut();
        });
        $('#scrollupNews').mousedown(function(){
//        	$('.boundingbox').scrollTop($('.boundingbox').scrollTop()+100);
        	$('.boundingbox').animate({scrollTop:$('.boundingbox').scrollTop()-200},700);
        	$('.news_cell').stop().animate({ backgroundColor: '#fff' },300);
        	newsOpen=false;
        	$('.news_cell').css('border-top','0');
        	$('.bigNewsBox').fadeOut();
        });
    	$('.boundingbox').shadow();
    	$('.scrollbar_bottom').shadow();
    	$('.newstitle').shadow();
    	$('.bigNewsBox').shadow();
    }
    if ($('.bigNewsBox')){
    	$('.news_cell').mousedown(function(){
    			newsOpen=this.id;
    			$('.news_cell').stop().animate({ backgroundColor: "#fff" },200);
    			$(this).stop().animate({ backgroundColor: "#ddd" },300);
    			$('.boundingbox').css('border-bottom','1px solid #000');
    			$('.boundingbox').css('border-top','1px solid #000');
    			$('.news_cell').css('border-top','0');
    			$('.bigNewsBox').hide();
    			$('div#newsid'+this.id).fadeIn();
    			lft = $(this).offset().left+$(this).outerWidth();
    			tp = $(this).offset().top;
    			$('div#newsid'+this.id).css("left",lft );
    			if ((tp+$('div#newsid'+this.id).outerHeight(true))>$('body').outerHeight(true)){
    				//newtp = tp-((tp+$('div#newsid'+this.id).outerHeight(true))-$('body').outerHeight(true));
    				newtp = ($('.boundingbox').offset().top+$('.boundingbox').outerHeight())-$('div#newsid'+this.id).outerHeight(true);
    				$('.boundingbox').css('border-bottom','2px solid #000');
    				$('div#newsid'+this.id).css("top",newtp+1);
    			}else{
    				if(tp<$('.boundingbox').offset().top){
        				$('.boundingbox').css('border-top','2px solid #000');
    					$('div#newsid'+this.id).css("top",$('.boundingbox').offset().top);
    				}else{
    	    			$(this).css('border-top','2px solid #000');
    					$('div#newsid'+this.id).css("top",tp );
    				}
    			}
    		});
    	$('.news_cell').hover(
    			function(){
    				$(this).stop().animate({ backgroundColor: '#ddd' },300);
    			},
    			function(){
    				if (newsOpen!=this.id){
    					$(this).stop().animate({ backgroundColor: '#fff' },300);
    				}
    			}
    	)
    } //End of if ($('.bigNewsBox'))
});

function closeNews(lid){
	$('#newsid'+lid).fadeOut();
	$('.news_cell').stop().animate({ backgroundColor: '#fff' },300);
	newsOpen=false;
	$('.news_cell').css('border-top','0');
	$('.boundingbox').css('border-bottom','1px solid #000');
	$('.boundingbox').css('border-top','1px solid #000');
}

function showNews(lid,who){
	
	$('.bigNewsBox').hide();
	$('#newsid'+lid).fadeIn();
	$('div#newsid'+lid).attr("left", function (arr) {
        return who.offset().left;
    });
}

