function initPage() {
	initMenu();
	initImgs();
	
	
//	FB.Event.subscribe('edge.create',
//		    function(response) {
//		 		$("#footer").css('width',$(window).width());
//		        $("#footer").animate({bottom:"160px",width:$(window).width()-200+"px"},500);
//		    }
//		);

	setVal('screenWidth', 600);
	setVal('screenHeight', $(window).height());

	$(function() {
		// setup ul.tabs to work as tabs for each div directly under div.panes
		$("ul.tabs").tabs("div.panes > div");
		$(".tabs li a").bind("click", function() {
			$(".messages").hide("slow");
		});
	});

	$('.jimgMenu ul').kwicks( {
		max : 210,
		duration : 500,
		easing : 'easeOutQuad',
		complete : 'callback'
	});

}

function setVal(f, v) {
	$.post("globalattr", {
		field : f,
		value : v
	}, function() {
	});
}

function initImgs() {
	
	$('.zoomer').zoomer({speedShow:200,speedHide:100,sensitiv:2,zoomTo:'300x300'});
	
	$('.preload').css('opacity', '0.3');
	$('.preload').bind('load', function() {
		if ($(this).hasClass('sensitiv')) {
			$(this).animate( {
				opacity : 0.5
			}, 250, function() {
				$(this).removeClass('preload');
			});
		} else {
			$(this).animate( {
				opacity : 1
			}, 250, function() {
				$(this).removeClass('preload');
			});
		}
	});
	$('.sensitiv').bind('mouseenter', function() {
		$(this).animate( {
			opacity : 1
		}, 250);
	});

	$('.sensitiv').bind('mouseout', function() {
		$(this).animate( {
			opacity : 0.5
		}, 250);
	});

}
function buildZoom(e){
}
function initMenu() {
	var actElement = $("#menu_projector ul li:eq(0)");
	setBacklight(actElement, 0);
	$("#menu_projector ul li").bind("mouseenter", function() {
		setBacklight($(this), 1);
	});
	if(parseInt($("#container").height()) < parseInt($(window).height()))
	$("#container").css('minHeight',$(window).height()+'px');
}
function calcLiOffset(e) {
	var allwidth = 0;

	$(e).prevAll().each(function() {
		allwidth = allwidth + $(this).width();
	});
	return allwidth;
}
function setBacklight(e, mode) {
	var actWidth = $(e).width();
	var actLeft = calcLiOffset(e);
	if (mode == 0) {
		$("#menu_backlight").css('width', actWidth + 'px');
		$("#menu_backlight").css('left', actLeft + 'px');
	} else {
		$("#menu_backlight").animate( {
			width : actWidth + "px",
			left : actLeft + "px"
		}, 500);
	}
}
     
function initGallery(e) {
	$('.logo').animate({paddingTop:"5px",paddingBottom:"5px"},500);
	$('.jimgMenu').animate({marginTop:"0px",marginBottom:"5px"},500);
	centerImage($('.gallery-first'));
	$('.gallery-first').removeClass('gallery-first');
	$("#gallery-scroll").find("li").bind("click", function() {
		centerImage($(this));
		loadPhoto($(this));
		return false;
	});
	$("#gallery #image img").bind('load', function() {
		var img = $("#gallery #image img");
		$(img).css("opacity", "0");
		
		$(img).parent().animate( {
			width : $(img).width() + "px",
			height : $(img).height() + "px",
			top   : (($(window).height()-$(img).height()-220)/2)+'px'
		}, 200, function() {
			$(img).animate( {
				opacity : 1
			}, 200, function() {
				$("#image").css("background", "none");
				$("#gallery #image div").animate( {
					height : "30px"
				}, 200);
			});
		});
	});

	$(window).resize(function() {
		$(".th" + $("#gallery #image").attr("idpic")).click();

	});

}


function loadPhoto(e) {
	$("#gallery #image div")
			.animate(
					{
						height : "0px"
					},					200,
					function() {
						$("#image").css("background", "white");
						$("#gallery #image img")
								.animate(
										{
											opacity : 0
										},200,function() {
											$.ajax( {
														type : "get",
														url : "imageinfo-"
																+ $(e).find("img").attr('call'),dataType : 'json',
														success : function(data) {
															$("#gallery #image img").attr("src","image-"
																					+ data[0]['name']
																					+ "-600x"
																					+ ($(window).height() - 230)
																					+ "x100");
															$("#gallery #image .title").html(data[0]['title']);
															$("#gallery #image .desc").html(data[0]['description']);
															$("#gallery #image").attr("idpic",data[0]['id']);
														}
													});
										});
					});
}

function centerImage(e) {
	var s = 0;
	$(e).prevAll().each(function() {
		s = s + $(this).width() + 10;
	});

	$(e).parent().parent().animate( {
		left : 250 - 45 - s + "px"
	}, 1000);
}



