$(document).ready(function(){
	// load initial section
    corporate = 'corporate-av';
    educate = 'educate-av';
    public = 'public-av';
    res = 'res-av';

    initial_section = corporate;
    block = '#' + initial_section + '-section';	   
	
	$(block).show();
	$('#' + initial_section).addClass(initial_section + '-selected');
	$('#' + initial_section).removeClass(initial_section);
	
	
	$('#head-contain #left div').mouseenter(function(){
													 
	
        selector = $(this).attr("id");
        newblock = '#' + selector + '-section';			
        
        if ($('#right ' + newblock).is(':visible')){
        } else {
            $('#' + corporate).addClass(corporate);
            $('#' + educate).addClass(educate);
            $('#' + public).addClass(public);
            $('#' + res).addClass(res);
            
            $('#' + corporate).removeClass(corporate + '-selected');
            $('#' + educate).removeClass(educate + '-selected');
            $('#' + public).removeClass(public + '-selected');
            $('#' + res).removeClass(res + '-selected');	
            
            
            $('#' + selector).addClass(selector + '-selected');
            
            
            $('#head-contain #right #corporate-av-section').hide();
            $('#head-contain #right #educate-av-section').hide();
            $('#head-contain #right #public-av-section').hide();
            $('#head-contain #right #res-av-section').hide();
            
            $(newblock).fadeIn('fast', function(){
                check();
            });
        }
    });
	
	
	// check to see if there is something displayed
	function check(){
		
		 count = 0;
		
		if ($('#' + public + '-section').is(':visible')){
			 count = count + 1;
		} else {
			 count = count - 1;
		}
		
		if ($('#' + educate + '-section').is(':visible')){
			 count = count + 1;
		} else {
			 count = count - 1;
		}		
		
		if ($('#' + corporate + '-section').is(':visible')){
			 count = count + 1;
		} else {
			 count = count - 1;
		}	
		
		if ($('#' + res + '-section').is(':visible')){
			 count = count + 1;
		} else {
			 count = count - 1;
		}			
		
		// if all sections are hidden then set it to the default block.		
		if (count == 0){

		
		$('#' + initial_section).addClass(initial_section + '-selected');
		$('#' + initial_section).removeClass(initial_section);
		
		$('#' + public).removeClass(public + '-selected');
		$('#' + educate).removeClass(educate + '-selected');
		$('#' + res).removeClass(res + '-selected');
		
		$('#' + public).addClass(public);
		$('#' + educate).addClass(educate);
		$('#' + res).addClass(res);
		
	
		$('#head-contain #right #corporate-av-section').hide();
		$('#head-contain #right #educate-av-section').hide();
		$('#head-contain #right #public-av-section').hide();
		$('#head-contain #right #res-av-section').hide();
		
		$(block).show();
		}
		
		if (count == -4){

		
		$('#' + initial_section).addClass(initial_section + '-selected');
		$('#' + initial_section).removeClass(initial_section);	
		
		$('#' + public).removeClass(public + '-selected');
		$('#' + educate).removeClass(educate + '-selected');
		$('#' + res).removeClass(res + '-selected');
		
		$('#' + public).addClass(public);
		$('#' + educate).addClass(educate);
		$('#' + res).addClass(res);
	
		$('#head-contain #right #corporate-av-section').hide();
		$('#head-contain #right #educate-av-section').hide();
		$('#head-contain #right #public-av-section').hide();
		$('#head-contain #right #res-av-section').hide();
		$(block).show();
		}
    }

    // linkify the images on the homepage lightbox thing
    var clickables = $('#left div[class*=-av]').click(function(e){
        if ($(this).attr('rel'))
            window.location = $(this).attr('rel');
    });
});




