function showLocations() {
	if (!$("#storeLocations").is(":visible")) {
		$("#storeLocations").slideDown('fast');
	} else {
		hideLocations();
	}
}

function hideLocations() {
	$("#storeLocations").slideUp('fast');
}


$(document).ready(function() {

	$("#nav a").hover(
				// over
				function(){
					// store the original image src
					$(this).children(":first-child").attr( "originalsrc" , $(this).children(":first-child").attr("src") );
					
					// add -over to the image unless it is already -over
					if (!$(this).children(":first-child").attr("src").match(/-over/) ) {
						$(this).children(":first-child").attr( "src", $(this).children(":first-child").attr("src").replace(/\./, "-over.") );
					}
					
				},
				
				// out
				function(){
					// replace the original src
					$(this).children(":first-child").attr(
						"src", $(this).children(":first-child").attr("originalsrc")
					);
					
					$(this).children(":first-child").attr(
						"originalsrc", null
					);
				}
			);


			
			$('.box, .accordian').cornerz({
				radius: 5
			});
			
			
			$('#bannerLinks a').cornerz({
				radius: 5,
				corners : "bl br"
			});
			
			
			
			
			$('.accordian dt.first').cornerz({
				radius: 5,
				corners : "bl br"
			});
			

			
			$('.accordian dt').not(".first").cornerz({
				radius: 5
			});
			
			

			
			
		$('a[rel*=lightbox]').lightBox({
				imageLoading: '/images/lightbox/ico-loading.gif',
				imageBtnClose: '/images/lightbox/btn-close.gif',
				imageBtnPrev: '/images/lightbox/btn-prev.gif',
				imageBtnNext: '/images/lightbox/btn-next.gif',
				imageBlank: '/images/lightbox/blank.gif'
	   		});
			
			
			$(".accordian dt").click(function() {
				if ($(this).next("dd").is(":hidden")) {
					var selected = $(this);
					$(".accordian dd:visible").slideUp('fast', function(){
						selected.next("dd").slideDown('fast');
					});
					
					// swap the plus/minus
					$(".accordian dt img").attr("src", "/images/plus.gif");
					$(this).children("img").attr("src", "/images/minus.gif");
				}
			});
		
		
		$("#bannerLinks a").click(function(){
		
			
			var theDiv = $(this).attr("href").substring(1);
			theDiv = theDiv.replace(/\/$/, "");
			showBanner(theDiv);

			// track it
			pageTracker._trackEvent('Home Banner Click', theDiv);
			
			// reset
			$('#bannerLinks a').each(function() {
				$(this).css('color', '#ffffff');
			});
			
			// set selected
			$(this).css('color', '#6A5648');
						
			return false;
		});
		
			
});

window.onload = function() {
		// preload
		$("#nav a img").each(
			function() {
				if (!$(this).attr("src").match(/-over/) ) {
					$("<img>").attr( "src", $(this).attr("src").replace(/\./, "-over.") );
				}
			}
		);
}


function showBanner(theDiv) {
	$("#banners div.banner:visible").hide();
	$("#" + theDiv).fadeIn();
}
