var listBackUp = "";
defaultStaff = "semra-arslan";

$(document).ready(function(){
	
	//initScroller
	$("#list .items .text").hide();
	$("div.scrollable").scrollable({
		vertical:true,
		size: 8,
		hoverClass: "hover"
	});
	var api = $("div.scrollable").scrollable();
	
	listBackUp = $("div.scrollable .items").html();
	
	//initContent
	showDetails(getCurrentStaff(),true)
	
	//activateItem
	$(".item[href='#"+currentStaff+"']").addClass("active");
		
	//changeView
	$("#views a").click(function(){
		if($(this).hasClass("selected")==false) {
			$("#views a").each(function(){
				$(this).toggleClass("selected");
			});
			if ($(this).hasClass("imageView")) {
				$("#list .items .text").hide();
				$("#list .items .image").show();
				api.getConf().size = 8;
			} else {
				$("#list .items .image").hide();
				$("#list .items .text").css("display","block");
				api.getConf().size = 14;
			}
			api.reload().begin();
		}
	});
	
	//changeChoose
	$("#choose a").click(function(){
		var currentView = $("#views a.selected").attr("name");
		if($(this).hasClass("selected")==false) {
			api.reload().begin();
			$("#choose a.selected").removeClass("selected");
			$(this).addClass("selected");
			selection = $(this).attr("id");
			$("div.scrollable .items").html(listBackUp);
			
			if (selection != "all") { api.getItems().filter(":not(."+selection+")").remove(); }
			
			if (currentView == "text") {
				$("#list .items .image").hide();
				$("#list .items .text").css("display","block");
				api.getConf().size = 14;
			}
			api.reload();
			$(".item[href='#"+getCurrentStaff()+"']").click();
		}
		return false;
	});
	
	//loadContent
	$(".item").live("click",function(){
		var currentStaff = $(this).attr("href").split("#");
		showDetails(currentStaff[1],false);
	});
});

function showDetails(newStaff,init) {
	if (getCurrentStaff()!=newStaff || init==true) {
		if ($.browser.msie == true) {
			$("#load").load("/agentur/mitarbeiter/details.cfm?id="+newStaff, function(){
					//$(document).pngFix();
				});
		} else {				
			$("#load").fadeOut(100, function(){
				$(this).load("/agentur/mitarbeiter/details.cfm?id="+newStaff, function(){
					$(this).fadeIn(400);
				});
			});
		}
	}
}

function getCurrentStaff() {
	currentStaff = window.location.hash.replace("#","");
	currentStaff == "" ? currentStaff=defaultStaff : currentStaff=currentStaff;
	return currentStaff;
}