$(document).ready(function(){
	$("a.dropDownLnk").click(function(e){
		e.stopPropagation();
		//$(this).width() + 4
		$("#dropDownTitle").attr('width', '100%')
							.get(0).innerHTML = (outerHTML($(this).get(0)));
		
		var width = 4;
		$("#dropDownTitle").children().each(function(){
			width += $(this).width();
		});
		
		$("#dropDownTitle").attr('width', width + 'px');
		
		$("#dropDownTbl").css('visibility', 'visible')
			.css('left', $(this).position().left - 14)
			.css('top', $(this).position().top - 7);
		
		$("#dropDownContent *").remove();
		var rel = $(this).attr('rel');
		if(rel) {
			if($('#' + rel).get().length) {
				$('#'+$(this).attr('rel')).clone().appendTo($("#dropDownContent"));
			}
		}
	});
	
	
	$("body").click(function(e){
		if($(e.target).parents(".ddCTbl").get().length == 0) {
			$("#dropDownTbl").css("visibility", "hidden");
		}
	});
	
	$("a.dropDownLnkRight").live('click', function(e){		
		e.stopPropagation();
		//$(this).width() + 4
		$("#dropDownTitleRight").attr('width', '100%')
							.get(0).innerHTML = (outerHTML($(this).get(0)));
		
		$("#dropDownTitleRight").children().removeClass('dropDownLnkRight');
		
		var width = 4;
		$("#dropDownTitleRight").children().each(function(){
			width += $(this).width();
		});
		
		$("#dropDownTitleRight").attr('width', width + 'px');
		
		var rel = $(this).attr('rel');
		if(rel) {
			if($('#' + rel).get().length) {
				$("#dropDownContentRight *").remove();
				$('#'+$(this).attr('rel')).clone().appendTo($("#dropDownContentRight"));
			}
		}
		
		$("#dropDownTblRight").css('left', '0px' );
		
		var position = findPos(this);
		var left = position.left;
		left -= $("#dropDownTblRight").width();
		left += width;
		left += 8;
		
		$("#dropDownTblRight").css('visibility', 'visible')
			.css('left', left )
			.css('top', position.top - 7);
	});
	
	$("body").click(function(e){
		if($(e.target).parents(".ddCTbl").get().length == 0) {
			$("#dropDownTblRight").css("visibility", "hidden");
		}
	});
	
	onresize.add(function(){
		$("#dropDownTbl").css("visibility", "hidden");
	});
});
