/* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-10-06 20:11:15 +0200 (Sa, 06 Okt 2007) $
 * $Rev: 3581 $
 *
 * Version: @VERSION
 *
 * Requires: jQuery 1.2+
 */

(function($){
	
$.dimensions = {
	version: '@VERSION'
};

// Create innerHeight, innerWidth, outerHeight and outerWidth methods
$.each( [ 'Height', 'Width' ], function(i, name){
	
	// innerHeight and innerWidth
	$.fn[ 'inner' + name ] = function() {
		if (!this[0]) return;
		
		var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
		    borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
		
		return num( this, name.toLowerCase() ) + num(this, 'padding' + torl) + num(this, 'padding' + borr);
	};
	
	// outerHeight and outerWidth
	$.fn[ 'outer' + name ] = function(options) {
		if (!this[0]) return;
		
		var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
		    borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
		
		options = $.extend({ margin: false }, options || {});
		
		return num( this, name.toLowerCase() )
				+ num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width')
				+ num(this, 'padding' + torl) + num(this, 'padding' + borr)
				+ (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
	};
});

// Create scrollLeft and scrollTop methods
$.each( ['Left', 'Top'], function(i, name) {
	$.fn[ 'scroll' + name ] = function(val) {
		if (!this[0]) return;
		
		return val != undefined ?
		
			// Set the scroll offset
			this.each(function() {
				this == window || this == document ?
					window.scrollTo( 
						name == 'Left' ? val : $(window)[ 'scrollLeft' ](),
						name == 'Top'  ? val : $(window)[ 'scrollTop'  ]()
					) :
					this[ 'scroll' + name ] = val;
			}) :
			
			// Return the scroll offset
			this[0] == window || this[0] == document ?
				self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
					$.boxModel && document.documentElement[ 'scroll' + name ] ||
					document.body[ 'scroll' + name ] :
				this[0][ 'scroll' + name ];
	};
});

$.fn.extend({
	position: function() {
		var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
		
		if (elem) {
			// Get *real* offsetParent
			offsetParent = this.offsetParent();
			
			// Get correct offsets
			offset       = this.offset();
			parentOffset = offsetParent.offset();
			
			// Subtract element margins
			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) && $.css(offsetParent, 'position') == 'static') )
			offsetParent = offsetParent.offsetParent;
		return $(offsetParent);
	}
});

function num(el, prop) {
	return parseInt($.css(el.jquery?el[0]:el,prop))||0;
};

})(jQuery);

function bookmark(url, description) {
	netscape="Netscape User's hit CTRL+D to add a bookmark to this site."
	if (navigator.appName=='Microsoft Internet Explorer') {
		window.external.AddFavorite(url, description);
	} else if (navigator.appName=='Netscape') {
		alert(netscape);
	}
}

function remove_item(id) {
	document.remove.id.value = id;
	document.remove.submit();
}

function pp_checkout() {
	if (document.tc.tc.checked) {
		alert('Once you have made your payment please ensure that you either wait for the page to refresh back to our website, or click the link to return to merchant. Failure to do this could result in your order being delayed. Thank you.');
		document.paypal.submit();
	} else {
		alert('You must agree to the Terms & Conditions before proceeding');
	}
}

function ai() {
	var addinfo = document.getElementById('addinfo');
	addinfo.innerHTML = 'Please provide the following details and then press Continue.<br />All fields must be completed.<table><tr><td>Firstname: </td><td><input type="text" name="firstname" size="20" /></td></tr><tr><td>Surname: </td><td><input type="text" name="surname" size="20" /></td></tr><tr><td>Address Line 1: </td><td><input type="text" name="address1" size="20" /></td></tr><tr><td>Address Line 2: </td><td><input type="text" name="address2" size="20" /></td></tr><tr><td>Address Line 3: </td><td><input type="text" name="address3" size="20" /></td></tr><tr><td>Postcode: </td><td><input type="text" name="postcode" size="20" /></td></tr><tr><td>Telephone Number: </td><td><input type="text" name="telephone" size="20" /></td></tr><tr><td>Email Address: </td><td><input type="text" name="email" size="20" /></td></tr></table><a href="javascript:sp_checkout();">Continue &gt;</a><br /><br />';
}

function sp_checkout() {
	if (document.sagepay.firstname.value == '') {
		alert('You must provide a first name');
	} else if (document.sagepay.surname.value == '') {
		alert('You must provide a last name');
	} else if (document.sagepay.address1.value == '') {
		alert('You must provide a full address');
	} else if (document.sagepay.address2.value == '') {
		alert('You must provide a full address');
	} else if (document.sagepay.address3.value == '') {
		alert('You must provide a full address');
	} else if (document.sagepay.postcode.value == '') {
		alert('You must provide a postcode');
	} else if (document.sagepay.telephone.value == '') {
		alert('You must provide a telephone number');
	} else if (document.sagepay.email.value == '') {
		alert('You must provide an email address');
	} else if (document.tc.tc.checked) {
		document.sagepay.submit();
	} else {
		alert('You must agree to the Terms & Conditions before proceeding');
	}
}

function tc() {
	termsWindow = window.open('/terms.html','terms','scrollbars=yes,toolbars=no,status=yes,width=600,height=600');
}

function pp() {
	privacyWindow = window.open('/pp.html','privacy','scrollbars=yes,toolbars=no,status=yes,width=600,height=600');
}



