$(document).ready(function(){

	   $(".boxcbtn").click(function(){
			var btn=$(this);
			var boxtop=$(this).parent(".boxtop");
			//var box=boxtop.parent(".box");
			var cont=boxtop.siblings("#boxcont");
			if(cont.css("display")!="none"){
				cont.hide(300);
				btn.css("background-position","bottom");
			} else
			{cont.show(300);
			btn.css("background-position","top");
			}
			//box.hide(300);
			});
	   $("#nav ul li").hover(function(){$(this).children("ul").slideDown(100);},
								function(){$(this).children("ul").fadeOut(100);});
	   
	   $(".boxbtmres").click(function(){
			var cont=$(this).siblings("#boxcont");
			cont.height(cont.height()+20);
			
			});
		
		foo = function (){alert('Bar');}
		
		/////////////////////
		refcmnts =function (pg){
			$('#shbAjax').css("display","block");
			$.ajax({
			  url: 'shoutbox/commentsnew2.php',
			  type: 'POST',
			  data: 'pg='+pg,
			  success: function(data) {
				$('#shbCont').html(data);
				$('#shbAjax').css("display","none");
				//rrwscr();
				$('#shbCont').jScrollPane({showArrows:true});
			  }
			});
		}
		
		postcmnt =function(){
			$('#shbAjax').css("display","block");
			var postdata= $('#shbfrm').serialize();
			$.ajax({
			  url: 'shoutbox/commentsnew2.php',
			  type: 'POST',
			  data: (postdata),
			  success: function(data) {
				$('#shbCont').html(data);
				$('#shbAjax').css("display","none");
				$('#bubcmnt').hide(300);
				$('.inpf').val(''); 
				rrwscr();
			  }
			});
		}

		
		cmntbbl = function(){
			var elem= $("#bubcmnt");
			elem.css("visibility","visible");
			var h=elem.height();
			elem.css("top","-"+h+"px");
			elem.show(300);
		}
		cmntbblX = function(){
			//$("#bubcmnt").css("visibility","hidden");
			$("#bubcmnt").hide(300);
		}
		
		rrwscr = function(){

				var dragbar=$("#shbScroll");
				var content=$("#shbCont");
				var dispbox=$("#shbDisp");
				
				var contH=content.height();
				var dispH=dispbox.height();
				var prop=dispH/contH;
				scrollh=dispH*prop;
				if(scrollh>dispH) scrollh=dispH;
				dragbar.css("height",scrollh+"px");
				dragbar.css("marginTop",'0px');
				content.css("marginTop",'0px');

			}
		ExtractNumber=function(value){var n = parseInt(value);return n == null || isNaN(n) ? 0 : n;}
		
		///////////////////////////////////////////
		
		var oldY = 0;
		


		$("#shbScroll").mousedown(function(e){
			oldY=e.clientY;
				
				$(document).mousemove(function(e){
				
				var diff=oldY-e.clientY;
				oldY=e.clientY;
				var cMarg=parseInt($(this).css("marginTop"));
				cMarg-=diff;
				
				if(cMarg<0) cMarg=0;
				if($(this).height()<$("#shbDisp").height()){
					var minbtm=($("#shbDisp").height()-$(this).height());
					if(cMarg>minbtm) cMarg=minbtm;
					}else cMarg=0;
				$(this).css("marginTop",cMarg+"px");
				doScroll();
				return false;
				});
		});
		
		doScroll = function(){

	var cont=$('#shbCont');
	var dragbar=$('#shbScroll');
	var dispbox=$('#shbDisp');
	
	var prop=(cont.height()-dispbox.height())/(dispbox.height()-dragbar.height());
	var dbmt=parseInt(dragbar.css("marginTop"));
	var hh=dbmt*prop;


	
	cont.css("marginTop" , -1*(hh)+'px');

		}

	   refcmnts(0);

     });


