function resize_window() {
		body_height = $('body').height();
		$("#blue_right").css({
			height: body_height
		});
		$("#grey_left").css({
			height: body_height
		});
}

function overlay_init() {
		var o_height = $(document).height();
		var w_height = $(window).height();
		var o_width = $(window).width();
		if (o_height > w_height){
			$("#staff_overlay, #video_overlay").css({
				'min-height': o_height,
				width: o_width,
				display: 'block'
			});
		}
		else {
			$("#staff_overlay, #video_overlay").css({
				'min-height': w_height,
				width: o_width,
				display: 'block'
			});
		}
}

$(window).load(function() {
	resize_window();
});

$(window).bind("resize", resize_window, overlay_init);

$(document).ready(function() {

	$('.accordion').fadeIn(300);

    // AJAX PREPEND
    $("body").prepend('<div id="overlay_container"></div>');
    $("body").append('<div id="blue_right"></div>');
    $("body").append('<div id="grey_left"></div>');

    // CALL RESIZE WINDOW
    resize_window();

	init_rel = $('ul#staff_manufacturing').attr('rel');
	$('ul#staff_manufacturing li.industry_summary ul').load('includes/ajax_job_feeds.php?industry=manufacturing&ae_count='+init_rel);

    $('#industry_showcase').liteAccordion({
        onActivate: function() {
            ind = $(this).parent('li').find('h2').attr('id');
			industry_ids = new Array();
			industry_ids['manufacturing'] = '2';
			industry_ids['pharmaceutical'] = '3';
			industry_ids['information_technology'] = '4';
			industry_ids['power_electronics'] = '7';
			industry_ids['distribution_logisitics'] = '6';
			industry_ids['retail'] = '5';
			industry_ids['quality'] = '8';
			industry_ids['it_sales'] = '9';
			industry_ids['construction'] = '10';
			industry_ids['power_generation'] = '11';
			ae_count = $('ul#staff_' +ind).attr('rel');
			
			$('ul#staff_' +ind + ' li.industry_summary ul').load('includes/ajax_job_feeds.php?industry='+ind+'&ae_count='+ae_count);
            $('ul.ae_preview').css('display', 'none');
            $('ul#staff_' + ind).css('display', 'block');
            lh = $('ul#' + ind).css('height');
            $('div#ae_list_container').css('height', lh);
			resize_window();
			
        },
        slideCallback: function() {},
        autoPlay: false,
        pauseOnHover: true,
        theme: 'dark',
        rounded: false,
        enumerateSlides: false
    });

	// STAFF OVERLAY INIT
	$('a.staff_overlay_button').click(function(){	
		$("#overlay_container").load("/includes/staff_overlay.php", function() {
			$('html, body').animate({scrollTop:0}, 'normal');
			$('div#staff_overlay').addClass('active_overlay');
			overlay_init();
			$('.youtube_iframe').hide();			
			$('ul#staff_overlay_list li').hover(
				function() {
					$(this).stop().animate({backgroundPosition: '0px -210px'}, 400, function() {
						$(this).find('.staff_overlay_blurb').stop().css('display', 'block');
					});
				}
				, 
				function() {
					$('.staff_overlay_blurb').stop().css('display', 'none');
					$('ul#staff_overlay_list li').stop().animate({backgroundPosition: '0px 0px'}, 400);
				}
			);
			$("ul#staff_overlay_list li div h3, ul#staff_overlay_list li div h4, ul#staff_overlay_list li div h5").click(function(){
				new_link = $(this).parent('div').find('a').attr('href');
				window.location = new_link;
				$(this).parent('div').find('a').trigger('click');
				return false;
			});
			$("ul#staff_overlay_list li").click(function(){
				new_link = $(this).find('a').attr('href');
				//console.log(new_link);
				window.location = new_link;
				$(this).parent('div').find('a').trigger('click');
				return false;
			});
		});
		return false;

	});
	
	
	// VIDEO OVERLAY INIT

	$('a#video_library_link').live('click', function(){	
		$("#overlay_container").load("/includes/video_overlay.php", function() {
			$('html, body').animate({scrollTop:0}, 'fast');
			$('div#video_overlay').addClass('active_overlay');
			video_overlay_fancybox();		
			overlay_init();	
			$('#overlay_close_button').click(function(){
				$("#overlay_container").empty();
				$('.youtube_iframe').show();
				return false;
			});
			$('.youtube_iframe').hide();
			setTimeout(overlay_init,500);

		});
		return false;
	});
	
	// OVERLAY CLICK CLOSE
    $('#staff_overlay').live('click', function (){
		$('.youtube_iframe').show();
		$('#overlay_container').empty();
    }); 
	
	
	// OVERLAY REFRESH
    $('#overlay_refresh_button').live('click', function (){
		return false;
    }); 
	
	
	// STAFF PANEL MENU
	$('a.staff_profile_button').click(function(){		
		var trigger = $(this).attr('id');
		$('a.staff_profile_button').removeClass('active');
		$(this).addClass('active');
		$('div.staff_profile_content').hide();
		$('div.staff_profile').find('div.'+trigger+'_region').show();
		return false;
	});
	
	// STAFF PANEL BACK BUTTON
	$('a.staff_profile_back').click(function(){	
		$('div.staff_profile').css('display', 'none');	
		$('div#staff_showcase').fadeOut(300, function() {
		$('div#industry_showcase').fadeIn(300);
            return false;
        });
	});
	
	// STAFF THUMB PROFILE INITIALIZE
	$('a.staff_profile_trigger').click(function(){
		var staffer_trigger = $(this).attr('href');
		$('div.staff_profile').css('display', 'none');
		$('div#industry_showcase').fadeOut(300, function() {
		$('div#staff_showcase').fadeIn(300);
			$('div.staff_profile_content').css('display', 'none');
			$('div.staff_profile').find('a.staff_profile_button').removeClass('active');
			$('div#'+staffer_trigger).fadeIn(200);
			$('div#'+staffer_trigger).find('div.staff_info_region').css('display', 'block');
			$('div#'+staffer_trigger).find('a#staff_info').addClass('active');
        });
		return false;
	});
	
    // STAFF NAME HOVER
    $('a.staffer_name_link').hover(
    function() {
        $(this).find("h3.staffer_name").css("color", "#bdeeff");
    }
    , 
    function() {
        $(this).find("h3.staffer_name").css("color", "#09c1ef");
	});
	
	
	// JOB BOARD RULES 
	
	// SEARCH SUBMIT 
	
	$("#form_submit_button").click(function(e){
		e.preventDefault();
		$(this).parents('form').submit();
	});
	
	
	// INDUSTRY SELECTOR
	
	$("#industry_selector").change(function(){
		var industry_selector_val = $(this).val();
		if (industry_selector_val != ""){
			//console.log(industry_selector_val);
			//console.log(industry_selector_val.toString());
			
			window.location = industry_selector_val;
		}
	});
	
	$("#job_search_submit").click(function(){
		$(this).parents("form").submit();
	});
	
	
	$('form.job_search_form h3').click(function(){										 
		$(this).parent('form').toggleClass('active');
		return false;
	});
	
	$('.form_toggle_btn').click(function(){										 
		$(this).parent('form').toggleClass('active');
		return false;
	});
	
	$('form.job_search_form.active').click(function(){
		if ($(this).hasClass('active')){													
			$(this).toggleClass('active').removeClass('hover');
		}
		return false;
	});
	
	$('form.job_search_form').hover(
		function(){
		if ($(this).hasClass('active')){													
			$(this).addClass('hover');
		}
		},
		function(){
			$(this).removeClass('hover');
		}
	);
	
	// STAFF PROFILE 
	
	$('#bio_toggle').click(
		function(){
			if ($(this).hasClass('active')){
				
				$(this).removeClass('active');
				$("#staff_bio").hide();

			}
			else {
				$(this).addClass('active');
				$("#staff_bio").show();

				$('#jobs_toggle').removeClass('active');
				$("#staff_jobs").hide();
				
			}
			
			resize_window();
			return false;

		}
	);
	
	$('#jobs_toggle').click(
		function(){
			if ($(this).hasClass('active')){
				$(this).removeClass('active');
				$("#staff_jobs").hide();
			}
			else{
				$(this).addClass('active');
				$("#staff_jobs").show();
		
				$('#bio_toggle').removeClass('active');
				$("#staff_bio").hide();
				
			}
			resize_window();
			return false;
		}
	);
	
	

    // GENERAL FORM RULES                               
    if ($("form").hasClass("body_form")) {
        $.getScript('/scripts/validate_rules.js');
        $.getScript('/scripts/jquery_placify.js');
        var count = 3;
        countdown = setInterval(function() {
            $("#timer").html("Please wait " + count + " seconds before you submit!");
            if (count == 0) {
                $('#timer').remove();
				$("#submit_container").html('<a href="#" class="submit_button "><span>Submit</span></a>');
                $(".submit_button").fadeIn('slow');
            }
            count--;
        }
        , 1000);
        $("a.submit_button").live('click', function() {
            $(this).parents("form").submit();
            return false;
        });
    }
});

