$(window).load(function() {

	
	// select search bar
	$('#top_bar_content form').click(function() { $(this).children().select(); $(this).children().css({ 'color' : '#333' }); });
	
	// to disable css (in case they do not have javascript)
	$('ul#nav li:hover > ul').css({ 'display' : 'none' });

	$('ul#nav li').children('ul').children('li').parents('ul').parents('li').each(function() {
		if ( $(this).children('ul').size() > 0 ) { 
			$(this).addClass('level_1 children'); 
			$(this).children('a').addClass('subnav'); 
			$(this).children('ul').children('li').removeClass('level_1 children'); 
		}
	});
	
	// add image of an arrow if the li has a subnav 
	$('#nav li.level_1').append('<img src="http://www.cppi.com/public/images/nav_rollover_arrow.png" />');
	
	// add image of arrow if a subnav li has a third level nav
	$('#nav li ul.level_2 li ul').parent().children('img').remove();
	$('#nav li ul.level_2 li ul').parent().append('<img src="http://www.cppi.com/public/images/nav_subnav_arrow.png" />');
	
	// add classes to clean up markup, for borders 
	$('ul#nav li:first').addClass('first');
	$('ul#nav li:last').addClass('last');
	$('ul.level_2 li:last').parents('li').addClass('bottom');
	
	$('ul#nav li ul li ul li:first').addClass('first');
	$('ul#nav li ul li ul li:last').addClass('last');
	
	// hover function for all navigation with sub_levels
	$('#nav li').hover(
		function() {
			$(this).children('img').hide();
			$(this).children('ul.level_2')
						.parents('li')
							.children('a')
								.css({ 'background-image' : 'url(http://www.cppi.com/public/images/nav_sub_rollover.jpg)', 'color' : '#bfa357', 'text-shadow' : 'none' })
									.addClass('hovered');
			$(this).animate({ opacity : .98 });
			$(this).children('ul').stop(true, true).slideDown();
		},
		function() {
			$(this).children('img').show();
			$(this).children('ul.level_2')
						.parents('li')
							.children('a')
								.css({ 'background-image' : 'none', 'color' : '#494949', 'text-shadow' : '0px 1px 0px rgba(255,255,255,.2)' })
									.removeClass('hovered');
			$(this).children('ul').stop(true, true).slideUp(100);
		}
	);	
	
	// zebra stripes
	$("tr:nth-child(odd)").addClass("odd");
	
	// hover opacity state for images with the class of hover
	$('a img').hover(
	function(){
		$(this).stop(true, true).animate({ opacity : .6 }, 250);
	}, 
	function(){
		$(this).stop(true, true).animate({ opacity : 1 }, 250);
	});
	
	$('#logos a img').animate({ opacity : .5 });
	$('#logos a img').hover(
	function(){
		$(this).stop(true, true).animate({ opacity : 1 }, 250);
	}, 
	function(){
		$(this).stop(true, true).animate({ opacity : .5 }, 250);
	});

	// $('#slider').append('<div class="overlay_image"></div>');
	
	$('.first_c h4').click(function(){
		var current_login = $(this).attr('class');
		if(current_login == 'login_employee') { 
			$(this).next().show(); 
			$('.log_client').hide(); 
		}
		if(current_login == 'login_client') { 
			$(this).next().show(); 
			$('.log_employee').hide();
		}
	});
	
	var sidebar_height = $('.sidebar').height();
	var full_page = $('.full_page').height();
	var twenty_percent = full_page / 3;
	$('.sidebar').height(full_page + twenty_percent);
});
