﻿
/**
  * jQuery.dimension.fixes
  * 
  * @description
  * Fixes jQUery.dimension bugs in different browsers
  * Unfortunately we're polluting the global namespace by adding num() and height_().
  *
  * @TODO: move new global vars into MSLM namespace
  * 
  * $.fn.position.left: safari
  * $(window).height: opera
  * 
  *
  * @copyright       Neue Digitale / Razorfish 
  * @author          martin.krause@neue-digitale.de
  * @version         0.2
  *
  * @revision        $Revision$
  * @lastmodified    $Date$
  *
  * @jslint          2009-01-28
  *
  */


/**
  * @bugfix: safari
  *
  * @description
  * Overrides jQuery.fn.position to correct a sarafi bug that's issued by using margin auto on div#wrapper.
  * 
  * @see inline commen at line 3471 in jquery.js 		
		// Subtract element margins
		// note: when an element has margin: auto the offsetLeft and marginLeft 
		// are the same in Safari causing offset.left to incorrectly be 0
  *
  * http://groups.google.com/group/jquery-dev/browse_thread/thread/ef08acc2314ed6e6
  *
  */

function num(elem, prop) {
	return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;
}
if (jQuery.browser.safari) {
	jQuery.fn.extend({
		position: function() {
			var left = 0, top = 0, results;

			if ( this[0] ) {
				// Get *real* offsetParent
				var offsetParent = this.offsetParent(),

				// Get correct offsets
				offset       = this.offset(),
				parentOffset = /^body|html$/i.test(offsetParent[0].tagName) ? { top: 0, left: 0 } : offsetParent.offset();

				// Subtract element margins
				// note: when an element has margin: auto the offsetLeft and marginLeft 
				// are the same in Safari causing offset.left to incorrectly be 0
	//			offset.top  -= num(elem, 'marginTop'); 
	//			offset.left -= num(elem, 'marginLeft'); 

				// Add offsetParent borders
				parentOffset.top  += num( offsetParent, 'borderTopWidth' );
				parentOffset.left += num( offsetParent, 'borderLeftWidth' );

				// Subtract the two offsets
				results = {
					top:  offset.top  - parentOffset.top,
					left: offset.left - parentOffset.left
				};
			}

			return results;
		},

		offsetParent: function() {
			var offsetParent = this[0].offsetParent;
			while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static') ) {
				offsetParent = offsetParent.offsetParent;
			}
			return jQuery(offsetParent);
		}
	});
}


/**
  * @bugfix: opera
  *
  * @description
  * $(window).height() returns wrong value in Opera 9.5+
  * 
  * @see http://dev.jquery.com/ticket/3046
  *
  */
var height_ = jQuery.fn.height;
jQuery.fn.height = function() {
    if ( this[0] == window && jQuery.browser.opera && jQuery.browser.version >= 9.50) {
        return window.innerHeight;
    }
    else { 
		return height_.apply($(this[0]));
	}
};
