var swap_text_boxes = [];

function initialize_search()
{
	
	$('#keywords').addClass('search-greyed');
	//Store the default value for each box
	$('#keywords').each(function() {
	  swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
	});

	//Add focus and blur events to set or clear the value
	$('#keywords').bind('focus', function() {
	  if($(this).val() == swap_text_boxes[$(this).attr('id')]) {
	    $(this).removeClass('search-greyed');
		$(this).val('');
	  }
	});

	$('#keywords').bind('blur', function() {
	  if($(this).val() == '') {
		$(this).addClass('search-greyed');
	    $(this).val(swap_text_boxes[$(this).attr('id')]);
	  }
		});
}

$(document).ready(function(){
	initialize_search();

	var flashvars = {};
	flashvars.xml_url = "/sites/xml-video-gallery/";
	var params = {allowscriptaccess:"always"};
	var attributes = {id:"homepage-video"};
	swfobject.embedSWF("/flash/bowen_homepage_video.swf", "alternateContent", "585", "465", "9.0.45", false, flashvars, params, attributes);
	
	var flashvars2 = {};
	var params2 = {allowscriptaccess:"always", allowfullscreen:"true"};
	var attributes2 = {id:"flash-player"};
	swfobject.embedSWF("/featured_careers.swf", "flash-player", "550", "296", "9.0.45", false, flashvars2, params2, attributes2);

	var current ='all';
	
	// PROFILES SECTION
	$('#nav-sub-container ul.profiles-category-list li a').bind('click', function(){
		var profilesURL = "/api/profiles/";
		var id = this.id;
		$('#nav-sub-container li.here').removeClass('here');
		current = id;
		var url = (id != 'all') ? profilesURL+'category/'+id+'/' : profilesURL+'category/';
		$('#profiles-list').children().fadeOut("fast", loadList('#profiles-list ', url));
		$(this).parent().addClass('here');
		return false;
	})
	
	// PROJECTS SECTION
	$('#nav-sub-container ul.projects-category-list li a').bind('click', function(){
		var projectsURL = "/api/projects/";
		var id = this.id;
		$('#nav-sub-container li.here').removeClass('here');
		current = id;
		var url = (id != 'all') ? projectsURL+'category/'+id+'/' : projectsURL+'category/';
		$('#projects-list').children().fadeOut("fast", loadList('#projects-list', url));
		$(this).parent().addClass('here');
		return false;
	})
	
	if(window.location.hash.length > 0)
	{
		var hash = window.location.hash;
		var id = hash.replace('#', '');

		if($('#nav-sub-container ul.projects-category-list').length > 0)
		{
			var projectsURL = "/api/projects/";
			var url = (id != 'all') ? projectsURL+'category/'+id+'/' : projectsURL+'category/';
			$('#projects-list').children().fadeOut("fast", loadList('#projects-list', url));
			$('#nav-sub-container ul.projects-category-list a#'+id).parent().addClass('here');
		}

		if($('#nav-sub-container ul.profiles-category-list').length > 0)
		{
			var profilesURL = "/api/profiles/";
			var url = (id != 'all') ? profilesURL+'category/'+id+'/' : profilesURL+'category/';
			$('#profiles-list').children().fadeOut("fast", loadList('#profiles-list', url));
			$('#nav-sub-container ul.profiles-category-list a#'+id).parent().addClass('here');
		}
	}
	
	function loadList(load_list, url)
	{	
		$(load_list).addClass('loading');
		$(load_list).load(url, function(){$(load_list).removeClass('loading');});
	}
	
	if($('#slideshow').length > 0)
	{
		$('#slideshow').cycle({ 
		    prev:   '#slideshow-prev', 
		    next:   '#slideshow-next', 
		    timeout: 0,
			pager: '#slideshow-nav',
			pagerAnchorBuilder: function(idx, slide) {
				return '#slideshow-nav li:eq('+idx+') a';
			}
		});
	}
	
	$("#freeform").validate();

	if($('.zeroinjury-box-content-wrapper').length > 0)
	{
		$('.zeroinjury-box-content-wrapper').cycle({  
			fx: 'fade',
			speed: 1000,
			timeout: 12000
			});	
	}
	
});