/**
 * 
 * 
 * 
 */
var fd_submenuSide = function (fd, element) {
	
	var self	= this;
	var submenu	= [];
	
	this.sizes;
	
	var menu;
	
	var _construct = function () {
		_setup();
		_watch();
	};
	
	var _setup = function () {
		self.sizes = {
			left: $(element).position().left,
			width: $(element).width()
		};
		
		$(element).find('ul.fd_submenuSide_menu').each(function () {
			menu = $(this);
		});
		
		return;
	};
	
	var _watch = function () {
		if (menu !== undefined) {
			menu.find('ul').each(function () {
				submenu.push( new fd_submenuSide_submenu(self, this));
			});
		}
	};
	
	_construct();
	return {
		
	};
};




/**
 * 
 */
var fd_submenuSide_submenu = function (fd_submenuSide, element) {

	var self = this;
	
	var options;
	
	var _construct = function () {
		_setup();
		
		_check();
	};
	
	var _setup = function () {
		$(element).css('display', 'block');
		options = {
			left: $(element).position().left, 
			width: $(element).width()
		};
		$(element).attr('style', '');
		return;
	};
	
	var _check = function () {
		if ((options.left + options.width) > (fd_submenuSide.sizes.left + fd_submenuSide.sizes.width)) {
			_moveToLeft();
		}
	};
	
	var _moveToLeft = function () {
		$(element).find('li').css('cssFloat', 'right');
		if ($(element).attr('rel') != '')
			$(element).css('marginLeft', '-' + ((options.width - $(element).parent('li').outerWidth()) - parseFloat($(element).attr('rel'))) + 'px');
		else
			$(element).css('marginLeft', '-' + (options.width - $(element).parent('li').outerWidth()) + 'px');
	};
	
	_construct();
	return {
		
	};
};
