$(document).ready(function(){
	// PNG fixes
	$("#global-nav-background, #kirklees-logo, .sub-nav-container, .sub-nav-footer, .mdd-bg, #skin-overlay").supersleight();
	
	
	// Accordion
	$("#popular-services").accordion({ autoHeight:false, active:0, collapsible:true });
	
	
	// Dropdowns
	$("#global-nav ul li").hover(function(){
		$(this).find("a.global").addClass("selected");
		//$(this).find(".sub-nav").delay(100).stop(true, true).css("display", "block");
		$(this).find(".sub-nav-container").delay(350).queue(function(){
			$(this).css("display", "block");
			$(this).dequeue();
		});
	}, function(){
		$(this).find("a.global").removeClass("selected");
		$(this).find(".sub-nav-container").dequeue();
		$(this).find(".sub-nav-container").css("display", "none");
	});
	
	
	// Tabs
	$("#feature-container").tabs({ fx:{ opacity:"toggle", duration:"fast" }}).tabs("rotate", 7000, true);
	/*$("#feature-container").hover(function(){
		$(this).tabs({ fx:{ opacity:"toggle", duration:"fast" }}).tabs("rotate", 0);
	}, function(){
		$(this).tabs({ fx:{ opacity:"toggle", duration:"fast" }}).tabs("rotate", 7000, true);
	});*/
	$("#featureToggle").toggle(function(){
		$("#feature-container").tabs({ fx:{ opacity:"toggle", duration:"fast" }}).tabs("rotate", 0);
		$(this).removeClass().addClass("paused");
		$(this).find("span").text("Play");
	}, function(){
		$("#feature-container").tabs({ fx:{ opacity:"toggle", duration:"fast" }}).tabs("rotate", 7000, true);
		$(this).removeClass().addClass("playing");
		$(this).find("span").text("Pause");
	});
	
	
	// Collapsable boxes
	$(".box a.collapse").toggle(function() {
		$(this).parents(".box:first").find(".inner").toggle();
		$(this).text("open");
	}, function() {
		$(this).parents(".box:first").find(".inner").toggle();
		$(this).text("close");
	});
	
	
	// Sortable boxes
	$("#right-column, #left-column").sortable({
		forcePlaceholderSize:"true",
		handle:"h2",
		items:".sortable",
		opacity:"0.6",
		placeholder:"highlight",
		revert:"slow",
		scroll:false,
		tolerance:"intersect",
		connectWith:"#right-column, #left-column"
	});
	
	
	// External links
	$("a[rel*='external'], a[rel*='pdf']").click(function() {
        window.open(this.href);
        return false;
    });
	$("a[rel*='external'], a[rel*='pdf']").attr("title", "Opens in a new browser window");
});
