/*!
 * vQuery JavaScript Library Core v1.0.0
 * http://vquery.mwebng.net/
 * Copyright (c) 2009 Tony Ogundipe
 * Date: 2009-02-19 17:34:21 -0500 (Thu, 19 Feb 2009)
 * vquery.core, vquery.fx, vquery.fn, vquery.events
 */

 /*! vquery.core */
//vquery class start
(function(){
	vQuery = window.vQuery = window.$ = function( selector,elements) {
		return new vQuery.fn.init( selector,elements);
	};

//declared into the vQuery Namespace
vQuery.readyBound=false,
vQuery.readyFx=new Array();

vQuery.fn = vQuery.prototype = {
	init: function (selector, context) {

	selector = selector || document;
	context = context || document;
	
	this.selector=selector;this.context=context; //save selector/context
	this.tags = vQuery.fs.select(selector,context);this.element=this.tags; //save returned elements
	vQuery.tags=this.tags;vQuery.elements=this.tags;
	vQuery.fn.elements=this.tags;vQuery.fn.tags=this.tags;

},

	version: function() {
		return "v1.00";
	},

	version2: function() {
		alert(this.version());
		return this;
	}	  
};
/*End of fn prototype */

vQuery.fx = vQuery.prototype = {
	speeds:{
		slow: 600,
 		fast: 200,
 		// Default speed
 		_default: 400
	},
	
	step: {

		opacity: function(fx){
			vQuery.attr(fx.elem.style, "opacity", fx.now);
		},

		_default: function(fx){
			if ( fx.elem.style && fx.elem.style[ fx.prop ] != null )
				fx.elem.style[ fx.prop ] = fx.now + fx.unit;
			else
				fx.elem[ fx.prop ] = fx.now;
		}
}
};

/*End of fx prototype */



vQuery.fs = vQuery.prototype = {

	select: function (selector,context) {
if(typeof(selector)=="object") {return new Array(selector);} 

if(selector.indexOf('<')!=-1) {return document;};

return Sizzle(selector,context);
},


	registerEvents: function(args) {
	var ex=args.split(",");
	for(key in ex) {
	var ev=ex[key];
	
	eval("vQuery.fn.extend({"+ev+": function() {return this.createEvent('"+ev+"',this."+ev+".arguments);}})");

	}
	
	}	
};
/*End of fs prototype */


//placeholder for the support class
vQuery.support = {};

var userAgent = navigator.userAgent.toLowerCase();

// Figure out what browser is being used
vQuery.browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
	safari: /webkit/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};


vQuery.event = {
add: function (evt,targ,handle2) {
if(targ.tagName==null&&typeof(targ)!='object') {this.log(targ.toString()+" is not a valid object handle - add::"+evt);return;};

//prepare handler
handler=function(event) {

//ie fix and sync
if (vQuery.browser.msie) {
event = window.event;target=event.srcElement; //ie fix
event.target=target;
} else {
target=event.target; //mozilla fix
};

//equivalent handlers for IE
if (vQuery.browser.msie) {
event.preventDefault=function() {window.event.returnValue = false;};
event.stopPropagation=function() {window.event.cancelBubble = true;};
};

ret=handle2.call(target,event);

if(!ret) {event.preventDefault();};
return ret;
};

try {

if(evt=="unload") {
 handler=function(event) {
 ret=handle2(event);
 vQuery.lastEvent=event;
 return ret;
};


window.onbeforeunload = handler;
return;
};

//cache event handler
  //uid = vQuery.data(targ);
  //alert(uid);

  vQuery.data(targ, evt, handler); 
  vQuery.data(targ, "_"+evt, handle2); 
  
	if(window.addEventListener) {
	targ.addEventListener(evt, handler, false);
	} else {
	targ.attachEvent('on'+evt,handler);
    }

} catch(err) {void(0);}
},

version: function () {
alert("Event Library 1.0");
},

log: function (err) {
try {console.log("vQuery:"+err);} catch(err) {void(0);};
},


trigger: function(event,target,data) {
if(target.tagName==null) {this.log(target.toString()+" is not a valid object handle - trigger::"+event);return;};

//cheat mode a.k.a smart mode
if(event=="focus") {target.focus();return;};

    if (vQuery.browser.msie){
        // dispatch for IE
		  var evt = document.createEventObject();
		  try {evt.pageX=0;evt.pageY=0;evt.button=0;} catch(err) {void(0);};
         return target.fireEvent('on'+event,evt);
    }
    else {
        // dispatch for firefox + others
		if(event=="click"||event=="dblclick") {
          var evt = document.createEvent("MouseEvents");
          evt.initMouseEvent(event, true, true, window,0, 0, 0, 0, 0, false, false, false, false, 0, null);
		} else {
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true ); // event type,bubbling,cancelable
      };
var canceled = !target.dispatchEvent(evt);
//if(canceled) {alert("canceled");} else {alert("not canceled");} 
return ;
    }
},

remove: function(evt,target,handler) {

//if event is not defined, then match all
if(typeof(evt)=="undefined") {
var ex=vQuery.fs.eventList.split(",");

var events=new Array();
for(i in ex) {
if(typeof(vQuery.data(target,ex[i]))!="undefined") {events.push(ex[i]);}
};

//parse the events used by selected object
for(e in events) {
event=events[e];
handler=vQuery.data(target,event);
this.remove(event,target,handler);
};return;
};
//end of find events

//event was defined but no handler
if(typeof(handler)=="undefined") {handler=vQuery.data(target,evt);};

if(target.tagName==null) {this.log(target.toString()+" is not a valid object handle - remove::"+evt);return;};
try{if(window.addEventListener) {
	target.removeEventListener(evt, handler, false);
	} else {
	target.detachEvent('on'+evt,handler);
    }
} catch(err) {void(0);}
}

};
/*End of Event Class */

vQuery.DOM = {
		/**
		 * Get a dom node
		 * @param {String} id The id of the element to get or the element itself
		 * @return {Element} The element found
		 */
		get: function(id){
			return vQuery.fs.select(id);
		},
		
		/**
		 * Get a style of an element
		 * @param {Element} el The element for the style to be retrieved from
		 * @param {String} prop The property or style that is to be found
		 * @return {Number} The value of the property
		 */
		getStyle: function(el, prop){
			prop = toCamelCase(prop);
			var view = document.defaultView;
			if(view && view.getComputedStyle){
				return el.style[prop] || view.getComputedStyle(el, "")[prop] || null;
			}else{
				if(prop == 'opacity'){
				try {
					var opacity = el.filters('alpha').opacity;
					return isNaN(opacity) ? 1 : (opacity ? opacity / 100 : 0);
					} catch(err) {return 1;} //'cos i noticed when nothing is set ie coughs
				}
				return el.style[prop] || el.currentStyle[prop] || null;
			}
		},
		
		/**
		 * Set a style for an element
		 * @param {Element} el The element the new value will be applied to
		 * @param {String} prop The property or style that will be set
		 * @param {String} value The value of the property to be set
		 */
		setStyle: function(el, prop, value){
			if(prop == 'opacity'){
				el.style.filter = "alpha(opacity=" + value * 100 + ")";
				el.style.opacity = value;
			}else{
				prop = toCamelCase(prop);
				el.style[prop] = value;
				//el.style.prop = value;
				//alert(prop+"::"+value);
				//alert("el.style."+prop+"='"+value+"';");
			}
		}
	};

		/**
	 * Convert a CSS property to camel case (font-size to fontSize)
	 * @param {String} str The property that requires conversion to camel case
	 * @return {String} The camel cased property string
	 */

	var cache2 = {};
	function toCamelCase(str) {
			if(!cache2[str]){
				return cache2[str] = str.replace( /-([a-z])/g, function($0,$1){
					return $1.toUpperCase();
				});
			}else{
				return cache2[str];
			}
  };

vQuery.className = {
// internal only, use addClass("class")
add: function( elem, classNames) {
cls=classNames.split(/\s+/);
  vQuery(elem).each(function (i) { 
  for(c in cls) {
 vQuery.className.jscss("add",this,cls[c]);
  }  
 });
},

remove: function( elem, classNames) {
cls=classNames.split(/\s+/);
  vQuery(elem).each(function (i) { 
  for(c in cls) {
 vQuery.className.jscss("remove",this,cls[c]);
  }  
 });
},

toggle: function( elem, classNames) {
cls=classNames.split(/\s+/);
  vQuery(elem).each(function (i) { 
  for(c in cls) {
  if(vQuery.className.jscss("check",this,cls[c])) {
 vQuery.className.jscss("remove",this,cls[c]);
  } else {
 vQuery.className.jscss("add",this,cls[c]);
}
}
  
 });
},

//style controller
 jscss:function (a,o,c1,c2) {
  switch (a){
    case 'swap':
      o.className=!this.jscss('check',o,c1)?o.className.replace(c2,c1): 
      o.className.replace(c1,c2);
    break;
    case 'add':
      if(!this.jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;};
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className);
    break;
  }
}
};


//create the plugin function
vQuery.extend = vQuery.fn.extend = function() {
	// copy reference to target object
	var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;

	// Handle a deep copy situation
	if ( typeof target === "boolean" ) {
		deep = target;
		target = arguments[1] || {};
		// skip the boolean and the target
		i = 2;
	};

	// Handle case when target is a string or something (possible in deep copy)
	if ( typeof target !== "object" && !vQuery.isFunction(target) )
		target = {};

	// extend vQuery itself if only one argument is passed
	if ( length == i ) {
		target = this;
		--i;
	};

	for ( ; i < length; i++ )
		// Only deal with non-null/undefined values
		if ( (options = arguments[ i ]) != null )
			// Extend the base object
			for ( var name in options ) {
				var src = target[ name ], copy = options[ name ];

				// Prevent never-ending loop
				if ( target === copy )
					{continue};

				// Recurse if we're merging object values
				if ( deep && copy && typeof copy === "object" && !copy.nodeType )
					target[ name ] = vQuery.extend( deep, 
						// Never move original objects, clone them
						src || ( copy.length != null ? [ ] : { } )
					, copy );

				// Don't bring in undefined values
				else if ( copy !== undefined )
					{target[ name ] = copy;};

			};

	// Return the modified object
	return target;
};


// Give the init function the vQuery prototype for later instantiation
vQuery.fn.init.prototype = vQuery.fn;
})();

//register core events
vQuery.fs.eventList="click,submit,dblclick,blur,error,change,focus,keydown,keypress,keyup,";
vQuery.fs.eventList+="load,mousedown,mousemove,mouseout,mouseover,resize,scroll,select,selectstart";
vQuery.fs.registerEvents(vQuery.fs.eventList);	

//sizzle engine


 /*! vquery.fx */
/*!
 * vQuery Fx Library
 */

function now(){return +new Date;};

 var expando = "vQuery" + now(), uuid = 0, windowData = {};

vQuery.extend({

log: function (err) {vQuery.event.log(err);},

speeds:{slow: 6,fast: 2,_default: 4},

version2: function() {return vQuery.fn.version2();},
version: function() {return vQuery.fn.version();},

	bindReady: function(){
	if (vQuery.readyBound ) {return;};
	vQuery.readyBound = true;
	// Mozilla, Opera and webkit nightlies currently support this event
	if ( document.addEventListener ) {
		document.addEventListener( "DOMContentLoaded", function(){
			vQuery.ready();
		}, false );

	// If IE event model is used
	} else {
		// ensure firing before onload,
		// maybe late but safe also for iframes
		document.attachEvent("onreadystatechange", function(){
			if ( document.readyState === "complete" ) {
				vQuery.ready();
			}
		});
	};
// A fallback to window.onload, that will always work
window.load=function() {vQuery.ready();}
	//vQuery.event.add( window, "load", vQuery.ready );
},

ready: function(fx){
//test box model
var div = document.createElement("div");
div.style.width = div.style.paddingLeft = "1px";

document.body.appendChild( div );
vQuery.boxModel = vQuery.support.boxModel = div.offsetWidth === 2;
document.body.removeChild( div ).style.display = 'none';

vQuery.readyList=vQuery.readyFx;

vQuery.each( vQuery.readyList, function(){
					this.call( document, vQuery);
				});
				// Reset the list of functions
				vQuery.readyList = null;
},

each: function( object, callback, args ) {
//this will help so that the object can be passed as param via fn
if(typeof (object.tags)!="undefined") {object=object.tags;};

var name, i = 0, length = object.length;

		if ( args ) {
			if ( length === undefined ) {return;
				for ( name in object )
					if ( callback.apply( object[ name ], args ) === false )
						break;
			} else 
				for ( ; i < length; )
					if ( callback.apply( object[ i++ ], args ) === false )
						break;

		// A special, fast, case for the most common use of each
		} else {
			if ( length === undefined ) {
				for ( name in object )
					if ( callback.call( object[ name ], name, object[ name ] ) === false )
						break;
			} else
				for ( var value = object[0];
					i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
		};

		return object;
},

queryUnload:function(evt,message) {
 if (typeof (evt) == 'undefined') {evt = window.event;};evt.returnValue = message;
},

eprompt:function(evt,message) {
 this.queryUnload(evt,message);
},


getScript: function(url,callback) {
	var fileref=document.createElement('script');
	fileref.setAttribute("type","text/javascript");
	fileref.setAttribute("src", url);  
    if(typeof(callback)=="undefined") {callback=function() {};}
	if(this.browser.msie) {
	fileref.onreadystatechange=function() {
    	  if(fileref.readyState=='loaded') {callback();}	
		}
	} else {
	fileref.onload=function() {callback();}
	};	
	document.getElementsByTagName("head")[0].appendChild(fileref);
	return this;
},	

getCss: function(url,callback) {
	var fileref=document.createElement("link");
    if(typeof(callback)=="undefined") {callback=function() {};}
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", url);
	if(this.browser.msie) {
	fileref.onreadystatechange=function() {
    	  if(fileref.readyState=='loaded') {callback();}	
		}
	} else {
	fileref.onload=function() {callback();}
	};	
	document.getElementsByTagName("head")[0].appendChild(fileref);
},



trim: function( text ) {
		return (text || "").replace( /^\s+|\s+$/g, "" );
},

	isFunction: function( obj ) {
	if(typeof(obj)=="function") {return true;} else {return false;}
	},

	isArray: function( obj ) {
	try {
		return toString.call(obj) === "[object Array]";
		} catch(err) {return false;}
	},

	// check if an element is in a (or is an) XML document
	isXMLDoc: function( elem ) {
		return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
			!!elem.ownerDocument && vQuery.isXMLDoc( elem.ownerDocument );
	},

		param: function( a ) {
		try {
		var s = [ ];

		function add( key, value ){
			s[ s.length ] = encodeURIComponent(key) + '=' + encodeURIComponent(value);
		};

		// If an array was passed in, assume that it is an array
		// of form elements
		try {if(a[0].tagName) {isTag=true;}} catch(err) {isTag=false;};
		if ((isTag)) {
			// Serialize the form elements
			vQuery.each( a, function(){
				add( this.name, this.value );
			});
			}

		// Otherwise, assume that it's an object of key/value pairs
		else 
			// Serialize the key/values
			for ( var j in a )
				// If the value is an array then the key names need to be repeated
				if ( vQuery.isArray(a[j]) ) {
					vQuery.each( a[j], function(i){
						add( j, this );
					});
				} else {
					add( j, vQuery.isFunction(a[j]) ? a[j]() : a[j] );
					};
					} catch(err) {alert("param:"+err.description);};

		// Return the resulting serialization
		return s.join("&").replace(/%20/g, "+");
	},

//data function intro
	cache: {},

	data: function( elem, name, data ) {
		elem = elem == window ?
			windowData :
			elem;

		var id = elem[ expando ];

		// Compute a unique ID for the element
		if ( !id )
			id = elem[ expando ] = ++uuid;

		// Only generate the data cache if we're
		// trying to access or manipulate it
		if ( name && !vQuery.cache[ id ] )
			vQuery.cache[ id ] = {};

		// Prevent overriding the named cache with undefined values
		if ( data !== undefined )
			vQuery.cache[ id ][ name ] = data;

		// Return the named cache data, or the ID for the element
		return name ?
			vQuery.cache[ id ][ name ] :
			id;
	},
	
	dataEx: function(target,prop,value) {
    //save the property value once
    if(typeof(vQuery.data(target,prop))!="undefined") {return vQuery.data(target,prop);};
    //retrieve value and save 
   vQuery.data(target,prop,value);
   return value;
  },

	removeData: function( elem, name ) {
		elem = elem == window ?
			windowData :
			elem;

		var id = elem[ expando ];

		// If we want to remove a specific section of the element's data
		if ( name ) {
			if ( vQuery.cache[ id ] ) {
				// Remove the section of cache data
				delete vQuery.cache[ id ][ name ];

				// If we've removed all the data, remove the element's cache
				name = "";

				for ( name in vQuery.cache[ id ] )
					break;

				if ( !name )
					vQuery.removeData( elem );
			}

		// Otherwise, we want to remove all of the element's data
		} else {
			// Clean up the element expando
			try {
				delete elem[ expando ];
			} catch(e){
				// IE has trouble directly removing the expando
				// but it's ok with using removeAttribute
				if ( elem.removeAttribute )
					elem.removeAttribute( expando );
			}

			// Completely remove the data cache
			delete vQuery.cache[ id ];
		}
	},
	queue: function( elem, type, data ) {
		if ( elem ){
	
			type = (type || "fx") + "queue";
	
			var q = vQuery.data( elem, type );
	
			if ( !q || vQuery.isArray(data) )
				q = vQuery.data( elem, type, vQuery.makeArray(data) );
			else if( data )
				q.push( data );
	
		};
		return q;
	},

	dequeue: function( elem, type ){
		var queue = vQuery.queue( elem, type ),
			fn = queue.shift();
		
		if( !type || type === "fx" )
			fn = queue[0];
			
		if( fn !== undefined )
			fn.call(elem);
	},

	speed: function(speed, easing, fn) {
		var opt = typeof speed === "object" ? speed : {
			complete: fn || !fn && easing ||
				vQuery.isFunction( speed ) && speed,
			duration: speed,
			easing: fn && easing || easing && !vQuery.isFunction(easing) && easing
		};

		opt.duration = vQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
			vQuery.fx.speeds[opt.duration] || vQuery.fx.speeds._default;

		// Queueing
		opt.old = opt.complete;
		opt.complete = function(){
			if ( opt.queue !== false )
				vQuery(this).dequeue();
			if ( vQuery.isFunction( opt.old ) )
				opt.old.call( this );
		};

		return opt;
	},

	easing: {
		linear: function( p, n, firstNum, diff ) {
			return firstNum + diff * p;
		},
		swing: function( p, n, firstNum, diff ) {
			return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
		}
	},

	timers: [],
	easing: {
		linear: function( p, n, firstNum, diff ) {
			return firstNum + diff * p;
		},
		swing: function( p, n, firstNum, diff ) {
			return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
		}
	},

	timers: [],

	fx: function( elem, options, prop ){
		this.options = options;
		this.elem = elem;
		this.prop = prop;

		if ( !options.orig )
			options.orig = {};
	},

offset:function(el) {
var curleft = 0;var curtop = 0;ob=el;
      if (el.offsetParent) {
            do {curleft += el.offsetLeft;curtop += el.offsetTop;
            } while (el = el.offsetParent);
      };
	  
	  cwidth=ob.clientWidth;cheight=ob.clientHeight;
	  cwidth2=ob.offsetWidth;cheight2=ob.offsetHeight;
	  dw=cwidth2-cwidth;
	return {left:curleft,top:curtop,width:cwidth,height:cheight,width2:cwidth2,height2:cheight2};
},
	
noConflict: function( deep ) {return vQuery;}
});


 /*! vquery.fn */
vQuery.fn.extend({
each: function( callback, args ) {
		return vQuery.each(this, callback, args );
},

ready: function(fx){
if (vQuery.readyBound ) {fx();return;};
vQuery.readyFx[vQuery.readyFx.length]=fx;
vQuery.bindReady();
},

appendTo: function(tag) {  
var elements=vQuery.fs.select(tag);
var html=this.selector; 

this.elements=elements;this.tags=elements;this.selector=tag;//sync

for(i=0;i<elements.length;i++) {
element=elements[i];
try {
var s=document.createElement("SPAN");
element.appendChild(s);
s.innerHTML=html;
} catch(err) {void(0);}
};
return this;
},


append: function(html) {  
if(typeof(html)=="object") {html=html.selector;};
vQuery(html).appendTo(this.selector);
return this;
},

prepend: function(html) {  
if(typeof(html)=="object") {html=html.selector;};
vQuery(html).prependTo(this.selector);return this;
},


prependTo: function(tag) {  
var elements=vQuery.fs.select(tag);
var html=this.selector; 

this.elements=elements;this.tags=elements;this.selector=tag;//sync

for(i=0;i<elements.length;i++) {
element=elements[i];
try {
if(vQuery.browser.msie) {
element.insertAdjacentHTML("beforeBegin",html);
} else {
var oSpan=document.createElement("SPAN");
element.insertBefore(oSpan, element.firstChild );
oSpan.innerHTML=html;
}

} catch(err) {void(0);}
};
return this;
},


attr: function(key, value,style) {

var args=this.attr.arguments;
if(args.length==2) {key=args[0];value=args[1];} 
else if(args.length==3) {key=args[0];value=args[1];style=args[2];} 
else if(args.length==1) {

var json=args[0];
//parse json param
if(typeof(json)=="object") {
for(key in json) {this.attr(key,json[key]);}
return;
} else {
//try get name
var targ=this.find();key=args[0];
if(!vQuery.browser.msie) {
return this.findAttribute(targ,key);
} else {
return this.find().getAttribute(json);
}
}

} else {
vQuery.event.log("Invalid number of parameters for attr");
return;
};

  vQuery.each(this.tags,function (i) { 
		if(style!="css") {
			try {this.setAttribute(key,value);} catch(e) {void(0);}
			} else {
			//try {this.style.cssText+=";"+key+":"+value;} catch(e) {void(0);}
			//try {eval("this.style."+key+"='"+value+"';");} catch(e) {void(0);}
			//try {vQuery.DOM.setStyle(this,key,value);} catch(e) {void(0);}
			vQuery.DOM.setStyle(this,key,value);
			}
			
		});
},

get: function() {
args=this.get.arguments;
if(args.length==0) {
return  this.elements;
} else {
return  this.elements[0];
}
},


remove: function() {
vQuery.each(this.tags,function(i) {
this.parentNode.removeChild(this);
}
);

return this;
},


eq: function(pos) {
ret=new Array(this.elements[pos]);
this.selector=ret;this.tags=ret;this.elements=ret;
return this;
},

index: function(targ) {
for(i=0;i<this.elements.length;i++) {
if(this.elements[i]==targ) {return i;}
};
return -1;
},

length: function() {return this.elements.length},
size: function() {return this.length();},


find: function() {
var args=this.find.arguments;
if(args.length==0) {return  this.get(0);};
selector=args[0];context=this.selector;
this.elements=this.tags=vQuery.fs.select(selector,context);
return this;
},

removeAttr: function(key) {
		vQuery(this).each(function (i) { 
			this.removeAttribute(key);
		});
},


css: function() {
var args=this.css.arguments;

if(args.length==2) {key=args[0];value=args[1];} else {
var json=args[0];
if(typeof(json)=="object") {
for(key in json) {this.css(key,json[key]);}
} else if(args.length==1) {
return vQuery.DOM.getStyle(this.find(),key);
};
return;
}

		// ignore negative width and height values
		if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
			value = undefined;
		this.attr( key, value, "css" );
		return this;
},

offset: function() {
args=this.offset.arguments;
if(args.length==0) {
  return vQuery.offset(this.find());
} else if(args.length==1) {
offset=args[0];
this.moveTo(offset.left,offset.top);
this.resizeTo(offset.width,offset.height);
};

return this; 
},


moveTo: function() {
args=this.moveTo.arguments;
for(i=0;i<args.length;i++) {
if(typeof(args[i])!="string") {args[i]=parseInt(args[i])+"px"}
}

try {
cleft=args[0];ctop=args[1];cwidth=args[2];cheight=args[3];
} catch(err) {void(0)}
if(typeof(ctop)=="undefined") {ctop="auto";}
if(typeof(cwidth)=="undefined") {cwidth="auto";}
if(typeof(cheight)=="undefined") {cheight="auto";}


//do the moving
vQuery.each(this.tags,function(i) {
if(args.length==0) {
} else if(args.length==1) {
vQuery(this).css({position:"absolute",left:cleft}); 
} else if(args.length==2) {
vQuery(this).css({position:"absolute",left:cleft,top:ctop}); 
} else if(args.length==3) {
vQuery(this).css({position:"absolute",left:cleft,top:ctop,cwidth:cwidth}); 
} else if(args.length==4) {
vQuery(this).css({position:"absolute",left:cleft,top:ctop,width:cwidth,height:cheight}); 
}
});
return this;
},

resizeTo: function() {
args=this.resizeTo.arguments;
if(args.length==0) {

} else if(args.length==2) {
for(i=0;i<args.length;i++) {
if(typeof(args[i])!="string") {args[i]=parseInt(args[i])+"px"}
};
width=args[0];height=args[1];
vQuery.each(this.tags,function(i) {
vQuery(this).css({width:width,height:height}); 
});
};
return this;
},

width: function() {
args=this.width.arguments;
if(args.length==0) {return this.css('width'); } 
else if(args.length==1) {
vQuery.each(this.tags,function(i) {
vQuery(this).css({width:args[0]}); 
});
};return this;
},

height: function() {
args=this.height.arguments;
if(args.length==0) {return this.css('height'); } 
else if(args.length==1) {
vQuery.each(this.tags,function(i) {
vQuery(this).css({height:args[0]}); 
});
};return this;
},


hide: function(speed) {
if(typeof(speed)=="undefined") {
this.attr("display","none","css");
this.attr("opacity","0","css");
} else {
try {this.fadeOut(speed);} catch(err) {vQuery.log("You need to add animation library to enable fadeOut");}
};return this;
},

show: function(speed) {
if(typeof(speed)=="undefined") {
this.attr("display","block","css");
this.attr("opacity","1","css");
} else {
try {this.fadeIn(speed);} catch(err) {vQuery.log("You need to add animation library to enable fadeIn");}
};return this;
},

toggle: function(f1,f2) {
if(typeof(f2)=="undefined") {
		vQuery.each(this.tags,function(i){
		var opacity=vQuery.DOM.getStyle(this,"opacity");
		var display=vQuery.DOM.getStyle(this,"display");
		if(opacity==0||display=="none") {vQuery(this).show();}
		else {vQuery(this).hide();}
		}); return this;
} else {
//animation
var fx={x:f1,y:f2,z:0}; //cache sent data
vQuery.each(this.tags,function (i) {
vQuery.data(this,'toggle', fx); 
vQuery(this).click(function () {
var fs=vQuery.data(this,'toggle');
if(fs.z==0) {fs.z=1;ex=fs.x;} else {fs.z=0;ex=fs.y;}
vQuery.data(this,'toggle', fs); //resave
ex.call(this);
});
}
);

};
return this;		
},

addClass: function( classNames ) {
		vQuery.className.add(this.selector, classNames );
},

removeClass: function( classNames ) {
		vQuery.className.remove(this.selector, classNames );
},

toggleClass: function(classNames ) {
		vQuery.className.toggle(this.selector, classNames );
},

html: function() {
args=this.html.arguments;
if(args.length==0) {
  return this.find().innerHTML;
} else {
vQuery.each(this.tags,function(i) {
  this.innerHTML=args[0];
  });
} 
},


text: function() {
args=this.text.arguments;
if(args.length==0) {
if(!vQuery.browser.msie) {
  return this.find().textContent;
  } else {
  return this.find().innerText;  
}
  
} else {

vQuery.each(this.tags,function(i) {
if(!vQuery.browser.msie) {
  this.textContent=args[0];
  } else {
  this.innerText=args[0];
}
});

} 
},

title: function() {
args=this.title.arguments;
if(args.length==0) {
  return this.find().title;
} else {
vQuery.each(this.tags,function(i) {
  this.title=args[0];
});
} 
},

val: function() {
args=this.val.arguments;
if(args.length==0) {
  return this.find().value;
} else {
vQuery.each(this.tags,function(i) {
  this.value=args[0];
});
} 
},

//data entry
	data: function( key, value ){
		var parts = key.split(".");
		parts[1] = parts[1] ? "." + parts[1] : "";

		if ( value === undefined ) {
			var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);

			if ( data === undefined && this.length )
				data = vQuery.data( this[0], key );

			return data === undefined && parts[1] ?
				this.data( parts[0] ) :
				data;
		} else
			return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){
				vQuery.data( this, key, value );
			});
	},

	removeData: function( key ){
		return this.each(function(){
			vQuery.removeData( this, key );
		});
	},
	queue: function(type, data){
		if ( typeof type !== "string" ) {
			data = type;
			type = "fx";
		}

		if ( data === undefined )
			return vQuery.queue( this[0], type );

		return this.each(function(){
			var queue = vQuery.queue( this, type, data );
			
			 if( type == "fx" && queue.length == 1 )
				queue[0].call(this);
		});
	},
	dequeue: function(type){
		return this.each(function(){
			vQuery.dequeue( this, type );
		});
	}
});


 /*! vquery.events */
vQuery.fn.extend({

createEvent: function(ev,args) {
if(args.length==0) {
vQuery.each(this.tags,function (i) {
 vQuery.event.trigger(ev,this);
});

} else {

//error event handler *special
if(ev=="error") {
//for other objects aside window
if(this.selector!=window) {

hdl=function(event) {
if (window.attachEvent) {event = window.event;event.target=event.srcElement;};
return args[0](event);
};

vQuery.each(this.tags,function (i) {
 vQuery.event.add(ev,this,args[0]);
});
return this;
};
//end of onerror for non-window objects


handle2=args[0];
handler=function(msg,url,line) {
return handle2(msg,url,line);
if(!ret) {event.preventDefault();};
return ret;
};

if(this.selector==window) {
this.selector.onerror = handler;return this;
};

return this;
};
//end of error event handler


vQuery.each(this.tags,function (i) {
 vQuery.event.add(ev,this,args[0]);
});

}

},

queryUnload:function(evt,message) {
 if (typeof (evt) == 'undefined') {evt = window.event;};evt.returnValue = message;
},

unload: function() {
args=this.unload.arguments;
if(args.length==0) {
vQuery.event.trigger("onbeforeunload",this.selector); //does not work
} else {
vQuery.event.add("unload",this.selector,args[0]);
}
},

	bind: function( type, data, fn ) {
		type == "unload" ? this.one(type, data, fn) : this.each(function(){
            vQuery.event.add(type,this,data);
		});
		return this;
	},

	one: function( type, data, fn ) {
		var one = function() {
			vQuery(this).unbind(type);
			return (data).apply(this, arguments);
		};
		this.each(function(){
            vQuery.event.add(type,this,one);
		}); return this;
	},

	trigger: function(type,data) {
		this.each(function(){
            vQuery.event.trigger(type,this,data);
		});return this;
	},

	triggerHandler: function(type) {
		this.each(function(){
		  handler=vQuery.data(this,"_"+type);
		  handler.call(target,this);
		});return this;
	},

	unbind: function( type, fn ) {
		this.each(function(){
            vQuery.event.remove(type,this,fn);
		});return this;
	},
	
	hover: function(f1,f2) {
		vQuery.each(this.tags,function(i){
            vQuery.event.add('mouseover',this,f1);
            vQuery.event.add('mouseout',this,f2);
		});return this;
	}

});



//i think sizzle engine should come after

/*!
 * Sizzle CSS Selector Engine - v1.0
 *  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,
	hasDuplicate = false;

var Sizzle = function(selector, context, results, seed) {
	results = results || [];
	var origContext = 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, contextXML = isXML(context);
	
	// 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 {
		// Take a shortcut and set the context if the root selector is an ID
		// (but not if it'll be faster if the inner selector is an ID)
		if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
				Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
			var ret = Sizzle.find( parts.shift(), context, contextXML );
			context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0];
		};

		if ( context ) {
			var ret = seed ?
				{ expr: parts.pop(), set: makeArray(seed) } :
				Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
			set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : 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, contextXML );
			}
		} else {
			checkSet = parts = [];
		}
	}

	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 && 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, origContext, results, seed );
		Sizzle.uniqueSort( results );
	};

	return results;
};

Sizzle.uniqueSort = function(results){
	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);
				}
			}
		}
	}
};

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 ( !/\W/.test(part) ) {
				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" && !/\W/.test(part) ) {
				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){
		try {
			match = " " + match[1].replace(/\\/g, "") + " ";
			} catch(err) {return false;};

			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 ( chunker.exec(match[3]).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 ( 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 ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source );
};

var makeArray = function(array, results) {
	array = Array.prototype.slice.call( array, 0 );

	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, 0 );

// 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("div"),
		id = "script" + (new Date).getTime();
	form.innerHTML = "<a 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 );
	root = form = null; // release memory in IE
})();

(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);
		};
	};

	div = null; // release memory in IE
})();

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);
	};

	for ( var prop in oldSizzle ) {
		Sizzle[ prop ] = oldSizzle[ prop ];
	};

	div = null; // release memory in IE
})();

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]);
		}
	};

	div = null; // release memory in IE
})();

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 && elem.ownerDocument.documentElement.nodeName !== "HTML";
};

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

window.Sizzle = Sizzle;
})();
