jQuery(document).ready(function() {

// NAV DROP DOWN

    jQuery("#siteNav li").hover(function(){
    
        $(this).addClass("hover");
        $('div:first',this).css('visibility', 'visible');
    
    }, function(){
   
        $(this).removeClass("hover");
        $('div:first',this).css('visibility', 'hidden');
    
    });

	jQuery('#siteNav ul li:last-child').addClass('last');

// HOMEPAGE SLIDE

	jQuery('#slides, #diningSlides').cycle({
	startingSlide: 0,
    fx: 'fade',
	speed: 2000,
    timeout: 10000,
    delay: 3500,
    requeueOnImageNotLoaded: true,
    requeueTimeout:  3000,
    slideExpr: 'div.slide',
	pager: 'div#thumbs',
	// callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) {
    var imgsrc = $(slide).find('img').attr('src');
    // alert(imgsrc);
       return '<a href="#"><img src="'+ imgsrc +'" width="50" /></a>';
    }
	});


// BREAD CRUMB STYLE
	
    if (jQuery('#pageHead h2 a').length) {
    jQuery('#pageHead h2 a:first-child').wrap('<span>');
    } else {
    jQuery('#pageHead h2').wrapInner('<span>');
    }

// SIDEBAR COLLAPSABLE MENU

	// find list item that contains children list items
	var hasGrandchild = jQuery('#pageNav li:has("ul")');
	
	// create expand button for list item that has children
	hasGrandchild.children('a:first-child').after('<a class="exp" href="#">+</a>');
	// hide children 
	hasGrandchild.children('ul').hide();
	
	// show children if parent is active
	var active = jQuery('#pageNav li.active');
	
    active.children('ul:first').show().prev().html('&ndash;');
    active.parents('ul').show().prev().html('&ndash;');
    
    // active.parents('ul').show().prev().html('&ndash;');	
	// active.parent().find('ul').show().prev().html('&ndash;');
	
	jQuery('a.exp').click(function() {
	if(jQuery(this).next().is(":hidden")) {jQuery(this).html('&ndash;').next().slideDown();} else if ($(this).next().is(":visible")) {jQuery(this).html('+').next().slideUp();}
	return false;
	});



// STAFF LIST

	// apply class to last row of staff members
	jQuery('ul#staffList li:last').addClass('lastRow').prev().addClass('lastRow');
	
    // define staff window vars
	var profileWin = 'div.profileWindow';
    
    // click event
    jQuery('#staffList li a, td.trainer a').click(function() {
        
    if (jQuery(profileWin).length == 0) {
    
    var toLoad = jQuery(this).attr('href')+ ' #viewStaff'; 
	
    // append load icon
	jQuery('#ajaxStaffLoad').stop().after('<div id="loadIcon">loading</div>').stop().load(toLoad,
    function() {
    	jQuery('#loadIcon').fadeOut('fast', function() {$(this).remove();});
        
        // number of pixels browser viewport from top
    	var staffTop = $(window).scrollTop();

        jQuery('#viewStaff').css('top',  (staffTop+140) + 'px').hide().fadeIn('slow').append('<div class="closeProfile"><a href="#">Close Window</a></div>');
        jQuery('div.closeProfile').click(function() {
        closeContent();

        return false;
        })
    });
    
         }
  
    return false;  
    
    });
    
    function closeContent() {
    jQuery('#viewStaff').fadeOut('fast', function() {jQuery(this).remove();});
    }
    
    // escape key hide window
	jQuery(document).keyup(function(event){
    if (event.keyCode == 27) {closeContent();}
	});
	
// LIGHTBOX FOR GALLERY

	jQuery('a.galItem').colorbox({
    maxWidth: 800,
    maxHeight: 600,
    onComplete: function() {$('#cboxTitle:empty').hide();}
    });

// SELECT BOXES STYLIZED
	jQuery('select#specialty, #userForm select').sSelect();

// SITEMAP STYLES
	jQuery('#siteParent ul#nav > li > a:first-child').addClass('first');
    jQuery('#siteParent ul#nav > li:even').addClass('reg');
    jQuery('#siteParent ul#nav > li:odd').addClass('alt');

// LOGIN IN HEADER

$('#uLogin form').append('<a class="close" href="#">X</a>');
$('#uLogin a').click(function() {
	$('#uLogin form').fadeIn('fast');
    return false;
});
$('#uLogin a.close').click(function() {
	$('#uLogin form').fadeOut('fast');
    return false;
});

});
