$(document).ready(function() {
		// created by extremegroup.
		// jsscript used in conjunction with healthview.
		// this script is used on the basis that the website is design
		// with expression engine and is using the expression engine pathing.

		// setup variables 
	//	$sublinks = $("#mainmenu li ul"); // all sub ul elements.
		$links = $("#mainmenu li a"); // all links in mainmenu
	//	$sublinks.hide(); // all hidden
	
	//	$sublinks.each(function(){
	//		$(this).children("li").children("a").addClass("sub");
	//	});
		
	//	$("#mainmenu li:has(.active1) ul").hide();
		$intcount = 0;
	   $('#s3slider').s3Slider({
	      timeOut: 4000
	   });
		
		
		/* ----------------------------------------	*/
		/*  			function list				*/
		/* ----------------------------------------	*/
		
		// find the active links by parsing the url
		function getActive(){
			// Grab url and strip everything after php and split by "/"
			var myurl = document.location;
			myurl = myurl.toString();
			myurl = myurl.toLowerCase();
			charlength = myurl.length;
			var incount = myurl.indexOf('.php');
			incount = incount + 5;
			myurl = myurl.substring(incount, charlength);
			var segments = new Array();
			if(incount > 4){ // amount of spaces after for .php
				segments = myurl.split('/');	
			}
			return segments;
		}
	
		
		// parse the active links and apply the active class to them.
		function activeLinks(n, p, x){ //n is the array. p is the location, x is the iteration.
			if(x === undefined){
				x = 0;
			}
			q = p.attr('href');
				check = q.match(n[x]);
				if(check != null && q != ''){
					p.parent('li').removeClass('active'+x);
					x++;					
					p.parent('li').addClass('active'+x);
					activeLinks(n, p, x);
				}else{
					return false;
				}
		}		
		
		// expand sub menus on call
		function expand(n){
			$sublinks.hide();
			n.toggle("300");
		}
		
		//rollover menu replace functions.
		function cleanImage(n){
			n = n.replace(/ /g,'');
			p = n.lastIndexOf("/");
			n = n.substring(0, p);
			p = n.lastIndexOf("/");
			l = n.length;
			n = n.substring(p+1, l);
			n = n.toLowerCase();
			return n;
		}


		function imageReplace(n, p){ //n=image p=imageheight
			$img = cleanImage(n.attr("href"));
			$last = $img.lastIndexOf("/");		
			// setup rollover.  CSS must be set to overview hidden. 
			n.text("").html("<img src='/images/menu_"+ $img +".gif' />");		
			n.children("img").css({marginTop:"0px"});
			n.css({display: "block", overflow: "hidden", height: ""+ p + "px"});
			n.hover(function(){
					n.children("img").css({marginTop:"-"+ p + "px"});
				},function(){
					n.children("img").css({marginTop:"0px"});
			});
		}
		// End of Functions //
		
		
		// process page.
		/*
		$segments = getActive();
		if($segments == "" || $segments == null){
			$links.eq(0).parent('li').addClass('active1');		
			}else{
		$links.each(function(){
				$item = $(this);
				$addclass = activeLinks($segments, $item);
			});
		}
		
		
		*/	
		$("#mainmenu ul li a").each(function(){
			imageReplace($(this), 75);
			$intcount = $intcount +1;
			$(this).parent("li").addClass("item"+ $intcount);
			});
			
		$("#otherlinks ul:first li a").each(function(){
			imageReplace($(this),75);
			$intcount = $intcount +1;
			$(this).parent("li").addClass("item"+ $intcount);
		});
		//setup submenus.  Removes links and adds toggles.
		/*
		$sublinks.parent("li").children("a").click(function(e){
			e.preventDefault();
			expand($(this).parent("li").children("ul"));
		});
		*/
});
