
function gallerySlideshow() {
	var pause = 2000;
	$("#gallery li.current").fadeOut(pause, function(){
		$(this).removeClass("current");
		
	});
	$("#gallery li.next").fadeIn(pause, function(){
		$("#gallerycounter li.current").removeClass("current");
		$("#gallerycounter ul li:nth-child(" + ($(this).index() + 1) + ")").addClass("current");
		
		if($("#gallery li.next").next().length == 0) {
			$('#gallery li:first-child').addClass('next');
		}
		else { 
			$("#gallery li.next").next().addClass('next');
		}		
		$(this).addClass("current")
		$(this).removeClass("next");
		
		setTimeout(gallerySlideshow, 5000);		
	});	
}

// initialise plugins
$(function(){
	$('ul.navigation').superfish();
	
	if($("#c75 li").length > 0) {
		$("#featureGraphic.home").css("background", "none");
		var slidercontent = "";
		var countercontent = "";
		$("#c75 li").each(function(thing){
			var thiscontent = "<li>" + $(this).html() + "</li>";
			countercontent = countercontent + "<li><a href='#'></a></li>";
			slidercontent = slidercontent + thiscontent;
		});
		$("#featureGraphic").html("<ul id='gallery'>" + slidercontent + "</ul><div id='gallerycounter'><ul>" + countercontent + "</ul></div>");

		$("#gallery li:nth-child(1)").addClass("current");
		$("#gallery li:nth-child(2)").addClass("next");
		
		
		$("#gallerycounter ul li:nth-child(1)").addClass("current");

		setTimeout(gallerySlideshow, 5000);
		
		$("#gallerycounter ul li a").click(function(event){
			event.preventDefault();
			//alert($(this).parent().index());
			$("#gallerycounter ul li.current").removeClass("current");
			$(this).parent().addClass("current");
			$("#gallery li.current").removeClass("current");
			$("#gallery li:nth-child(" + ($(this).parent().index() + 1) + ")").addClass("current");
			
			if($("#gallery li:nth-child(" + ($(this).parent().index() + 1) + ")").next().length == 0){
				
				$("#gallery li.next").removeClass("next");
				$("#gallery li:nth-child(1)").addClass("next");
			}else {
				$("#gallery li.next").removeClass("next");
				$("#gallery li:nth-child(" + ($(this).parent().index() + 1) + ")").next().addClass("next");
			}
		});
								
	}
	

	/*
	 *
	 *      Handle file uploads
	 *
	 */
	var midUpload = false;
	if($("#members-area-tabs ul li").length > 0){
		if(($(".csc-frame-frame2 input[name='cancelEdit']").length > 0) || ($(".csc-frame-frame2 input[name='cancelCatEdit']").length > 0) || ($(".csc-frame-frame2 input[name='cancel_versioning']").length > 0) || ($(".csc-frame-frame2 input[name='ok']").length > 0)){
			midUpload = true;
		}
		
		if(midUpload){
			$(".csc-frame-frame1").hide();
			$("li#member-resources").addClass("behind");
		}else{
			$(".csc-frame-frame2").hide();
			$("li#add-resource").addClass("behind");
		}
		
		if($("#single-error-msgt").length > 0){
			if($("#single-error-msgt").html().indexOf("The deletion of the dam file was not sucessful. Reason is a database problem. Please report, that there was a problem with dam uid") > 0){
				$("#single-error-special").html("Unfortunatly you do not have permission to modify this file. <br /><br /><a href='/members-area/'>Return to members area</a><br />");
			}
		}
		
		if($(".treeelem").length == 2){
			$(".csc-frame-frame2 .tx-damfrontend-pi1").hide();
			$(".csc-frame-frame2 .tx-damfrontend-pi1 form input[name='catOK']").trigger("click");
		}
		

		$("li#member-resources a").click(function(event){
			event.preventDefault();
			if(!midUpload){
				$("li#member-resources").removeClass("behind");
				$("li#add-resource").addClass("behind");
				$(".csc-frame-frame2").hide();
				$(".csc-frame-frame1").show();
			}

		});
		$("li#add-resource a").click(function(event){
			event.preventDefault();		
			if(!midUpload){	
				$("li#add-resource").removeClass("behind");
				$("li#member-resources").addClass("behind");
				$(".csc-frame-frame1").hide();
				$(".csc-frame-frame2").show();
			}
		});
			
		$("#file_label").html($("h6").html());
		
		
		if($("input[value='new_record']").length > 0){
			$(".csc-frame-frame2 .tx-damfrontend-pi1").hide();
			$("input[value='new_record']").attr("checked", "checked");
			$("input[name='submit_versioning']").trigger("click");
		}
			
	}
	
	


	
});

