$(document).ready(function() {
	menuItems();
	menuItemCurrent();
	galleryThumbs();
	buttonBehaviour();
	
});


function menuItems() {
	$("#menu li a img").each(function(i) {
		$(this).hover( 		function()	{$(this).animate({ marginTop: -50 }, 1);}, function(){$(this).animate({marginTop: 0}, 1);} );
		$(this).mousedown(	function()	{$(this).animate({ marginTop: -50 }, 1);});
		$(this).mouseup(	function()	{$(this).animate({ marginTop: -50 }, 1);});
	});
}
function menuItemCurrent() {
	$("#menu li a.current img").each(function(i) {
		$(this).hover(		function()	{$(this).animate({ marginTop: -150 }, 0); },function(){$(this).animate({ marginTop: -150 }, 0);} );
		$(this).mousedown(	function()	{$(this).animate({ marginTop: -150 }, 0);});
		$(this).mouseup(	function()	{$(this).animate({ marginTop: -150 }, 0);});
	});
}

function galleryThumbs() {
	$(".thumbs li.thumb a").each(function(i)	{
		$(this).hover(		function()	{$(this).animate({ marginTop: 0 }, 50);},	function(){$(this).animate({ marginTop: 0 }, 50);} );
		$(this).mousedown(	function()	{$(this).animate({ marginTop: 1 }, 50);	});
		$(this).mouseup(	function()	{$(this).animate({ marginTop: 0 }, 50);});
	});
}

function buttonBehaviour() {
	$(".formbutton").each(function(i)	{
		$(this).hover(		function()	{$(this).animate({ marginTop: -50 }, 1); },	function(){$(this).animate({ marginTop: 0 }, 1);});
		$(this).mousedown(	function()	{$(this).animate({ marginTop: -49 }, 1);});
		$(this).mouseup(	function() 	{$(this).animate({ marginTop: -50 }, 1);});
	});
}


///////////////////////
//// MENU FUNCTIONS ///
///////////////////////

$(document).ready(function() {

// VARIABLES

	$.tweenHeight = 35;
	$.section1 = $.url.segment(0);
	$.submenuOpen = false;

	if($.section1 == 'visualdevelopment' || $.section1 == 'illustration' || $.section1 == '3d' ) {
		$('#menu ul ul').hide(); // also taken care of in css
		$('#header').animate({height: '+=' + $.tweenHeight},{duration:300, easing: 'jswing'}).queue(function(){
			$('#menu-' + $.section1 + ' > ul').css({opacity: 0}).show().animate({opacity: 1, marginTop: 5},{duration:150, easing: 'jswing'});
			$(this).dequeue();
		});	
		$.submenuOpen = true;
	}

	$('#menu li.hasSubmenu > a').click(
 
		function() {

			var selectedSection = '#' + this.parentNode.id + ' > ul';

			if($.submenuOpen != true){ // Show submenu
				$('#menu ul ul').hide();
				$('#header').animate({height: '+=' + $.tweenHeight},{duration:300, easing: 'jswing'}).queue(function(){
					$(selectedSection).css({opacity: 0}).show().animate({opacity: 1, marginTop: 8},{duration:150, easing: 'jswing'});
					$(this).dequeue();
      				});	
				$.submenuOpen = true;
				return false;

			}else if($.submenuOpen){

				if ($(selectedSection).is(':visible')) { // Close submenu
					$(selectedSection).css({opacity: 1}).animate({opacity: 0, marginTop: 0},{duration:150, easing: 'jswing'}).queue(function(){
						$('#header').animate({height: '-=' + $.tweenHeight},{duration:300, easing: 'jswing'});
      						$(this).dequeue();
      					});
					$.submenuOpen = false;
					return false;

				} else { // Refresh with new submenu
					$('#menu ul ul').animate({opacity: 0, marginTop: 0},{duration:150, easing: 'jswing'}).queue(function(){
						$('#menu ul ul').hide();
						$(selectedSection).css({opacity: 0}).show().animate({opacity: 1, marginTop: 8},{duration:150, easing: 'jswing'});
      						$(this).dequeue();
      					});
				}
				return false;
			}

		}	
	);
	
	
	
///////////////////////
//   ACCOUNT PANEL   //
///////////////////////

/*
	var COOKIE_LOGGEDIN = 'Foo';
	function checkLoginStatus() {
		if($.cookie(COOKIE_LOGGEDIN) == 'yes') {
			$('#panel .loggedin').show();
		} else {		
			$('#panel .default').show();	
			$('.loggedOut').show();	
		}
	}
	checkLoginStatus();
	
		
	// PANEL OPENID //
	$('#panel .trigger').click(
		function() {
			$('#panel').animate({top: '-=200'},{duration:300, easing: 'easeInBack'}).queue(function(){
				$('#panel').animate({opacity: 1.0}, 300) // A little forced delay hack
				$('#panel .default').remove();
				$('#panel .login').show();
				$('#panel').animate({top: '+=200'},{duration:500, easing: 'easeOutBack'});
				$(this).dequeue();
      		});	
			return false;		
		}		
	);
	
	// PANEL LOGIN //
	$('#panel .login').click(
		function() {
			$('#panel').animate({top: '-=200'},{duration:300, easing: 'easeInBack'}).queue(function(){
				$.cookie(COOKIE_LOGGEDIN, 'yes');
				location.reload(true);
			});	
		}		
	);
	
	// PANEL PROFILE //
	$('#panel .logout').click(
		function() {
			$('#panel').animate({top: '-=200'},{duration:300, easing: 'easeInBack'}).queue(function(){
				$.cookie(COOKIE_LOGGEDIN, null);
				location.reload(true);
			});	
			return false;		
		}		
	);
*/


	

});
