	var categories;
	var clist;
	var cTimeout;
	var blockage;
	var indicator;


	function GUID() {
	    var S4 = function() {
	       return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
	    };
	    return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
	}

	function reCaptcha()
	{
		
		$('.captcha').css('background-image','url(/images/captcha.php?'+ GUID() +')');
	}
	
	function readCookie(name) 
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) 
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) 
			return c.substring(nameEQ.length,c.length);
		}
		return 0;
	}


	function initMenu()
	{
		categories = document.getElementById('dropDown');
		clist;
		cTimeout;
		blockage;
		indicator = document.getElementById("indicator");
		
		if(categories != null) 
		{
			clist = categories.getElementsByTagName('ul')[0];
			
			categories.onmouseover = function() 
			{
				blockage = true;
				clist.style.display = 'block';
				indicator.innerHTML = '▼';
			};
			
			categories.onmouseout = function() 
			{
				clearTimeout(cTimeout);
				blockage = false;
				cTimeout = setTimeout('if(!blockage) { clist.style.display = "none"; indicator.innerHTML = "▶";}', 300);
			};
		}	
	}
	
	function saveMessage(id)
	{
		$('#itl-' + id).show();
		var content = $('#editField-' + id).val();
		
		$.post("/callback/editComment.php", { 'id' : id, 'description' : content },
			function(data) 
			{
				
				if(data.error != 'no')
				{
					alert(data.error);
				}
				else
				{
					
		            $('.postContent-' + id).html(data.html + '<p style="margin-top:1em"><small>Last edited <strong>just now</strong>, syntax highlighting requires refresh.</small></p>');
				}
				
				cancelEdit(id);
				
			}, 'json');
		
		
	}
	
	function editMessage(id)
	{
		$('#itl-' + id).show();
				
		$.post("/callback/loadQuote.php", { 'id' : id },
			function(data) 
			{
				$('#editField-' + id).remove();
				$('#editGlyph-' + id).text('Save');
				$('#editGlyph-' + id).attr('href', 'javascript:saveMessage('+ id +')');
				$('#cancel-' + id).show();
				$('.postContent-' + id).hide();
				$('#m-' + id).append('<textarea style="width:925px;height:250px" id="editField-'+ id +'"></textarea>');
				$('#editField-' + id).html(data.content);
				$('#itl-' + id).hide();
				
			}, 'json');
	}
	
	function cancelEdit(id)
	{
		$('#editField-' + id).remove();
		$('#editGlyph-' + id).text('Edit');
		$('#editGlyph-' + id).attr('href', 'javascript:editMessage('+ id +')');
		$('#cancel-' + id).hide();
		$('.postContent-' + id).show();
		$('#itl-' + id).hide();
	}
	
	function replyToUser(id)
	{
					
		$.post("/callback/loadQuote.php", { 'id' : id },
			function(data) 
			{
				
		        var B = document.getElementById('desc');
		        B.focus();
		        
		        if (document.selection) 
		        {
		  
		            var C = document.selection.createRange();
		            C.text = '[quote]'+  "\n" + 'Posted by [b]' + data.username + '[/b] on [b]' + data.date + '[/b]' + "\n\n" + data.content +  "\n" +  '[/quote]'; 
		             
		        } 
		        else 
		        {
		            if (B.selectionStart || B.selectionStart == "0") 
		            {
		            
		                B.value = B.value.substring(0, B.selectionStart) + '[quote]'+  "\n" + 'Posted by [b]' + data.username + '[/b] on [b]' + data.date + '[/b]'  + "\n\n"  + data.content +  "\n" +  '[/quote]' + B.value.substring(B.selectionEnd);
		            
		            } 
		            else 
		            {
		            
		                B.value += '[quote]'+  "\n" + 'Posted by [b]' + data.username + '[/b] on [b]' + data.date + '[/b]'  + "\n\n"  + data.content + "\n" + '[/quote]';
		            
		            }
		        }
        
				
		}, 'json');
					

	}
					
	
	function LoginChecker()
	{
		var memberid = readCookie('userid');
		var username = readCookie('username');
		var session  = readCookie('checksum');
	
		if(!memberid == 0 && !username == 0 && !session == 0)
		{
					
			$('#login').remove();
			$('#register').remove();
			$('#nav').append('<li><a href="/settings">Settings</a></li><li><a href="/logout.php">Log out</a></li>');
		
		}
	}


	function insertTag(A, D) 
	{
        var B = document.getElementById('desc');
        B.focus();
        
        if (!D) 
        {
            D = A
        }
 
        if (document.selection) 
        {
            var C = document.selection.createRange();
            C.text = "[" + A + "]" + C.text + "[/" + D + "]"  
        } 
        else 
        {
            if (B.selectionStart || B.selectionStart == "0") 
            {
                B.value = B.value.substring(0, B.selectionStart) + "[" + A + "]" + B.value.substring(B.selectionStart, B.selectionEnd) + "[/" + D + "]" + B.value.substring(B.selectionEnd)
            } 
            else 
            {
                B.value += "[" + A + "][/" + D + "]"
            }
        }
    }

	function sendReply(id)
	{
		var captcha = $('.captcha').val();
		var description = $('.description').val();
		
	    $('.ajaxloading').show();
		
		$.post("/message/" + id + "/void/1", { 'captcha': captcha, 'description': description },
			function(data) {
				if(data.success == 'no')
				{
					$('.ajaxloading').hide();
					alert(data.error);
				}
				else
				{
					$('.ajaxloading').hide();
					document.location = data.url;
				}
		}, 'json');
	}
	
	
	function startThread(id)
	{
		var title 		= $('.title').val();
		var captcha 	= $('.captcha').val();
		var description = $('.description').val();
			
	
	    $('.ajaxloading').show();

		
		$.post("/create/"+ id , { 'captcha': captcha, 'description':description , 'title' : title},
			function(data) {
				if(data.success == 'no')
				{
					$('.ajaxloading').hide();
					alert(data.error);
				}
				else
				{
					$('.ajaxloading').hide();
					document.location = data.url;
				}
		}, 'json');
	}

	$(document).ready(function() 
	{
		$("embed").attr("wmode", "opaque").wrap('<div>');
		
		$('.bold').bind('click', function() {
			insertTag('b', 'b');
		});
		
		$('.italic').bind('click', function() {
			insertTag('i', 'i');
		});
		
		$('.quote').bind('click', function() {
			insertTag('quote', 'quote');
		});
		
		$('.code').bind('click', function() {
			insertTag('code=plain text' , 'code');
		});
		
		$('.link').bind('click', function() {
			insertTag('url=http://', 'url');
		});
		
		
	});

	function path()
	{
		var args = arguments,
			result = []
			;
			
		for(var i = 0; i < args.length; i++)
			result.push(args[i].replace('@', '/js/sh/'));
			
		return result
	};
	



	
	
