$.fn.dropdown = function() {
	$(this).hover(function(){
		$(this).addClass("hover");
		$('> .dir',this).addClass("open");
		$('ul:first',this).css('visibility', 'visible');
	},function() {
		$(this).removeClass("hover");
		$('.open',this).removeClass("open");
		$('ul:first',this).css('visibility', 'hidden');
	});
}

function megaHoverOut() { 
	$(this).find(".sub").stop().fadeTo('fast', 0, function() {
		$(this).hide(); 
	});
}

function megaHoverOver() {
	$(this).find(".sub").stop().fadeTo('fast', 1).show();
	(function($) {											//Calculate width of all ul's
		jQuery.fn.calcSubWidth = function() {
			rowWidth = 0;
			//Calculate row
			$(this).find("ul").each(function() {					
				rowWidth += $(this).width(); 
			});	
		};
	})(jQuery); 

	if ( $(this).find(".row").length > 0 ) {				//If row exists...
		var biggestRow = 0;
		$(this).find(".row").each(function() {				//Calculate each row
			$(this).calcSubWidth();
			if(rowWidth > biggestRow) {						//Find biggest row
				biggestRow = rowWidth;
			}
		});
		$(this).find(".sub").css({'width' :biggestRow});	//Set width
		$(this).find(".row:last").css({'margin':'0'});
	} else {												//If row does not exist...
		$(this).calcSubWidth();
		$(this).find(".sub").css({'width' : rowWidth});		//Set Width
	}
}



$(document).ready(function() {

	$(".DnBtn").hover(function() {
		var btnurl = $(this).attr("src").replace("_off", "_on");
		$(this).attr("src",btnurl);
	}, function() {
		var btnurl = $(this).attr("src").replace("_on", "_off");
		$(this).attr("src",btnurl);
	});
	
// Top DropDownMenu

	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: 300, // number = milliseconds delay before onMouseOut    
		out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
	
// Left DropDownMenu
 
	$("ul.dropdown li").dropdown();

// MouseOver Thumbnails

	$('div.thumb').hover(function() {
		$(this).css({'z-index' : '1000'});
		$(this).find('img').addClass("hover").stop()
			.animate({
				marginTop: '-110px', 
				marginLeft: '-110px', 
				top: '50%', 
				left: '50%', 
				width: '200px', 
				height: '200px',
				padding: '0px' 
			}, 200);
	}, function() {
		$(this).css({'z-index' : '0'});
		$(this).find('img').removeClass("hover").stop()
			.animate({
				marginTop: '0', 
				marginLeft: '0',
				top: '3', 
				left: '3', 
				width: '100px', 
				height: '100px', 
				padding: '0px'
			}, 400);
	});

// PrettyPhoto

	$("a[rel^='prettyPhoto']").prettyPhoto({
		theme:'facebook'
	});

});

