$(document).ready(function() {
	//homepage "What do you want to know" and right-column Categories page 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").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('bluedot');
				$('li#pageDot'+newPage).find('span').addClass('bluedot');
				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);
			}
			$(activeTab).show(); //Fade in the active ID content
			
			return false;
		});
		
		//On Click Event for blue 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('bluedot');
			$(this).find('span').addClass('bluedot');
			prevPage=currentPage*1-1;	if(prevPage==0){prevPage=1}
			nextPage=currentPage*1+1; if(nextPage > maxPage){nextPage=maxPage}
			
			$('#prevScrollAnchor').removeClass("pagLeftFade").addClass("pagLeft");
			$('#nextScrollAnchor').removeClass("pagRightFade").addClass("pagRight");
			if(currentPage==1){
				$('#prevScrollAnchor').removeClass("pagLeft").addClass("pagLeftFade");
			}else if(currentPage==maxPage){
				$('#nextScrollAnchor').removeClass("pagRight").addClass("pagRightFade");
			}
			$('#prevScrollAnchor').attr('href','#scroll_tab'+prevPage);
			$('#nextScrollAnchor').attr('href','#scroll_tab'+nextPage);
			$(activeTab).show(); //Fade in the active ID content

			return false;
		});
	
	//blog-list page fader
	$(".blogtab_content").hide(); //Hide all content
	$("ul.blogtabs li:first").addClass("active").show(); //Activate first tab
	$(".blogtab_content:first").show(); //Show first tab content
		//On Click Event
		$("ul.blogtabs li").click(function() {
			$("ul.blogtabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".blogtab_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 = $('#currentBlogTab').html();
			var maxPage = $('#maxBlogTab').html();
			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){
				$('#currentBlogTab').html(newPage);
				$('li.pageDotsBlog').find('span').removeClass('bluedot');
				$('li#pageDotBlog'+newPage).find('span').addClass('bluedot');
				prevPage=newPage-1;	if(prevPage==0){prevPage=1}
				nextPage=newPage+1; if(nextPage > maxPage){nextPage=maxPage}
				
				$(this).parent().find("#prevAnchor").removeClass("pagLeftFade").addClass("pagLeft");
				$(this).parent().find("#nextAnchor").removeClass("pagRightFade").addClass("pagRight");
				if(newPage==1){
					$(this).parent().find("#prevAnchor").removeClass("pagLeft").addClass("pagLeftFade");
				}else if(newPage==maxPage){
					$(this).parent().find("#nextAnchor").removeClass("pagRight").addClass("pagRightFade");
				}
				$(this).parent().find('#prevAnchor').attr('href','#tab'+prevPage);
				$(this).parent().find('#nextAnchor').attr('href','#tab'+nextPage);
			}
			$(activeTab).fadeIn(); //Fade in the active ID content
			
			return false;
		});
		
		//On Click Event for blue dots
		$("li.pageDotsBlog").click(function() {
			$(".blogtab_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 = $('#maxBlogTab').html();
			
			$('#currentBlogTab').html(currentPage);
			$('li.pageDotsBlog').find('span').removeClass('bluedot');
			$(this).find('span').addClass('bluedot');
			prevPage=currentPage*1-1; if(prevPage==0){prevPage=1}
			nextPage=currentPage*1+1; if(nextPage > maxPage){nextPage=maxPage}
			
			$('#prevAnchor').removeClass("pagLeftFade").addClass("pagLeft");
			$('#nextAnchor').removeClass("pagRightFade").addClass("pagRight");
			if(currentPage==1){
				$('#prevAnchor').removeClass("pagLeft").addClass("pagLeftFade");
			}else if(currentPage==maxPage){
				$('#nextAnchor').removeClass("pagRight").addClass("pagRightFade");
			}
			$('#prevAnchor').attr('href','#tab'+prevPage);
			$('#nextAnchor').attr('href','#tab'+nextPage);
			$(activeTab).fadeIn(); //Fade in the active ID content

			return false;
		});
});

function fncSwapTabs(tab){
	document.tabForm.selectedTab.value=tab;
	for (i=1;i<=3;i=i+1) {
		$("div#introTabs").find("#tabLink"+i).removeClass("on");
	}
	$("div#introTabs").find("#tabLink"+tab).addClass("on");
	ajaxFormFunction(document.getElementById('tabForm'),completeSwap,'swap_tabs.iml');
}

function completeSwap(sc,st,rt,rxml) {
	document.getElementById("tabContainer").innerHTML=rt;
}

function popupSubmitDiv(){
	var middleHeight=$('div#mainBox').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#mainBox').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";
}
