$(document).ready(function(){
	
	//showtheshow($("#leftbuttons h1 a").eq(0).attr("alt"));
	
	
	//poppers stuff
	
	
	$('.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+"'\>");
		//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);
	
	
});
