(function($){

	$.buero = {
		
		images:{},
		information:{},
		offset:0,
		
		init:function(images, information){
			$('body.home #content').append('<img src="" class="hidden img1" />').append('<img src="" class="hidden img2" />').find('img').load(function(){
				var c = $(this).hasClass('img1') ? 'img.img2' : 'img.img1';
				$('body.home #content').find(c).fadeOut(400);
				$(this).fadeIn(400, function(){
					$.buero.next();					
				});
			});
			
			$('body.home').mousemove(function(e){
				if((e.pageX > 50) && (e.pageX < 600) && (e.pageY > 115)){
					if($('.item').css('display') == 'none'){
						$('.item').fadeIn(100);
					}
				}else{
					$('.item').fadeOut(400);
				}
				$('.item').css('top', e.pageY-33).css('left', e.pageX-2);
			});
			
			$.buero.images = images;
			$.buero.information = information;
			$.buero.load();
		},
		load:function(){
			var c = ($.buero.offset%2==0) ? 'img.img1' : 'img.img2';
			$('body.home #content').find(c).attr('src', $.buero.images[$.buero.offset]);
			$('body.home #content .item').find('h3 span').html($.buero.information[$.buero.offset].title).parent().attr('href', '/projects/'+$.buero.information[$.buero.offset].repository+'/').parent().parent().find('p span').html($.buero.information[$.buero.offset].category).parent().attr('href', '/projects/'+$.buero.information[$.buero.offset].repository+'/');
		},
		next:function(){
			window.setTimeout(function(){
				$.buero.offset = ($.buero.offset + 1 < $.buero.images.length) ? ($.buero.offset + 1) : 0;
				$.buero.load();		
			}, 3000);
		}
	};
	
	
	$.imagesnav = {
		images:{},
		offset:0,
		start:0,
		
		init:function(images){
			$('body.project #content .project-image').find('img').load(function(){
				var c = $(this).hasClass('img1') ? 'img.img2' : 'img.img1';
				
				if($.imagesnav.start == 1){
					$('body.project #content .project-image').find(c).fadeOut(400);
					$(this).fadeIn(400, function(){
					//$.imagesnav.next();					
					});
					
				}
				//$.imagesnav.start = 1;
			});
			
			$.imagesnav.images = images;
			$.imagesnav.load();
			
			$('a.about').click(function(){
				$.imagesnav.fadeInfoIn();
			});
		
			$('#content .project-image').click(function(){
				var c = $('.img1').css("display")=="none" ? ".img2" : ".img1";
				if($(c).css("opacity") == 1.0){
					$.imagesnav.next();
					$.imagesnav.fadeInfoOut();
				}else{
					$.imagesnav.fadeInfoOut();
				}
			});
			$('#content #close-info').click(function(){
				$.imagesnav.fadeInfoOut();
			});
		
			$('#nav li .aright').click(function(){
				$.imagesnav.next();
				var c = $('.img1').css("display")=="none" ? ".img2" : ".img1";
				if($(c).css("opacity") < 1.0){
					$.imagesnav.fadeInfoOut();
				}
			});
			$('#nav li .aleft').click(function(){
				$.imagesnav.prev();
				var c = $('.img1').css("display")=="none" ? ".img2" : ".img1";
				if($(c).css("opacity") < 1.0){
					$.imagesnav.fadeInfoOut();
				}
			});
		},
		load:function(){
			var c = ($.imagesnav.offset%2==0) ? 'img.img1' : 'img.img2';
			$('body.project #content .project-image').find(c).attr('src', '');
			$('body.project #content .project-image').find(c).attr('src', $.imagesnav.images[$.imagesnav.offset]);
			
		},
		next:function(){
			$.imagesnav.offset = ($.imagesnav.offset + 1 < $.imagesnav.images.length) ? ($.imagesnav.offset + 1) : 0;
			$.imagesnav.load();
			$.imagesnav.start = 1;
		},
		prev:function(){
			$.imagesnav.offset = ($.imagesnav.offset - 1 >= 0) ? ($.imagesnav.offset - 1) : $.imagesnav.images.length-1;
			$.imagesnav.load();	
			$.imagesnav.start = 1;
		},
		fadeInfoIn:function(){
			$('.project').css("background-image", "none");
			$('li.about').addClass("project-navigation-selected");
			
			var c = $('.img1').css("display")=="none" ? ".img2" : ".img1";
			$(c).fadeTo(400, 0.05);
			$('#content .item').fadeIn(400);
			return false;
		},
		fadeInfoOut:function(){
			$('.project').css("background-image", "url(img/load.gif);background-repeat: no-repeat;background-position: 5px 5px");
			$('li.about').removeClass("project-navigation-selected");
			
			var c = $('.img1').css("display")=="none" ? ".img2" : ".img1";
			$(c).fadeTo(400, 1.0);
			$('#content .item').fadeOut(400);
			return false;
		}
	};
	
})(jQuery);

function getTextHeight(num){			
	var j=0;
	while(j<num) {
		var h = parseInt(115 - ($("#" + j + " h3").height() + $("#" + j + " p").height())/2) + "px";
		$("#" + j + " h3").css("margin-top", h);
		j++;
	}
}
	
function imgHover(target){
	$(target).hover(
 	function(){
  		$(this).animate({
            opacity: 0.9
        }, {
            queue: false
        });
 	},
 	function(){
 		$(this).animate({
            opacity: 0.0
        }, {
            queue: false
        });
 	}
);}
	
function getPage(url){
	window.location.href = url;
}



