/**
 * @author rgilbert
 */


jQuery(document).ready(function(){

if (jQuery(".staffSwitch").length>0) {
var cat = jQuery("#imgHolder").offset();
var cattop = cat.top;
console.log("script loaded, categories offset is " + cattop);


/*google analytics adds strange elements to single quotes - the #page selector was breaking, so I added double quotes - seems to be fixed now*/
  
    jQuery(".crossfade").each(function(i){
    
        /* Set all crossfading elements to display none and give a lower z-index value */
        jQuery(this).css({
            'position': 'absolute',
            'z-index': 50
        }).hide();
        
        /* Bring block 1 to the front and display it */
        if (i == 0) 
            jQuery(this).show().css('z-index', 100);
    });
    
        
    jQuery.fn.equalHeights = function(px) {
//console.log("equalHeights" + px)
	jQuery(this).each(function(){
		var currentTallest = 0;
		jQuery(this).children().each(function(i){
			if (jQuery(this).height() > currentTallest) { currentTallest = jQuery(this).height(); 
			console.log(currentTallest);
			};
		});
		//if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		//if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		jQuery(this).css({'height': currentTallest}); 
		var h=jQuery(this).height();
		console.log("height=" + h);
	});
	return this;
};

jQuery('#wrapper').equalHeights();

    jQuery(".staffSwitch").click(function(){
    
    	var offset=jQuery("div.active").offset();
  	var moreOffset=offset.top - 8;
	console.log("offset=" + offset.top);
	
        var selected = jQuery(jQuery(this).attr('href'));
        
        // get the adjacent elements to the selected one
        var siblings = selected.siblings();
        
        
        
        
        // increase the z-index of the adjacent elements (will work on one currently show) so that it stays ontop of the selected element and fade it out
        siblings.css('z-index', '100').fadeOut('medium', function(){
			selected.css('z-index', '50').fadeIn('slow');
			//jQuery("<div style='clear:both'></div>").appendTo(siblings);
			//jQuery('#wrapper').equalHeights();
			});
		 jQuery('html,body').animate({scrollTop: moreOffset});
        console.log(offset.top + ", " + moreOffset);
		return false;
		// reduce the z-index of the selected element as if previously selected it will be set at 100
		
		
		
    })
    
    }
    else {
    console.log("wrong page");
    	}
    
});




