$(function() {
	
 	// If the User has a cookie set with the name of popup, then dont load the movie
 	if ($.cookie("popup")) { } 
 	
 	// If they do not, this means they haven't visited the site yet or the cookie has expired 
 	// So therefore load the movie here. 
 	else { window.open('http://financialpicture.com/Ingram/boxvideo.html', '', 'height=520,width=870,scrollbars=no'); }
	
	// set cookie with the name of popup, the value of video, and an expiration date of 5 days
	$.cookie("popup", "video", { expires: 5 });
	
	// The box shadows on the homepage 
	var boxes = $('.shadow');
	boxes.append('<div class="top_shadow"></div>');
	boxes.append('<div class="right_shadow"></div>');
	boxes.append('<div class="bottom_shadow"></div>');
	boxes.append('<div class="left_shadow"></div>');
	
	// The inner shadow for the subnavigation rollovers
	$('ul#navigation li#primary ul li').hover(
		function() {
			$(this).append('<div class="sn_top_left"></div>');
			$(this).append('<div class="sn_top"></div>');
			$(this).append('<div class="sn_top_right"></div>');
			$(this).append('<div class="sn_right"></div>');
			$(this).append('<div class="sn_bottom_right"></div>');
			$(this).append('<div class="sn_bottom"></div>');
			$(this).append('<div class="sn_bottom_left"></div>');
			$(this).append('<div class="sn_left"></div>');
		}, 								 
		function() { 
			$(this).not('.selected').children('div').remove();	
		}
	);
	
	// The subnavigation selected inner shadows
	var sn_selected = $('ul#navigation li ul li.selected');
	sn_selected.append('<div class="sn_top_left"></div>');
	sn_selected.append('<div class="sn_top"></div>');
	sn_selected.append('<div class="sn_top_right"></div>');
	sn_selected.append('<div class="sn_right"></div>');
	sn_selected.append('<div class="sn_bottom_right"></div>');
	sn_selected.append('<div class="sn_bottom"></div>');
	sn_selected.append('<div class="sn_bottom_left"></div>');
	sn_selected.append('<div class="sn_left"></div>');

	
	// add selected class to the primary nav bar depending on subnav location
	$('ul#navigation li ul li.selected').parents('#primary').addClass('selected');
	
	// Accordian Menu's 
	/* $("#accordion").accordion({ autoHeight: false }); */
	$('#accordion').parent().children().children('a').click(function() {
		
		$(this).next().slideToggle().animate({ opacity : 100 });;
		$(this).toggleClass('active');
		return false;
	}).next().hide();

	$('.show').click(function() {
		$(this).parent().children('div').slideDown('fast').animate({ opacity : 100 });
		$(this).parent().children('a').addClass('active');
		return false;
	});
	
	$('.close').click(function() {
		$(this).parent().children('div').slideUp('fast');
		$(this).parent().children('a').removeClass('active');
		return false;
	});
	
	// Match heights in left, right columns
	var  leftHeight = $('.left').height();
	$('.right').height(leftHeight);

	// popup movie when clicked
	$('#movie').click(function() {
		window.open($(this).attr('href'), '', 'height=520,width=870,scrollbars=no');
	 	return false;
	});

	// popup page when clicked, on the insurance page
	$('.ins_links').click(function() {
		window.open($(this).attr('href'), '', 'height=425,width=675,scrollbars=no');
	 	return false;
	});
	
	// popup page when clicked, on the insurance page
	$('.ins_quote').click(function() {
		window.open($(this).attr('href'), '', 'height=750,width=715,scrollbars=yes');
	 	return false;
	});
	
	// employee login
	$('#e_login').click(function() {
		
		// append the overlay and fade the screen to 75% opacity
		$('body').append('<div class="overlay"></div>');
		$('.overlay').animate({ opacity : .75 }).fadeIn();
		
		// append the login box 
		$('body').append('<div class="login_container"></div>');
		$('.login_container').fadeIn();
		
		var current_page = $('#current_page').attr('title');
		if (current_page == '') { 
			$('.login_container').load('index.php/login', 
				function(){ 
					$('input#cancel').click(function() {
						$('.login_container').fadeOut();
						$('.overlay').fadeOut();
					});				
				});
		} else { 
			$('.login_container').load('login', 
				function(){ 
					$('input#cancel').click(function() {
						$('.login_container').fadeOut();
						$('.overlay').fadeOut();
					});				
				});
		}
		
		return false;
	});
	
});