/*

To do 

Make sure remove function works

Add a text function to build up existing textual contents needed for Ripper

*/
// Getme.js
// Author Rob Reid
// 
// Basic DOM manipulation framework to return elements by selector, ID, class, tag and carry our various manipulations against
// the result sets such as setting styles, classNames, properties etc. Developed as an example of how a framework could be build.
//
// Version 1.0.1 - 28-Sep-09 - Created
// Version 1.0.2 - 01-Oct-09
// Version 1.0.3 - 04-Oct-09
// Version 1.0.4 - 02-Nov-09
// Version 1.0.5 - 10-Nov-09
// Version 1.0.5 - 17-Nov-09 - Combined Sizzle with Getme, removed querySelector call from Getme, added TAG.CLASS test in G
// Version 1.0.6 - 21-Nov-09 - Added item method

(function(){

	// set some shortcuts to optimise references to global vars
	var window = this,	// pointing window to this (which refers to the global object) speeds up references to window
				
		undefined,		// this creates an undefined variable we can use to test other undefined variables against

		query = !!document.querySelectorAll; // check whether querySelectorAll is available for use
					

		// the G function is a short cut to instantiating with Getme object
		G = function(sel, context){

			ShowDebug("IN G create new Getme.getit object");

			return new Getme(sel, context);
		}

		// the Getme constuctor pass in a selector/context
		// can handle multiple forms of selector
		// ID - #ID to return element by id e.g G('#myID') 
		// CLASS - .myClass to return elements by className
		// TAG - <P> or <SPAN> to return all elements of a certain node type
		// SELECTOR - DIV P SPAN to return all elements that are SPANS decendants of P who are decendants of DIV
		// NodeList - <DIV><SPAN>hello there</SPAN></DIV> will return a nodelist containing the elements specified by the HTML passed in
		Getme = function(sel, context){		

			ShowDebug("In Getme.getit sel = " + sel + " context = " + context);

			this.Getme = "Getme version 1.0.5",

			this.nodes = this.nodes || [],

			this.context = this.context || document; // default context to document

			// main regEx to determine if selector is HTML string, ID or classname
			var re_getme = /^<([^> ]+)[^>]*>(?:.|\n)+?<\/\1>$|^(\#([-\w]+)|\.(\w[-\w]*))$/i,
	
				// regEx to match <SPAN> <P> <H1> tags
				re_tag = /^<([a-z1-9]+?)>$/i,			
			
				// regEx to match TAG.CLASS e.g SPAN.myClass
				reTagClass = /^(\w+)\.(\w[-\w]*)$/,

				match;

			// if no selector passed in default to document
			if(!sel) sel = document;

			// if we have been passed a string then this could either be
			// an id of an element, a class name, a tag or an HTML string
			if(typeof(sel)==="string"){

				ShowDebug("selector is string check for tag");

				// look for a single HTML tag e.g <P> or <SPAN>
				match = re_tag.exec(sel);				
				
				if(match && match[1]){

					ShowDebug("tag = " + match[1] + " return getElementsByTagName");
					
					// return all nodes matching the tag						
					this.nodes = this.context.getElementsByTagName(match[1]);
				}else{

					ShowDebug("look for class, id or html");

					// run regex to look for ID, class or HTML string
					// match[1] = HTML string - matching start and end tag
					// match[3] = ID
					// match[4] = class name
					var match = re_getme.exec(sel)||[];

					// if we have an ID with or without a # e.g #myid or myid treated as an ID
					if(match[3]){					
						
						ShowDebug("getElementById = '" + match[3] + "'")
						
						// get element by id
						this.nodes[0] = document.getElementById(match[3]);

						ShowDebug("node[0] = " + this.nodes[0] + " from getDetails == " + Getme.funcs.getDetails(this.nodes[0]));
						ShowDebug("document.getElementById(" + match[3] + ") == " + Getme.funcs.getDetails(document.getElementById(match[3])));
					// if we have a class name e.g .myClass
					}else if(match[4]){
						
						ShowDebug("getElementsByClassName = " + match[4])

						// get elements by class name
						this.nodes = Getme.funcs.getElementsByClassName( match[4],this.context);
					
					// if we have a valid HTML string e.g <P><STRONG>hello</STRONG></P>
					}else if(match[1]){

						ShowDebug("create nodes from = " + match[1])

						// create nodes from html
						var div = document.createElement("DIV");

						div.innerHTML = sel;
							
						this.nodes = div.childNodes;	
						
					}else{
						ShowDebug("selector OR tag.class " + sel);
						
						// a simple tag.class e.g SPAN.myClass which we can split and call with getElementsByClassName						

						var ct = reTagClass.exec(sel);

						if(ct && ct[1] && ct[2]){						

							ShowDebug("tag = "+ ct[1] + " class = " + ct[2])

							this.nodes =  Getme.funcs.getElementsByClassName( ct[2],this.context,ct[1]);
						}else{
							ShowDebug("selector = " + sel)

							// just reference Getme.find which points to Sizzle
							// this will use querySelectorAll is available for modern browsers we can use that e.g
							// FF 3.2+, Safari 3.2+, Opera 10, Chrome 3, IE 8 (standards mode)
							this.nodes = Getme.find(sel,this.context);
						}
						
					}
				}
			}else if(sel.nodeType){
				
				ShowDebug("got nodes")

				// already got a node add
				this.nodes[0] = sel;
			
			}else if(Getme.funcs.isArray(sel)){				
				
				ShowDebug("return array")

				this.nodes = sel;
			
			}else{

				ShowDebug("make array");

				this.nodes = Getme.funcs.makeArray(sel);
			}
			
			this.length = this.nodes.length;

			ShowDebug("length of nodes = "+ this.length);

			this.showNodes();
			
			return this; //.nodes;
		}

		// we do this so that getit can be used as a constructor as well as part of the prototype
		Getme.prototype = {			
		
			// returns number of nodes in current selection
			items : function(){
				return (this.nodes && this.nodes.length) ? this.nodes.length : 0;
			},

			// returns the specified element from the current nodeList
			get	: function(idx){			

				//ShowDebug("in get idx = " + idx)


				var node = null;

				if(this.nodes && this.nodes.length>0){
					return (typeof(idx)=="number") ? this.nodes[idx] : this.nodes[0];					
				}else{
					return null;
				}				
				
			},
			
			showNodes : function(){
				ShowDebug("in showNodes");

				var x=0;
				//if(Getme.funcs.isArray(this.nodes)){
					for(var x=0;x<this.nodes.length;x++){
						ShowDebug("node["+x+"] == " + Getme.funcs.getDetails(this.nodes[x]));
					}
				//}

				ShowDebug("all nodes shown");
				return;
			},

			getHtml : function(combine){
				
				ShowDebug("in getHtml combine = " + combine)

				if(this.nodes && this.nodes.length>0){
					
					ShowDebug("we have " + this.nodes.length + " nodes");

					// if we are combining then we join the innerHTML of all nodes otherwise
					// we just return the html of the first one
					if (this.nodes.length>1){

						var totalhtml = "";

						this.each(function(){

							ShowDebug("IN this.each this = "+ Getme.funcs.getDetails(this));

							var html = this.innerHTML;
							
							if(combine){
								totalhtml += html + combine;
							}else{
								totalhtml += html;
							}
						})

						return totalhtml;
					}else{
						//ShowDebug("we have one node = " + Getme.funcs.getDetails(this.nodes[0]))
						
						// make sure node is not null
						if(this.nodes[0]){
							return this.nodes[0].innerHTML;
						}
					}
				}

				return "";
			},
			
			setHtml : function(content){

				ShowDebug("setHTML content = " + content);

				if(content){					
					
					// if a node has been passed in we take its innerHTML
					if(content.nodeType){
						html = content.innerHTML;				
					}else if(typeof(content)==="string"){
						html = content;
					}else{
						html = "";
					}

					ShowDebug("html is " + html);

					this.showNodes();

					// loop through all elements removing existing html
					this.each(function(){
						
						ShowDebug("in this.each look at this == " + Getme.funcs.getDetails(this) );

						
						if ( this.hasChildNodes() ){
							while ( this.childNodes.length >= 1 ){
								this.removeChild( this.firstChild );       
							} 
						}
						
						//ShowDebug("set html = " + html);

						//ShowDebug(Getme.funcs.getDetails(this));
						
						ShowDebug("now set html to " + html);

						ShowDebug("this = " + Getme.funcs.getDetails(this));

						this.innerHTML = html;

						ShowDebug("should have been set lets double check innerHTML = " + this.innerHTML);
					})

				}

				return this;
			},
		

			// allows Getme object to reference the foreach function automatically passing the current node list e.g G('<SPAN>').each(function(){})
			each : function(callback){

				ShowDebug("in each callback = "+ callback);

				ShowDebug("how many in this.nodes = " + this.nodes.length);

				this.foreach(this.nodes,callback);

				return this;
			},

			// A method to handle multiple functions
			// set style values, classes, attributes and object properties
			// for html nodes we can set attribute values, style values sets multiple attributes on an element - internal use only use .setAtts
			setProperties : function(atts){				

				//enumObj(atts)

				var obj = this;

				ShowDebug("in setProperties obj = " + Getme.funcs.getDetails(obj) + " - " + atts);

				if(obj && atts){

					// if object is an html node
					if(obj.nodeType){

						ShowDebug("is html object");

						for(var a in atts){				
						
							if(a == "class" || a == "className"){
								
								//ShowDebug("set className = " + atts[a]);

								// handle class specially
								obj.className = atts[a];								
							
							}else if(a == "style"){
								
								//ShowDebug("set style.cssText = " + atts[a]);

								// use cssText to set multiple styles in one go
								obj.style.cssText = atts[a];
							
							}else{
								
								//ShowDebug("setAttribute " + a + " = " + atts[a]);

								// other attributes
								obj.setAttribute(a,atts[a]);
							}
						}
					// if we passed in a style object - duck type test we can reformat the value to camelCase
					}else if("cssText" in obj){
						
						//ShowDebug("cssText is in obj")

						var js;

						for(var a in atts){								
							
							// make sure style value is in correct camelCase
							var js = a.replace(/\-(\w)/g, function(all, letter){	return letter.toUpperCase();});

							//ShowDebug("set style " + js + " = " + atts[a]);

							// set style property
							obj[js] = atts[a];
						}						
					// otherwise we extend the object with each property/value from the atts object
					}else{

						//ShowDebug("call extend object");

						Getme.funcs.extend(obj,atts);
						
					}
				}
				return obj;
			},
			
			// set attributes for an object			
			setAtts : function(attribute, val){
				
				//ShowDebug("in setAtts = " + attribute + " - " + val);

				if(attribute){
					
					var self = this,

						atts;

					// may have passed att=val pair or a object hash for atts

					if(val !== undefined){	
						//ShowDebug("create object hash")
						// create object hash
						// make sure class is converted to className as it will break in IE
						if(attribute == "class") attribute = "className";
						atts = eval('({'+attribute+':"'+val+'"})');						
					}else{						
						//ShowDebug("point atts to attribute")
						atts = attribute;
					}
					
					//ShowDebug("call foreach for each node");

					// call our internal foreach method which will run a callback function against each value in an array/nodeList
					// we supply the current node list into this function
					this.each(function(){							
							self.setProperties.call(this,atts);
						})
				}

				return this;
			},
				
			setStyle : function(style, val){
				
				//ShowDebug("in setStyle = " + style + " - " + val);

				if(style){
					
					var self = this,
					
						atts;

					// may have passed att=val pair or a object hash for atts

					if(val !== undefined){
						// create object hash						
						// we wrap property names in quotes to handle styles such as font-size which is invalid
						atts = eval('({"'+style+'":"'+val+'"})');
						
					}else{
						atts = style;
					}

					//ShowDebug("call foreach for each node");

					this.each(function(){							
							self.setProperties.call(this.style,atts);
						})
				}

				return this;
			}
			
		}


		// static functions which can be referenced by themselves e.g var a = Getme.funcs.getDetails(obj)
		// we will also extend the Getme prototype so that any Getme objects also have these methods attached
		Getme.funcs = {
			
			// extend one object with another
			extend : function(extendObj,addObj){

				ShowDebug("in extend")

				for(var a in addObj){

					extendObj[a] = addObj[a];
				}
			},

			// foreach function will loop through a node list or array and call a supplied function
			// for each item passing in the the element. A function can be supplied instead of a nodelist
			// to generate the nodelist e.g a call to G or GC (get elements by class/tag/id)
			foreach : function(list, callback, args){

				ShowDebug("in foreach list = " + list + " - " + callback + " - " + args);

				S.enumObj(list);

				var obj;
				
				// if typeof list is a function then run that to generate node list
				if(this.isFunction(list)){					
					list = list.call();
				}
				
				// two loops one for array like objects the other for hash objects
				if(this.isArrayLike(list)){
					
					if(args){
					
						for(var x=0,l=list.length;x<l;x++){	
							ShowDebug("1 callback.apply list[x] = " + Getme.funcs.getDetails(list[x]));
							callback.apply(list[x],args);
						}
					}else{
				
						for(var x=0,l=list.length;x<l;x++){		
							ShowDebug("2 callback.call list[x] = " + Getme.funcs.getDetails(list[x]));
							callback.call(list[x]);
						}
					}
				}else{

					if(args){

						for(var x in list){			
							ShowDebug("3 callback.apply list[x] = " + Getme.funcs.getDetails(list[x]));
							callback.apply(list[x],args);
						}
					}else{

						for(var x in list){		
							ShowDebug("4 callback.call list[x] = " + Getme.funcs.getDetails(list[x]));
							callback.call(list[x]);
						}
					}
				}

				return list;

			},

			remove : function(el){
								
				if (el.parentNode){
					el.parentNode.removeChild( el );
				}

				// Remove any remaining nodes
				while ( el.childNodes.length >= 1 ){
					el.removeChild( el.firstChild );       
				} 
				
			},

			isArray : function(o){
				return Object.prototype.toString.call(o)=="[object Array]";
			},

			// tests for objects with array like properties (array/nodelist)
			isArrayLike : function(o){
				// The window, strings (and functions) also have 'length'
				return (o && o.length && !this.isFunction(o) && !this.isString(o) && o!==window);
			},

			isFunction : function(o){				
				return ((o) instanceof Function);
			},		
			
			isString : function(o){
				return (typeof(o)=="string");
			},

			// return identifying details about node object
			getDetails : function(o){
						
				var d = "NA";

				if(o){					
					d = (o===window) ? "window" : (o===document) ? "document" : (o.nodeName) ? o.nodeName : "UNKNOWN";
					d+= (o.id) ? "."+o.id : (o.name) ? "."+o.name : (o.nodeValue) ? " [" + o.nodeValue + "]" : "";
				}

				return d;
			},

			// returns elements filtered by className, node and tag
			getElementsByClassName : function(clsName,node,tag){
			
				ShowDebug("IN getElementsByClassName " + clsName + " - " + node + " - " + tag);

				node = node || this.context || document,
				tag = tag || "*";

				// use native function if it exists FF 3, Opera 9 etc
				if(document.getElementsByClassName){

					// FF3 Safari Opera
					if(tag=="*"){
						
						var els = node.getElementsByClassName(clsName);
						
						return els;
					}else{
						
						var cls = node.getElementsByClassName(clsName),
						
							els = [],
						
							tag=tag.toUpperCase();

						for(var x=0,l=cls.length;x<l;x++){
							if(cls[x].nodeName==tag){
								els.push(cls[x]);
							}
						}
						return els;
					}			
				
				// use manual function for older browsers and IE 8
				}else{
					
					// Use document.all if possible for all tags
					var retVal = [], 

						els = (tag=="*" && node.all) ? node.all : node.getElementsByTagName(tag),

						re = new RegExp("(^|\\s)"+clsName.replace(/\-/,"\\-")+"(\\s|$)");

					for(var i=0,j=els.length;i<j;i++){
						re.test(els[i].className) ? retVal.push(els[i]) : "";
					}

					return retVal;
				}		
			}
		}

		ShowDebug("extend Getme with Getme.funcs")

		// call the extend function to extend the Getme.prototype with all methods from Getme.funcs
		// this will add these methods to all Getme objects.
		Getme.funcs.extend(Getme.prototype,Getme.funcs);

		//enumObj(Getme.prototype);

		ShowDebug("EXTENDED");
})();

/*!
 *  Sizzle
 *  Author: John Resig
 *  Code to handle selectors for older browsers e.g FF 1-3.4, IE 5-7

 *  Sizzle CSS Selector Engine - v0.9.3
 *  Copyright 2009, The Dojo Foundation
 *  Released under the MIT, BSD, and GPL Licenses.
 *  More information: http://sizzlejs.com/
 */


(function(){


var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,
	done = 0,
	toString = Object.prototype.toString;

var Sizzle = function(selector, context, results, seed) {
	results = results || [];
	context = context || document;

	if ( context.nodeType !== 1 && context.nodeType !== 9 )
		return [];
	
	if ( !selector || typeof selector !== "string" ) {
		return results;
	}

	var parts = [], m, set, checkSet, check, mode, extra, prune = true;
	
	// Reset the position of the chunker regexp (start from head)
	chunker.lastIndex = 0;
	
	while ( (m = chunker.exec(selector)) !== null ) {
		parts.push( m[1] );
		
		if ( m[2] ) {
			extra = RegExp.rightContext;
			break;
		}
	}

	if ( parts.length > 1 && origPOS.exec( selector ) ) {
		if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
			set = posProcess( parts[0] + parts[1], context );
		} else {
			set = Expr.relative[ parts[0] ] ?
				[ context ] :
				Sizzle( parts.shift(), context );

			while ( parts.length ) {
				selector = parts.shift();

				if ( Expr.relative[ selector ] )
					selector += parts.shift();

				set = posProcess( selector, set );
			}
		}
	} else {
		var ret = seed ?
			{ expr: parts.pop(), set: makeArray(seed) } :
			Sizzle.find( parts.pop(), parts.length === 1 && context.parentNode ? context.parentNode : context, isXML(context) );
		set = Sizzle.filter( ret.expr, ret.set );

		if ( parts.length > 0 ) {
			checkSet = makeArray(set);
		} else {
			prune = false;
		}

		while ( parts.length ) {
			var cur = parts.pop(), pop = cur;

			if ( !Expr.relative[ cur ] ) {
				cur = "";
			} else {
				pop = parts.pop();
			}

			if ( pop == null ) {
				pop = context;
			}

			Expr.relative[ cur ]( checkSet, pop, isXML(context) );
		}
	}

	if ( !checkSet ) {
		checkSet = set;
	}

	if ( !checkSet ) {
		throw "Syntax error, unrecognized expression: " + (cur || selector);
	}

	if ( toString.call(checkSet) === "[object Array]" ) {
		if ( !prune ) {
			results.push.apply( results, checkSet );
		} else if ( context.nodeType === 1 ) {
			for ( var i = 0; checkSet[i] != null; i++ ) {
				if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
					results.push( set[i] );
				}
			}
		} else {
			for ( var i = 0; checkSet[i] != null; i++ ) {
				if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
					results.push( set[i] );
				}
			}
		}
	} else {
		makeArray( checkSet, results );
	}

	if ( extra ) {
		Sizzle( extra, context, results, seed );

		if ( sortOrder ) {
			hasDuplicate = false;
			results.sort(sortOrder);

			if ( hasDuplicate ) {
				for ( var i = 1; i < results.length; i++ ) {
					if ( results[i] === results[i-1] ) {
						results.splice(i--, 1);
					}
				}
			}
		}
	}

	
	return results;
};

Sizzle.matches = function(expr, set){
	return Sizzle(expr, null, null, set);
};

Sizzle.find = function(expr, context, isXML){
	var set, match;

	if ( !expr ) {
		return [];
	}

	for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
		var type = Expr.order[i], match;
		
		if ( (match = Expr.match[ type ].exec( expr )) ) {
			var left = RegExp.leftContext;

			if ( left.substr( left.length - 1 ) !== "\\" ) {
				match[1] = (match[1] || "").replace(/\\/g, "");
				set = Expr.find[ type ]( match, context, isXML );
				if ( set != null ) {
					expr = expr.replace( Expr.match[ type ], "" );
					break;
				}
			}
		}
	}

	if ( !set ) {
		set = context.getElementsByTagName("*");
	}

	return {set: set, expr: expr};
};


Sizzle.filter = function(expr, set, inplace, not){
	var old = expr, result = [], curLoop = set, match, anyFound,
		isXMLFilter = set && set[0] && isXML(set[0]);

	while ( expr && set.length ) {
		for ( var type in Expr.filter ) {
			if ( (match = Expr.match[ type ].exec( expr )) != null ) {
				var filter = Expr.filter[ type ], found, item;
				anyFound = false;

				if ( curLoop == result ) {
					result = [];
				}

				if ( Expr.preFilter[ type ] ) {
					match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );

					if ( !match ) {
						anyFound = found = true;
					} else if ( match === true ) {
						continue;
					}
				}

				if ( match ) {
					for ( var i = 0; (item = curLoop[i]) != null; i++ ) {
						if ( item ) {
							found = filter( item, match, i, curLoop );
							var pass = not ^ !!found;

							if ( inplace && found != null ) {
								if ( pass ) {
									anyFound = true;
								} else {
									curLoop[i] = false;
								}
							} else if ( pass ) {
								result.push( item );
								anyFound = true;
							}
						}
					}
				}

				if ( found !== undefined ) {
					if ( !inplace ) {
						curLoop = result;
					}

					expr = expr.replace( Expr.match[ type ], "" );

					if ( !anyFound ) {
						return [];
					}

					break;
				}
			}
		}

		// Improper expression
		if ( expr == old ) {
			if ( anyFound == null ) {
				throw "Syntax error, unrecognized expression: " + expr;
			} else {
				break;
			}
		}

		old = expr;
	}

	return curLoop;
};

var Expr = Sizzle.selectors = {
	order: [ "ID", "NAME", "TAG" ],
	match: {
		ID: /#((?:[\w\u00c0-\uFFFF_-]|\\.)+)/,
		CLASS: /\.((?:[\w\u00c0-\uFFFF_-]|\\.)+)/,
		NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF_-]|\\.)+)['"]*\]/,
		ATTR: /\[\s*((?:[\w\u00c0-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,
		TAG: /^((?:[\w\u00c0-\uFFFF\*_-]|\\.)+)/,
		CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,
		POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,
		PSEUDO: /:((?:[\w\u00c0-\uFFFF_-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/
	},
	attrMap: {
		"class": "className",
		"for": "htmlFor"
	},
	attrHandle: {
		href: function(elem){
			return elem.getAttribute("href");
		}
	},
	relative: {
		"+": function(checkSet, part, isXML){
			var isPartStr = typeof part === "string",
				isTag = isPartStr && !/\W/.test(part),
				isPartStrNotTag = isPartStr && !isTag;

			if ( isTag && !isXML ) {
				part = part.toUpperCase();
			}

			for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
				if ( (elem = checkSet[i]) ) {
					while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}

					checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ?
						elem || false :
						elem === part;
				}
			}

			if ( isPartStrNotTag ) {
				Sizzle.filter( part, checkSet, true );
			}
		},
		">": function(checkSet, part, isXML){
			var isPartStr = typeof part === "string";

			if ( isPartStr && !/\W/.test(part) ) {
				part = isXML ? part : part.toUpperCase();

				for ( var i = 0, l = checkSet.length; i < l; i++ ) {
					var elem = checkSet[i];
					if ( elem ) {
						var parent = elem.parentNode;
						checkSet[i] = parent.nodeName === part ? parent : false;
					}
				}
			} else {
				for ( var i = 0, l = checkSet.length; i < l; i++ ) {
					var elem = checkSet[i];
					if ( elem ) {
						checkSet[i] = isPartStr ?
							elem.parentNode :
							elem.parentNode === part;
					}
				}

				if ( isPartStr ) {
					Sizzle.filter( part, checkSet, true );
				}
			}
		},
		"": function(checkSet, part, isXML){
			var doneName = done++, checkFn = dirCheck;

			if ( !part.match(/\W/) ) {
				var nodeCheck = part = isXML ? part : part.toUpperCase();
				checkFn = dirNodeCheck;
			}

			checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML);
		},
		"~": function(checkSet, part, isXML){
			var doneName = done++, checkFn = dirCheck;

			if ( typeof part === "string" && !part.match(/\W/) ) {
				var nodeCheck = part = isXML ? part : part.toUpperCase();
				checkFn = dirNodeCheck;
			}

			checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML);
		}
	},
	find: {
		ID: function(match, context, isXML){
			if ( typeof context.getElementById !== "undefined" && !isXML ) {
				var m = context.getElementById(match[1]);
				return m ? [m] : [];
			}
		},
		NAME: function(match, context, isXML){
			if ( typeof context.getElementsByName !== "undefined" ) {
				var ret = [], results = context.getElementsByName(match[1]);

				for ( var i = 0, l = results.length; i < l; i++ ) {
					if ( results[i].getAttribute("name") === match[1] ) {
						ret.push( results[i] );
					}
				}

				return ret.length === 0 ? null : ret;
			}
		},
		TAG: function(match, context){
			return context.getElementsByTagName(match[1]);
		}
	},
	preFilter: {
		CLASS: function(match, curLoop, inplace, result, not, isXML){
			match = " " + match[1].replace(/\\/g, "") + " ";

			if ( isXML ) {
				return match;
			}

			for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
				if ( elem ) {
					if ( not ^ (elem.className && (" " + elem.className + " ").indexOf(match) >= 0) ) {
						if ( !inplace )
							result.push( elem );
					} else if ( inplace ) {
						curLoop[i] = false;
					}
				}
			}

			return false;
		},
		ID: function(match){
			return match[1].replace(/\\/g, "");
		},
		TAG: function(match, curLoop){
			for ( var i = 0; curLoop[i] === false; i++ ){}
			return curLoop[i] && isXML(curLoop[i]) ? match[1] : match[1].toUpperCase();
		},
		CHILD: function(match){
			if ( match[1] == "nth" ) {
				// parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
				var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
					match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" ||
					!/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);

				// calculate the numbers (first)n+(last) including if they are negative
				match[2] = (test[1] + (test[2] || 1)) - 0;
				match[3] = test[3] - 0;
			}

			// TODO: Move to normal caching system
			match[0] = done++;

			return match;
		},
		ATTR: function(match, curLoop, inplace, result, not, isXML){
			var name = match[1].replace(/\\/g, "");
			
			if ( !isXML && Expr.attrMap[name] ) {
				match[1] = Expr.attrMap[name];
			}

			if ( match[2] === "~=" ) {
				match[4] = " " + match[4] + " ";
			}

			return match;
		},
		PSEUDO: function(match, curLoop, inplace, result, not){
			if ( match[1] === "not" ) {
				// If we're dealing with a complex expression, or a simple one
				if ( match[3].match(chunker).length > 1 || /^\w/.test(match[3]) ) {
					match[3] = Sizzle(match[3], null, null, curLoop);
				} else {
					var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
					if ( !inplace ) {
						result.push.apply( result, ret );
					}
					return false;
				}
			} else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
				return true;
			}
			
			return match;
		},
		POS: function(match){
			match.unshift( true );
			return match;
		}
	},
	filters: {
		enabled: function(elem){
			return elem.disabled === false && elem.type !== "hidden";
		},
		disabled: function(elem){
			return elem.disabled === true;
		},
		checked: function(elem){
			return elem.checked === true;
		},
		selected: function(elem){
			// Accessing this property makes selected-by-default
			// options in Safari work properly
			elem.parentNode.selectedIndex;
			return elem.selected === true;
		},
		parent: function(elem){
			return !!elem.firstChild;
		},
		empty: function(elem){
			return !elem.firstChild;
		},
		has: function(elem, i, match){
			return !!Sizzle( match[3], elem ).length;
		},
		header: function(elem){
			return /h\d/i.test( elem.nodeName );
		},
		text: function(elem){
			return "text" === elem.type;
		},
		radio: function(elem){
			return "radio" === elem.type;
		},
		checkbox: function(elem){
			return "checkbox" === elem.type;
		},
		file: function(elem){
			return "file" === elem.type;
		},
		password: function(elem){
			return "password" === elem.type;
		},
		submit: function(elem){
			return "submit" === elem.type;
		},
		image: function(elem){
			return "image" === elem.type;
		},
		reset: function(elem){
			return "reset" === elem.type;
		},
		button: function(elem){
			return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON";
		},
		input: function(elem){
			return /input|select|textarea|button/i.test(elem.nodeName);
		}
	},
	setFilters: {
		first: function(elem, i){
			return i === 0;
		},
		last: function(elem, i, match, array){
			return i === array.length - 1;
		},
		even: function(elem, i){
			return i % 2 === 0;
		},
		odd: function(elem, i){
			return i % 2 === 1;
		},
		lt: function(elem, i, match){
			return i < match[3] - 0;
		},
		gt: function(elem, i, match){
			return i > match[3] - 0;
		},
		nth: function(elem, i, match){
			return match[3] - 0 == i;
		},
		eq: function(elem, i, match){
			return match[3] - 0 == i;
		}
	},
	filter: {
		PSEUDO: function(elem, match, i, array){
			var name = match[1], filter = Expr.filters[ name ];

			if ( filter ) {
				return filter( elem, i, match, array );
			} else if ( name === "contains" ) {
				return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
			} else if ( name === "not" ) {
				var not = match[3];

				for ( var i = 0, l = not.length; i < l; i++ ) {
					if ( not[i] === elem ) {
						return false;
					}
				}

				return true;
			}
		},
		CHILD: function(elem, match){
			var type = match[1], node = elem;
			switch (type) {
				case 'only':
				case 'first':
					while (node = node.previousSibling)  {
						if ( node.nodeType === 1 ) return false;
					}
					if ( type == 'first') return true;
					node = elem;
				case 'last':
					while (node = node.nextSibling)  {
						if ( node.nodeType === 1 ) return false;
					}
					return true;
				case 'nth':
					var first = match[2], last = match[3];

					if ( first == 1 && last == 0 ) {
						return true;
					}
					
					var doneName = match[0],
						parent = elem.parentNode;
	
					if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) {
						var count = 0;
						for ( node = parent.firstChild; node; node = node.nextSibling ) {
							if ( node.nodeType === 1 ) {
								node.nodeIndex = ++count;
							}
						} 
						parent.sizcache = doneName;
					}
					
					var diff = elem.nodeIndex - last;
					if ( first == 0 ) {
						return diff == 0;
					} else {
						return ( diff % first == 0 && diff / first >= 0 );
					}
			}
		},
		ID: function(elem, match){
			return elem.nodeType === 1 && elem.getAttribute("id") === match;
		},
		TAG: function(elem, match){
			return (match === "*" && elem.nodeType === 1) || elem.nodeName === match;
		},
		CLASS: function(elem, match){
			return (" " + (elem.className || elem.getAttribute("class")) + " ")
				.indexOf( match ) > -1;
		},
		ATTR: function(elem, match){
			var name = match[1],
				result = Expr.attrHandle[ name ] ?
					Expr.attrHandle[ name ]( elem ) :
					elem[ name ] != null ?
						elem[ name ] :
						elem.getAttribute( name ),
				value = result + "",
				type = match[2],
				check = match[4];

			return result == null ?
				type === "!=" :
				type === "=" ?
				value === check :
				type === "*=" ?
				value.indexOf(check) >= 0 :
				type === "~=" ?
				(" " + value + " ").indexOf(check) >= 0 :
				!check ?
				value && result !== false :
				type === "!=" ?
				value != check :
				type === "^=" ?
				value.indexOf(check) === 0 :
				type === "$=" ?
				value.substr(value.length - check.length) === check :
				type === "|=" ?
				value === check || value.substr(0, check.length + 1) === check + "-" :
				false;
		},
		POS: function(elem, match, i, array){
			var name = match[2], filter = Expr.setFilters[ name ];

			if ( filter ) {
				return filter( elem, i, match, array );
			}
		}
	}
};

var origPOS = Expr.match.POS;

for ( var type in Expr.match ) {
	Expr.match[ type ] = RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source );
}

var makeArray = function(array, results) {
	array = Array.prototype.slice.call( array );

	if ( results ) {
		results.push.apply( results, array );
		return results;
	}
	
	return array;
};

// Perform a simple check to determine if the browser is capable of
// converting a NodeList to an array using builtin methods.
try {
	Array.prototype.slice.call( document.documentElement.childNodes );

// Provide a fallback method if it does not work
} catch(e){
	makeArray = function(array, results) {
		var ret = results || [];

		if ( toString.call(array) === "[object Array]" ) {
			Array.prototype.push.apply( ret, array );
		} else {
			if ( typeof array.length === "number" ) {
				for ( var i = 0, l = array.length; i < l; i++ ) {
					ret.push( array[i] );
				}
			} else {
				for ( var i = 0; array[i]; i++ ) {
					ret.push( array[i] );
				}
			}
		}

		return ret;
	};
}

var sortOrder;

if ( document.documentElement.compareDocumentPosition ) {
	sortOrder = function( a, b ) {
		var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1;
		if ( ret === 0 ) {
			hasDuplicate = true;
		}
		return ret;
	};
} else if ( "sourceIndex" in document.documentElement ) {
	sortOrder = function( a, b ) {
		var ret = a.sourceIndex - b.sourceIndex;
		if ( ret === 0 ) {
			hasDuplicate = true;
		}
		return ret;
	};
} else if ( document.createRange ) {
	sortOrder = function( a, b ) {
		var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange();
		aRange.selectNode(a);
		aRange.collapse(true);
		bRange.selectNode(b);
		bRange.collapse(true);
		var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange);
		if ( ret === 0 ) {
			hasDuplicate = true;
		}
		return ret;
	};
}

// Check to see if the browser returns elements by name when
// querying by getElementById (and provide a workaround)
(function(){
	// We're going to inject a fake input element with a specified name
	var form = document.createElement("form"),
		id = "script" + (new Date).getTime();
	form.innerHTML = "<input name='" + id + "'/>";

	// Inject it into the root element, check its status, and remove it quickly
	var root = document.documentElement;
	root.insertBefore( form, root.firstChild );

	// The workaround has to do additional checks after a getElementById
	// Which slows things down for other browsers (hence the branching)
	if ( !!document.getElementById( id ) ) {
		Expr.find.ID = function(match, context, isXML){
			if ( typeof context.getElementById !== "undefined" && !isXML ) {
				var m = context.getElementById(match[1]);
				return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
			}
		};

		Expr.filter.ID = function(elem, match){
			var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
			return elem.nodeType === 1 && node && node.nodeValue === match;
		};
	}

	root.removeChild( form );
})();

(function(){
	// Check to see if the browser returns only elements
	// when doing getElementsByTagName("*")

	// Create a fake element
	var div = document.createElement("div");
	div.appendChild( document.createComment("") );

	// Make sure no comments are found
	if ( div.getElementsByTagName("*").length > 0 ) {
		Expr.find.TAG = function(match, context){
			var results = context.getElementsByTagName(match[1]);

			// Filter out possible comments
			if ( match[1] === "*" ) {
				var tmp = [];

				for ( var i = 0; results[i]; i++ ) {
					if ( results[i].nodeType === 1 ) {
						tmp.push( results[i] );
					}
				}

				results = tmp;
			}

			return results;
		};
	}

	// Check to see if an attribute returns normalized href attributes
	div.innerHTML = "<a href='#'></a>";
	if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
			div.firstChild.getAttribute("href") !== "#" ) {
		Expr.attrHandle.href = function(elem){
			return elem.getAttribute("href", 2);
		};
	}
})();

if ( document.querySelectorAll ) (function(){
	var oldSizzle = Sizzle, div = document.createElement("div");
	div.innerHTML = "<p class='TEST'></p>";

	// Safari can't handle uppercase or unicode characters when
	// in quirks mode.
	if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
		return;
	}
	
	Sizzle = function(query, context, extra, seed){
		context = context || document;

		// Only use querySelectorAll on non-XML documents
		// (ID selectors don't work in non-HTML documents)
		if ( !seed && context.nodeType === 9 && !isXML(context) ) {
			try {
				return makeArray( context.querySelectorAll(query), extra );
			} catch(e){}
		}
		
		return oldSizzle(query, context, extra, seed);
	};

	Sizzle.find = oldSizzle.find;
	Sizzle.filter = oldSizzle.filter;
	Sizzle.selectors = oldSizzle.selectors;
	Sizzle.matches = oldSizzle.matches;
})();

if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){
	var div = document.createElement("div");
	div.innerHTML = "<div class='test e'></div><div class='test'></div>";

	// Opera can't find a second classname (in 9.6)
	if ( div.getElementsByClassName("e").length === 0 )
		return;

	// Safari caches class attributes, doesn't catch changes (in 3.2)
	div.lastChild.className = "e";

	if ( div.getElementsByClassName("e").length === 1 )
		return;

	Expr.order.splice(1, 0, "CLASS");
	Expr.find.CLASS = function(match, context, isXML) {
		if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
			return context.getElementsByClassName(match[1]);
		}
	};
})();

function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
	var sibDir = dir == "previousSibling" && !isXML;
	for ( var i = 0, l = checkSet.length; i < l; i++ ) {
		var elem = checkSet[i];
		if ( elem ) {
			if ( sibDir && elem.nodeType === 1 ){
				elem.sizcache = doneName;
				elem.sizset = i;
			}
			elem = elem[dir];
			var match = false;

			while ( elem ) {
				if ( elem.sizcache === doneName ) {
					match = checkSet[elem.sizset];
					break;
				}

				if ( elem.nodeType === 1 && !isXML ){
					elem.sizcache = doneName;
					elem.sizset = i;
				}

				if ( elem.nodeName === cur ) {
					match = elem;
					break;
				}

				elem = elem[dir];
			}

			checkSet[i] = match;
		}
	}
}

function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
	var sibDir = dir == "previousSibling" && !isXML;
	for ( var i = 0, l = checkSet.length; i < l; i++ ) {
		var elem = checkSet[i];
		if ( elem ) {
			if ( sibDir && elem.nodeType === 1 ) {
				elem.sizcache = doneName;
				elem.sizset = i;
			}
			elem = elem[dir];
			var match = false;

			while ( elem ) {
				if ( elem.sizcache === doneName ) {
					match = checkSet[elem.sizset];
					break;
				}

				if ( elem.nodeType === 1 ) {
					if ( !isXML ) {
						elem.sizcache = doneName;
						elem.sizset = i;
					}
					if ( typeof cur !== "string" ) {
						if ( elem === cur ) {
							match = true;
							break;
						}

					} else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
						match = elem;
						break;
					}
				}

				elem = elem[dir];
			}

			checkSet[i] = match;
		}
	}
}

var contains = document.compareDocumentPosition ?  function(a, b){
	return a.compareDocumentPosition(b) & 16;
} : function(a, b){
	return a !== b && (a.contains ? a.contains(b) : true);
};

var isXML = function(elem){
	return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
		!!elem.ownerDocument && isXML( elem.ownerDocument );
};

var posProcess = function(selector, context){
	var tmpSet = [], later = "", match,
		root = context.nodeType ? [context] : context;

	// Position selectors must be done after the filter
	// And so must :not(positional) so we move all PSEUDOs to the end
	while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
		later += match[0];
		selector = selector.replace( Expr.match.PSEUDO, "" );
	}

	selector = Expr.relative[selector] ? selector + "*" : selector;

	for ( var i = 0, l = root.length; i < l; i++ ) {
		Sizzle( selector, root[i], tmpSet );
	}

	return Sizzle.filter( later, tmpSet );
};

// EXPOSE Sizzle to Getme.js

window.Sizzle = Sizzle;

Getme.find = Sizzle;
Getme.filter = Sizzle.filter;
Getme.expr = Sizzle.selectors;
Getme.expr[":"] = Getme.expr.filters;

Sizzle.selectors.filters.hidden = function(elem){
	return elem.offsetWidth === 0 || elem.offsetHeight === 0;
};

Sizzle.selectors.filters.visible = function(elem){
	return elem.offsetWidth > 0 || elem.offsetHeight > 0;
};


return;

})();

