$().ready(function(){	   
	$("#header_nav_links a[href='#login']").CreateBubblePopup({ 
															  innerHtml: 'Click to go to the login form.',
															  themeName: 'all-black',
															  themePath: 'images/jquerybubblepopup-theme' 
															  });
	
	$("#footer_nav_links a[href='?page=']").CreateBubblePopup({ 
															  innerHtml: 'Return to the home page.',
															  themeName: 'all-black',
															  themePath: 'images/jquerybubblepopup-theme'
															  });	
	$("#footer_nav_links a[href='?page=about_us']").CreateBubblePopup({ 
																innerHtml: 'Learn more about Gilchrist Construction Company.',
																themeName: 'all-black',
																themePath: 'images/jquerybubblepopup-theme' 
																});
	$("#footer_nav_links a[href='?page=careers']").CreateBubblePopup({ 
																innerHtml: 'Learn more about career opportunities at GGG.',
																themeName: 'all-black',
																themePath: 'images/jquerybubblepopup-theme' 
																});
	$("#footer_nav_links a[href='?page=safety']").CreateBubblePopup({ 
																innerHtml: 'Learn about our emphasis on safety or lookup MUTCD/Flagger Certificates.',
																themeName: 'all-black',
																themePath: 'images/jquerybubblepopup-theme' 
																});
	$("#footer_nav_links a[href='?page=community']").CreateBubblePopup({ 
																innerHtml: 'View some of our contributions we\'ve made back to the community.',
																themeName: 'all-black',
																themePath: 'images/jquerybubblepopup-theme' 
																});
	$("#footer_nav_links a[href='?page=awards']").CreateBubblePopup({ 
																innerHtml: 'Review some of GCC\'s awards.',
																themeName: 'all-black',
																themePath: 'images/jquerybubblepopup-theme' 
																});
	$("#footer_nav_links a[href='?page=contact_us']").CreateBubblePopup({ 
																innerHtml: 'How to get in touch with us.',
																themeName: 'all-black',
																themePath: 'images/jquerybubblepopup-theme' 
																});
	$("#footer_nav_links a[href='/equipment']").CreateBubblePopup({ 
																innerHtml: 'Browse our inventory of equipment for sale.',
																themeName: 'all-black',
																themePath: 'images/jquerybubblepopup-theme' 
																});
	
	
	$("a[href='#login']").click(function(){
		$('#username').focus();
		$("html").animate({ scrollTop: $(document).height() }, 1000);
		return false;
	});
	$("a[href='#top']").click(function() {
	  $("html").animate({ scrollTop: 1 }, 1000);
	  return false;
	});

	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$('#slideshow').show();
		$('#slideshow img,#slideshow span').hide();
		seed = Math.round(Math.random()*3);
		$('#slideshow img:eq('+seed+')').wrap('<center></center>').show();
	} else {
		$('#slideshow').coinslider({ hoverPause: true,width: 500 })
		$('#slideshow').show();
	}
	$('#logo').bind('click',function(){document.location = '?page='});
		
	
	$('a[href="?page='+page+'"]').addClass("currentPage");

	var background_offset = 0;
	if(page && page != 'home')
	{
		$('#slideshow_container').remove();
	}

	//$("#footer").css("height",$("#footer").height()+"px");
	    if((($('#footer').offset().top+$('#footer').height()+60) < $(document).height()))
		{//if the footer needs to be slapped down
			$('#footer').css('position','absolute');
			$('#footer').css('bottom','0px');
		}
    $(window).resize(function(){
        if((($('#footer').offset().top+$('#footer').height()+60) < $(document).height()))
		{//if the footer needs to be slapped down
			$('#footer').css('position','absolute');
			$('#footer').css('bottom','0px');
		}
    });

//login
	$('#security_question_block').hide();
	$('#login_form').submit(function(){
	if($('.login_type:checked').val()=='Main Website')
	{
			if($('#username').val() == '' || $('#password').val() == '')
			{
				alert('Please fill out the username and password fields.');	
			} else {
				$.post("Scripts/ldap.php",
				  { 
					  username: $("#username").val(), 
					  password: $("#password").val()
				  },
				  function(data){
				 
					if(data!="Unable to connect to the server." && data!="Your Username and/or Password were incorrect.") {
						$("#content").hide(500,function(){
							$("#content").html(data).show(500);
						});
					} else {
						alert(data);
					}
				
				});
			}
	return false;
	} else {//logging into MyGCC
		if($('#login_button').val()=='Login')
		{
			
			if($('#username').val() == '' || $('#password').val() == '')
			{
				alert('Please fill out the username and password fields.');	
			} else {
				if($('#question').val()=='')
					{
					$.get("Scripts/get_security_question.php", { username: $('#username').val() },
					function(data){
						if(data != '|') {
						
							data = data.split('|');
							
							$('#qid').val(data[0]);
							$('#security_question').text(data[1]);
							$('.mainsitelogin').hide(500);
							$('#security_question_block').show(500);
							$('#question').focus();
							
							return false;
							
						} else {//if it's their first login
							
							$('#login_form').unbind('submit');
							$('#submit').val('Login').click();
							return true;
							
						}
					}
					);
				} else {
					return true;
				}
			}
		}
	}

	return false;
	});

//end login

//apply online
$('#career_opportunity_banner img').bind('click',function(){
	document.location = 'http://www.gilchristconstruction.com/application';
});


//get projects list
$('#projects_list').load('Pages/projects.php h2:lt(9)',function(){
	var index = 0;
	$('#projects_list h2').each(function(){
		$(this).after('<li><a href="?page=projects&project='+index+'">'+$(this).text()+'</a></li>').remove();
		index++;
	});
	$('#projects_list').append('<li><a href="?page=projects"> &raquo; View All Projects...</a></li>');
});

//jobs page search
	if($('.job_opening').length>0)
	{
		//$('#content h2:eq(0)').after('Blah blah balha');
		$.each($('.job_opening'),function(){
			$(this).before('<div class="job_header">&bull;<u>'+$(this).find('.job_opening-title').text()+'</u></div>').hide();
		});
	}
	$('.job_header').live('click',function(){
			$(this).next().is(':visible')==true ? $(this).next().slideUp(500) : $(this).next().slideDown(500);
	});
});
