$(document).ready(function() {

	if($("#navbar-sep-act").length > 0) {
		if(hideSlidingParts(calculateGlassBar()))  {
			animateSubMenu();
		}
	} else {
		if(hideSlidingSubNav()) {
			animateShadowedBox();
		}
	}
	
	if($(".animate").length > 0) {
		if(hideFlyingClaim()) {
			if($("#flyingclaim1").length > 0) {
				animateFlyingClaim(1, "left", 0);
			} else if($("#flyingclaim2").length > 0) {
				animateFlyingClaim(2, "left", 230);
			} else if($("#flyingclaim3").length > 0) {
				animateFlyingClaim(3, "left", 296);
			} else if($("#flyingclaim4").length > 0) {
				animateFlyingClaim(4, "right", 399);
			} else if($("#flyingclaim5").length > 0) {
				animateFlyingClaim(5, "right", 633);
			}
		}
	}

	if($("#shadowedbox form").length > 0) {
		fillLoginForm();
	}

	if($("#js-reset-button").length > 0) {
		renderResetButton();
	}


});

function  hideFlyingClaim() {
	if($("#flyingclaim1").length > 0) {
		$("#flyingclaim1").css("margin-left", "-175px");
	} else if($("#flyingclaim2").length > 0) {
		$("#flyingclaim2").css("margin-left", "-175px");
	} else if($("#flyingclaim3").length > 0) {
		$("#flyingclaim3").css("margin-left", "-175px");
	} else if($("#flyingclaim4").length > 0) {
		$("#flyingclaim4").css("margin-left", "979px");
	} else if($("#flyingclaim5").length > 0) {
		$("#flyingclaim5").css("margin-left", "979px");
	}
	return true;
}

function animateFlyingClaim(nr, comeFrom, goToPx) {
	if(comeFrom == "left") {
		goToPx = goToPx + 50;
		$("#flyingclaim" + nr)
			.animate({marginLeft:(goToPx)+"px"}, 2000)
				.animate({marginLeft:"-=50px"}, 1800);	
	} else if (comeFrom == "right") {
		goToPx = goToPx - 50;
		$("#flyingclaim" + nr)
			.animate({marginLeft:(goToPx)+"px"}, 2000)
				.animate({marginLeft:"+=50px"}, 1800);
	}
}

function calculateGlassBar() {
	var allImgsArray 		= new Array;
	var activeImg 			= new Array;
	var filteredImgsArray 	= new Array;
	var cnt 				= 0;
	var contImg 			= 0;
	var ImagesWidth 		= 0;
	var navwidth			= 190;
		
	allImgsArray 		= $("#navbar-list img");
	activeImg 			= $(".navbar-img-act");
	filteredImgsArray 	= $(".navbar-img");

	for (cnt = 0; cnt < allImgsArray.length; cnt++) {
		if(allImgsArray[cnt].width != activeImg[0].width) {
			ImagesWidth = ImagesWidth + allImgsArray[cnt].width;
			contImg++;
		} else {
			break;
		}
	}


	if(contImg != 0) {
		ImagesWidth = ImagesWidth + activeImg[0].width - navwidth + (contImg * 1);
	} else {
		ImagesWidth = 0;
	}

	return ImagesWidth;
}

function hideSlidingParts(glasswidth) {
	$("#navbar-sep-act").height("1px");
	$("#horizontal-glass").height("0px");

	if(glasswidth == 0) {
		$("#horizontal-glass")
			.css("left", "0px")
				.width($(".navbar-img-act").width());
		$("#glass-shadow-top").css("background-image", "none");
		$("#shadowedbox-wrap").css("padding-top", "0px");
	} else {
		$("#horizontal-glass")
			.css("left", "190px")
				.width(glasswidth);
	}

	$("#glass-shadow-top").hide();
	$("#sub-nav").hide();
	$("#shadowedbox-wrap").hide();
	$("#glass-shadow-bottom").hide();

	return true;
}

function hideSlidingSubNav() {
	$("#navbar-sep-act").hide();
	$("#horizontal-glass").hide();
	$("#glass-shadow-top").hide();
	$("#sub-nav").hide();
	$("#shadowedbox-wrap").css("padding-top", "0px").hide();
	$("#glass-shadow-bottom").hide();

	return true;
}

function animateSubMenu() {
	
	$("#navbar-sep-act").animate({height:"58px"}, 600, null, function(){
		$("#horizontal-glass").animate({height:"4px"}, 150, null, function(){
			$("#glass-shadow-top").slideDown(150, function(){
				$("#sub-nav").slideDown(500);
				$("#shadowedbox-wrap").slideDown(500, function(){
					$("#glass-shadow-bottom").slideDown(150);
				});
			});
		});	
	});	
}

function animateShadowedBox() {
	$("#shadowedbox-wrap").slideDown(650, function(){
		$("#glass-shadow-bottom").slideDown(200);
	});
}

// function renderResetButton() {
// 	$("#js-reset-button").html('<input type="reset" value="Zurücksetzen" />');
// 	$("#js-reset-button").click(function(){
// 	
// 		$("#headnote").removeAttr("value");
// 		$("#lawdate").removeAttr("value");
// 		$("#court").removeAttr("value");
// 		$("#src").removeAttr("value");
// 		$("#law").removeAttr("value");
// 		$("#paragraph").removeAttr("value");
// 		
// 		$("#keyword1 option").removeAttr("selected");
// 		$("#keyword2 option").removeAttr("selected");
// 		$("#keyword3 option").removeAttr("selected");
// 		
// //		$("#keywordconnor").removeAttr("checked");
// //		$("#keywordconn").attr("checked", "checked");
// 	});
// }


function fillLoginForm() {

	if($("#shadowedbox input:eq(5)").attr("type") == "text")  {

		
	}

	if($("#shadowedbox input:eq(6)").attr("type") == "password")  {

		
	}
	
}

