(function( pb, $ )
{
	pb.columnManager = function()
	{
		this.columnObject = null;
		this.currentSize = 0;
		this.currentType = 0;
	};
	
	pb.columnManager.prototype = 
	{
			register : function( columnObject )
			{
				if( typeof(columnObject) != "object")
				{
					alert("ColumnObject is not an Object");
					return;
				}
				
				this.columnObject = columnObject;
				this.setButtonEvents();
			}
		
		,	setButtonEvents : function()
			{
				var thisObject = this;
				
				this.columnObject.find("ul.show li a").bind("mousedown", function(){ return false; });
				this.columnObject.find("ul.show li a").bind("click", function()
				{
					if(document.documentElement.scrollTop && (window.pageYOffset + window.innerHeight) === document.documentElement.scrollHeight)
						window.scrollTo(0, (document.documentElement.scrollTop-1));
					
					var	size = ($(this).hasClass("news")) ? 200 : 574;
					var	type = ($(this).hasClass("news")) ? "left" : "right";
					var	otherColumn = (type == "left") ? "right" : "left";
					var	url = $(this).attr("href");
					
					if(thisObject.currentSize == size)
					{
						$("td."+otherColumn).find(".item-content").fadeOut( function()
						{
							thisObject.loadPage(otherColumn, url);
							$("td."+otherColumn).find(".item-content").css( { display:"block", height:0, overflow:"auto" } );
						});
					}
					else
					{
						thisObject.currentSize = size;
						thisObject.resizeColumnsTo( size, type, url );
					}
					
					delete size, type, otherColumn, url;
					
					return false;
				});
				
				delete thisObject;
			}
			
		,	resizeColumnsTo : function( size, type, url )
			{
				var thisObject = this;
				var	otherColumn = (type == "left") ? "right" : "left";
				
				this.currentType = type;
				
				$("td."+type).find("li").addClass("small");
				
				this.columnObject.find("tr td.left").animate( { width : size  }, function()
				{
					$("td."+otherColumn).find(".items-titles").fadeOut(function()
					{
						$("td."+otherColumn).find(".item-content").css( { display:"block", height:0, width:"auto", overflow:"auto" } );
						
						if(url)
							thisObject.loadPage(otherColumn, url);
					});
				});
				
				delete thisObject, size, otherColumn, type, url;
			}
			
		,	loadPage : function(otherColumn, url )
			{
				var thisObject = this;
				
				$("td."+otherColumn).find(".item-content").load(url, function( )
				{
				
					
					$("td."+otherColumn).find(".item-content").animate( { height : $("td."+otherColumn).find(".item-content").get(0).scrollHeight});
					
					thisObject.columnObject.find("a.changeToJobs").bind("mousedown", function(){ $(this).addClass("changeToJobs-down"); return false; });
					thisObject.columnObject.find("a.changeToJobs").bind("click", function()
					{ 
						var	thisClickObject = this;
							thisObject.currentSize = 574;
							
							$("td.column").find("li").removeClass("small");
							
							$("td.right").find(".item-content").css( { display:"block", height:1, width:1, overflow:"hidden" } );
							$("td.right").find(".items-titles").fadeIn(function()												 
							{
								thisObject.resizeColumnsTo( 574, "right",  $(thisClickObject).attr("href") );
							});
							
						delete thisClickObject;
						
						return false;
					});
					
					thisObject.columnObject.find("a.changeToNews").bind("mousedown", function(){ $(this).addClass("changeToNews-down"); return false; });
					thisObject.columnObject.find("a.changeToNews").bind("click", function()
					{ 
						var	thisClickObject = this;
							thisObject.currentSize = 200;
						
							$("td.column").find("li").removeClass("small");
							
							$("td.left").find(".item-content").css( { display:"block", height:1, width:1, overflow:"hidden" } );
							$("td.left").find(".items-titles").fadeIn(function()												 
							{
								thisObject.resizeColumnsTo( 200, "left",  $(thisClickObject).attr("href") );
							});
							
						delete thisClickObject;
						
						return false;
					});	
					
					thisObject.columnObject.find("a.changeToOverview").bind("mousedown", function(){ $(this).addClass("changeToOverview-down"); return false; });
					thisObject.columnObject.find("a.changeToOverview").bind("click", function()
					{ 
						var	thisClickObject = this;
							thisObject.currentSize = 387;
					
							//$(document).unbind("mouseup");
							
							$("td.column").find("li").removeClass("small");
					
							$("td.column").find(".item-content").css( { display:"block", height:1, width:1, overflow:"hidden" } );
							$("td.column").find(".item-content").css( { display:"block", height:1, width:1, overflow:"hidden" } );
							
							$("td.column").find(".items-titles").fadeIn(function()												 
							{
								if($(this).parent().hasClass("left"))
									$(this).parent().animate( { width : 387 } );
							});
						
						delete thisClickObject;
					
						return false;
						
					});
					
					$(document).bind("mouseup", function()
					{ 
						thisObject.columnObject.find("a.changeToOverview").removeClass("changeToOverview-down"); 
						thisObject.columnObject.find("a.changeToJobs").removeClass("changeToJobs-down"); 
					});
					
					$(this).find(".mailto").each( function()
					{
						$(this).attr("href", $(this).attr("href").toString().replace("###", "@"));
						$(this).text($(this).text().toString().replace("###", "@"));
					})
				});
				
				delete thisObject;
			}
	}
})( Pluxbox, jQuery );
