$().ready(function () {
	
	// all li:s that don't hold a sub ul
	$('#nav-holder li').not($('#nav-holder ul').parent('li')).not($('#nav-holder ul li ul li')).each(function (i) {
		$(this).hover(function () {
			$('#subnav-holder').slideUp();
		},
		function () {
			
		})
	});
	
	//css('background-color','blue');
	
	// find all second level ul parent li:s
	$('#nav-holder ul').parent('li').each(function (i) {
		//console.log('hello ' + i + " " + this);
		//console.log('i ' + i);
		var hej = i;
		//$(this).addClass('hover' + i); // old class version
		$(this).attr('id', 'hover' + i);
		
		$(this).hover(
			function () {
				//console.log($(this).attr('class'));
				var ulClass = $(this).attr('id');
				//console.log($('#subnav-holder .' + ulClass));// .hasClass(ulClass).show());
				//console.log(ulClass);
				$('#subnav-holder .hover0').css('display','none');
				$('#subnav-holder .hover1').css('display','none');
				$('#subnav-holder .hover2').css('display','none');
				$('#subnav-holder .' + ulClass).css('display','block');
				$('#subnav-holder').slideDown();
				//var test = $('#subnav-holder .subnav')[hej];
				
				//console.log('over ' + $(this).attr('class') );
				// li:n ska kunna räkna ut sin egen position här
	  		},
	  		function (hej) {
				//$(this).addClass(testClass);
				
				//$('#subnav-holder').slideUp();
				//$('#subnav-holder ul').css('display','none');
				//var test = $('#subnav-holder .subnav')[hej];
				//$(test).hide();
				//console.log('out ' + hej );
	  		}
		);
	
	}); // end each li
	
	//$('#nav-holder li').not(('#nav-holder ul').parent('li')).css('background-color','red');
	
	
	$('#nav-holder ul ul').each(function(i) {
		$(this).appendTo('#subnav-holder').addClass('subnav').addClass('hover' + i);
	});
	
	
	$('#subnav-holder li.selected').each(function(i) {
		$('#subnav-holder .hover0').css('display','none');
		$('#subnav-holder .hover1').css('display','none');
		$('#subnav-holder .hover2').css('display','none');		
		$('#subnav-holder li.selected').parent().show();
		$('#subnav-holder').show();
	});
	
		
	var i = 1;
	$('#personal div').each( function() {
		var tweetRotation = Math.random()*6;
		var poitiveOrNegative = Math.floor(Math.random()*2);
		var ex = ""; if (poitiveOrNegative>0) ex = "-";
		$(this).css("-webkit-transform", "rotate(" + ex + tweetRotation + "deg)"); // webkit
		
		if (poitiveOrNegative>0) {
			$(this).css("filter", "progid:DXImageTransform.Microsoft.Matrix(M11=0.99862953, M12=0.05233596, M21=-0.05233596, M22=0.99862953,sizingMethod='auto expand')");
		} else {
			$(this).css("filter", "progid:DXImageTransform.Microsoft.Matrix(M11=0.99862953, M12=-0.05233596, M21=0.05233596, M22=0.99862953,sizingMethod='auto expand')");	
		}
		
		$(this).data("frisör", i);
		i++;
	});
	
	$("#texter .person .top").height(90);
	
	$("#personal div").hover(
	  function (event) {
		var i = $(this).data("frisör");
		var offset = $(this).offset();
		var mod = (i-1) % 3;
		var pos = $(this).position();
		
		if (mod > 0) { // every 2nd and 3rd picture
			$("#texter .person:nth-child(" + i + ")").css("left", pos.left-410);				
		} else { // every 1st picture
			$("#texter .person:nth-child(" + i + ")").css("left", pos.left+190);
		}	
		$("#texter .person:nth-child(" + i + ")").css("top", pos.top + 100);
		
		//console.log("offset.top: " + pos.top + " offset.left " + pos.left + " i: " + i + " mod: " + mod)	
	  },
	  function () {
		var i = $(this).data("frisör");
		$("#texter .person:nth-child(" + i + ")").css("top", -700);
	  }
	);	
	
	

}); // end $().ready

