$(document).ready(function(){
	
	
	
	
	
	
	
	
	//community button work
	
	$("#minibuttons a").each(function(){
		
		
	if($(this).find("img").attr("alt")!=$("#theactivecom").attr("alt")){
		
		
	$(this).hover(
	function(){
		
		$(this).find("img").attr("src","/imagesNS/commleftbar/"+$(this).find("img").attr("alt")+".png");
		
	},
	function(){
		
		$(this).find("img").attr("src","/imagesNS/commleftbar/"+$(this).find("img").attr("alt")+"_g.png");
		
	});	
		
		
		
		
		
		
		
	}
		
		
		
		
		
		
		
		
		
	});
	
	// end of communnity button stuff
	
	
	
	
	
	//$(".inditab").css("width",$(".tabshower").width()+"px");
	

	
	
	
	$("#blkshader").css("opacity",".5");
	
	if ($(".tabbuttons a").length>0){
		
		tabdoer(0);
		
	}
	
	
	
	$(".tabbuttons a").click(function(){
		
		tabdoer($(this).index(".tabbuttons a"));
		
	
		
		
	});
	
	
	
	function tabdoer(whichtab){
		//alert(whichtab);
		$(".tabbuttons a").css("background-color","#eee");
		$(".tabbuttons a").eq(whichtab).css("background-color","#fff");
		$(".inditab").css("top","-2500px");
		$(".tabloader").css("top","200px");
		$(".tabloader").animate({"top":"200px"},{queue:false, duration:1000,complete:function(){
			
			tabdoer2(whichtab);
		}});
	
	}
	
	
	function tabdoer2(whichtab){
		
		$(".tabloader").css("top","-2500px");
		$(".inditab").css("top","-2500px");
		
		$(".tabshower").css("height",($(".inditab").eq(whichtab).height()+40)+"px");
		
		$(".inditab").eq(whichtab).css("top","0px");
	
	}
	
	
	
	
	//showtheshow($("#leftbuttons h1 a").eq(0).attr("alt"));
	
	
	//poppers stuff
	
	$(".poppers").each(function(){
		
		$(this).css("width",$(this).find("img").width()+"px");
		
		
	});
	
	slideribbon();
	function rollin(){
		$("#theribbon").animate({"left":"102px"},{queue:false, duration:750, easing:"easeOutBounce",complete:slideribbon});
	}
	
	$("#theribbon").hover(function(){
		$(this).stop().animate({"left":"10px"},{queue:false, duration:300});
		
	}, function(){
		
		rollin();
	});
	
	function slideribbon(){
		var randomnumber=Math.floor(Math.random()*4);
		
		
		if(randomnumber==2){
			howfast=250;
		}
		//alert ($("#theribbon").position().left);
		if($("#theribbon")){
		
		if($("#theribbon").position().left<100){
			
			endpoint=102;
		} else {
			
			var randomnumber=Math.floor(Math.random()*8);
		
		
		
		endpoint=$("#theribbon").position().left;
		
		if(randomnumber==2){
			endpoint=98;
		}
			
			
			
			
		}
		
		
		
		
		
		$("#theribbon").animate({"left":endpoint+"px"},{queue:false, duration:250, complete:slideribbon});
		
		
		}
		
		
		
		
	}//end of slideribbon
	
	
	
	
	
	
	$('.poppers').live('click', function() {


popstart($(this).attr("title"));


});

$('.closer').live('click', function() {

//alert("what");

$(".screener").remove();
$(".screenholder").remove();


});
	
	
	
	
	
	
	
	
	
	
	
	function popstart(whatpop){
		$("body").append("<div class='screener' style='width:"+$(window).width()+"px;height:"+$(document).height()+"px'/>");
		$(".screener").css("opacity",0);
		//starttop=$(window).scrollTop()*1;
		//alert("here troy"+(starttop+125));
		$("body").append("<div class='screenholder'style='width:"+$(window).width()+"px;height:"+$(window).height()+"px;top:"+($(window).scrollTop()+125)+"px'/>");
		$(".screenholder").append("<div class='screenitem'><span class='widthgetter'></span></div>");
		$(".screenitem").css("opacity",0);
		
		$(".widthgetter").append("<img src='"+whatpop+"'\>");
		if($(".widthgetter").width()<1){
			$(".widthgetter").css("width","980px");
		}
		//alert($(".widthgetter").width());
		adjustpos=($(window).width()/2) - ($(".widthgetter").width()/2);
		$(".screenitem").css("left",adjustpos+"px");
		$(".screenitem").append("<a href='Javascript:;' class='closer'><img src='/imagesNS/closesquare.jpg' border='0'></a>");
		$(".closer").css("left",$(".widthgetter").width()-27+"px");
		passpop=whatpop;
		$(".screener").animate({"opacity":.8},{queue:false, duration:1000, complete:function(){
			adjustpos=($(window).width()/2) - ($(".widthgetter").width()/2);
		$(".screenitem").css("left",adjustpos+"px");
		$(".closer").css("left",$(".widthgetter").width()-27+"px");
			
			
			$(".screenitem").animate({"opacity":1},{queue:false, duration:1000});
			//popme(passpop);
		}});
		
	}
	
	
	
	
	
	
	
	
	
	function popme(whatpop){
		
		
		
		
		
		//alert($("screenitem").css("left"));
		//alert($(".widthgetter").width()/2);
	}
	
	
	
	
	
	
	$("#leftbuttons h1 a").click(
	function(){
		mypasser=$(this).attr("alt");
		
		$("#overtext").animate({"opacity":"0"},{queue:false, duration:400, complete:function(){
			
			//alert(mypasser);
			
			
			
			
			showtheshow(mypasser)
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		}
		});
		//$("#wholeshade").stop().animate({"top":"600px"},{queue:false, duration:750});
	//alert("im here");
	
	
	
		
	}
	
	
	);
	
	
	function showtheshow(which){
		
		checky=$.get("fetchstuff.php", { ID: which}, function(data) {
  $('#overtext').html(data);
  //$("#wholeshade").animate({"top":(500-$('#overtext').height())+"px"},{queue:false, duration:750});
 // alert('Load was performed.');
 $("#overtext").animate({"opacity":"1"},{queue:false, duration:400});
} );
		
		
		
		
		
		
	}
	
	
	
	$(".bgslider").css("opacity",0);
		$('.title a').hover(function(){
			pageleft=parseInt($("#menuholder").offset().left);
			//alert(pageleft+"therepagleft");
			myleft=parseInt($(this).offset().left)-pageleft;
			mywidth=$(this).width()+parseInt($(this).css("padding-left"))+parseInt($(this).css("padding-right"));
			//alert($(this).offset().left+"px");
			//alert(myleft);
			
			$(".bgslider").stop().animate({"left":myleft+"px"},{queue:false, duration:250});
			$(".bgslider").animate({"opacity":"1"},{queue:false, duration:250});
			$(".bgslider").animate({"width":mywidth+"px"},{queue:false, duration:250});
			
		},
		function(){
			$(".bgslider").animate({"opacity":"0"},{queue:false, duration:1250});
		}
		
		);
						   
						   
						   //make my curvey corners
						   $('.curveycorners').wrapInner('<div class="curveycontent" />');
						   
	$('.curveycorners').each(function(){
									  myright=$(this).width()-10;
									  myheight=$(this).height()-10;
	$(this).append("<div class='tops' style='top:0px;left:0px;width:"+(myright+10)+"px'></div><div class='bottoms' style='top:"+myheight+"px;left:0px;width:"+(myright+10)+"px'></div><div class='lefts' style='top:0px;left:0px;height:"+(myheight+10)+"px'></div><div class='rights' style='top:0px;left:"+myright+"px;height:"+(myheight+10)+"px'></div><div class='topleftcorner' style='top:0px;left:0px'></div><div class='toprightcorner' style='top:0px;left:"+myright+"px'></div><div class='bottomrightcorner' style='top:"+myheight+"px;left:"+myright+"px'></div><div class='bottomleftcorner' style='top:"+myheight+"px;left:0px'></div>");

									  });
	
	
	//newsflash
	
	
	function startnews(whichnews){
		if(whichnews+1>=$(".newsitem").length){
			nextnews=0;
			
		} else {
			nextnews=whichnews+1;
		}
		$(".newsitem").eq(whichnews).animate({"opacity":"1"},{queue:false, duration:750});
		$(".newsitem").eq(whichnews).animate({"top":"0px"},{queue:false, duration:2500,complete:function(){
																										 
																				pausenews(nextnews);						 
																										 }
																										 });
		//alert("im moving "+whichnews);
		
		$(".newsitem").each(function(){
									// alert("in start of function"+nextnews);
									 nextnews=nextnews;
					if($(this).css("top")!="400px"	){
						//alert($(this).css("top"));
						$(this).animate({"top":"-400px"},{queue:false, duration:2500,complete:function(){
																							$(this).css("top","400px");
																							//alert(nextnews);
																							//startnews(nextnews);
																									  }
																									  });
						$(this).animate({"opacity":"0"},{queue:false, duration:750});
						
					}
									 
	});
		
		
	}
	
	function pausenews(whichpass){
		$("#newsbox").animate({"top":$("#newsbox").css("top")},{queue:false, duration:10000, complete:function(){
																											startnews(whichpass);  
																											  }
																											  });
	}
	
	//startnews(0);
	
	function startnewnews(whichnews){
		//alert("here is whichnews plus 1"+intval(whichnews+1+"here is news length"+$(".news").length);
		if(whichnews+1>=$(".news").length){
			//alert("here is whichnews plus 1"+whichnews+1+"here is news length"+$(".news").length);
			nextnews=0;
			
		} else {
			nextnews=whichnews+1;
			//alert(nextnews);
		}
		$(".news").eq(whichnews).animate({"opacity":"1"},{queue:false, duration:750});
		$(".news").eq(whichnews).animate({"top":"25px"},{queue:false, duration:2500,complete:function(){
																										 
																				pausenewnews(nextnews);						 
																										 }
																										 });
		//alert("im moving "+whichnews);
		
		$(".news").each(function(){
									// alert("in start of function"+nextnews);
									 nextnews=nextnews;
					if($(this).css("top")!="400px"	){
						//alert($(this).css("top"));
						$(this).animate({"top":"-400px"},{queue:false, duration:2500,complete:function(){
																							$(this).css("top","400px");
																							//alert(nextnews);
																							//startnews(nextnews);
																									  }
																									  });
						$(this).animate({"opacity":"0"},{queue:false, duration:750});
						
					}
									 
	});
		
		
	}
	
	function pausenewnews(whichpass){
		//alert("got in pause"+whichpass);
		$("#headsection").animate({"top":"0px"},{queue:false, duration:10000, complete:function(){
																									   //alert("got in pause complete and whichpass="+whichpass);
																											startnewnews(whichpass);  
																											  }
																											  });
	}
	
	startnewnews(0);
	
	
});
