jQuery(document).ready(function(){
		
		//Used to toggle text from form fields along with jquery.toggleval_2.1.min.js plugin
		$(".SideNav input:text").toggleVal();
		$(".SideNav form").submit(function() {
			$(this).find(".toggleval").each(function() {
			  if($(this).val() == $(this).data("defText")) {
				$(this).val("");
			  }
			});
		  });

		
		//Adds corners to an element and uses jquery.curvycorners.packed.js
		//$("#LoginForm").corner("bottom");
										
        $('#tabs-nav-container').append('<ul id="tabs-nav" class="middlelist"></ul>')
 
        $('.tabs').each(function(i){    
            // Gives element a unique ID -
            this.id = 'tab'+i;
            // If a title does not exist then use the ID for anchor text -
            var title = (this.title) ? this.title : this.id;
            // Define contents of link (to go within list items) -
            var link = '<a href="#' + this.id + '">' + title + '</a>';
            // Append list items to UL -
            $('#tabs-nav').append('<li>'+link+'</li>');
            // Check if the URL contains an anchor
            var url = document.location.toString();
            if (url.match('#')) {
                // Get the name of the anchor used in the URL
                var anc = '#' + url.split('#')[1];
                // Hide all TABS -
                $('.tabs').fadeOut();
                // Show the corresponding content
                $(anc).fadeIn();  
            } else {    
                // Hide all Tabs except the first one -
                if(i===0) $('.tabs:not(#'+this.id+')').hide(); 
				if(i===0) $('#tabs-nav a').addClass("tabs-selected");
			}
		if (url.match('#')) {		
			// Get the name of the anchor used in the URL    
			var anc = '#' + url.split('#')[1];
			$('#tabs-nav a[href='+anc+']').addClass("tabs-selected"); }// < ADD THIS LINE
        })         
        $('#tabs-nav a').click(function(){                                        
            // get ID of tab to be shown -
            var id = '#'+this.href.split('#')[1];           
            // Hide all TABS -
            $('.tabs').hide();          
            // Show the tab which matches anchor's href -
            $(id).fadeIn(800);  
            $('a').removeClass("tabs-selected");
            $(this).addClass("tabs-selected");			
			// Removes the title attribute from the div so it does not showup on hover -
			$('.tabs').removeAttr('title');       
            // Don't forget to return false -
            return false;
           
        })
		//Creates the fadin and out on all links
			$("#tabs-nav li, a img, .SideNav a").hover(function(){
					$(this).fadeTo(350, 0.5); // This should set the opacity to 100% on hover
				},function(){
					$(this).fadeTo(450, 1.0); // This should set the opacity back to 60% on mouseout	
			});	
			
			//Creates the back to top link and adds the scroll
			//$('body').prepend('<a name="begin" id="Top"></a>');
			$('.footer').prepend(
			'<div class="back-to-top" style="display:block;text-align:right;padding:5px;"><a href="javascript:;">Back to Top</a></div>');			
			$('.back-to-top a').click(function(){ //this must come after the link is created above
				$('html, body').animate({scrollTop:0}, '900');	
			});
			
			//Adds a focus class to the parent element so you can see what field you are on 
			$(".Content input").focus(function() {
				$(this).parent().addClass("curFocus")
			});
				$(".Content input").blur(function() {
				$(this).parent().removeClass("curFocus")
			});	
			
			//Adds the print link to page and needs jquery.PrintArea.js in template
			//$('.bodySub .Content').append(
			//'<div id="print_button">Print</div>');
			//$("#print_button").click(function(){
			//	$(".Content").printArea();
			//});
			
			//Adds the icons after links and makes external links open in new window
			var fileTypes = {
			  doc: 'doc.gif',
			  xls: 'xls.gif',
			  pdf: 'pdf.gif'
			};
			 
			$('.Content a').each(function() {
			 
			  var $a = $(this);
			  var href = $a.attr('href');
			  
			  if (!$a.children('img').size()) { 
				  if ((href.match(/^http\:/i)) && (!href.match(document.domain))) {				 
					// use a special image for external links
					var image = 'extlink.gif';
					//makes external links open in new window
					$a.attr("target", "_blank"); 
				  } 				  
				  else {					  
						if (href.match(/^mailto\:/i)) {				 
						// use a special image for mailto links
						var image = 'mailto.gif';					
						}
						else {
						// get the extension from the href
						var hrefArray = href.split('.');
						var extension = hrefArray[hrefArray.length - 1];
						var image = fileTypes[extension];
					  }
				  }
				   if (image) {
					$a.after('<img src="/images/hacu/Template/css/img/icons/'+image+'" alt="Link Icon" align="absmiddle" style="margin:2px 3px 0px 4px;">');
				  }
				}
			});	
			
			//Makes links to the following file types open in new windows
			$("a[href*=.pdf]").attr("target", "_blank");
			$("a[href*=.doc]").attr("target", "_blank");  
			$("a[href*=.xls]").attr("target", "_blank");  
			$("a[href*=.ppt]").attr("target", "_blank"); 
			$("a[href*=.pps]").attr("target", "_blank");  	
				
				
			$(".Content img").each(function(){											   
					if ($(this).attr('width') > 550) {
						//alert('Change that biatch');
					$(this).removeAttr("style")
					$(this).attr({width: '525'});
					}
				});	
		
        });		

