$(document).ready(function() {
// Cufon
	//Cufon.replace('.caption h2, .caption p, .promoContent h2, .thumbs a', {hover: true});

// Watermarks
	watermark(jQuery('#searchInput'), 'Search');



// Navigation Dropdown
	function megaHoverOver(){
		$(this).find('a').not('.sub a').addClass('hover');
		$(this).find(".sub").stop(true, true).show();
	}

	function megaHoverOut(){
		$(this).find('a').removeClass('hover');
		$(this).find(".sub").stop(true, true).hide();
	}

	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 0, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 0, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("#nav li").hoverIntent(config);

// Navigation Hover Dim
	$('#overlay').css('opacity', .2);
	function dimIn(){
		$('#overlay').fadeIn(100);
	}

	function dimOut(){ 
		$('#overlay').fadeOut(100);
	}

	var config2 = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 0, // number = milliseconds for onMouseOver polling interval    
		 over: dimIn, // function = onMouseOver callback (REQUIRED)    
		 timeout: 100, // number = milliseconds delay before onMouseOut    
		 out: dimOut // function = onMouseOut callback (REQUIRED)    
	};

	$('#nav').hoverIntent(config2);

// Table Hover Highlighting and Sorting
	$('.assetTable').tableHover({
		colClass: 'hover',
		cellClass: 'hovercell',
		clickClass: 'click'
	}).tablesorter({
			 sortList: [[0,0]]  
		});;

// Managers Hover
	$('#managers li').hover(
		function(){
			$(this).find('a').fadeIn();
		},
		function(){
			$(this).find('a').fadeOut();
		}
	);

// Transparent Boxes Hover
	$('.carouselBox').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).css({'background-image':'url(_images/trans-gray-75.png)'});
		} else {
			$(this).css({'background-image':'url(_images/trans-gray.png)'});
		}
	});

// Homepage Gallery
/*	var gallery = $('#thumbs').galleriffic({
        delay:                     8500, // in milliseconds
        numThumbs:                 11, // The number of thumbnails to show page
        preloadAhead:              -1, // Set to -1 to preload all images
        enableTopPager:            false,
        enableBottomPager:         false,
        maxPagesToShow:            7,  // The maximum number of pages to display in either the top or bottom pager
        imageContainerSel:         '#slideshow', // The CSS selector for the element within which the main slideshow image should be rendered
        controlsContainerSel:      '#controls', // The CSS selector for the element within which the slideshow controls should be rendered
        captionContainerSel:       '#caption', // The CSS selector for the element within which the captions should be rendered
        loadingContainerSel:       '#loading', // The CSS selector for the element within which should be shown when an image is loading
        renderSSControls:          false, // Specifies whether the slideshow's Play and Pause links should be rendered
        renderNavControls:         false, // Specifies whether the slideshow's Next and Previous links should be rendered
        playLinkText:              'Play',
        pauseLinkText:             'Pause',
        prevLinkText:              'Previous',
        nextLinkText:              'Next',
        nextPageLinkText:          'Next &rsaquo;',
        prevPageLinkText:          '&lsaquo; Prev',
        enableHistory:             false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes
        enableKeyboardNavigation:  true, // Specifies whether keyboard navigation is enabled
        autoStart:                 true, // Specifies whether the slideshow should be playing or paused when the page first loads
        syncTransitions:           true, // Specifies whether the out and in transitions occur simultaneously or distinctly
        defaultTransitionDuration: 1500, // If using the default transitions, specifies the duration of the transitions
        onSlideChange:             undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
        onTransitionOut:           undefined, // accepts a delegate like such: function(slide, caption, isSync, callback) { ... }
        onTransitionIn:
        	function(slide, caption, isSync){
        		slide.fadeTo('slow', 1.0);
        		caption.fadeTo('slow', 1.0);
        		//Cufon.refresh();
        	}, // accepts a delegate like such: function(slide, caption, isSync) { ... }
        onPageTransitionOut:
        	function(callback) {
				this.fadeTo('slow', 0.0, callback);
			}, // accepts a delegate like such: function(callback) { ... }
        onPageTransitionIn:
        	function() {
				var prevPageLink = this.find('a.prev').css('opacity', .5);
				var nextPageLink = this.find('a.next').css('opacity', .5);
				
				// Show appropriate next / prev page links
				if (this.displayedPage > 0)
					prevPageLink.css('opacity', 1);
	
				var lastPage = this.getNumPages() - 1;
				if (this.displayedPage < lastPage)
					nextPageLink.css('opacity', 1);
	
				this.fadeTo('slow', 1.0);
				
			}, // accepts a delegate like such: function() { ... }
        onImageAdded:              undefined, // accepts a delegate like such: function(imageData, $li) { ... }
        onImageRemoved:            undefined  // accepts a delegate like such: function(imageData, $li) { ... }
    });
    
    gallery.find('a.prev').click(function(e) {
		gallery.previousPage();
		e.preventDefault();
	});

	gallery.find('a.next').click(function(e) {
		gallery.nextPage();
		e.preventDefault();
	}); */
}); 

function watermark(obj, text) {
    // set the watermark text
    jQuery(obj).val(text);
    
    // clear on focus
    jQuery(obj).focus(function() {
        if (jQuery(obj).val() == text) {
            jQuery(obj).val('');
        }
    });
    
    // restore on blur
    jQuery(obj).blur(function() {
        if (jQuery(obj).val() == '') {
            jQuery(obj).val(text);
        }
    });
}
