$(document).ready(function(){
	$("ul.menu li").hover(function(){
		$(this).addClass('active');
	}, 
	function(){
		if($(this).attr("id") != 'current' && !$(this).children().slice(-1).is('ul')){
			$(this).removeClass('active');
		}
	});
	
	$("ul.menu li ul li").hover(function(){
		$(this).addClass('sub_active');
	}, 
	function(){
		if($(this).attr("id") != 'current')
			$(this).removeClass('sub_active');
	});
	
	$(".ger_navi").hover(function(){
		$('.ger_navi').css('border-top', '4px solid black');
	}, 
	function(){
		$('.ger_navi').css('border-top', '4px solid #FFCC33');
	});
	
	$(".en_navi").hover(function(){
		$('.en_navi').css('border-top', '4px solid black');
	}, 
	function(){
		$('.en_navi').css('border-top', '4px solid #FFCC33');
	});
	
	$('.ger_navi').click(function(){
		$('#ger').click();
	});
	
	$('.en_navi').click(function(){
		$('#en').click();
	});
	
	if($("#project_show")){
		
		if($("#project_show").html() == "here"){
			init_project_show();
		}
		var i = 0;
		$("#project_show").click(function(e){
			var elem = $(e.target);
			if(elem.hasClass('next_link')){
				$("#project_show_wrapper").animate({
						marginLeft: "-=252px"
					}, 1000);
					i = next(i);
			}
			
			if(elem.hasClass('prev_link')){
				$("#project_show_wrapper").animate({
						marginLeft: "+=252px"
					}, 1000);
					i = prev(i);
			}
		});
	}
});

function init_project_show(){
	var i = 1;
	var url_parts = document.location.search.split(/&/);
	var lang = '';
	for(i in url_parts){
		if(/lang=(.*)/.exec(url_parts[i])){
			lang = url_parts[i].replace('lang=', '');
		}
	}
	if(lang == '')
		lang = 'de'
		
	$.ajax({
		'type' : 'POST',
		'url': "project_show.php",
		'data':'what=init&lang='+lang,
		'success': function(msg){
			$("#project_show").html(msg);
			prev(i);
			$("#project_show #project_show_main").mousemove(function(e){
				$(".text_displayer").css({'top': e.pageY+5, 'left': e.pageX+5});
			}).find('.img').hover( function(e){
				$(this).fadeTo(250,0.7);
				var id = get_id($(this).attr('id'));
				$(".text_displayer").children().hide();
				$(".text_displayer").find('#img_div_'+id+'_text').show();
				}, function(){
					$(this).fadeTo(500,1);
			});
			
			$('#project_show_main .img').hover(function() {
				$(".text_displayer").show();
			},
			function() {
				$(".text_displayer").hide();
			});
		}
	});
}

function get_id(div_id){
	var id = div_id.replace('img_div_', '');
	return id;
}

function next(i){
	i=i+1
	var elem_count = $('#project_show_wrapper').children().length;
	//alert(i + "=>" + id);
	if((i+2)==(elem_count-1)){
		$('.next_link').hide();
	}
	
	$('.prev_link').show();
	
	return i;
}

function prev(i){
	i = i-1;
	if(i==0){
		$('.prev_link').hide();
	}
	
	$('.next_link').show();
	
	return i;
}

