(function($) {
	var TRUE = true,
		FALSE = false,
		NULL = null,
		window = self,
		undefined,
		browserVersion = parseInt($.browser.version, 10),
		hasFlash = typeof swfobject != "undefined" && swfobject.hasFlashPlayerVersion("9"),
		isIE = typeof screen.fontSmoothingEnabled != "undefined",
		isIE8 = isIE && browserVersion === 8,
		isIE7 = isIE && browserVersion === 7,
		isIE6 = isIE && browserVersion === 6,
		pngfix = function(selectors) {
			if(typeof DD_belatedPNG == "undefined") {
				return;
			}
			else {
				$(window).load(function() {
					DD_belatedPNG.fix(selectors);
				});
			}
		},
		$html = $("html");
	
	$html.addClass("js-enabled");
	hasFlash && $html.addClass("flash-enabled");
	
	// On document ready:
	$(function() {
		var $body = $("body");

		// Open in a new window:
		$("a.external").attr({
			target: "_blank",
			title: function() {
				var t = this.title,
					tInfo = $(this).text() + " (opens in new window)";
				if(t && t != tInfo) { return t + " " + tInfo; }
				return tInfo;
			}
		});        
        
        // hole rollover
        jQuery.fn.fadeToggle = function(speed, easing, callback) { 
		   return this.animate({opacity: 'toggle'}, speed, easing, callback); 
		};
        $('.trigger').hover(function() {
			//$('.hole_popup').toggle();
			$(this).next('.hole_popup').toggle();
			return false;
		});
        
        // fade in hole detail
		$('.trigger').click(function() {
			$('.hole-info').hide();
			var $target = $($(this).attr('href'));
			$target.fadeIn();
			return false;
		});
		$('.next-hole').attr('alt','Next hole').click(function() {
			var $target_next = $($(this).attr('href'));
			$target_next.fadeIn();
			return false;
		});
			$('.next-hole').attr('alt','Next hole').click(function() {
				$(this).parent().parent().parent().hide();
			});
		$('.previous-hole').attr('alt','Previous hole').click(function() {
			var $target_previous = $($(this).attr('href'));
			$target_previous.fadeIn();
			return false;
		});
			$('.previous-hole').attr('alt','Previous hole').click(function() {
				$(this).parent().parent().parent().hide();
			});
		$('.close-hole').attr('alt','Close').click(function() {
			$('#'+$(this).attr('data-target')).fadeOut();
		});
		
		
		// home page rotators
		$('#course-swap').cycle({
		    fx: 'fade',
		    speed: 'fast',
		    timeout: 0,
		    next: '.next-course', prev: '.prev-course',
			cleartypeNoBg: true
		});
		$('#design-swap').cycle({
		    fx: 'fade',
		    speed: 'fast',
		    timeout: 0,
		    next: '.next-design', prev: '.prev-design'
		});
		$('#renovation-swap').cycle({
		    fx: 'fade',
		    speed: 'fast',
		    timeout: 0,
		    next: '.next-renovation', prev: '.prev-renovation'
		});
		$('#news-swap').cycle({
		    fx: 'fade',
		    speed: 'fast',
		    timeout: 0,
		    next: '.next-news', prev: '.prev-news',
			cleartypeNoBg: true
		});
		
		
		// footer hover items
		$('.download-list').hide();
		$('.download-item').hover(function() {
			$('.download-list').slideToggle('fast');
			return false;
		});
		$('.people-list').hide();
		$('.people-item').hover(function() {
			$('.people-list').slideToggle('fast');
			return false;
		});
		
	});
	
	// Cufon font-replacement:
	Cufon.replace(".site-nav a", {
		hover: TRUE
	});
	
	// IE6 helpers:
	pngfix("#header, #logo, .home #courses, .home #news, #courses-navigation li a:hover, .thumb-navigation li a:hover, .thumb-navigation li.current-menu-item a");
	isIE6 && document.createElement("abbr");
	
})(jQuery);
