	
	var img_index = 0;
	var page_index = 0;
	var total_pages = 0;
	var th_width = 0;
	var page_width = 0;
	var start_left = 0;
	var over = null;
	var col_unit = 0;
	var visible_cols = 5;
	var reverseLoop = false;
	
	function removeStr(s,r){
		return s.substr(0,s.indexOf(r));
	}
	
	function removeThumbRef(s){
		var start = s.substr(0,s.indexOf('.thumb'));
		var suffix = s.substr(s.lastIndexOf('.'));
		return start+suffix;
	}
	
	$(document).ready(function(){
		
		$(".featuresnav ul li a").click(function(){
										var index = $(".featuresnav ul li a").index(this);
										var section_id = $(this).attr("href").substr(1);
										section_id = section_id.replace(" ","_");
										section_id = section_id.toLowerCase();
										resetNav();
										$(this).attr("class","active");
										$("#"+section_id).attr("class","list_section active_features");
										//alert(section_id);
		});
		
		$(".featuresimgs li a").click(
			function(){
				var src = $(this).attr("href").substr(1);
				var p = $(this).find("p");
				if($(p).length > 0){
					$("#imageViewer h5").attr("class", "active");
				}else{
					$("#imageViewer h5").attr("class", "inactive");
				}
				$("#imageViewer h5").html($(p).html());
				$("#imageViewer img").attr("src", src);
				if(layers){
					layers.popups.showAssoc("imageViewer");
				}
			}
		);
		
	});
	
	function resetNav(){
		$(".featuresnav ul li a").each(function(){
										$(this).attr("class","inactive");
		});
		
		$(".list_section").each(function(){
										$(this).attr("class","list_section inactive_features");
		});
	}
	
	function movePrev(){
		var rev = reverseLoop;
		previousPage();
		updateTracker();
		//alert(rev);
		if(page_index==0){
			var check_width = 0;
		}else if(page_index!=0 && reverseLoop){
			//alert("dog");
			var check_width = (page_index*page_width) - ((visible_cols-over) * (Number(col_unit)-10));
		}else{
			//alert('cat');
			var check_width = page_index*page_width;
		}
			var new_margin = -1*((check_width)-start_left) + "px";
		$(".th_ctr").animate({ 
			left:new_margin
		  }, 1000, "swing" );
	}
	
	function moveNext(){
		if(page_index==total_pages-1){
			var check_width = (page_index*page_width) - ((visible_cols-over) * Number(col_unit));
			//alert(page_index*page_width);
			//alert(over);
		}else{
			var check_width = page_index*page_width;
		}
			var new_margin = -1*((check_width)-start_left) + "px";
		$(".th_ctr").animate({ 
			left:new_margin
		  }, 1000, "swing" );
	}
	
	
	function update(n,s,l){
		$(".large_img img").attr('src', removeThumbRef(s,'.thumb'));
		$(".th a").each(
			function(){
				$(this).attr("class", "");
			}
		);
		l.attr("class", "active");
	}
	
	function nextPage(){
		if(page_index < total_pages-1){
			page_index++;
			if(page_index==total_pages-1){
				reverseLoop=true;
			}
		}
	}
	
	function previousPage(){
		if(page_index > 0){
			page_index--;
			if(page_index==0){
				reverseLoop=false;
			}
		}
	}
	
	function updateTracker(){
		$(".page_tracker .current_page").text(page_index+1);
	}