$(document).ready(function() {

	$('#in-hidden-drawer-products li').hover(function() {
		$(this).stop(true).animate({opacity: 1});
	}, function() {
		$(this).stop(true).animate({opacity: 0});	
	});
	$('.input-box').each(function() {
		this.text = this.value;
	});
	$('.input-box').focus(function() {
		if( $(this).val() == this.text ) {
			$(this).val('');
		}
	});
	$('.input-box').blur(function() {
		if( $(this).val() == '' ) {
			$(this).val(this.text);
		}
	});


	//Navigation Stuff
	$('#left-menu ul li ul').each(function() {
		
		var this_offset = $(this).offset();
		var this_height = $(this).height();
		
		$(this).parent().hover(function() {
			
			var scroll = document.documentElement.scrollTop;		
			var this_offset = $(this).find('>ul').offset();
			var parent_li_offset = $(this).offset();
			
			if( (Math.round(this_offset.top+this_height)-scroll) > window_height ) {
						
				//alert($(this).find('>ul').css('position'));
				//$(this).find('>ul').css('top','-150px');
						
				if( $(this).find('ul').length > 0 ) {
					//get parent top
					var parent_li_bottom = (parent_li_offset.top)+$(this).height();
				}
				
				this.top_value = $(this).find('>ul').offset().top - parent_li_offset.top;
				var height = $(this).find('>ul').height();
				var offset = Math.round(this_offset.top+this_height) - Math.round(scroll+window_height);
				$(this).find('>ul').css({height: height+'px'}).animate({top: '-'+offset+'px'});
				$(this).find('>ul img').animate({top: (offset+65)+'px'});
			}
			
		}, function() {
			$(this).find('>ul').animate({top: '20px'});
			$(this).find('>ul img').css('position','absolute').animate({top: '50px'});
		});

		
	});

	//Navigation Code
	$('#left-menu #listMenuRoot li ul').each(function() {
	
		if( $(this).find('li').length < 2 ) {
			$(this).remove();
		}
		
		$(this).append('<img src="images/arrow.png" class="arrow-styles" />');
		
	});

});

var window_height = $(window).height();

var sfEls;
//Make all this IE7 Specific?!!
sfHover = function() {
	sfEls = document.getElementById("listMenuRoot").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			for( var x = 0; x < sfEls.length; x++ ) {
				if( x != i )
					sfEls[x].className=sfEls[x].className.replace(' sfhover','');
			}
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(' sfhover','');
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

