jQuery().ready(function()
{	
	
	$('#navigation ul li a').mouseover(function() {
		$(this).stop(true, true).animate({'fontSize' : '19px'}, 400, function() {});
	}).mouseout(function() {
		$(this).stop(true, true).animate({'fontSize' : '14px'}, 400, function() {});
	});
	
	$('#preview').css('opacity', '0');
	
	$('#navigation ul li.categories a').mouseenter(function() {
		$('#preview').stop().animate({opacity: '1'}, 300);
		previews = $(this).attr('rel').split(';');
		$('#preview1').css('background', 'url(' + previews[0] + ') no-repeat 0 0').stop().animate({backgroundPosition : "(0 80)"}, {duration: 300});
		$('#preview2').css('background', 'url(' + previews[1] + ') no-repeat 0 100px').stop().animate({backgroundPosition : "(0 0)"}, {duration: 300});
		$('#preview3').css('background', 'url(' + previews[2] + ') no-repeat 0 0').stop().animate({backgroundPosition : "(0 120)"}, {duration: 300});
	}).mouseleave(function() {
		$('#preview1, #preview2, #preview3').stop();
		$('#preview').stop().animate({opacity: '0'}, 300);
	});
	
	$('#navigation ul li:not(.categories)').click(function() {
		$('#' + $(this).attr('id').toString().replace('-link', '')).stop(false, true).fadeIn('slow');
		$('#navigation').stop(true, true).fadeOut('slow');
	});
	
	$('.infobox .menu-back').click(function() {
		$('#navigation').stop(false, true).fadeIn('slow');
		$(this).parent().stop(true, true).fadeOut('slow');
	});
	
	$('#projects #list').jcarousel({
		scroll : 1,
		initCallback: function(carousel, state) {
			$('img:first', '#projects ul#list > li').click(function() {
				carousel.next();
			});
			
			$('#projects #dots a').click(function () {
				$('#projects #dots a').removeClass('selected');
				$(this).addClass('selected');
				carousel.scroll(parseInt($(this).text()) + 1);
			});
		},
		
		itemVisibleInCallback: {
			onAfterAnimation: function(carousel, item, index, state) {
				$('#projects #dots a').removeClass('selected');
				$('#projects #dots a:eq('+ parseInt($('#projects #dots a').length - index) +')').addClass('selected');
			}
		}
	});
	
	$('.jcarousel-prev, .jcarousel-next').mouseover(function() {
		$(this).css('background-position', 'right center');
	}).mouseout(function() {
		$(this).css('background-position', 'left center');
	});
	
	$('.showinfo').mouseenter(function() {
		$(this).fadeOut();
		$('.info', $(this).parents('li:first')).animate({'height' : '65px', 'opacity' : '1'}, 500, function() {});
	});
	
	$('.info').mouseleave(function() {
		$(this).animate({'height' : '0px', 'opacity' : '0'}, 400, function() {});
		$('.showinfo', $(this).parents('li:first')).fadeIn();
	});
	
	$('.changer').click(function () {
		$('img:first', $(this).parents('li:eq(1)')).stop(false, true).fadeOut('slow');
		$('img:first', $(this).parents('li:eq(1)')).attr('src', $('img', this).attr('src').replace('57x57', '810x510'));
		$('img:first', $(this).parents('li:eq(1)')).stop(true, true).fadeIn('slow');
	});
	
});

(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);
