// runs before images load (chrome)
$(function(){
	
});

// runs after images load (chrome)
$(window).load(function() {
	var document_height = $(document).height();
	$('#sidebar').height('500px');
	$('#sidebar .accordion').css({'display':'none'});
	
	// clear form fiels on focus
	$('.search input[type=text]').clearField();
	$('.form input[type=text],.form input[type=password]').focus(function() {
		$(this).parent().addClass('focused');
	});
	$('.form input[type=text],.form input[type=password]').focusout(function() {
		$(this).parent().removeClass('focused');
	});
	
	// sidebar accordion
	$('#sidebar h3 img').toggle(
		function(){
			$(this).attr('src', $(this).attr('src').replace('hide', 'show'));
			$(this).parent().next().stop(false,true).slideUp();
		},
		function(){
			$(this).attr('src', $(this).attr('src').replace('show', 'hide'));
			$(this).parent().next().stop(false,true).slideDown();
		}
	);
	
	// tab submenu
	$('.tabs li').hover(
		function(){
			$(this).children('ul').stop(false,true).fadeIn(200);
		},
		function(){
			$(this).children('ul').stop(false,true).fadeOut(200);
		}
	);
	// $('.tabs li').bind({
		// mouseenter: function(){
			// $(this).stop();
			// $(this).children('ul').fadeIn(200);
		// },
		// mouseleave: function(){
			// $(this).stop();
			// $(this).children('ul').fadeOut(200);
		// }
	// });
	
	// sidebar hide/show
	$('#sidebar .toggle').toggle(
		function(){
			var sidebar_height = $('#sidebar .accordion').height();
			$('#sidebar .toggle img').attr('src', $('#sidebar .toggle img').attr('src').replace('_off', '_on'));
			$('html').height(document_height + 50);
			$('#sidebar .accordion').css({'display':'block'});
			$(this).parent().animate({'left':'0'}, 200).css({'height':sidebar_height});
		},
		function(){
			$('#sidebar .toggle img').attr('src', $('#sidebar .toggle img').attr('src').replace('_on', '_off'));
			$('#sidebar .accordion').css({'display':'none'});
			$(this).parent().animate({'left':'-423px'}, 200).css({'height':'500px'});
			$('html').height('auto');
		}
	);
});
