$(document).ready(function() {
	$('div#popWindowInner').css('display','none');
	
	//homepage "What do you want to know" fader
	$(".know_content").hide(); //Hide all content
	$("ul.knowtabs li:first").addClass("active").show(); //Activate first tab
	$(".know_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.knowtabs li.navArrow").click(function() {
		$("ul.knowtabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".know_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		var activeTabDirection = $(this).find("a").attr("direction");
		var currentPage = $('#nextScrollAnchor').attr('currentPageNumber');
		var maxPage = $('#nextScrollAnchor').attr('lastPageNumber');
		var allowChange=0;
		if(activeTabDirection=="up"){
			newPage = currentPage*1+1;
			if(newPage <= maxPage*1){
				allowChange=1;
			}
		}else{
			newPage = currentPage*1-1;
			if(newPage >= 1){
				allowChange=1;
			}
		}
		if(allowChange){
			$('#nextScrollAnchor').attr('currentPageNumber',newPage);
			$('li.pageDots').find('span').removeClass('yeldot').addClass('graydot');
			$('li#pageDot'+newPage).find('span').removeClass('graydot').addClass('yeldot');
			prevPage=newPage-1;	if(prevPage==0){prevPage=1}
			nextPage=newPage+1; if(nextPage > maxPage){nextPage=maxPage}
			
			$(this).parent().find("#prevScrollAnchor").removeClass("pagLeftFade").addClass("pagLeft");
			$(this).parent().find("#nextScrollAnchor").removeClass("pagRightFade").addClass("pagRight");
			if(newPage==1){
				$(this).parent().find("#prevScrollAnchor").removeClass("pagLeft").addClass("pagLeftFade");
			}else if(newPage==maxPage){
				$(this).parent().find("#nextScrollAnchor").removeClass("pagRight").addClass("pagRightFade");
			}
			$(this).parent().find('#prevScrollAnchor').attr('href','#scroll_tab'+prevPage);
			$(this).parent().find('#nextScrollAnchor').attr('href','#scroll_tab'+nextPage);
		}
		if((newPage <= maxPage*1)&&(newPage >= 1)){
			$(activeTab).fadeIn(); //Fade in the active ID content
		}else{
			$(activeTab).show(); //Show the active ID content
		}
		
		return false;
	});
	
	//On Click Event for nav dots
	$("li.pageDots").click(function() {
		$(".know_content").hide(); //Hide all tab content

		var activeTab = $(this).attr("scrollHREF"); //Find the href attribute value to identify the active tab + content
		var currentPage = $(this).attr("myPage");
		var maxPage = $('#nextScrollAnchor').attr('lastPageNumber');
		$('#nextScrollAnchor').attr('currentPageNumber',currentPage);
		$('li.pageDots').find('span').removeClass('yeldot').addClass('graydot');
		$(this).find('span').removeClass('graydot').addClass('yeldot');
		prevPage=currentPage*1-1;	if(prevPage==0){prevPage=1}
		nextPage=currentPage*1+1; if(nextPage > maxPage){nextPage=maxPage}
		
		$('#prevScrollAnchor').attr('href','#scroll_tab'+prevPage);
		$('#nextScrollAnchor').attr('href','#scroll_tab'+nextPage);
		$(activeTab).fadeIn(); //Fade in the active ID content

		return false;
	});
});

function popupSubmitDiv(){
	var middleHeight=$('div#middleBox').height();
	if(middleHeight==null){
		var middleHeight=$('div#inMidBox').height();
	}
	newHeight=middleHeight+2000;
	var scrollTop = $(window).scrollTop();
	newPos=scrollTop+150;
	document.getElementById("popWindowOuter").style.display="";
	document.getElementById("popWindowOuter").style.height=newHeight+"px";
	document.getElementById("popWindowInner").style.display="";
	document.getElementById("popWindowInner").style.top=newPos+"px";
}
function hideSubmitDiv(){
	document.getElementById("popWindowOuter").style.display="none";
	document.getElementById("popWindowInner").style.display="none";
}
function popupSuccessDiv(){
	document.getElementById("popWindowInner").style.display="none";
	var middleHeight=$('div#middleBox').height();
	if(middleHeight==null){
		var middleHeight=$('div#inMidBox').height();
	}
	newHeight=middleHeight+2000;
	var scrollTop = $(window).scrollTop();
	newPos=scrollTop+150;
	document.getElementById("popWindowOuter").style.display="";
	document.getElementById("popWindowOuter").style.height=newHeight+"px";
	document.getElementById("popSuccessInner").style.display="";
	document.getElementById("popSuccessInner").style.top=newPos+"px";
}
function hideSuccessDiv(){
	document.getElementById("popWindowOuter").style.display="none";
	document.getElementById("popSuccessInner").style.display="none";
}
