$(document).ready(function(){
						   mycolor="#8da47e";
						   mycurrentslide=0; // going to use this for pause etc access via window.mycurrentslide
						   myduration=20000;  // slide roataion duration
						   
						if($('.indislide').length>1){
							//alert($('.indislide').length);
							
							
						$('.indislide').each(function(){
													  $(this).css("opacity",0);
									 // here I'm adding the slide navigation first part is the numbers
									 
	$("#slidenavs").append("<div class='slideswitchers'><a href='#'>"+($('.indislide').index(this)+1)+"</a></div>");

									  });   
						
						$("#slidenavs").append("<div class='slidepauseplay'><a href='Javascript:;'>II</a></div>");
						$(".slideswitchers a").click(function(){
														 mymove=$(".slideswitchers a").index(this);
														// alert(mymove);
														$(".slidepauseplay a").html(">");
														 
														 
		$(".slidepauseplay").css("background-color", window.mycolor);
														 
										rotateslide(mymove, "yes")	;			 
														 });
						
						
						
						
						
						
						
						
						
						
						
						
						
						$('.stoptrig').click(function(){
							
							
							
							
							$(this).html("<iframe  width='580' height='400' src='http://www.youtube.com/embed/"+$(this).attr("id")+"?autoplay=1' frameborder='0' allowfullscreen></iframe>");
							
							
						
						//alert("clicked");
						
						$(".slidepauseplay a").html(">");
														 mymove=window.mycurrentslide;
														 
		$(".slidepauseplay").css("background-color", window.mycolor);
		
														// alert(mymove);
														 
										//rotateslide(mymove, "yes")	;
										$("#allslides").stop(true,false);
										
										
						}
						);
										
										
										
										
										
										
										
										
										
										
										
										
										
										
										
										
										
										
										
										
										
										
										
										
										
						
						
						
						
						
						$(".slidepauseplay a").click(function(){  // for the pause button play button
															  
															  
														if($(".slidepauseplay a").html()=="II"){	 
														$(".slidepauseplay a").html(">");
														 mymove=window.mycurrentslide;
														 
		$(".slidepauseplay").css("background-color", window.mycolor);
		
														// alert(mymove);
														 
										//rotateslide(mymove, "yes")	;
										$("#allslides").stop(true,false);
														} else {
															$(".slidepauseplay a").html("II");
															if(window.mycurrentslide+1>=$('.indislide').length){
														 mymove=0;
															} else {
																 mymove=window.mycurrentslide+1;
															}
														// alert(mymove);
														$(".slidepauseplay").css("background-color","#000000");
														 
										rotateslide(mymove, "restart")	;
															
														}
														 });
						
						}// end of if > 1 slide
						   
						   
	
	$(".topscreenbgs").css("opacity",.65);
	
	
	
	
	// fixing an ie goofyness
	$(".slideswitchers").css("opacity",1);
	$(".slidepauseplay").css("opacity",1);
	
	//trying to repair
	$(".topscreenbgs").css("opacity",0);
	$(".topscreens").css("opacity",0);

	
	
	function fixvids(){
		
		$(".stoptrig").each(function(){
			
			$(this).html("<a href='#'><img src='images/vidstills/"+$(this).attr("id")+".jpg' width='580' height='400' border='0' /></a>");
			
		}
		);
		
	}
	
	function rotateslide(whichslide, isstop){
		fixvids();
		//$("#allslides").stop(true,false);
		window.mycurrentslide=whichslide;
		
		//alert("putting in slide"+whichslide);
		
		
		
									
									
		function showthisslide(whichshow){
			myguy=$(".indislide").eq(whichshow);
			//alert ("showiung slide "+whichshow);
			myalert="putting in slide"+whichslide;
										//alert($(".indislide").index(this));
										$(myguy).css("z-index",10);
										$(myguy).find(".topscreenbgs").stop().css("opacity",.65);
										$(myguy).find(".topscreens").stop().css("opacity",1);
										$(myguy).find(".featdiv").stop().css("opacity",1);
										$(myguy).stop().animate({"opacity":1},{queue:false, duration:1000}); 
										
										
										changeswitcher(whichshow);
			
			
		}
		
		
		
		$(".indislide").each(function(){
									 //end of if indislide = which slide
									
									
										
										
									
									
									if($(this).css("opacity")>0&&$(".indislide").index(this)!=window.mycurrentslide){
										//if($(".indislide").index(this)!=whichslide){
										//alert ("sending slide "+$(".indislide").index(this)+" to zero");
										$(this).css("z-index",1);
										$(this).animate({"opacity":0},{queue:false, duration:1000}); //removed stop 
										$(this).find(".topscreenbgs").animate({"opacity":0},{queue:false, duration:200}); //removed stop
										$(this).find(".topscreens").animate({"opacity":0},{queue:false, duration:200}); //removed stop
										$(this).find(".featdiv").animate({"opacity":0},{queue:false, duration:200});	 //removed stop
										//myalert=myalert+"send number "+$(".indislide").index(this);
										
									} //end of if opacity>0
									 }); //end of each indislide
		
		showthisslide(whichslide);
		
		
		
		if(whichslide+1>=$(".indislide").length){
			nextslide=0;
		} else {
			nextslide=whichslide+1;
		} // end of check for next slide
		isstoppass=isstop;
		$("#allslides").animate({"opacity":1},{queue:false, duration:window.myduration, complete:function(){ //added stop
																										  
																										  //myalert=myalert+" the opacity of whichslide is "+$(".indislide").eq(whichslide).css("opacity");
		//alert(myalert);
																										  
																							 if(isstoppass=="yes"){
																										 //setpauseplay(nextslide);
																									 } 
																									 if(isstoppass=="continue"||isstoppass=="restart"){
																							  //alert("i'm flipping");
																							  
																							//  setpausenumber(nextslide);
																							  //alert("im switching to "+nextslide);
																							  
																							 rotateslide(nextslide, "continue"); 
																									 }  
																							   }
								
								
								});
	}
	
	function changeswitcher(whichswitcher){
		$(".slideswitchers").css("border-color","#ffffff");
		$(".slideswitchers a").css("color","#ffffff");
		$(".slideswitchers").eq(whichswitcher).css("border-color", window.mycolor);
		$(".slideswitchers a").eq(whichswitcher).css("color", window.mycolor);
	}
	
	function showfades(){
		$(".topscreenbgs").css("opacity",.65);
	}
	function hidefades(){
		$(".topscreenbgs").css("opacity",0);
	}
	//start the animation without using timout
	//changeswitcher(0);
	//$("#allslides").animate({"opacity":"1"},{queue:false, duration:10000, complete:function(){
																							// rotateslide(1); 
																							  // }
								
								
								//});
	if($('.indislide').length>1){
	rotateslide(0, "continue");
	} else {
		rotateslide(0, "yes");
	}
	
});
