function initEvents() {

   //Header buttons and navigation hover
   $("ul.buttons>li, ul.nav>li").has('ul').unbind("hover").hover(function() {
       $("ul", this).stop(true, true).delay(250).slideDown(50);
   }, function() {
       $("ul", this).stop(true, true).delay(350).slideUp(200);
   });

   //thumbnail and photo action menu
   $("li.uploadPhoto, div#photo").has("ul.actions, div.photoSet").stop().unbind("hover").hover(function() {
       $("ul.actions, div.photoSet", this).stop(true, true).delay(250).slideDown(50);
   }, function() {
       $("ul.actions, div.photoSet", this).stop(true, true).slideUp(200);
   });
   
   $("li.uploadPhoto.hover").has("p").stop().unbind("hover").hover(function() {
       $("ul.properties", this).stop(true,true).delay(500).slideUp(50);
       $("p", this).stop(true,true).delay(500).slideDown(50);
   }, function() {
       $("ul.properties", this).stop(true,true).slideDown(100);
       $("p", this).stop(true,true).slideUp(100);
   });
/*
   $("li.uploadPhoto").stop().unbind("hover").hover(function() {
   alert("hoi";
       $("p", this).stop(true, true).delay(250).slideUp(50);
   }, function() {
       $("p", this).stop(true, true).slideDown(200);
   });
   */
   
   $(".notification .exit").unbind("click").click(function() {
       $(this).parent().stop(true, true).slideUp(200);
   });

	// multi input
	$("form input.multi").unbind("keypress").keypress(function(event) {
		var arr = this.name.split('[');
		var currentName = arr[0];
		var currentNr = parseInt(arr[1].substr(0, arr[1].length - 1));
		var nextID = currentName + "_" + (currentNr+1);
		var keyCode = (event.keyCode ? event.keyCode : event.which);
		// handle comma
		if (keyCode == 44) {
			if ($('#' + nextID)) {
				if (!$('#' + nextID).is(':visible')) {
					$('#' + nextID).delay(10).fadeIn('slow', function() {
						$(this).blur();
						$('#' + nextID + ' input:first').focus();
					});
				} else {
					$(this).blur();
					$('#' + nextID + ' input:first').focus();
				}
			}
			event.preventDefault();
			return false;
		}
		if (keyCode >= 65 && keyCode <= 122) {
			if (!$('#' + nextID).is(':visible')) {
				$('#' + nextID).delay(10).fadeIn('slow');
			}
		}
	});
	
	$("form input.multi").unbind("paste").bind("paste", function(event) {
		var arr = this.name.split('[');
		var currentName = arr[0];
		var currentNr = parseInt(arr[1].substr(0, arr[1].length - 1));
		var nextID = currentName + "_" + (currentNr+1);

		if (!$('#' + nextID).is(':visible')) {
			$('#' + nextID).delay(10).fadeIn('slow');
		}
	});
	
}

// FanxyBox
function initFancyBox() {
   $("a#userPhoto").fancybox({
		'zoomSpeedIn': 50, 
		'titleShow'     : false,
		'zoomSpeedOut':	200, 
		'zoomOpacity': false,
		'overlayOpacity': 0.75,
		'padding': 0,
		'imageScale': false,
		'centerOnScroll': false,
		'overlayShow': true,
		'hideOnContentClick': true,
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic'
	});
   $("a.uploadPhoto").fancybox({
		'zoomSpeedIn': 50, 
		'titleShow'     : false,
		'zoomSpeedOut':	200, 
		'zoomOpacity': false,
		'overlayOpacity': 0.75,
		'padding': 0,
		'imageScale': false,
		'centerOnScroll': false,
		'overlayShow': true,
		'hideOnContentClick': true,
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic'
	});
	$("a.gallery").fancybox({
		'zoomSpeedIn': 50, 
		'titleShow': false,
		'zoomSpeedOut':	200, 
		'zoomOpacity': false,
		'overlayOpacity': 0.75,
		'padding': 0,
		'imageScale': false,
		'centerOnScroll': false,
		'overlayShow': true
	});
   
   $("a#inline").fancybox({
   		'width'				: '75%',
		'height'			: '75%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'zoomSpeedIn': 50, 
		'titleShow': false,
		'zoomSpeedOut':	200, 
		'zoomOpacity': false,
		'overlayOpacity': 0.75,
		'padding': 0,
		'imageScale': false,
		'centerOnScroll': false,
		'overlayShow': true,
		'hideOnContentClick': true
	});
}

$(document).ready(function() {
   
   // Execute events
   initEvents();
   
   // Execute fancybox
   if (typeof $.fancybox != "undefined") {
      initFancyBox();
   }
 
   $("button").has('span.creditCost').addClass('creditButton');

   // Position relative fix IE7
   if($.browser.version <= 7) {
      var zIndexNumber = 1000;
      $('ul.nav, ul.nav li, ul.nav ul, div.header p, div.header').each(function() {
         $(this).css('zIndex', zIndexNumber);
         zIndexNumber -= 1;
      });
   };
   
   $('div.photoSet').stop(true, true).delay(2000).slideUp(200);
});

