function showHide(theID) { // written by Rob to show/hide a DIV (identified by ID)
	if(document.getElementById(theID).style.display == 'none') {
			document.getElementById(theID).style.display = 'block';
	} else {
			document.getElementById(theID).style.display = 'none';
	}
}

$(document).ready(function() {
	$(".lightbox").lightbox();
	$('.homeRotator').cycle({
	fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}
 	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 200, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};
 
	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config); 
	$('a').filter(function() {
	    return this.hostname && this.hostname !== location.hostname;
	  })
	  .click(function () { 
		  var x=window.confirm('You are about to leave winchesterva.gov. Any link (including hyperlinks, buttons, or referral devices of any kind) used on this or any other City of Winchester site is provided for the use and convenience of the visitor. The appearance of a link on this or any other City of Winchester site does not constitute an endorsement, recommendation, or certification by the City of Winchester of the third party site, nor should the presence of a link in any way be construed as a suggestion that the site has any relationship with the City of Winchester. The City of Winchester does not endorse these sites, is not responsible for their content, and can not assure that the information contained therein will be accurate, reliable, helpful, or useful. The City of Winchester expressly disclaims any and all responsibility and liability for the information presented on a site linked from the City of Winchester web site including any errors and/or omissions which may appear in those third party sites. Click OK to proceed or Cancel to stay at winchesterva.gov.');
			var val = false;
			if (x)
				val = true;
			else
				val = false;
			return val;
 
        });
// grab each link on the page
    $('a').each(function() {
    
        // extract the link address from the link
        var strLink = $(this).attr("href");
    
        // check if its a link to one of our list
        if (IsLocalTrackableLink(strLink)) {
        
            // add an onclick method to it
            $(this).click(function() {
            
                // run the google page view function
                pageTracker._trackPageview(strLink);
            });
        } 
    });
		function IsLocalTrackableLink(linkUrl) {
				// check that a link is not null, local, 
				// and contains our file extensions
				if (linkUrl != null && 
						linkUrl.indexOf("http://") < 0 && 
						linkUrl.match(/\.(?:doc|xls|pdf|zip|rar|exe|mp3)($|\&|\?)/)) {
						return true;
				}
				return false;
		}
});
