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

$(".tborder  tbody[id$='_e'], .tborder2 tbody[id$='_e']").fancyCollapses();

if ( $("#debug a").length == 1) {
$("#debug").hide();
var debug_link = $("#debug a").attr("href");
$("#debug a").remove();
var debug = $("#debug").html().replace('[','').replace(']','');
$("#debug_link").attr("title", debug).attr("href", debug_link);
} else {
$("#debug").hide();
$("#debug_link").hide();
}


$('.guest_panel input.textbox').focus(function() {
    $(".guest_panel .guest_login_options").fadeIn();
    $(".guest_panel .guest_login_register").fadeOut();
}).blur(function() {
    $(".guest_panel .guest_login_options").fadeOut();
    $(".guest_panel .guest_login_register").fadeIn();
});

$("#search .search_input").focus(function() {
    $(this).css("color","#FFF");
}).blur(function() {
    $(this).css("color","#404040");
});;

var file_name, file_end, file_page, file_page, fid;


var containerId = 'container',
containerWidth = $('#' + containerId).css('width'),
fluidWidth = 98;

$('#click').click(function() {
	if ( $('#' + containerId).css('width') == containerWidth ) {
		$('#' + containerId).animate({ width: fluidWidth + '%' });
		$.cookie('SiteWidth', 'fluid');
	} else {
		$('#' + containerId).animate({ width: containerWidth });
		$.cookie('SiteWidth', 'fixed');
	}
	return false;
});
 
 if ( $.cookie('SiteWidth') == 'fluid' ) {
	$('#' + containerId).css('width', fluidWidth + '%');
 }
 if ( $.cookie('SiteWidth') == 'fixed' ) {
	$('#' + containerId).css('width', containerWidth);
 }

$("#breadcrumb ul li").first().next().hide(); //hide the second <li> in the breadcrumb menu

$(".tip").tipTip();

$('#panel .panel_links').hide();

$("a#userbar_toggle").hover(function() {

	if(  $("#panel .panel_left").hasClass("panel_left_exp")  ) {
		$("#panel .panel_left").addClass("panel_left_exp_hover");
	} else {
		$("#panel .panel_left").addClass("panel_left_hover");
	};

}, function() {
   	 $("#panel .panel_left").removeClass("panel_left_exp_hover").removeClass("panel_left_hover");
});


$("a#userbar_toggle").click(function() {

	if(  $('#panel .panel_links').is(':hidden') ){
	  	$("#panel .panel_links").show().css('width',0).animate({
			width: 280
		},1000);

		$("#panel .panel_left").addClass("panel_left_exp");

	} else {
	  	$("#panel .panel_links").animate({
			width: 0
		},1000,function() {
			$(this).hide();
		});

		$("#panel .panel_left").removeClass("panel_left_exp");
	}
	return false;
});

$("table tbody.forums tr").each(function() {
	$(this).click(function() {
		fid =  $(this).attr("id").match(/\d+/);
		document.location.href =  $("tr#forum_" + fid).find("td strong a:first").attr("href");
	});
});

//Add pathname to html tag
file_name = document.location.href;
file_end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
file_page = file_name.substring(file_name.lastIndexOf("/")+1, file_end);
file_page = file_page.replace('.php','').replace('#','');

$('body').addClass("page_" + file_page);

if (file_page !== '') {
	$('#nav li').removeClass('active');
	$("#nav")
		.find('a[href *="' + file_page  + '.php"]')
		.parent("li")
		.addClass("active");
}

    $(".ajax_mark_read").parent("tr").each(function() {
    	$(this).hover(function() {
    		$(this).stop().addClass("active");
    		$(this).click(function() {
    			document.location.href =  $(this).find("td strong a:first").attr("href");
    		});
    	}, function() {
    		$(this).stop().removeClass("active");
    	});
    });

});
