$(function() {
	if($("#file_textarea").length != 0){
		$("#page_title").hide();
		var oFCKeditor = new FCKeditor( 'file_textarea' ) ;
		oFCKeditor.BasePath = '/rsc/fckeditor/' ;
		oFCKeditor.Width = '100%;'
		oFCKeditor.Height = '454px;'
		oFCKeditor.ReplaceTextarea() ;
	}
	var dialog = new ModalDialog ("#login-box");
    $("#login-btn").click (function() {
            dialog.show();
        });
    $("#close-btn").click (function () {
        dialog.hide();
    });
    $("#logout-btn").click(function (){
        $("#logout-form").submit();
    });

	$(".hover").click(function (){ return false; });
	var login_options = {
		target : '#login-status',
		clearForm:true,
		success:showLoggedInResponse
	}
	var logout_options = {
		success:showLoggedOutResponse
	}
	$("#login-form").ajaxForm(login_options);
    $("#logout-form").ajaxForm(logout_options);

	if($("#imgss").length == 0){
		$("#content").jScrollPane({scrollbarWidth:8, scrollbarMargin:10, dragMaxHeight:20, showArrows:false});
	}
    $("#firstpane p.menu_head").click(function()
    {
		$(this).next("div.menu_body").slideToggle(300, function() { $("#content").jScrollPane({scrollbarWidth:8, scrollbarMargin:10, dragMaxHeight:20, showArrows:false }); } ).siblings("div.menu_body").slideUp("slow");
	});
	
	if($("#content_wrapper").outerHeight() < ($("#content").outerHeight() - 50)){
		var bttbtn = $('<a></a>').html($('<div></div>').attr({'id':'bttdiv'})).attr({'class':'to-top', 'title':'Back to top', 'href':'javascript;', 'rel':'.page_top'});
		$("#backtotop").append(bttbtn);
		$('a.to-top').bind(
			'click',
			function(){
				var destinationSelector = $(this).attr('rel');
				$("#content").each(function() { this.scrollTo(destinationSelector);});
				return false;
			}
		);
		} else {
			$("#content").jScrollPaneRemove();
		}
});
    
function showLoggedInResponse(responseText, statusText)  {
	if(responseText == "Success"){
        location.reload();
    } 
}
function showLoggedOutResponse(responseText, statusText)  {
	if(responseText == "Success"){
        location.reload();
    } 
}

function doSearch(keyword){
	var url = "/search?keyword=" + keyword;
	window.location = url;
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

