/*  Copyright (c) 2007, 2008 Stephen Whiteley (http://jui.ce.it)
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 *
 *  Juice Library core.juice.js, version 0.1.2.20080911
 *
/*--------------------------------------------------------------------------*/

(function() {

	window.Juice = {

		Version: '0.1.1.20080325',

		$: function() {

			var a = [];

			var i, e;
			for ( i = 0; i < arguments.length; i++ ) {
				e = arguments[i];
				if ( typeof e == 'string' ) { e = document.getElementById( e ); }
				if ( arguments.length === 1 ) { return e; }
				a.push( e );
			}

			return a;

		},

		Bookmark: function( ele, e ) {

			Juice.Event.cancel( e );

			var w = window;

			if ( w.sidebar ) {
				w.sidebar.addPanel( ele.title, ele.href, '' );
			} else if ( w.opera && w.print ) {
				ele.rel = 'sidebar';
			} else if ( w.external ) {
				w.external.AddFavorite( ele.href, ele.title );
			} else {
				alert( 'Your Browser does not support dynamic bookmarking, please try bookmarking manually.' );
			}

			return false;

		},

		Browser: new function() {

			this.detect = function() {

				var a = navigator.userAgent, b = {};

				b.opera		= ( a.indexOf( 'Opera' ) != -1 );
				b.konqueror	= ( a.indexOf( 'Konqueror' ) != -1 );
				b.safari	= ( a.indexOf( 'Safari' ) != -1 );
				b.mozilla	= ( a.indexOf( 'Gecko' ) != -1 && !b.konqueror && !b.safari );
				b.ie7		= ( a.indexOf( 'MSIE 7' ) != -1 && !b.opera );
				b.ie6		= ( a.indexOf( 'MSIE' ) != -1 && !b.ie7 && !b.opera );
				b.ie		= ( b.ie7 || b.ie6 );
				b.quirks	= ( this.mode() == 'quirks' ? true : false );

				return b;

			};

			this.details = function() {

				var n = navigator;

				return {
					agent:		n.userAgent,
					code:		n.appCodeName,
					cookies:	n.cookieEnabled,
					name:		n.appName,
					platform:	n.platform,
					version:	n.appVersion
				};

			};

			this.dimensions = function() {

				var s = { width: 0, height: 0 };

				if ( typeof window.innerWidth == 'number' ) {
					s.width = window.innerWidth;
					s.height = window.innerHeight;
				} else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
					s.width = document.documentElement.clientWidth;
					s.height = document.documentElement.clientHeight;
				} else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
					s.width = document.body.clientWidth;
					s.height = document.body.clientHeight;
				}

				return s;

			};

			this.flash = function() {

				var c, d, f = { enabled: false, version: false }, n = navigator;

				if ( n.plugins && n.plugins.length ) {
					c = n.plugins['Shockwave Flash'];
					if ( c ) {
						f.enabled = true;
						if ( c.description ) {
							d = d.description;
							f.version = d.charAt( d.indexOf( '.' ) - 1 );
						}
					}
				} else if ( n.mimeTypes && n.mimeTypes.length ) {
					c = n.mimeTypes['application/x-shockwave-flash'];
					if ( c && d.enabledPlugin ) {
						f.enabled = true;
					}
				} else {
					for ( var v = 9; v > 0; v-- ) {
						try {
							c = new ActiveXObject( 'ShockwaveFlash.ShockwaveFlash.' + v );
							f.enabled = true;
							f.version = v;
							break;
						} catch( e ) {}
					}
				}

				return f;

			};

			this.inner = function() {

				var s = { x: 0, y: 0 }, w = Juice.Browser.dimensions();

				if ( window.innerHeight && window.scrollMaxY ) {
					s.x = document.body.scrollWidth;
					s.y = window.innerHeight + window.scrollMaxY;
				} else if ( document.body.scrollHeight > document.body.offsetHeight ) {
					s.x = document.body.scrollWidth;
					s.y = document.body.scrollHeight;
				} else {
					s.x = document.body.offsetWidth;
					s.y = document.body.offsetHeight;
				}

				return {
					width: ( s.x < w.width ) ? w.width : s.x,
					height: ( s.y < w.height ) ? w.height : s.y
				};

			};

			this.mode = function() {

				var c, m = false;

				if ( c = document.compatMode ) {
					switch ( c.toLowerCase() ) {
						case 'backcompat': m = 'quirks'; break;
						case 'css1compat': m = 'compliant'; break;
						default: m = 'hybrid';
					}
				}

				return m;

			};

		},

		Container: new function() {

			this.create = function( s ) {

				if ( !s ) { s = {}; }

				var c = {
					outer:	Juice.Element.create( 'DIV', null, s.id || null, s.className || null ),
					inner:	Juice.Element.create( 'DIV', s.value || null, null, 'inner' ),
					shadow: Juice.Element.create( 'DIV' )
				};

				c.outer.style.zIndex		= s.zIndex || 1;
				c.outer.style.position		= s.fixed === true ? 'relative' : 'absolute';

				if ( s.width ) { c.outer.style.width = s.width + 'px'; }

				c.inner.style.border		= '1px solid ' + ( s.border || '#808080' );
				c.inner.style.background	= s.background || 'white';

				if ( s.padding )	{ c.inner.style.padding = s.padding + 'px'; }
				if ( s.height )		{ c.inner.style.height = ( s.height - ( s.padding ? s.padding * 2 : 0 ) - 2 ) + 'px'; }

				c.shadow.style.position		= 'absolute';
				c.shadow.style.background	= s.shadow || '#999999';
				c.shadow.style.zIndex		= -1;
				c.shadow.style.top			= '2px';
				c.shadow.style.right = c.shadow.style.bottom = c.shadow.style.left = '-3px';

				Juice.Element.opacity( c.shadow, s.opacity || 30 );
				Juice.Element.append( c.outer, [ c.inner, c.shadow ] );

				return c;

			};

			this.render = function( c, e ) {

				if ( !e ) { e = document.body; }

				e.appendChild( c.outer );

				Juice.Container.fix( c );

			};

			this.fix = function( c ) {

				if ( c && ( Juice.Browser.detect().ie6 || Juice.Browser.detect().quirks ) ) {

					var d = Juice.Element.dimensions( c.outer );

					c.shadow.style.width = d.width + 6 + 'px';
					c.shadow.style.height = d.height + 1 + 'px';

					Juice.Element.obstructions( c.outer );

				}

			};

		},

		Convert: new function() {

			this.namehex = function( n ) {

				var c = {
					'aqua': '#00FFFF', 'black': '#000000', 'blue': '#0000FF', 'fuchsia': '#FF00FF',
					'gray': '#808080', 'green': '#008000', 'lime': '#00FF00', 'maroon': '#800000',
					'navy': '#000080', 'olive': '#808000', 'purple': '#800080', 'red': '#FF0000',
					'silver': '#C0C0C0', 'teal': '#008080', 'white': '#FFFFFF', 'yellow': '#FFFF00'
				};

				if ( c[n] ) { return c[n]; }

				return false;

			};

			this.hexrgb = function( h ) {

				if ( !Juice.Type.hexColour( h ) ) { h = this.namehex( h ); }
				if ( !Juice.Type.hexColour( h ) ) { return; }

				var x = new RegExp( '^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$', 'i' ), m = false;

				if ( m = h.match( x ) ) {
					return {
						r: parseInt( m[1], 16 ),
						g: parseInt( m[2], 16 ),
						b: parseInt( m[3], 16 )
					};
				} else {
					Juice.Debug( new Error( 'Juice.Core: Invalid hex value: ' + h ) );
				}

				return false;

			};

			this.hsvrgb = function( h, s, v ) {

				var r, g, b;

				if ( s == 0 ) {
					if ( v == 0 ) {
						r = g = b = 0;
					} else {
						r = g = b = parseInt( v * 255 / 100 );
					}
				} else {

					if ( h == 360 ) { h = 0; }

					h /= 60, s /= 100, v /= 100;

					var i = parseInt( h );
					var f = h - i;
					var p = v * ( 1 - s );
					var q = v * ( 1 - ( s * f ) );
					var t = v * ( 1 - ( s * ( 1 - f ) ) );

					switch ( i ) {
						case 0: r = v; g = t; b = p; break;
						case 1: r = q; g = v; b = p; break;
						case 2: r = p; g = v; b = t; break;
						case 3: r = p; g = q; b = v; break;
						case 4: r = t; g = p; b = v; break;
						case 5: r = v; g = p; b = q; break;
					}

					r = parseInt( r * 255 );
					g = parseInt( g * 255 );
					b = parseInt( b * 255 );

				}

				return { r: r, g: g, b: b };

			};

			this.rgbhex = function( r, g, b ) {

				var hex = '', i;

				for ( i = 0; i < arguments.length; i++ ) {
					hex += Juice.Format.pad( parseInt( arguments[i] ).toString( 16 ), 2 );
				}

				if ( Juice.Type.hexColour( hex ) ) {
					return '#' + hex;
				} else {
					return false;
				}

			};

			this.rgbhsv = function( r, g, b ) {

				var h, s, v, min, delta;

				min		= Math.min( r, g, b );
				v		= Math.max( r, g, b );
				delta	= v - min;
				s		= v == 0 ? 0 : ( delta / v ) * 100;

				if ( s == 0 ) {
					h = 0;
				} else {
					if ( r == v ) {
						h = 60 * ( g - b ) / delta;
					} else {
						if ( g == v ) {
							h = 120 + 60 * ( b - r ) / delta;
						} else {
							h = 240 + 60 * ( r - g ) / delta;
						}
					}
				}

				if ( h < 0 ) { h = h + 360; }

				return { h: h, s: s, v: ( v / 255 ) * 100 };

			};

			this.fullrgbhex = function( r ) {

				var x = new RegExp( '^rgb\\(([0-9]{3}), ([0-9]{3}), ([0-9]{3})\\)' ), m = false;

				if ( m = r.toLowerCase().match( x ) ) {
					return this.rgbhex( m[1], m[2], m[3] );
				}

				return false;

			};

		},

		Debug: function( e ) {
			if ( Juice.Prefs.debug === true ) {
				throw e;
			}
		},

		Element: new function() {

			this.addClassName = function( e, n, c ) {
			
				if ( ( typeof c == 'boolean' ) && c !== true ) {
					alert('not added');
					return false;
				}

				if ( !this.hasClassName( e, n ) ) {
					e.className += ' ' + n;
				} else {
					return false;
				}

				return true;

			};

			this.append = function( p, c ) {

				if ( Juice.Type.array( c ) ) {
					for ( var i = 0; i < c.length; i++ ) {
						p.appendChild( c[i] );
					}
				} else {
					p.appendChild( c );
				}

			};

			this.blur = function() {

				return window.focus();

			};

			this.byClassName = function( c, e ) {

				if ( !e ) { e = document; }

				var a = [];
				var n = e.getElementsByTagName( '*' );
				var i;

				for ( i = 0; i < n.length; i++ ) {
					if ( this.hasClassName( n[i], c ) ) {
						a.push( n[i] );
					}
				}

				return a;

			};

			this.contains = function( p, c ) {

				while ( c != document ) {
					if ( c == p ) {
						return true;
					}
					c = c.parentNode;
				}

				return false;

			};

			this.create = function( t, h, i, c, n ) {

				if ( !t ) { return false; }

				var p, s;

				if ( ( p = t.indexOf( ':' ) ) !== -1 ) {
					s = t.substring( p + 1, t.length );
					t = t.substring( 0, p );
				}

				var e = document.createElement( t.toUpperCase() );

				if ( i ) { e.id = i; }
				if ( c ) { e.className = c; }

				switch ( e.nodeName ) {
					case 'A':
						if ( h ) { e.innerHTML = h; }
						if ( n ) { e.href = n; }
					break;
					case 'IFRAME':
						if ( h ) { e.src = h; }
						if ( n ) { e.name = n; }
					break;
					case 'IMG':
						if ( h ) { e.src = h; }
					break;
					case 'INPUT':
						e.type = s;
						if ( h ) { e.value = h; }
						if ( n ) { e.name = n; }
					break;
					case 'OPTION':
						if ( h ) {
							e.innerHTML = h;
							e.value = n || n == '' ? n : h;
						}
					break;
					case 'SELECT':
						if ( n ) { e.name = n; }
					break;
					default:
						if ( h ) { e.innerHTML = h; }
				}

				return e;

			};

			this.dimensions = function( ele ) {

				var s = { height: 0, width: 0 };

				if ( ele.offsetHeight ) {
					s.height	= ele.offsetHeight;
					s.width		= ele.offsetWidth;
				} else {
					s.height	= ele.style.pixelHeight;
					s.width		= ele.style.pixelWidth;
				}

				return s;

			};

			this.empty = function( e ) {

				var c = Juice.$( e );

				if ( c.hasChildNodes() ) {
					while ( c.hasChildNodes() ) {
						c.removeChild( c.firstChild );
					}
				}

			};

			this.hasClassName = function( e, c ) {

				var x = new RegExp( '\\b' + c + '\\b', 'ig' );

				if ( e.className && e.className.match( x ) ) {
					return true;
				}

				return false;

			};

			this.insertAtCaret = function( n, b, a ) {

				n = Juice.$( n );
				if ( n.nodeName == 'TEXTAREA' ) {
					n.focus();
					if ( !a ) { a = ''; }
					if ( document.selection ) {
						var r = document.selection.createRange();
						if ( r.parentElement() != n ) { return false; }
						r.text = b + r.text + a;
						r.moveStart ('character', r.text.length - a.length );
						r.moveEnd ('character', r.text.length - ( a.length > 0 ? b.length - a.length : 0 ) );
						r.select();
					} else if ( n.selectionStart >= 0 ) {
						var s = n.selectionStart, e = n.selectionEnd, c = b + n.value.substring( s, e ) + a;
						if ( c != b + a ) {
							n.value = n.value.substring( 0, s ) + c + n.value.substring( e, n.value.length );
							n.setSelectionRange( s + c.length, s + c.length );
						} else {;
							n.value = n.value.substring( 0, s ) + b + a + n.value.substr( e );
							n.setSelectionRange( s + b.length, s + c.length - a.length );
						}
					} else {
						n.value = n.value + b + a;
					}
					n.focus();
				}
				return; 
	
			};

			this.nextNode = function( n, t ) {

				n = Juice.$( n );

				if ( n.firstChild ) {
					n = n.firstChild;
				} else if ( n.nextSibling ) {
					n = n.nextSibling;
				} else if ( n.parentNode != t ) {
					while ( ( n = n.parentNode ) && n != t ) {
						if ( n.nextSibling ) {
							n = n.nextSibling;
							break;
						}
					}
				} else {
					return null;
				}
				if ( n == t ) {
					return null;
				}
				if ( n != null ) {
					if ( n.nodeType != 1 ) {
						n = this.nextNode( n, t );
					}
				}

				return n;

			};

			this.prevNode = function( n, t ) {

				n = Juice.$( n );

				if ( n.lastChild ) {
					n = n.lastChild;
				} else if ( n.previousSibling ) {
					n = n.previousSibling;
				} else if ( n.parentNode != t ) {
					while ( ( n = n.parentNode ) && n != t ) {
						if ( n.previousSibling ) {
							n = n.previousSibling;
							break;
						}
					}
				} else {
					return null;
				}
				if ( n == t ) {
					return null;
				}
				if ( n != null ) {
					if ( n.nodeType != 1 ) {
						n = this.prevNode( n, t );
					}
				}

				return n;

			};

			this.obstructions = function( n ) {

				if ( Juice.Browser.detect().ie6 ) {

					if ( n.firstChild && n.firstChild.className == 'JuiceObstruction' ) {
						n.removeChild( n.firstChild );
					}

					var d = Juice.Element.dimensions( n );

					var f					= Juice.Element.create( 'IFRAME' );
						f.src				= 'about:blank';
						f.className			= 'JuiceObstruction';
						f.scrolling			= 'no';
						f.frameBorder		= 0;
						f.style.width		= d.width + 'px';
						f.style.height		= d.height + 'px';
						f.style.zIndex		= -1;
						f.style.position	= 'absolute';
						f.style.filter		= 'filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';

					if ( n.firstChild ) {
						n.insertBefore( f, n.firstChild );
					} else {
						n.appendChild( f );
					}

					n.style.zIndex = 900;

				}

			};

			this.opacity = function( e, o ) {

				e.style.opacity	= e.style.MozOpacity = e.style.KHTMLOpacity = ( o / 100 );
				e.style.filter	= 'alpha(opacity=' + o + ')';

				return true;

			};

			this.output = function( e ) {

				if ( typeof e == 'string' ) {
					if ( e.indexOf( '#' ) != -1 ) {
						return ( document.getElementById( e ) || false );
					} else {
						return ( document.getElementsByTagName( e ).item(0) || false );
					}
				}

				return false;

			};

			this.position = function( e ) {

				if ( !e ) { return false; }

				var p = { top: 0, left: 0 };

				if ( e.offsetParent ) {

					p.top	= e.offsetTop;
					p.left	= e.offsetLeft;

					while ( e.offsetParent ) {
						e		= e.offsetParent;
						p.top	+= e.offsetTop;
						p.left	+= e.offsetLeft;
					}

				}

				return p;

			};

			this.remove = function( a, v ) {

				for ( var i = 0; i < a.length; i++ ) {
					if ( v == a[i] ) {
						a.splice( i, 1 );	
					}
				}
				return a;

			};

			this.removeClassName = function( e, c ) {

				if ( this.hasClassName( e, c ) ) {
					e.className = Juice.Format.trim( e.className.replace( new RegExp( '\\b' + c + '\\b', 'ig' ), '' ) );
				} else {
					return false;
				}

				return true;

			};

			this.replaceClassName = function( e, c, r ) {

				if ( this.hasClassName( e, c ) ) {
					Juice.Element.removeClassName( e, c );
					Juice.Element.addClassName( e, r );
				} else {
					return false;
				}

				return true;

			};

			this.scroll = function( e ) {

				var p = { top: 0, left: 0 };

				if ( e ) {

					for ( var n = e; n; n = n.offsetParent ) {
						p.top	+= n.offsetTop;
						p.left	+= n.offsetLeft;
					}

				} else {

					var w = window, d = document;

					if ( typeof w.pageYOffset == 'number' ) {
						p.top	= w.pageYOffset;
						p.left	= w.pageXOffset;
					} else if ( d.body && d.body.scrollTop ) {
						p.top	= d.body.scrollTop;
						p.left	= d.body.scrollLeft;
					} else if ( d.documentElement && d.documentElement.scrollTop ) {
						p.top	= d.documentElement.scrollTop;
						p.left	= d.documentElement.scrollLeft;
					}

				}

				return p;

			};

			this.scrollTo = function( n, e, p ) {

				if ( e ) { Juice.Event.cancel( e ); }

				var o, a, r = 1, d = 3, s = this.scroll(), f = this.scroll( Juice.$( n ) );
				
				if ( s.top < f.top ) {
					o = s.top + Math.max( r, ( ( f.top - s.top ) / d ) );
					a = ( f.top - r <= o );
				} else {
					o = s.top - Math.max( r, ( ( s.top - f.top ) / d ) );
					a = ( f.top - r >= o );
				}

				if ( a || s.top == f.top || p == o ) {
					window.scrollTo( 0, f.top );
				} else {
					window.scrollTo( 0, o );
					setTimeout( function() {
						Juice.Element.scrollTo( n, false, o );
					}, 50 );
				}

			};

			this.search = function( n, h ) {

				if ( typeof h != 'object' ) { return false; }

				for ( var i = 0; i < h.length; i++ ) {
					if ( h[i] == n ) { return true; }
				}

				return false;

			};

			this.searchReplace = function( t, s, r ) {

				return t.replace( new RegExp( s, 'ig' ), r );

			};

			this.style = function( e, s ) {

				if ( !Juice.Browser.detect().ie ) {
					s = s.replace( new RegExp( '[A-Z]', 'g' ), function( m, c ) {
						return '-' + s.charAt( c ).toLowerCase();
					} );
				}

				if ( e.currentStyle ) {
					return e.currentStyle[s];
				} else if ( window.getComputedStyle ) {
					return document.defaultView.getComputedStyle( e, null ).getPropertyValue( s );
				}

				return false;

			};

			this.toggle = function( e ) {

				var c = Juice.$( e );

				if ( c.style.display != 'none' ) {
					c.style.display = 'none';
				} else {
					c.style.display = '';
				}

			};

		},

		Event: new function() {

			this.add = function( e, n, o, c ) {

				e = Juice.$( e );

				if ( e.addEventListener ) {
					e.addEventListener( n, o, c );
				} else if ( e.attachEvent ) {
					e.attachEvent( 'on' + n, o );
				} else {
					return false;
				}

				return true;

			};

			this.blur = function( e, l ) {

				var n = Juice.Event.source( e );

				while ( n != document ) {
					if ( n == l ) { break; }
					n = n.parentNode;
				}

				if ( n != l ) { return true; }

				return false;

			};

			this.cancel = function( e ) {

				if ( !e ) { return false; }

				e = e || window.event;

				if ( e.stopPropagation ) {
					e.preventDefault();
					e.stopPropagation();
				} else {
					e.returnValue	= false;
					e.cancelBubble	= true;
				}

				return true;

			};

			this.remove = function( e, n, o, c ) {

				e = Juice.$( e );

				if ( e.removeEventListener ) {
					e.removeEventListener( n, o, c );
				} else if ( e.detachEvent ) {
					e.detachEvent( 'on' + n, o );
				} else {
					return false;
				}

				return true;

			};

			this.key = function( e ) {

				e = e || window.event;

				if ( !e ) return;

				var k = e.keyCode || e.which || null;

				return { code: k, value: String.fromCharCode( k ).toLowerCase() };

			};

			this.mouse = function( e ) {

			   e = e || window.event, d = document.body;

			   var p = { left: 0, top: 0 };

				if ( e.pageX || e.pageY ) {
					p.left	= e.pageX;
					p.top	= e.pageY;
				} else if ( e.clientX || e.clientY ) {
					var s = Juice.Element.scroll();
					p.left	= e.clientX + s.left;
					p.top	= e.clientY + s.top;
				}

			   return p;

			};

			this.preload = function( s ) {

				var image = new Image();

				if ( typeof s == 'object' ) {
					for ( var i in s ) {
						image.src = s[i];
					}
				} else {
					image.src = s;
				}

			};

			this.source = function( e ) {

				e = e || window.event;

				return ( e.target || e.srcElement );

			};

			this.type = function( e ) {

				e = e || window.event;

				return ( e.type );

			};

		},

		Format: new function() {

			this.decode = function( v ) {

				return decodeURIComponent( v );

			};

			this.email = function( r, d, e ) {

				var a = r + '@' + d + e;

				return '<a href="mailto:' + a + '">' + a + '</a>';

			};

			this.encode = function( v ) {

				return encodeURIComponent( v );

			};

			this.stripTags = function( s ) {

				return s.value.replace( /<\S[^><]*>/g, '' );

			};

			this.entities = function( t ) {

				var d = document.createElement( 'DIV' );
					d.appendChild( document.createTextNode( t ) );
				
				return d.innerHTML;

			};

			this.implode = function( s, a ) {

				if ( Juice.Type.array( a ) ) {
					return a.join( s );
				}

				return false;

			};

			this.ltrim = function( s ) {

				while ( s.substr( 0, 1 ) == ' ' ) {
					s = s.substring( 1, s.length ) ;
				}

				return s;

			};

			this.number = function( n, d, p, g ) {

				var ns = n.toString();
				var s = n < 0 ? '-' : '';
				if ( d ) { n = this.round( n, d ); }
				var i = ( n > 0 ? Math.floor( n ) : Math.abs( Math.ceil( n ) ) ).toString();
				p = p ? p : '.';
				var f = n.toString().substring( i.length + s.length );
				if ( f = d || f.length > 1 ? ( p + f.substring( 1 ) ) : '' ){
					for ( var j = f.length - 1; j < d; j++ ) {
						f += '0';
					}
				}
				if ( g = ( g && g != p ) ? g : ',' ) {
					for ( var j = i.length - 3; j > 0; j -= 3 ) {
						i = i.substring ( 0, j ) + g + i.substring( j );
					}
				}
				return s + i + f;
	
			};

			this.pad = function( v, l, c ) {

				var s = '' + v;

				if ( !c ) { c = '0'; }

				while ( s.length < l ) {
					s = c + s;
				}

				return s;

			};

			this.querySting = function( a ) {

				var u = '';

				for ( var i in a ) {
					u += ( !u.length ? '?' : '&' ) + this.encode( i ) + '=' + this.encode( a[i] );
				}

				return u;

			};

			this.random = function( l, u ) {

				if ( !l || !u ) { l = 1; u = 99999; }

				return Math.floor( Math.random() * ( u - l + 1 ) + l );

			};

			this.round = function( n, d ) {

				if ( Juice.Type.number( n ) ) {
					var m = Math.pow( 10, d );
					return Math.round( n * m ) / m;
				}
				return n;

			};

			this.rtrim = function( s ) {

				while ( s.substr( s.length - 1 , 1 ) == ' ' ) {
					s = s.substring( 0, s.length - 1 );
				}

				return s;

			};

			this.trim = function( s ) {
				return this.rtrim( this.ltrim( s ) );
			};

		},

		Type: new function() {

			this.array = function( o ) {
				return ( o instanceof Array ? true : false );
			};

			this.callback = function( v ) {
				return ( typeof v == 'function' ? true : false );
			};

			this.hexColour = function( v ) {

				if ( v ) {
					return v.match( new RegExp( '^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$', 'i' ) ) ? true : false;
				}

				return false;

			};

			this.number = function( v ) {
				return ( !isNaN( v ) ? true : false );
			};

		},

		Window: new function() {

			this.open = function( url, focus ) {

				var win = window.open( url );

				if ( focus ) { win.focus(); }

				return win;

			};

		},

		Prefs: {
			container: 'body',
			debug: false,
			image: '/includes/library/juice/images/'
		}

	}

})();
