var overrideIndex;
var slideInterval;
function setupSubnav(){
	$("#subNav ul li").hover(
		function(e){
			$(this).children("img.menuBack").fadeIn('slow');
		},
		function(e){		
			$(this).children("img.menuBack").fadeOut('slow');
	});
}
function drsLoadDiv(theDiv){
	var theLi;
	$("#drsnavBar li").each(function(i){
		if($(this).children("a").length>0){
			if($(this).children("a").attr("href").indexOf(theDiv)>-1){
				theLi=$(this);	
			}
		}
	});
	$("#drsnavBar li").removeClass('current');
	$(theLi).addClass("current");
	$("#drsContent").children("div").hide();
	$("#"+theDiv).show();
	$("#landingpg").hide(); 
	$("#drsContent").show();
}
function loadDiv(theDiv){
	var theLi;
	var theImg;
	$("#subNav li").each(function(i){
		if($(this).children("a").attr("href").indexOf(theDiv)>-1){
			theLi=$(this);
		}
	});
	if(overrideIndex){
		var x=0;
		$(overrideIndex).each(function(i){
			if($(theLi).children("a").attr("href").indexOf(this)>-1){
				theImg=overrideImage[x];	
			} else {
				theImg='';	
			}
			x++;
		});
	}
	$("#subNav li").removeClass('current');
	$(theLi).addClass("current");
	$("#subNav li").each(function(){
		if(!($(this).hasClass("current"))){
			$(this).children("img.menuBack").hide();
		}
	});
	$("#otherContent").children("div").hide();
	$("#"+theDiv).show();
	$("#landingpg").hide(); 
	$("#otherContent").show();
	$("#imageArea").show();
	if($("#"+theDiv+" .flashload").length>0){
		$('#flash').html($("#"+theDiv+" .flashload").html());
		$('#flash IMG:first').addClass('active');
		slideInterval=setInterval("slideSwitch()", 4000);	
		$("#flash").show();
		$("#otherContent").css("height","288px");
	} else if(theImg) {
		$("#flash").html("<img src='"+theImg+"' alt='' />");
		$("#flash").show();	
		$("#otherContent").css("height","288px");
	} else {
		$("#flash").html('');
		$("#flash").hide();
		$("#otherContent").css("height","600px");
	}
}
function centersLoadDiv(theDiv, theImg){
	var theLi;
	$("#subNav li").each(function(i){
		if($(this).children("a").attr("href").indexOf(theDiv)>-1){
			theLi=$(this);	
		}
	});
	if(overrideIndex){
		var x=0;
		$(overrideIndex).each(function(i){
			if($(theLi).children("a").attr("href").indexOf(this)>-1){
				theImg=overrideImage[x];	
			}
			x++;
		});
	}
	$("#subNav li").removeClass('current');
	$(theLi).addClass("current");
	$("#subNav li").each(function(){
		if(!($(this).hasClass("current"))){
			$(this).children("img.menuBack").hide();
		}
	});
	if(theImg){
		flashLoaded=false;
		$("#flash").hide();
		$("#loadImage").attr("src",theImg);
		$("#loadImage").show();
	} else {
		if(flashLoaded==false){
			$('#flash IMG:first').addClass('active');
			slideInterval=setInterval("slideSwitch()", 5000);
			$("#flash").show();
			$("#loadImage").hide();
		}
		flashLoaded=true;
	}
	$("#theContent").children("div").hide();
	$("#"+theDiv).show();
	$("#landingpg").hide(); 
	$("#theContent").show();
}
function loadDivImg(theDiv){
	var theLi;
	var theImg;
	var theIndex=0;
	
	$("#subNav li").each(function(i){
		if($(this).children("a").attr("href").indexOf(theDiv)>-1){
			theLi=$(this);
			$("#imageArea").attr("src",theImages[theIndex]);
			if(theImages[theIndex]){
				if(theImages[theIndex].length>0){
					$("#imageArea").show();
				} else {
					$("#imageArea").hide();	
				}
			} else {
				$("#imageArea").hide();	
			}
		}
		theIndex++;
	});
	
	$("#subNav li").removeClass('current');
	$(theLi).addClass("current");
	$("#subNav li").each(function(){
		if(!($(this).hasClass("current"))){
			$(this).children("img.menuBack").hide();
		}
	});
	$("#theContent").children("div").hide();
	$("#"+theDiv).show();
	$("#landingpg").hide(); 
	$("#theContent").show();
}

var theData;
var photoIndex=0;
function showFrame(theId){
	$.ajax({
			url: "/pages/gallery/"+theId+".html",
			//url: "../gallery/"+theId+".html",
			dataType: "php",
			beforeSend: function(){
				$("#popupback").fadeIn();
				$("#photosframeholder").show();
				$("#photosframeholder #photosframe #inner").html("<img src='/images/loader.gif' id='loader' />");
			},
			success: function(data){
				theData=data;
			    $("#photosframe #inner").html("<span id='caution'><p><b>CAUTION</b><br><br>The photographs on this page may contain nudity and are meant for educational purposes only. They are not meant for children under the age of 18. If you are offended by such material or are not at least 18 years of age, please click on the CANCEL<br>button now. Otherwise, click OKAY.<br><br><a href='javascript:closePop();'>CANCEL</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:frameSuccess();'>OKAY</a></p></span>");
			}
		});
}

function frameSuccess() {
	$("#arrowright").show();
	$("#arrowleft").show();
	$("#closepop").show();
	$("#photosframe #inner").html(theData);
	var divLength=$("#photosframe #inner .photoFrame").children(".frame").length;
	$("#photosframe #inner .photoFrame").children(".frame:eq(0)").show();
	setupArrows(divLength);	
}

function setupArrows(divNumber){
	$("#arrowright").click(function(){
		$("#photosframe #inner .photoFrame").children(".frame:eq("+photoIndex+")").fadeOut(function(){
			if(photoIndex<divNumber-1){
				photoIndex++;
			} else {
				photoIndex=0;	
			}			
			$("#photosframe #inner .photoFrame").children(".frame:eq("+photoIndex+")").fadeIn();																		
		});
	});
	$("#arrowleft").click(function(){
		$("#photosframe #inner .photoFrame").children(".frame:eq("+photoIndex+")").fadeOut(function(){
			if(photoIndex==0){
				photoIndex=divNumber-1;
			} else {
				photoIndex--;	
			}
			$("#photosframe #inner .photoFrame").children(".frame:eq("+photoIndex+")").fadeIn();
		});
	});
	$("#arrowright").mouseover(function(){
		var theImg=$(this).attr("src");
		if(theImg.indexOf("_off.gif")>-1){
			$(this).attr("src",$(this).attr("src").replace("_off.gif","_on.gif"));
		}
	}).mouseout(function(){
		var theImg=$(this).attr("src");
		if(theImg.indexOf("_on.gif")>-1){
			$(this).attr("src",$(this).attr("src").replace("_on.gif","_off.gif"));	
		}
	});
	$("#arrowleft").mouseover(function(){
		var theImg=$(this).attr("src");
		if(theImg.indexOf("_off.gif")>-1){
			$(this).attr("src",$(this).attr("src").replace("_off.gif","_on.gif"));
		}
	}).mouseout(function(){
		var theImg=$(this).attr("src");
		if(theImg.indexOf("_on.gif")>-1){
			$(this).attr("src",$(this).attr("src").replace("_on.gif","_off.gif"));	
		}
	});
}
function closePop(){
	$("#popupback").fadeOut();
	$("#arrowright").css("display","none");
	$("#arrowleft").css("display","none");
	$("#closepop").css("display","none");
	$("#photosframeholder").hide();
	$("#photosframe #inner").empty();
	photoIndex=0;
	$("#arrowright").unbind("click");
	$("#arrowleft").unbind("click");
}
// bhaley adding function to show videos in lightbox
function showVid(theVid){
	$("#popupback").fadeIn();
	$("#vidholder").show();
	$("#vidholder .inner").html("<img src='/images/loader.gif' id='loader' />");
	$("#vidholder .inner").html('<iframe class="youtube-player" type="text/html" width="720" height="420" src="http://www.youtube.com/embed/'+theVid+'" frameborder="0"></iframe>');
}
function closeVid(){
	$("#popupback").fadeOut();
	$("#vidholder").hide();
	$("#vidholder .inner").empty();
}
function checkHash(section){
	var theHash=document.location.toString();
	if(theHash.indexOf("#"+section)>-1){
		theHash=theHash.substr(theHash.indexOf("#"+section));
		var divToUse=theHash.substr(theHash.indexOf("_")+1);
	}
	if($("#"+divToUse).length>0){
		flashLoaded=false;
		loadDiv(divToUse);	
	}
}
function drCheckHash(section){
	var theHash=document.location.toString();
	if(theHash.indexOf("#"+section)>-1){
		theHash=theHash.substr(theHash.indexOf("#"+section));
		var divToUse=theHash.substr(theHash.indexOf("_")+1);
	}
	if($("#"+divToUse).length>0){
		flashLoaded=false;
		drsLoadDiv(divToUse);	
	}
}
function checkHashImg(section){
	var theHash=document.location.toString();
	if(theHash.indexOf("#"+section)>-1){
		theHash=theHash.substr(theHash.indexOf("#"+section));
		var divToUse=theHash.substr(theHash.indexOf("_")+1);
	}
	if($("#"+divToUse).length>0){
		flashLoaded=false;
		loadDivImg(divToUse);	
	}
}
function centersCheckHash(section){
	var theHash=document.location.toString();
	if(theHash.indexOf("#"+section)>-1){
		theHash=theHash.substr(theHash.indexOf("#"+section));
		var divToUse=theHash.substr(theHash.indexOf("_")+1);
	}
	if($("#"+divToUse).length>0){
		flashLoaded=false;
		centersLoadDiv(divToUse);
	}
}
function slideSwitch() {
	var $active=$('#flash IMG.active');
	if($active.length==0)$active=$('#flash IMG:last');
	var $next=$active.next().length?$active.next():$('#flash IMG:first');
	//the following line makes the slideshow loop once, then end on the first slide. comment it out or remove it for endless loop
	if($active.next().length==0){clearInterval(slideInterval);}
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
		$active.removeClass('active last-active');
	});
}


