$(function(){
	
	// button rollover
	if ($('.imgBtn, input#locatorBtn, input#newsletterBtn, .pages ul img') != null) {
	$('.imgBtn, input#locatorBtn, input#newsletterBtn, .pages ul img').hover(function(){
			$(this).attr("src", $(this).attr("src").replace(/^(.*?)(?:-hover)?(\..*?)$/i,'$1-hover$2'));
		},
		function(){
				$(this).attr("src", $(this).attr("src").replace(/^(.*)-hover(\..*?)$/i, '$1$2'));
			});
    }
	// menu rollover animation
	if ($('.nav a') != null) {
	    $('.nav a').hover(function(){
			    $(this).stop().animate({
					    paddingLeft: 25
				    }, 200);
		    },
		    function(){
				    $(this).stop().animate({
						    paddingLeft: 15
					    }, 200);
			    });
    }
    
	// menu rollover animation
	$(".nav .expanding").click(function(){
			if($(this).hasClass('expand')) {
				$(this).removeClass('expand').attr({href:'#'});
				$(this).next('ul').stop().css({
						height: $(this).next('ul').height()
					});
				$(this).next('ul').animate({
					    height: 0
				    }, 200, 'swing', function(){
							//alert($(this).html());
							$(this).children('.expand').each(function(){
									$(this).removeClass('expand').next().css({
											height: 0
										});
								});
						});
			}
			else {
				$(this).addClass('expand');
				var h = $(this).next('ul').stop().css({
						height: '100%'
					}).height();
				$(this).next('ul').css({
						height: 0
					})
				$(this).next('ul').animate({
					    height: h
				    }, 200, 'swing', function(){
							$(this).css({
									height: '100%'
								});
						});
			}
			return false;
		});
	if(typeof mID != 'undefined'){

		$('a#' + mID).parents('li.sub').children('.expanding').addClass('expand')
		$('a#' + mID).parents('ul.nav *').children('ul').each(function(){
			$(this).css({
					height: '100%'
			});
		});


		/*$('a[href=' + mURL + ']').parents('ul.nav *').children('.expanding').andSelf().addClass('expand').children('ul').each(function(){
				$(this).css({
						height: '100%'
					});
			});*/
	}
	if(typeof mURL != 'undefined'){

		$('a[href=' + mURL + ']').parents('li.sub').children('.expanding').addClass('expand').parents('li.sub').children('ul').each(function(){
					$(this).css({
							height: '100%'
						});
				});
		}

	// search field js
	if ($('#newsletter') != null) {
	    $('#newsletter').focus(function(){
			    if($(this).val() == 'Insert email')
				    $(this).val('');
		    });
    }
    if ($('#newsletter') != null) {
	    $('#newsletter').blur(function(){
			    if($(this).val() == '')
				    $(this).val('Insert email');
		    });
	}		
	// preload image rollovers
	if ($(".pages ul img, img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']") != null) {
	    $(".pages ul img, img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']").each(function(){
			    $("<img>").attr("src", $(this).attr("src").replace(/(btn-.*)(\..*?)/i, '$1-hover$2'));
		    });
    }
	// progressive enhancement
	if ($(".nav li:first-child") != null) 
	    $(".nav li:first-child").addClass("f");

	// JQuery Select Box
	if ($('#store') != null)
	    $('#store').selectbox({debug: true});
	
	// JQuery Select Box
	if ($('#storeSide') != null)
	    $('#storeSide').selectbox({debug: true});
	    
	// Smooth scrolling
	$('#scrollit').click(function() {
			var divOffset = $('#scrollable').offset().top;
			var pOffset = $('#scrollable p:eq(2)').offset().top;
			var pScroll = pOffset - divOffset;
			$('#scrollable').animate({scrollTop: '+=' + pScroll + 'px'}, 1000, 'bounceout');
		});
});

