// The below code is property of xenfocus.com and may not be copied without permission

$(document).ready(function($){

	$(".nav_background").click(function(){
		$("#toggle_background").slideToggle();
	});
	
	$("#custom_background span").click(function(){
		$.cookie('custom_url',null,{ expires: -5, path: '/'});
		var bgid = $(this).attr("id");
		$.cookie('custombg',bgid,{ expires: 365, path: '/'});
		$("body").removeClass().addClass(bgid);
	});
	
	$("#custom_submit").click(function(){
		$.cookie('custombg',"bg_custom",{ expires: 365, path: '/'});
		var customurl = $("#custom_input").val();
		$.cookie('custom_url',customurl,{ expires: 365, path: '/'});
		$("<style type='text/css'>body.bg_custom, .bg_custom .maintitle, .bg_custom #header, .bg_custom .footer, .bg_custom .footerLegal .pageContent, .bg_custom .node .forumNodeInfo .nodeIcon, .bg_custom .node .categoryForumNodeInfo .nodeIcon{ background-image: url(" + customurl + ")}</style>").appendTo("head");
		$("body").removeClass().addClass("bg_custom");
	});
		
	if ( ($.cookie('custombg') != null))	{
		$("body").addClass($.cookie('custombg'));
	}
	else{
		$("body").addClass("bg1");
	}
	
	if ( ($.cookie('custom_url') != null))	{
		$("<style type='text/css'>body.bg_custom, .bg_custom .maintitle, .bg_custom #header, .bg_custom .footer, .bg_custom .footerLegal .pageContent, .bg_custom .node .forumNodeInfo .nodeIcon, .bg_custom .node .categoryForumNodeInfo .nodeIcon{ background-image: url(" + $.cookie('custom_url') + ")}</style>").appendTo("head");
		$("body").addClass("bg_custom");
	}
	
});
