

$("document").ready(function () {

	$("#actionLogin, #loginPopup .close, .openLogin").click(function (e) {
	
		e.preventDefault();
		
		var pWidth = self.innerWidth || document.documentElement.clientWidth,
			eWidth = $("#loginPopup").width();
		
		var pLeft = (pWidth-eWidth)/2,
			pTop = $("").scrollTop() + 150;
		
		$("#loginPopup").css({'left': pLeft, 'top': pTop}).toggle();
		
		$("#login_username").focus();
	
	});

});

function removeTopic(topicID, URL, category) {

	var checker = confirm('Er du sikker på at du vil slette indlægget og alle kommentarerne?');
	
	if (checker) {
	
		$("#topic").slideUp("slow", function () {
		
			$(this).load(URL + "static/_forumActions.php?removeTopic=" + topicID + "&url=" + URL + category, function () {
			
				$(this).slideDown("normal");
			
			});
		
		});
		
		$("#replyWrapper").slideUp("normal");
	
	}

}

function quoteTopic(topicID, URL) {

	$("#respond").load(URL + "static/_forumActions.php?contentTopic=" + topicID, function () {
	
		document.getElementById('respond').focus();
		
		document.getElementById(respond).value = '[quote]' + Content + '[/quote]\n';
	
	});

}

function editTopic(postID, URL) {

	$("#topicText").slideUp("normal", function() {
	
		$(this).load(URL + "static/_forumActions.php?editTopic=" + postID, function () {
		
			$(this).slideDown("normal");
			
			$("topicEditInput").focus();
			
			// Annuller
			
			$("#topicCancel").click(function () {
			
				$("#topicText").slideUp("normal", function() {
				
					$(this).load(URL + "static/_forumActions.php?contentTopic=" + postID, function () {
					
						$(this).slideDown("normal");
					
					});
				
				});
			
			});
			
			// Gem
			
			$("#topicSave").click(function () {
			
				$("#topicText").slideUp("normal", function() {
				
					$(this).load(URL + "static/_forumActions.php?editSaveComment=" + postID + "&editContentComment=" + escape(document.getElementById("comment" + postID + "EditInput").value), function () {
					
						$(this).slideDown("normal");
					
					});
				
				});
			
			});
		
		});
	
	});

}

function quoteComment(textID, formID) {

	document.getElementById(formID).focus();
	
	document.getElementById(formID).value = '[quote]' + Content[textID] + '[/quote]\n';

}

function editComment(postID, formID, URL) {

	$("#comment" + postID + "text").slideUp("normal", function() {
	
		$(this).load(URL + "static/_forumActions.php?editComment=" + postID, function () {
		
			$(this).slideDown("normal");
			
			$("#comment" + postID + "EditInput").focus();
			
			// Annuller
			
			$("#comment" + postID + "Cancel").click(function () {
			
				$("#comment" + postID + "text").slideUp("normal", function() {
				
					$(this).load(URL + "static/_forumActions.php?contentComment=" + postID, function () {
					
						$(this).slideDown("normal");
					
					});
				
				});
			
			});
			
			// Gem
			
			$("#comment" + postID + "Save").click(function () {
			
				$("#comment" + postID + "text").slideUp("normal", function() {
				
					$(this).load(URL + "static/_forumActions.php?editSaveComment=" + postID + "&editContentComment=" + escape(document.getElementById("comment" + postID + "EditInput").value), function () {
					
						$(this).slideDown("normal");
					
					});
				
				});
			
			});
		
		});
	
	});

}

function removeComment(postID, URL) {

	var checker = confirm('Er du sikker på at du vil slette indlægget?');
	
	if (checker) {
	
		$("#comment" + postID).html('')
			.load(URL + "static/_forumActions.php?deleteComment=" + postID, function () {
			
				setTimeout("doFadeOut('#comment" + postID + "')", 3000);
				
			
			});
		
	
	}

}

function doFadeOut(Element) {

	$(Element).fadeOut(1000);

}

function vote(URL) {

	var don = document.getElementsByName('poll_answer')
	
	for(var i=0;i<don.length;i++) {
	
		if(don[i].checked) {
		
			$("#poll_feature").slideUp("normal", function () {
			
				$(this).load(URL + "static/_pollActions.php?answer=" + don[i].value + '&ip=' + document.getElementById('poll-ip-addr').value, function () {
				
					$(this).slideDown("normal");
				
				});
			
			});
			
			return true;
		
		}
	
	}
	
	alert('Du har lige glemt at vælge hvad du vil stemme på');
	
	return false;

}

function vote_blank(URL) {

	$("#poll_feature").slideUp("normal", function () {
	
		$(this).load(URL + "static/_pollActions.php?show", function () {
		
			$(this).slideDown("normal");
		
		});
	
	});
	
	return true;

}

function get_vote(URL) {

	$("#poll_feature").slideUp("normal", function () {
	
		$("#poll_feature").load(URL + "static/_pollActions.php?vote=true", function () {
		
			$("#poll_feature").slideDown("normal");
		
		});
	
	});
	
	return true;

}


/** Galleri **/

function gallery_next() {

	if (gallery_leftMargin < (gallery_maxMargin - 594)) {
	
		gallery_leftMargin = gallery_leftMargin + 594;
		
		$("#gallery_images").animate({marginLeft: "-" + gallery_leftMargin + "px"}, 1500);
		
		$("#gallery_navigator_left").css({background: 'url(gallery_content/left_active.png)'});
		
		if (gallery_leftMargin == (gallery_maxMargin - 594))
			$("#gallery_navigator_right").css({background: 'url(gallery_content/right_inactive.png)'});
	
	} else {
	
		gallery_leftMargin = 0;
		
		$("#gallery_images").animate({marginLeft: "0px"}, 1000);
		
		$("#gallery_navigator_left").css({background: 'url(gallery_content/left_inactive.png)'});
		
		$("#gallery_navigator_right").css({background: 'url(gallery_content/right_active.png)'});
	
	}

}

/** Nyhedskarrusel **/

function news_carousel_start() {

	news_t = clearInterval(news_t);
	
	news_t = setInterval("news_carousel_change()", 10000);

}

function news_carousel_change() {

	if (news_carousel_next == 0) {
	
		var nextOne = news_carousel_current +1;
		
		if (news_carousel_max == news_carousel_current) {
		
			var nextOne = 1;
		
		}
	
	} else {
	
		var nextOne = news_carousel_next;
		
		news_carousel_next = 0;
	
	}
	
	if (nextOne != news_carousel_current) {
	
		$("#news_carousel_item" + news_carousel_current).fadeOut(500, function() {
		
			$("#news_carousel_item" + nextOne).fadeIn(500);
		
		})
		
		$("#news_carousel_headers span").css({backgroundColor: "#FFFFFF", color: "#000000"});
		
		$("#news_carousel_header" + nextOne).css({backgroundColor: "#FF6601", color: "#FFFFFF"});
		
		news_carousel_current = nextOne;
	
	}

}

