(function($){
    $.fn.getStyleObject = function(){
        var dom = this.get(0);
        var style;
        var returns = {};
        if(window.getComputedStyle){
            var camelize = function(a,b){
                return b.toUpperCase();
            };
            style = window.getComputedStyle(dom, null);
            for(var i = 0, l = style.length; i < l; i++){
                var prop = style[i];
                var camel = prop.replace(/\-([a-z])/g, camelize);
                var val = style.getPropertyValue(prop);
                returns[camel] = val;
            };
            return returns;
        };
        if(style = dom.currentStyle){
            for(var prop in style){
                returns[prop] = style[prop];
            };
            return returns;
        };
        return this.css();
    }
})(jQuery);


$ (function()
{
	var current_page = (window.location.toString()).split ('/');
	current_page = (current_page [(current_page.length - 1)]).replace (/\?.*$/, '');

	// Check if a link contains current page
	if ($ ('div#menu ul li a[href="./' + current_page + '"]').size() > 0)
	{
		var $this = $ ('div#menu ul li a[href="./' + current_page + '"]'),
			$parent = $this.parent(),
			$anchor = $parent.find ('a.header');
			
		$anchor.addClass ('hover');
	}
	
	// Check if a sub link contains current page
	if ($ ('div#menu ul li ul li a[href="./' + current_page + '"]').size() > 0)
	{
		var $this = $ ('div#menu ul li ul li a[href="./' + current_page + '"]'),
			$parent = $this.parent().parent().parent(),
			$anchor = $parent.find ('a.header');
			
		$anchor.addClass ('hover');
	}

	$ ('div#menu ul li ul').css ('position', 'absolute');
	$ ('div#menu ul li ul li').css ('display', 'block');
	$ ('div#menu ul li a.header').hover (function()
	{
		// MAKES THE THING WORK
		/*var styles = $ (this).getStyleObject();
		
		$ (this).css (styles);*/
		
		$children = $ (this).parent().find ('ul');
		$width = parseInt ($ (this).width());
		if ($children.size() > 0)
		{
			$myOffset = $ (this).offset();
			$myWidth = parseInt ($children.find ('li a').width());
			
			$children.css ({ top: $myOffset.top + $ (this).outerHeight() + 'px', left: $myOffset.left + 'px' }).show();
			
				if ($width > $myWidth)
					$children.find ('li a').css ({ width: $width + 'px' }).show();
		}
	});
	
	$ ('div#menu ul li').hover (function()
	{
	
	},
	function()
	{
		$ (this).find ('a.header').removeAttr ('style').removeClass ('hover').end().find ('ul').hide();
	});
});
