jQuery(document).ready(function($) {
	
	var sdgal = {
		buttons: '<a href="#" id="g-next" class="g-nav">Next</a><a href="#" id="g-prev" class="g-nav">Previous</a>',
		pager: "#nav-inner",
		next: "#g-next",
		prev: "#g-prev",
		pagerAnchorBuilder: function(index, slide) {
			return "<a href='#"+index+"'><img src='"+galleryData[index].thumbnail+"' /></a>";
		}
	};
	
	var galleryElement = $("#gallery ul");
	
	if ( typeof("gallery") !== 'undefined' && galleryElement.children().size() > 1 ) {
		
		$("#gallery-nav").append(sdgal.buttons);
		galleryElement.cycle(sdgal);
		$("#nav-inner > a:first-child").addClass("first");	
	}
	else {
		$("#gallery-nav").hide();
	}
	
	// testing for css transition support: use them instead of animation if appropriate
	var cssTransitionsSupported = false;
	(function() {
		var div = document.createElement('div');
		div.setAttribute('style', 'transition:top 1s ease;-webkit-transition:top 1s ease;-moz-transition:top 1s ease;-o-transition:top 1s ease');
		cssTransitionsSupported = !!(div.style.transition || div.style.webkitTransition || div.style.MozTransition || div.style.OTransition );
		delete div;
	})();	
	
	// set up some hovers on a not-open menu for browsers without transitions
	
	if ( ! cssTransitionsSupported ) {
		$("#nav li.machines:not(.open)")
			.hover(function(ev) {
				$(this).addClass("show hover");

				$("ul.subs", this).stop().fadeTo(350, 1);

			}, function(ev) {
				var parent = $(this);
				parent.removeClass("hover");
				$("ul.subs", this).stop().fadeTo(150, 0, function(){
					parent.removeClass("show");
				});
			})
			.find("ul.subs").css('opacity', 0);
	}
	

});

jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
};
