jQuery.fn.modal = function() {
	return this.each(function(){
		var ah = $(this).height();
        var wh = $(window).height();
        var nh = (wh/2) - (ah/2);
 
        var aw = $(this).width();
        var ww = $(window).width();
        var nw = (ww/2) - (aw/2);
 
        // Trim body height, append overlay, and disable scrolling (this can be undone with a custom close button)
        $("body").height(wh).css('overflow','hidden').append('<div class="overlay"><\/div>');
        $(".overlay").fadeTo("slow", .8);
        $(this).css({'top':nh, 'left':nw}).fadeIn("slow");
	});
};

jQuery.fn.sticky = function() {
	return this.each(function(){

		// First, lets absolutely position our element where it already is		
		$(this).css(
			{ 
				'position'	: 'fixed',
				'top'		: $(this).offset().top,
				'left'		: $(this).offset().left 
			}
		);
		
		/* If i ever get to it, I might make this scroll or something cool
		var mTop = $(window).height()/3;
		var mLeft = ($(window).width()-$(".cloud").width())/2;
		
		$("#subscribe").css({top: mTop});
		
		var name = "#subscribe";
		var menuYloc = null;
		
		menuYloc = parseInt( $(name).css("top").substring(0,$(name).css("top").indexOf("px")) );
		$(window).scroll(function () {
			var offset = menuYloc+$(document).scrollTop()+"px";
			$(name).animate({top:offset},{duration:500,queue:false});
		});
		*/

	});
};

$(document).ready( function () {
	$('.nav-top li').hover(
		function () { $(this).children('ul').slideDown(); },
		function () { $(this).children('ul').hide(); }
	);
	
	$('.nav-left li').hover(
		function () { $(this).children('ul').slideDown(); },
		function () { $(this).children('ul').hide(); }
	);
	
	$('#menu-left-menu > li:nth-child(1)').addClass('startups');
	$('#menu-left-menu > li:nth-child(2)').addClass('entrepreneur');
	$('#menu-left-menu > li:nth-child(3)').addClass('gear');
	$('#menu-left-menu > li:nth-child(4)').addClass('business');
	$('#menu-left-menu > li:nth-child(5)').addClass('tv');
	
	$('#logo-martini')
		.click(function(){
			$('html, body').animate({scrollTop: '0px'}, 300);
		    return false;
		})
		.sticky();
	
	


	setInterval( function () {
		$('#sub-logo').animate({'opacity':.5}, 1000);
		$('#sub-logo').animate({'opacity':1}, 1000);			
	}, 1000 )

	
/*
	$('.accordian h2').click( function () {
		if ( $(this).hasClass('ui-state-active') )
			window.location = $(this).children('a').attr('href');
	});
	
	
	$('.accordian').accordion({ 
		header: 'h2',
		autoHeight: false,
		event:		'click'
	});
*/
	
	
	$('.quick-view').fancybox({ 
		overlayColor: '#000',
		transitionIn: 'elastic',
		transitionOut: 'elastic',
		overlayOpacity: .8,
		centerOnScroll: true
	});
});
