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

function closethera(lid){
	$('#theraid'+lid).fadeOut();
	$('.thera_cell').stop().animate({ backgroundColor: '#fff' },300);
	theraOpen=false;
	$('.thera_cell').css('border-top','0');
	$('.boundingbox_thera').css('border-bottom','1px solid #000');
	$('.boundingbox_thera').css('border-top','1px solid #000');
}

function showthera(lid,who){
	
	$('.bigtheraBox').hide();
	$('#theraid'+lid).fadeIn();
	$('div#theraid'+lid).attr("left", function (arr) {
        return who.offset().left;
    });
}

