/*
 * jQuery Templating Plugin
 * Copyright 2010, John Resig
 * Dual licensed under the MIT or GPL Version 2 licenses.
 */
(function( jQuery, undefined ){
	var oldManip = jQuery.fn.domManip, tmplItmAtt = "_tmplitem", htmlExpr = /^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,
		newTmplItems = {}, wrappedItems = {}, appendToTmplItems, topTmplItem = { key: 0, data: {} }, itemKey = 0, cloneIndex = 0, stack = [];

	function newTmplItem( options, parentItem, fn, data ) {
		// Returns a template item data structure for a new rendered instance of a template (a 'template item').
		// The content field is a hierarchical array of strings and nested items (to be
		// removed and replaced by nodes field of dom elements, once inserted in DOM).
		var newItem = {
			data: data || (parentItem ? parentItem.data : {}),
			_wrap: parentItem ? parentItem._wrap : null,
			tmpl: null,
			parent: parentItem || null,
			nodes: [],
			calls: tiCalls,
			nest: tiNest,
			wrap: tiWrap,
			html: tiHtml,
			update: tiUpdate
		};
		if ( options ) {
			jQuery.extend( newItem, options, { nodes: [], parent: parentItem } );
		}
		if ( fn ) {
			// Build the hierarchical content to be used during insertion into DOM
			newItem.tmpl = fn;
			newItem._ctnt = newItem._ctnt || newItem.tmpl( jQuery, newItem );
			newItem.key = ++itemKey;
			// Keep track of new template item, until it is stored as jQuery Data on DOM element
			(stack.length ? wrappedItems : newTmplItems)[itemKey] = newItem;
		}
		return newItem;
	}

	// Override appendTo etc., in order to provide support for targeting multiple elements. (This code would disappear if integrated in jquery core).
	jQuery.each({
		appendTo: "append",
		prependTo: "prepend",
		insertBefore: "before",
		insertAfter: "after",
		replaceAll: "replaceWith"
	}, function( name, original ) {
		jQuery.fn[ name ] = function( selector ) {
			var ret = [], insert = jQuery( selector ), elems, i, l, tmplItems,
				parent = this.length === 1 && this[0].parentNode;

			appendToTmplItems = newTmplItems || {};
			if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
				insert[ original ]( this[0] );
				ret = this;
			} else {
				for ( i = 0, l = insert.length; i < l; i++ ) {
					cloneIndex = i;
					elems = (i > 0 ? this.clone(true) : this).get();
					jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
					ret = ret.concat( elems );
				}
				cloneIndex = 0;
				ret = this.pushStack( ret, name, insert.selector );
			}
			tmplItems = appendToTmplItems;
			appendToTmplItems = null;
			jQuery.tmpl.complete( tmplItems );
			return ret;
		};
	});

	jQuery.fn.extend({
		// Use first wrapped element as template markup.
		// Return wrapped set of template items, obtained by rendering template against data.
		tmpl: function( data, options, parentItem ) {
			return jQuery.tmpl( this[0], data, options, parentItem );
		},

		// Find which rendered template item the first wrapped DOM element belongs to
		tmplItem: function() {
			return jQuery.tmplItem( this[0] );
		},

		// Consider the first wrapped element as a template declaration, and get the compiled template or store it as a named template.
		template: function( name ) {
			return jQuery.template( name, this[0] );
		},

		domManip: function( args, table, callback, options ) {
			// This appears to be a bug in the appendTo, etc. implementation
			// it should be doing .call() instead of .apply(). See #6227
			if ( args[0] && args[0].nodeType ) {
				var dmArgs = jQuery.makeArray( arguments ), argsLength = args.length, i = 0, tmplItem;
				while ( i < argsLength && !(tmplItem = jQuery.data( args[i++], "tmplItem" ))) {}
				if ( argsLength > 1 ) {
					dmArgs[0] = [jQuery.makeArray( args )];
				}
				if ( tmplItem && cloneIndex ) {
					dmArgs[2] = function( fragClone ) {
						// Handler called by oldManip when rendered template has been inserted into DOM.
						jQuery.tmpl.afterManip( this, fragClone, callback );
					};
				}
				oldManip.apply( this, dmArgs );
			} else {
				oldManip.apply( this, arguments );
			}
			cloneIndex = 0;
			if ( !appendToTmplItems ) {
				jQuery.tmpl.complete( newTmplItems );
			}
			return this;
		}
	});

	jQuery.extend({
		// Return wrapped set of template items, obtained by rendering template against data.
		tmpl: function( tmpl, data, options, parentItem ) {
			var ret, topLevel = !parentItem;
			if ( topLevel ) {
				// This is a top-level tmpl call (not from a nested template using {{tmpl}})
				parentItem = topTmplItem;
				tmpl = jQuery.template[tmpl] || jQuery.template( null, tmpl );
				wrappedItems = {}; // Any wrapped items will be rebuilt, since this is top level
			} else if ( !tmpl ) {
				// The template item is already associated with DOM - this is a refresh.
				// Re-evaluate rendered template for the parentItem
				tmpl = parentItem.tmpl;
				newTmplItems[parentItem.key] = parentItem;
				parentItem.nodes = [];
				if ( parentItem.wrapped ) {
					updateWrapped( parentItem, parentItem.wrapped );
				}
				// Rebuild, without creating a new template item
				return jQuery( build( parentItem, null, parentItem.tmpl( jQuery, parentItem ) ));
			}
			if ( !tmpl ) {
				return []; // Could throw...
			}
			if ( typeof data === "function" ) {
				data = data.call( parentItem || {} );
			}
			if ( options && options.wrapped ) {
				updateWrapped( options, options.wrapped );
			}
			ret = jQuery.isArray( data ) ?
				jQuery.map( data, function( dataItem ) {
					return dataItem ? newTmplItem( options, parentItem, tmpl, dataItem ) : null;
				}) :
				[ newTmplItem( options, parentItem, tmpl, data ) ];
			return topLevel ? jQuery( build( parentItem, null, ret ) ) : ret;
		},

		// Return rendered template item for an element.
		tmplItem: function( elem ) {
			var tmplItem;
			if ( elem instanceof jQuery ) {
				elem = elem[0];
			}
			while ( elem && elem.nodeType === 1 && !(tmplItem = jQuery.data( elem, "tmplItem" )) && (elem = elem.parentNode) ) {}
			return tmplItem || topTmplItem;
		},

		// Set:
		// Use $.template( name, tmpl ) to cache a named template,
		// where tmpl is a template string, a script element or a jQuery instance wrapping a script element, etc.
		// Use $( "selector" ).template( name ) to provide access by name to a script block template declaration.

		// Get:
		// Use $.template( name ) to access a cached template.
		// Also $( selectorToScriptBlock ).template(), or $.template( null, templateString )
		// will return the compiled template, without adding a name reference.
		// If templateString includes at least one HTML tag, $.template( templateString ) is equivalent
		// to $.template( null, templateString )
		template: function( name, tmpl ) {
			if (tmpl) {
				// Compile template and associate with name
				if ( typeof tmpl === "string" ) {
					// This is an HTML string being passed directly in.
					tmpl = buildTmplFn( tmpl )
				} else if ( tmpl instanceof jQuery ) {
					tmpl = tmpl[0] || {};
				}
				if ( tmpl.nodeType ) {
					// If this is a template block, use cached copy, or generate tmpl function and cache.
					tmpl = jQuery.data( tmpl, "tmpl" ) || jQuery.data( tmpl, "tmpl", buildTmplFn( tmpl.innerHTML ));
				}
				return typeof name === "string" ? (jQuery.template[name] = tmpl) : tmpl;
			}
			// Return named compiled template
			return name ? (typeof name !== "string" ? jQuery.template( null, name ):
				(jQuery.template[name] ||
					// If not in map, treat as a selector. (If integrated with core, use quickExpr.exec)
					jQuery.template( null, htmlExpr.test( name ) ? name : jQuery( name )))) : null;
		},

		encode: function( text ) {
			// Do HTML encoding replacing < > & and ' and " by corresponding entities.
			return ("" + text).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;");
		}
	});

	jQuery.extend( jQuery.tmpl, {
		tag: {
			"tmpl": {
				_default: { $2: "null" },
				open: "if($notnull_1){_=_.concat($item.nest($1,$2));}"
				// tmpl target parameter can be of type function, so use $1, not $1a (so not auto detection of functions)
				// This means that {{tmpl foo}} treats foo as a template (which IS a function).
				// Explicit parens can be used if foo is a function that returns a template: {{tmpl foo()}}.
			},
			"wrap": {
				_default: { $2: "null" },
				open: "$item.calls(_,$1,$2);_=[];",
				close: "call=$item.calls();_=call._.concat($item.wrap(call,_));"
			},
			"each": {
				_default: { $2: "$index, $value" },
				open: "if($notnull_1){$.each($1a,function($2){with(this){",
				close: "}});}"
			},
			"if": {
				open: "if(($notnull_1) && $1a){",
				close: "}"
			},
			"else": {
				_default: { $1: "true" },
				open: "}else if(($notnull_1) && $1a){"
			},
			"html": {
				// Unecoded expression evaluation.
				open: "if($notnull_1){_.push($1a);}"
			},
			"=": {
				// Encoded expression evaluation. Abbreviated form is ${}.
				_default: { $1: "$data" },
				open: "if($notnull_1){_.push($.encode($1a));}"
			},
			"!": {
				// Comment tag. Skipped by parser
				open: ""
			}
		},

		// This stub can be overridden, e.g. in jquery.tmplPlus for providing rendered events
		complete: function( items ) {
			newTmplItems = {};
		},

		// Call this from code which overrides domManip, or equivalent
		// Manage cloning/storing template items etc.
		afterManip: function afterManip( elem, fragClone, callback ) {
			// Provides cloned fragment ready for fixup prior to and after insertion into DOM
			var content = fragClone.nodeType === 11 ?
				jQuery.makeArray(fragClone.childNodes) :
				fragClone.nodeType === 1 ? [fragClone] : [];

			// Return fragment to original caller (e.g. append) for DOM insertion
			callback.call( elem, fragClone );

			// Fragment has been inserted:- Add inserted nodes to tmplItem data structure. Replace inserted element annotations by jQuery.data.
			storeTmplItems( content );
			cloneIndex++;
		}
	});

	//========================== Private helper functions, used by code above ==========================

	function build( tmplItem, nested, content ) {
		// Convert hierarchical content into flat string array
		// and finally return array of fragments ready for DOM insertion
		var frag, ret = content ? jQuery.map( content, function( item ) {
			return (typeof item === "string") ?
				// Insert template item annotations, to be converted to jQuery.data( "tmplItem" ) when elems are inserted into DOM.
				(tmplItem.key ? item.replace( /(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g, "$1 " + tmplItmAtt + "=\"" + tmplItem.key + "\" $2" ) : item) :
				// This is a child template item. Build nested template.
				build( item, tmplItem, item._ctnt );
		}) :
		// If content is not defined, insert tmplItem directly. Not a template item. May be a string, or a string array, e.g. from {{html $item.html()}}.
		tmplItem;
		if ( nested ) {
			return ret;
		}

		// top-level template
		ret = ret.join("");

		// Support templates which have initial or final text nodes, or consist only of text
		// Also support HTML entities within the HTML markup.
		ret.replace( /^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/, function( all, before, middle, after) {
			frag = jQuery( middle ).get();

			storeTmplItems( frag );
			if ( before ) {
				frag = unencode( before ).concat(frag);
			}
			if ( after ) {
				frag = frag.concat(unencode( after ));
			}
		});
		return frag ? frag : unencode( ret );
	}

	function unencode( text ) {
		// Use createElement, since createTextNode will not render HTML entities correctly
		var el = document.createElement( "div" );
		el.innerHTML = text;
		return jQuery.makeArray(el.childNodes);
	}

	// Generate a reusable function that will serve to render a template against data
	function buildTmplFn( markup ) {
		return new Function("jQuery","$item",
			"var $=jQuery,call,_=[],$data=$item.data;" +

			// Introduce the data as local variables using with(){}
			"with($data){_.push('" +

			// Convert the template into pure JavaScript
			jQuery.trim(markup)
				.replace( /([\\'])/g, "\\$1" )
				.replace( /[\r\t\n]/g, " " )
				.replace( /\$\{([^\}]*)\}/g, "{{= $1}}" )
				.replace( /\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,
				function( all, slash, type, fnargs, target, parens, args ) {
					var tag = jQuery.tmpl.tag[ type ], def, expr, exprAutoFnDetect;
					if ( !tag ) {
						throw "Template command not found: " + type;
					}
					def = tag._default || [];
					if ( parens && !/\w$/.test(target)) {
						target += parens;
						parens = "";
					}
					if ( target ) {
						target = unescape( target );
						args = args ? ("," + unescape( args ) + ")") : (parens ? ")" : "");
						// Support for target being things like a.toLowerCase();
						// In that case don't call with template item as 'this' pointer. Just evaluate...
						expr = parens ? (target.indexOf(".") > -1 ? target + parens : ("(" + target + ").call($item" + args)) : target;
						exprAutoFnDetect = parens ? expr : "(typeof(" + target + ")==='function'?(" + target + ").call($item):(" + target + "))";
					} else {
						exprAutoFnDetect = expr = def.$1 || "null";
					}
					fnargs = unescape( fnargs );
					return "');" +
						tag[ slash ? "close" : "open" ]
							.split( "$notnull_1" ).join( target ? "typeof(" + target + ")!=='undefined' && (" + target + ")!=null" : "true" )
							.split( "$1a" ).join( exprAutoFnDetect )
							.split( "$1" ).join( expr )
							.split( "$2" ).join( fnargs ?
								fnargs.replace( /\s*([^\(]+)\s*(\((.*?)\))?/g, function( all, name, parens, params ) {
									params = params ? ("," + params + ")") : (parens ? ")" : "");
									return params ? ("(" + name + ").call($item" + params) : all;
								})
								: (def.$2||"")
							) +
						"_.push('";
				}) +
			"');}return _;"
		);
	}
	function updateWrapped( options, wrapped ) {
		// Build the wrapped content.
		options._wrap = build( options, true,
			// Suport imperative scenario in which options.wrapped can be set to a selector or an HTML string.
			jQuery.isArray( wrapped ) ? wrapped : [htmlExpr.test( wrapped ) ? wrapped : jQuery( wrapped ).html()]
		).join("");
	}

	function unescape( args ) {
		return args ? args.replace( /\\'/g, "'").replace(/\\\\/g, "\\" ) : null;
	}
	function outerHtml( elem ) {
		var div = document.createElement("div");
		div.appendChild( elem.cloneNode(true) );
		return div.innerHTML;
	}

	// Store template items in jQuery.data(), ensuring a unique tmplItem data data structure for each rendered template instance.
	function storeTmplItems( content ) {
		var keySuffix = "_" + cloneIndex, elem, elems, newClonedItems = {}, i, l, m;
		for ( i = 0, l = content.length; i < l; i++ ) {
			if ( (elem = content[i]).nodeType !== 1 ) {
				continue;
			}
			elems = elem.getElementsByTagName("*");
			for ( m = elems.length - 1; m >= 0; m-- ) {
				processItemKey( elems[m] );
			}
			processItemKey( elem );
		}
		function processItemKey( el ) {
			var pntKey, pntNode = el, pntItem, tmplItem, key;
			// Ensure that each rendered template inserted into the DOM has its own template item,
			if ( (key = el.getAttribute( tmplItmAtt ))) {
				while ( pntNode.parentNode && (pntNode = pntNode.parentNode).nodeType === 1 && !(pntKey = pntNode.getAttribute( tmplItmAtt ))) { }
				if ( pntKey !== key ) {
					// The next ancestor with a _tmplitem expando is on a different key than this one.
					// So this is a top-level element within this template item
					// Set pntNode to the key of the parentNode, or to 0 if pntNode.parentNode is null, or pntNode is a fragment.
					pntNode = pntNode.parentNode ? (pntNode.nodeType === 11 ? 0 : (pntNode.getAttribute( tmplItmAtt ) || 0)) : 0;
					if ( !(tmplItem = newTmplItems[key]) ) {
						// The item is for wrapped content, and was copied from the temporary parent wrappedItem.
						tmplItem = wrappedItems[key];
						tmplItem = newTmplItem( tmplItem, newTmplItems[pntNode]||wrappedItems[pntNode], null, true );
						tmplItem.key = ++itemKey;
						newTmplItems[itemKey] = tmplItem;
					}
					if ( cloneIndex ) {
						cloneTmplItem( key );
					}
				}
				el.removeAttribute( tmplItmAtt );
			} else if ( cloneIndex && (tmplItem = jQuery.data( el, "tmplItem" )) ) {
				// This was a rendered element, cloned during append or appendTo etc.
				// TmplItem stored in jQuery data has already been cloned in cloneCopyEvent. We must replace it with a fresh cloned tmplItem.
				cloneTmplItem( tmplItem.key );
				newTmplItems[tmplItem.key] = tmplItem;
				pntNode = jQuery.data( el.parentNode, "tmplItem" );
				pntNode = pntNode ? pntNode.key : 0;
			}
			if ( tmplItem ) {
				pntItem = tmplItem;
				// Find the template item of the parent element.
				// (Using !=, not !==, since pntItem.key is number, and pntNode may be a string)
				while ( pntItem && pntItem.key != pntNode ) {
					// Add this element as a top-level node for this rendered template item, as well as for any
					// ancestor items between this item and the item of its parent element
					pntItem.nodes.push( el );
					pntItem = pntItem.parent;
				}
				// Delete content built during rendering - reduce API surface area and memory use, and avoid exposing of stale data after rendering...
				delete tmplItem._ctnt;
				delete tmplItem._wrap;
				// Store template item as jQuery data on the element
				jQuery.data( el, "tmplItem", tmplItem );
			}
			function cloneTmplItem( key ) {
				key = key + keySuffix;
				tmplItem = newClonedItems[key] =
					(newClonedItems[key] || newTmplItem( tmplItem, newTmplItems[tmplItem.parent.key + keySuffix] || tmplItem.parent, null, true ));
			}
		}
	}

	//---- Helper functions for template item ----

	function tiCalls( content, tmpl, data, options ) {
		if ( !content ) {
			return stack.pop();
		}
		stack.push({ _: content, tmpl: tmpl, item:this, data: data, options: options });
	}

	function tiNest( tmpl, data, options ) {
		// nested template, using {{tmpl}} tag
		return jQuery.tmpl( jQuery.template( tmpl ), data, options, this );
	}

	function tiWrap( call, wrapped ) {
		// nested template, using {{wrap}} tag
		var options = call.options || {};
		options.wrapped = wrapped;
		// Apply the template, which may incorporate wrapped content,
		return jQuery.tmpl( jQuery.template( call.tmpl ), call.data, options, call.item );
	}

	function tiHtml( filter, textOnly ) {
		var wrapped = this._wrap;
		return jQuery.map(
			jQuery( jQuery.isArray( wrapped ) ? wrapped.join("") : wrapped ).filter( filter || "*" ),
			function(e) {
				return textOnly ?
					e.innerText || e.textContent :
					e.outerHTML || outerHtml(e);
			});
	}

	function tiUpdate() {
		var coll = this.nodes;
		jQuery.tmpl( null, null, null, this).insertBefore( coll[0] );
		jQuery( coll ).remove();
	}
})( jQuery );

/*
 * jQuery 2d Transform
 * http://wiki.github.com/heygrady/transform/
 *
 * Copyright 2010, Grady Kuhnline
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 */
(function(f,g,i,b){var c=180/Math.PI;var j=200/Math.PI;var e=Math.PI/180;var d=2/1.8;var h=0.9;var a=Math.PI/200;f.extend({angle:{runit:/(deg|g?rad)/,radianToDegree:function(k){return k*c},radianToGrad:function(k){return k*j},degreeToRadian:function(k){return k*e},degreeToGrad:function(k){return k*d},gradToDegree:function(k){return k*h},gradToRadian:function(k){return k*a}}})})(jQuery,this,this.document);(function(f,e,b,g){var c=/progid:DXImageTransform\.Microsoft\.Matrix\(.*?\)/;f.extend({transform:function(h){h.transform=this;this.$elem=f(h);this.transformProperty=this.getTransformProperty();this.applyingMatrix=false;this.matrix=null;this.height=null;this.width=null;this.outerHeight=null;this.outerWidth=null;this.boxSizingValue=null;this.boxSizingProperty=null;this.attr=null}});f.extend(f.transform,{funcs:["matrix","origin","reflect","reflectX","reflectXY","reflectY","rotate","scale","scaleX","scaleY","skew","skewX","skewY","translate","translateX","translateY"],rfunc:{angle:/^rotate|skew[X|Y]?$/,length:/^origin|translate[X|Y]?$/,scale:/^scale[X|Y]?$/,reflect:/^reflect(XY|X|Y)?$/}});f.fn.transform=function(h,i){return this.each(function(){var j=this.transform||new f.transform(this);if(h){j.exec(h,i)}})};f.transform.prototype={exec:function(h,i){var j=this.transformProperty;i=f.extend(true,{forceMatrix:false,preserve:false},i);this.attr=null;if(i.preserve){h=f.extend(true,this.getAttrs(true,true),h)}else{h=f.extend(true,{},h)}this.setAttrs(h);if(j&&!i.forceMatrix){return this.execFuncs(h)}else{if(f.browser.msie||(j&&i.forceMatrix)){return this.execMatrix(h)}}return false},execFuncs:function(i){var h=[];var k=this.transformProperty;for(var j in i){if(j=="origin"){this[j].apply(this,f.isArray(i[j])?i[j]:[i[j]])}else{if(f.inArray(j,f.transform.funcs)!=-1){h.push(this.createTransformFunc(j,i[j]))}}}this.$elem.css(k,h.join(" "));return true},execMatrix:function(l){var r,j=this.transformProperty,h;var p=function(C,m){h[C]=parseFloat(m)};for(var i in l){if(f.matrix[i]||i=="matrix"){h=f.isArray(l[i])?l[i]:[l[i]];f.each(h,p);var q;if(i=="matrix"){q=new f.matrix.M2x2(h[0],h[1],h[2],h[3]);if(h[4]){this.setAttr("translateX",h[4])}if(h[5]){this.setAttr("translateY",h[5])}}else{q=f.matrix[i].apply(this,h)}if(!r){r=q}else{r=r.x(q)}}else{if(i=="origin"){h=f.isArray(l[i])?l[i]:[l[i]];this[i].apply(this,h)}}}var n=this.getAttr("translate")||0,B=this.getAttr("translateX")||0,A=this.getAttr("translateY")||0;if(!f.isArray(n)){n=[n,0]}if(!r){r=new f.matrix.M2x2(1,0,0,1)}var y=parseFloat(parseFloat(r.e(1,1)).toFixed(8)),w=parseFloat(parseFloat(r.e(2,1)).toFixed(8)),v=parseFloat(parseFloat(r.e(1,2)).toFixed(8)),u=parseFloat(parseFloat(r.e(2,2)).toFixed(8)),z=0,x=0;if(n[0]||n[1]||B||A){var o=r.x(new f.matrix.V2(parseFloat(n[0])+parseFloat(B),parseFloat(n[1])+parseFloat(A)));z=parseFloat(parseFloat(o.e(1)).toFixed(8));x=parseFloat(parseFloat(o.e(2)).toFixed(8))}if(j&&j.substr(0,4)=="-moz"){this.$elem.css(j,"matrix("+y+", "+w+", "+v+", "+u+", "+z+"px, "+x+"px)")}else{if(j){this.$elem.css(j,"matrix("+y+", "+w+", "+v+", "+u+", "+z+", "+x+")")}else{if(jQuery.browser.msie){var s=this.$elem[0].style;var t="progid:DXImageTransform.Microsoft.Matrix(M11="+y+", M12="+v+", M21="+w+", M22="+u+", sizingMethod='auto expand')";var k=s.filter||jQuery.curCSS(this.$elem[0],"filter")||"";s.filter=c.test(k)?k.replace(c,t):k?k+" "+t:t;this.applyingMatrix=true;this.matrix=r;this.fixPosition(r,z,x);this.applyingMatrix=false;this.matrix=null}}}return true},origin:function(i,l){var k=this.transformProperty,h=this.safeOuterHeight(),j=this.safeOuterWidth();switch(i){case"left":i="0";break;case"right":i=j;break;case"center":i=j*0.5;break}switch(l){case"top":l="0";break;case"bottom":l=h;break;case"center":case g:l=h*0.5;break}i=/%/.test(i)?j*parseFloat(i)/100:parseFloat(i);if(typeof(l)!=="undefined"){l=/%/.test(l)?h*parseFloat(l)/100:parseFloat(l)}if(k){if(!l&&l!==0){this.$elem.css(k+"-origin",i+"px")}else{this.$elem.css(k+"-origin",i+"px "+l+"px")}}if(!l&&l!==0){this.setAttr("origin",i)}else{this.setAttr("origin",[i,l])}return true},getTransformProperty:function(){if(this.transformProperty){return this.transformProperty}var h=b.body;var i={transform:"transform",MozTransform:"-moz-transform",WebkitTransform:"-webkit-transform",OTransform:"-o-transform"};for(var j in i){if(typeof h.style[j]!="undefined"){this.transformProperty=i[j];return i[j]}}return null},createTransformFunc:function(k,l){if(f.transform.rfunc.reflect.test(k)){var j=l?f.matrix[k]():f.matrix.empty(),i=j.e(1,1),h=j.e(2,1),n=j.e(1,2),m=j.e(2,2);return"matrix("+i+", "+h+", "+n+", "+m+", 0, 0)"}l=d(k,l);if(!f.isArray(l)){return k+"("+l+")"}else{if(k=="matrix"){return"matrix("+l[0]+", "+l[1]+", "+l[2]+", "+l[3]+", "+(l[4]||0)+", "+(l[5]||0)+")"}else{return k+"("+l[0]+", "+l[1]+")"}}},fixPosition:function(q,n,m,s,h){var l=new f.matrix.calc(q,this.safeOuterHeight(),this.safeOuterWidth()),r=this.getAttr("origin");var k=l.originOffset({x:parseFloat(r[0]),y:parseFloat(r[1])});var i=l.sides();var j=this.$elem.css("position");if(j=="static"){j="relative"}var p={top:0,left:0};var o={position:j,top:(k.top+m+i.top+p.top)+"px",left:(k.left+n+i.left+p.left)+"px",zoom:1};this.$elem.css(o)}};var a=/^([\+\-]=)?([\d+.\-]+)(.*)$/;function d(j,o){var q=!f.isArray(o)?[o]:o,h=f.transform.rfunc.angle,p=f.transform.rfunc.length;for(var l=0,m=q.length;l<m;l++){var k=a.exec(q[l]),n="";if(h.test(j)){n="deg";if(k[3]&&!f.angle.runit.test(k[3])){k[3]=null}}else{if(p.test(j)){n="px"}}if(!k){q[l]=0+n}else{if(!k[3]){q[l]+=n}}}return m==1?q[0]:q}})(jQuery,this,this.document);(function(d,c,a,f){d.extend(d.transform.prototype,{safeOuterHeight:function(){return this.safeOuterLength("height")},safeOuterWidth:function(){return this.safeOuterLength("width")},safeOuterLength:function(l){var o="outer"+(l=="width"?"Width":"Height");if(d.browser.msie){l=l=="width"?"width":"height";if(this.applyingMatrix&&!this[o]&&this.matrix){var k=new d.matrix.calc(this.matrix,1,1),m=k.size(),g=this.$elem[o]()/m[l];this[o]=g;return g}else{if(this.applyingMatrix&&this[o]){return this[o]}}var n={height:["top","bottom"],width:["left","right"]};var h=this.$elem[0],j=parseFloat(d.curCSS(h,l,true)),p=this.boxSizingProperty,i=this.boxSizingValue;if(!this.boxSizingProperty){p=this.boxSizingProperty=e()||"box-sizing";i=this.boxSizingValue=this.$elem.css(p)||"content-box"}if(this[o]&&this[l]==j){return this[o]}else{this[l]=j}if(p&&(i=="padding-box"||i=="content-box")){j+=parseFloat(d.curCSS(h,"padding-"+n[l][0],true))||0+parseFloat(d.curCSS(h,"padding-"+n[l][1],true))||0}if(p&&i=="content-box"){j+=parseFloat(d.curCSS(h,"border-"+n[l][0]+"-width",true))||0+parseFloat(d.curCSS(h,"border-"+n[l][1]+"-width",true))||0}this[o]=j;return j}return this.$elem[o]()}});var b=null;function e(){if(b){return b}var h={boxSizing:"box-sizing",MozBoxSizing:"-moz-box-sizing",WebkitBoxSizing:"-webkit-box-sizing",OBoxSizing:"-o-box-sizing"},g=a.body;for(var i in h){if(typeof g.style[i]!="undefined"){b=h[i];return b}}return null}})(jQuery,this,this.document);(function(c,d,g,b){var h=/(origin|matrix|reflect(X|XY|Y)?|rotate|scale[XY]?|skew[XY]?|translate[XY]?)\((.*?)\)/g,f=/^origin|matrix|reflect(XY|[XY])?|rotate|scale[XY]?|skew[XY]?|translate[XY]?$/,e="data-transform",i=/\s/,a=/,\s/;c.extend(c.transform.prototype,{setAttrs:function(j){var k="",m;for(var l in j){if(f.test(l)){m=j[l];if(c.isArray(m)){m=m.join(", ")}k+=" "+l+"("+m+")"}}this.attr=c.trim(k);this.$elem.attr(e,this.attr)},setAttr:function(p,q){if(!f.test(p)){return}if(c.isArray(q)){q=q.join(", ")}q=c.trim(q);var n=this.attr||this.$elem.attr(e);if(!n){this.attr=q;this.$elem.attr(e,this.attr)}else{if(n.indexOf(p)>-1){this.attr=n+" "+q;this.$elem.attr(e,this.attr)}}var m=[],j,r;h.exec("");while((j=h.exec(n))!==null){m.push(j[0])}for(var o=0,k=m.length;o<k;o++){h.exec("");r=h.exec(m[o]);if(p==r[1]){m[o]=q;break}}this.attr=m.join(" ");this.$elem.attr(e,this.attr)},getAttrs:function(){var o=this.attr||this.$elem.attr(e);if(!o){return{}}var m=[],n={},j,r,q;h.exec("");while((j=h.exec(o))!==null){m.push(j[0])}for(var p=0,k=m.length;p<k;p++){h.exec("");r=h.exec(m[p]);if(r&&f.test(r[1])){q=r[3].split(a);n[r[1]]=q.length==1?q[0]:q}}return n},getAttr:function(k){if(!f.test(k)){return null}var j=this.attr||this.$elem.attr(e);var s=c.transform.rfunc.scale;if(k!="origin"&&k!="matrix"&&(!j||j.indexOf(k)===-1)){return s.test(k)?1:null}var r=[],t,n,p=null;h.exec("");while((t=h.exec(j))!==null){r.push(t[0])}for(var o=0,m=r.length;o<m;o++){h.exec("");n=h.exec(r[o]);if(k==n[1]){p=n[3].split(a);return p.length==1?p[0]:p}}if(k=="origin"){var q=/%/;p=this.transformProperty?this.$elem.css(this.transformProperty+"-origin"):[this.safeOuterWidth()*0.5,this.safeOuterHeight()*0.5];p=c.isArray(p)?p:p.split(i);if(q.test(p[0])){if(q.test(p[0])){p[0]=this.safeOuterWidth()*(parseFloat(p[0])/100)}if(q.test(p[1])){p[1]=this.safeOuterHeight()*(parseFloat(p[1])/100)}}}else{if(k=="matrix"){p=[1,0,0,1,0,0]}else{if(s.test(k)){p=1}}}return c.isArray(p)&&p.length==1?p[0]:p}})})(jQuery,this,this.document);(function(c,b,a,d){c.extend({matrix:{}});c.extend(c.matrix,{calc:function(e,f,g){this.matrix=e;this.outerHeight=f;this.outerWidth=g},V2:function(e,f){this.elements=[e,f]},M2x2:function(f,e,h,g){this.elements=[f,e,h,g]},empty:function(){return new c.matrix.M2x2(1,0,0,1)},reflect:function(){return new c.matrix.M2x2(-1,0,0,-1)},reflectX:function(){return new c.matrix.M2x2(1,0,0,-1)},reflectXY:function(){return new c.matrix.M2x2(0,1,1,0)},reflectY:function(){return new c.matrix.M2x2(-1,0,0,1)},rotate:function(i){var f=c.angle.degreeToRadian(i),h=Math.cos(f),j=Math.sin(f);var g=h,e=j,l=-j,k=h;return new c.matrix.M2x2(g,l,e,k)},scale:function(f,e){f=f||f===0?f:1;e=e||e===0?e:f;return new c.matrix.M2x2(f,0,0,e)},scaleX:function(e){return c.matrix.scale(e,1)},scaleY:function(e){return c.matrix.scale(1,e)},skew:function(h,f){h=h||0;f=f||0;var i=c.angle.degreeToRadian(h),g=c.angle.degreeToRadian(f),e=Math.tan(i),j=Math.tan(g);return new c.matrix.M2x2(1,e,j,1)},skewX:function(e){return c.matrix.skew(e)},skewY:function(e){return c.matrix.skew(0,e)}});c.matrix.calc.prototype={coord:function(e,h){var g=this.matrix,f=g.x(new c.matrix.V2(e,h));return{x:f.e(1),y:f.e(2)}},corners:function(){var f=this.outerHeight,e=this.outerWidth;return{tl:this.coord(0,0),bl:this.coord(0,f),tr:this.coord(e,0),br:this.coord(e,f)}},sides:function(){var f=this.corners();var g={top:0,bottom:0,left:0,right:0},e,i;for(var h in f){e=f[h].x;i=f[h].y;if(i<g.top){g.top=i}if(i>g.bottom){g.bottom=i}if(e<g.left){g.left=e}if(e>g.right){g.right=e}}return g},size:function(){var e=this.sides();return{height:Math.abs(e.bottom-e.top),width:Math.abs(e.right-e.left)}},originOffset:function(h,g){h=h?h:{x:this.outerWidth*0.5,y:this.outerHeight*0.5};g=g?g:{x:0,y:0};var e=this.coord(h.x,h.y);var f=this.coord(g.x,g.y);return{top:(f.y-g.y)-(e.y-h.y),left:(f.x-g.x)-(e.x-h.x)}}};c.matrix.M2x2.prototype={x:function(g){var f=this.elements,e=g.elements;if(e.length==2){return new c.matrix.V2(f[0]*e[0]+f[1]*e[1],f[2]*e[0]+f[3]*e[1])}else{if(e.length==4){return new c.matrix.M2x2(f[0]*e[0]+f[1]*e[2],f[0]*e[1]+f[1]*e[3],f[2]*e[0]+f[3]*e[2],f[2]*e[1]+f[3]*e[3])}}return false},e:function(g,e){var f=0;if(g==1&&e==2){f=1}else{if(g==2&&e==1){f=2}else{if(g==2&&e==2){f=3}}}return this.elements[f]}};c.matrix.V2.prototype={e:function(e){return this.elements[e-1]}}})(jQuery,this,this.document);(function(e,d,b,f){var a=/^([+\-]=)?([\d+.\-]+)(.*)$/;var c=/^(.*?)\s+([+\-]=)?([\d+.\-]+)(.*)$/;var h=e.fn.animate;e.fn.animate=function(m,j,l,k){if(m&&!jQuery.isEmptyObject(m)){var i=this;jQuery.each(m,function(n,o){if(e.inArray(n,e.transform.funcs)!=-1){if(e.transform.rfunc.reflect.test(n)){var p=o?e.matrix[n]():e.matrix.empty(),t=p.elements;o=[t[0],t[1],t[2],t[3]]}var r=a.exec(o);if((r&&r[3])||e.isArray(o)){var q,u,v=[];if(e.isArray(o)){e.each(o,function(w){r=a.exec(this);q=parseFloat(r[2]);u=r[3]||"px";v.push({end:(r[1]?r[1]:"")+q,unit:u})})}else{q=parseFloat(r[2]);u=r[3]||"px";v.push({end:(r[1]?r[1]:"")+q,unit:u});var s=0;while(r=c.exec(u)){v[s].unit=r[1];v.push({end:(r[2]?r[2]:"")+parseFloat(r[3]),unit:r[4]});u=r[4];s++}}i.data("data-animate-"+n,v);m[n]=v[0].end}}})}return h.apply(this,arguments)};var g=e.fx.prototype.cur;e.fx.prototype.cur=function(k){if(e.inArray(this.prop,e.transform.funcs)!=-1){this.transform=this.transform||this.elem.transform||new e.transform(this.elem);var i=e.transform.rfunc;var j=this.transform.getAttr(this.prop),l=a.exec(e.isArray(j)?j[0]:j);if(j===null||l===null){j=i.scale.test(this.prop)||i.reflect.test(this.prop)?1:0;l=[null,null,j]}return parseFloat(l[2])}return g.apply(this,arguments)};e.fx.multivalueInit=function(l){var j=e(l.elem),i=l.transform.getAttr(l.prop),k=j.data("data-animate-"+l.prop);if(k){j.removeData("data-animate-"+l.prop)}if(e.transform.rfunc.reflect.test(l.prop)){i=l.transform.getAttr("matrix")}l.values=[];if(e.isArray(i)&&!e.isArray(k)){k=[{end:parseFloat(l.end),unit:l.unit},{end:e.transform.rfunc.scale.test(l.prop)?1:0,unit:l.unit}]}if(k){var o,n=e.transform.rfunc.scale,m;e.each(k,function(p,q){if(e.isArray(i)){o=i[p]}else{if(p>0){o=n.test(l.prop)?i:null}else{o=i}}if(!o&&o!==0){o=n.test(l.prop)?1:0}o=parseFloat(o);m=a.exec(q.end);if(m&&m[1]){q.end=((m[1]==="-="?-1:1)*parseFloat(m[2]))+o}l.values.push({start:parseFloat(o),end:parseFloat(q.end),unit:q.unit})})}else{l.values.push({start:parseFloat(l.start),end:parseFloat(l.end),unit:l.unit})}};e.fx.multivalueStep={_default:function(i){e.each(i.values,function(j,k){i.values[j].now=k.start+((k.end-k.start)*i.pos)})}};e.each(e.transform.funcs,function(j,k){e.fx.step[k]=function(n){if(!n.transformInit){n.transform=n.transform||n.elem.transform||new e.transform(n.elem);e.fx.multivalueInit(n);if(n.values.length>1){n.multiple=true}var m=e.transform.rfunc;if(m.angle.test(n.prop)){n.unit="deg"}else{if(m.scale.test(n.prop)){n.unit=""}else{if(m.reflect.test(n.prop)){n.unit=""}else{if(n.prop=="matrix"){n.unit=""}}}}e.each(n.values,function(p){n.values[p].unit=n.unit});n.transformInit=true}if(n.multiple){(e.fx.multivalueStep[n.prop]||e.fx.multivalueStep._default)(n)}else{n.values[0].now=n.now}var l=[];e.each(n.values,function(p,q){if(q.unit=="deg"){while(q.now>=360){q.now-=360}while(q.now<=-360){q.now+=360}}l.push(parseFloat(parseFloat(q.now).toFixed(8))+q.unit)});var i={},o=e.transform.rfunc.reflect.test(n.prop)?"matrix":n.prop;i[o]=n.multiple?l:l[0];n.transform.exec(i,{preserve:true})}})})(jQuery,this,this.document);

if (!jQuery.event.special.frame) {

// jquery.events.frame.js
// 1.1 - lite
// Stephen Band
//
// Project home:
// webdev.stephband.info/events/frame/
//
// Source:
// http://github.com/stephband/jquery.event.frame

(function(d,h){function i(a,b){function e(){f.frameCount++;a.call(f)}var f=this,g;this.frameDuration=b||25;this.frameCount=-1;this.start=function(){e();g=setInterval(e,this.frameDuration)};this.stop=function(){clearInterval(g);g=null}}function j(){var a=d.event.special.frame.handler,b=d.Event("frame"),e=this.array,f=e.length;for(b.frameCount=this.frameCount;f--;)a.call(e[f],b)}var c;if(!d.event.special.frame)d.event.special.frame={setup:function(a){if(c)c.array.push(this);else{c=new i(j,a&&a.frameDuration);
c.array=[this];var b=setTimeout(function(){c.start();clearTimeout(b);b=null},0)}},teardown:function(){for(var a=c.array,b=a.length;b--;)if(a[b]===this){a.splice(b,1);break}if(a.length===0){c.stop();c=h}},handler:function(){d.event.handle.apply(this,arguments)}}})(jQuery);

}

// t: current time, b: begInnIng value, c: change In value, d: duration
$.easing.jswing = $.easing.swing;

$.extend($.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert($.easing.default);
		return $.easing[$.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;if ((t/=d)==1) return b+c;if (!p) p=d*.3;
		if (a < Math.abs(c)) {a=c;var s=p/4;}
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;if ((t/=d)==1) return b+c;if (!p) p=d*.3;
		if (a < Math.abs(c)) {a=c;var s=p/4;}
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;if ((t/=d/2)==2) return b+c;if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) {a=c;var s=p/4;}
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - $.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return $.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return $.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

$.initShare = function() {
	var $sh = $('#shareBox');
	if (!$sh.length) return;

	$sh.find('.shareWithTumblr').click(function() {
		var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://www.tumblr.com/share',l=d.location,e=encodeURIComponent,p='?v=3&u='+e(l.href) +'&t='+e(d.title) +'&s='+e(s),u=f+p;try{if(!/^(.*\.)?tumblr[^.]*$/.test(l.host))throw(0);tstbklt();}catch(z){a =function(){if(!w.open(u,'t','toolbar=0,resizable=0,status=1,width=450,height=430'))l.href=u;};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else a();}void(0);
		return false;
	});
};


/*
 * jQuery history plugin
 *
 * sample page: http://www.serpere.info/jquery-history-plugin/samples/
 *
 * Copyright (c) 2006-2009 Taku Sano (Mikage Sawatari)
 * Copyright (c) 2010 Takayuki Miwa
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Modified by Lincoln Cooper to add Safari support and only call the callback once during initialization
 * for msie when no initial hash supplied.
 */

(function($) {
	var prev = false;

    var locationWrapper = {
        put: function(hash, win) {
        	prev = true;
            (win || window).location.hash = hash;
        },
        get: function(win) {
        	var w = (win || window),
            	hash = (w.location.hash).replace(/^#/, '');

            if (prev && (w.location.toString() == $.base) && (hash == '')) hash = 'index';
            return $.browser.fx ? hash : hash;
        }
    };

    var iframeWrapper = {
        id: "__jQuery_history",
        init: function() {
            var html = '<iframe id="'+ this.id +'" style="display:none" src="javascript:false;" />';
            $("body").prepend(html);
            return this;
        },
        _document: function() {
            return $("#"+ this.id)[0].contentWindow.document;
        },
        put: function(hash) {
            var doc = this._document();
            doc.open();
            doc.close();
            locationWrapper.put(hash, doc);
        },
        get: function() {
            return locationWrapper.get(this._document());
        }
    };

    // public base interface
    var _ = {
        appState: undefined,
        callback: undefined,
        init:  function(callback) {},
        check: function() {},
        load:  function(hash) {},
		back: true,
        setTitle: function(title) {window.document.title = title || ' ';}
    };
    $.history = _;

    var SimpleImpl = {
        init: function(callback) {
            _.callback = callback;
            var current_hash = locationWrapper.get();
            _.appState = current_hash;
            _.callback(current_hash);
            setInterval(_.check, 100);
        },
        check: function() {
            var current_hash = locationWrapper.get();
            if(current_hash != _.appState) {
                _.appState = current_hash;
                _.callback(current_hash);
            }
        },
        load: function(hash) {
            //if(hash != _.appState) {
                locationWrapper.put(hash);
                _.appState = hash;
                _.callback(hash);
            //}
        }
    };

    var IframeImpl = {
        init: function(callback) {
            _.callback = callback;
            var current_hash = locationWrapper.get();
            _.appState = current_hash;
            iframeWrapper.init().put(current_hash);
            _.callback(current_hash);
            setInterval(_.check, 100);
        },
        check: function() {
            var current_hash = iframeWrapper.get();
            if(current_hash != _.appState) {
                locationWrapper.put(current_hash);
                _.appState = current_hash;
                _.callback(current_hash);
            }
        },
        load: function(hash) {
            //if(hash != _.appState) {
                locationWrapper.put(hash);
                iframeWrapper.put(hash);
                _.appState = hash;
                _.callback(hash);
            //}
        }
    };

    if($.browser.msie && ($.browser.version < 8 || document.documentMode < 8)) {
        $.extend(_, IframeImpl);
    } else {
        $.extend(_, SimpleImpl);
    }
})(jQuery);



$.frontendValidator = {

	_digit: function() {
		$(this).val($(this).val().replace(/[^0-9]/gi,""));
	},

	_instantRequest: function() {
		$(this).parents("form").submit();
	},

	_instantRequestFocus: function() {
		$.WBValidatorTempTextFocus = $(this).val();
	},

	_instantRequestBlur: function() {
		if ($.WBValidatorTempTextFocus != $(this).val()) $(this).parents("form").submit();
		$.WBValidatorTempTextFocus;
	},

	init: function(el) {
		var fv = this;
		var filter = "";

		if (typeof el != "undefined") filter = "#" + el.attr("id") + " ";

		$(filter + ".digitValidator")
			.unbind("keyup", fv._digit)
			.bind("keyup", fv._digit);

		$(filter + ".instantRequest").each(function() {
			$this = $(this);

			if ($this.attr("type") == "text") {
				$.WBValidatorTempTextFocus = "";
				$this.unbind("focus", fv._instantRequestFocus).bind("focus", fv._instantRequestFocus);
				$this.unbind("blur", fv._instantRequestBlur).bind("blur", fv._instantRequestBlur);
			} else {
				$this.unbind("change", fv._instantRequest).bind("change", fv._instantRequest);
			}



		});
	}

};

// wbGallery 2.0 by Drawain
$(function() {

	$.wbGallery = (function($, undefined) {

		// Gallery pre-initialization, struct creation
		var gallery = this,
			dataset, $dataset,
			opened = false,
			$triggers,
			$gallery = $("#galleryTemplate").tmpl(),
			$overlay = $gallery.find('.overlay'),
			$images	= $gallery.find('.imagePlaceholder'),
			$toolbar = $gallery.find('.toolkit'),
			$thumbs = $gallery.find('.thumbsPlaceholder'),
			$title = $gallery.find('.title').hide(),
			$prev = $gallery.find('.prev'),
			$next = $gallery.find('.next'),
			$loader = $gallery.find('.loader').css({display: 'none', opacity: 0}),
			act = 0, imagesNum,
			$actLabel = $gallery.find('.act'),
			$endLabel = $gallery.find('.end'),

			$imageTemplate = $images.children(),
			$thumbTemplate = $thumbs.children(),

			opts = {
				overlayOpacity: 0.8,
				showAnimSettings: { duration: 300, easing: 'swing' },

				fadeOutImage: function($el, cb) {
					if (!$el || !$el.length) return;

					$el.stop().animate({ left: '+=10', opacity: 0 }, 400, 'swing', cb);
				},
				fadeInImage: function($el, cb) {
					if (!$el || !$el.length) return;

					$el.stop().animate({ left: '-=10', opacity: 0 }, 0).animate({ left: '+=10', opacity: 1 }, 400, 'swing', cb);
				},

				largeImageIsBackground: false,
				largeImageTop: 0,
				largeImageLeft: 0,

				autoDataset: true,												// auto find dataset in the global scope every init
				collectImagesOnPage: true,										// collect images on page and add to dataset every init
				collectImagesContext: $("#mainContent"),						// (jQuery selector) context, where to find the images to collect
				triggerContext: $("#mainContent")								// (jQuery selector) context, the trigger events will be delegated to this
			};


		// Parse dataset and initialize the gallery struct
		var initializeStruct = function(dataset) {
			if (!dataset || !dataset.length) return;

			imagesNum = dataset.length;

			var tempArray = {}, dataset2 = [];
			for (var i=0, original; i<imagesNum; i++) {
				original = dataset[i].original;
				if (tempArray[original]) continue;

				tempArray[original] = original;
				dataset2.push(dataset[i]);
			}

			dataset = dataset2;

			$dataset = [];
			imagesNum = dataset.length;
			$endLabel.text(imagesNum);

			for (var i=0, el, $el, $thumb; i<imagesNum; i++) {
				el = dataset[i];
				el.loaded = false;

				$el = $imageTemplate.clone();
				$thumb = $thumbTemplate.clone();

				if ($thumb.is('.thumb')) $thumb.attr('src', el.thumb);
				else $thumb.find('.thumb').attr('src', el.thumb);

				if ($el.is('.image')) el.$image = $el;
				else el.$image = $el.find('.image');

				if ($.trim(el.title) == $.trim(el.original.replace(/.*\//gi,''))) el.title = '';

				$el.data('data', el);
				$el.css({position: 'absolute', top: 0, left: 0});
				$dataset.push($el);

				$thumbs.append($thumb);
			}

		}

		var initializeTriggers = function() {
			opts.triggerContext.undelegate('.wbGallery_image, .wbGallery_contentImage, .wbGallery_trigger', 'click.wbGalleryOpen').delegate('.wbGallery_image, .wbGallery_contentImage, .wbGallery_trigger', 'click.wbGalleryOpen', function(e) {
				e.preventDefault();

				var $this = $(this),
					ori = $this.attr('wb:original'),
					next = 0;

				if (ori) {
					for (var i=0; i<imagesNum; i++) {
						if (dataset[i].original == ori) {
							next = i;
							break;
						}
					}
				}

				openGallery(next);
			});

			$gallery.undelegate('.close, .overlay', 'click.wbGalleryClose').delegate('.close, .overlay', 'click.wbGalleryClose', function(e) {
				e.preventDefault();
				closeGallery();
			});

			$gallery.undelegate('.next', 'click.wbGalleryMove').delegate('.next', 'click.wbGalleryMove', function(e) {
				e.preventDefault();
				openGalleryNext();
			});

			$gallery.undelegate('.prev', 'click.wbGalleryMove').delegate('.prev', 'click.wbGalleryMove', function(e) {
				e.preventDefault();
				openGalleryPrev();
			});

			$(window).unbind('resize.wbGalleryResize').bind('resize.wbGalleryResize', function(e) {
				if (opened) positionImage($dataset[act]);
			});

			$(document).unbind('keydown.wbGalleryMove').bind('keydown.wbGalleryMove', function(e) {
				if (opened) {
					switch (e.keyCode) {
						// Right
						case 39:openGalleryNext();e.preventDefault();break;

						// Left
						case 37:openGalleryPrev();e.preventDefault();break;

						// Up
						case 38:openGalleryNext();e.preventDefault();break;

						// Down
						case 40:openGalleryPrev();e.preventDefault();break;
					}
				}
			});
		}

		var positionImage = function($el) {
			if (!$el.length) return;

			var height = $el.height(),
				width = $el.width(),
				$window = $(window),
				windowWidth = $window.width(),
				windowHeight = $window.height();

			$el.css({ left: Math.floor(windowWidth/2 - width/2 + opts.largeImageLeft)+'px', top: Math.floor(windowHeight/2 - height/2 + opts.largeImageTop)+'px'});
		}

		var loading = function(status) {
			if (status) {
				$loader.stop().css({display: 'block', opacity: 1});
				if ($.browser.msie && ($.browser.version < 9)) $loader.get(0).style.removeAttribute('filter');
			} else {
				$loader.stop().css({display: 'none'});
			}
		}

		var openGalleryNext = function() {
			var n = act + 1;
			if (n >= imagesNum) n = 0;

			openGallery(n);
		}

		var openGalleryPrev = function() {
			var n = act - 1;
			if (n < 0) n = imagesNum - 1;

			openGallery(n);
		}

		var openGallery = function(next) {
			if (!dataset || !dataset.length) return;

			var $act = $dataset[act],
				$next = $dataset[next],
				nextData = $next.data('data'),
				$image = nextData.$image, $$image;

			// If there is no next element in the dataset or the given next is the actual image
			if (!$next.length || (($act >=0) && ($act.index($next) >= 0))) return;

			if (!opened) {
				$gallery.appendTo('body');

				if (!($.browser.msie && $.browser.version < 9)) {
					$gallery.stop().css({ opacity: 0 }).animate({ opacity: 1 }, opts.showAnimSettings);
				}

				opened = true;
			}

			opts.fadeOutImage($act, function() {
				$act.detach();
			});

			var getNextImage = function($next) {
				if (!($.browser.msie && $.browser.version < 8)) {
					$next.css({opacity: 0});
				}

				$next.appendTo($images);
				positionImage($next);
				opts.fadeInImage($next);
			}

			loading(1);
			act = next;

			if (!nextData.loaded) {
				if (!opts.largeImageIsBackground) {
					$image.attr('src', nextData.large);
					$$image = $image;
				} else {
					$image.css({backgroundImage: 'url('+nextData.large+')'});
					$$image = $('<img />').attr('src', nextData.large).css({ opacity: 0 }).appendTo($image);
				}

				nextData.loaded = true;
				$next.data('data', nextData);

				var triggerForce = true;
				$$image.unbind('load.wbGalleryLoad').bind('load.wbGalleryLoad', (function($n) { return function() {
					if ($dataset && $dataset[act] && $dataset[act].index($n) >= 0) getNextImage($n);
					loading(0);
					triggerForce = false;
					$gallery.find('.act').text(next+1);
				}})($next));

				/* INTERNET EXPLORER TRIGGER LOAD BUG WORKAROUND */
				setTimeout(function() {
					if (!triggerForce) return;
					triggerForce = false;
					$$image.trigger("load.wbGalleryLoad");
				}, 5000);
			} else {
				getNextImage($next);
				loading(0);
			}

			$title.stop().css({ opacity: 0, display: 'none' });
			if (nextData.title != '') $title.css({display: 'block'}).html(nextData.title).animate({ opacity: 1 }, 300, 'swing');

		}

		var closeGallery = function() {
			if (!opened) return;
			opened = false;

			if (!($.browser.msie && $.browser.version < 9)) {
				$gallery.stop().animate({ opacity: 0 }, {
					easing: opts.showAnimSettings.easing,
					duration: opts.showAnimSettings.duration,
					complete: function() {
						if ($dataset[act]) $dataset[act].detach();

						act = -1;
						$gallery.detach();
					}
				});
			} else {
				if ($dataset[act]) $dataset[act].detach();
				act = -1;
				$gallery.detach();
			}
		}

		return {
			// Init has to be called after all pageload
			init: function(options, justInitOptions) {
				var $el;

				opts = $.extend(opts, options);

				if (justInitOptions) return true;

				this.initAuto();

				dataset = [];
				act = -1;

				$images.empty();
				$thumbs.empty();

				$overlay.css('opacity', opts.overlayOpacity);

				if (opts.collectImagesOnPage) {
					$triggers = opts.collectImagesContext.find('.wbGallery_image, .wbGallery_contentImage');
					for (var i=0, l=$triggers.length, trigger; i<l; i++) {
						$el = $triggers.eq(i);
						dataset.push({
							title: $el.attr('wb:title'),
							original: $el.attr('wb:original'),
							large: $el.attr('wb:large'),
							thumb: $el.attr('wb:thumb')
						});
					}
				}

				if (opts.autoDataset && $.wbGalleryDataset) {
					dataset = $.merge(dataset, $.wbGalleryDataset);
					$.wbGalleryDataset = false;
				}

				initializeStruct(dataset);
				initializeTriggers();
			},

			initAuto: function() {
				$("#mainContent img.WBImage").each(function() {
					var $this = $(this),
						$img = $this, $template, image,
						fl = $img.css("float"),
						srcPage 	= $img.attr("src"),
						srcOrig 	= srcPage.replace("_medium/", "").replace("_small/", "").replace("_large/", ""),
						srcGallery 	= srcPage.replace("_medium/", "_large/").replace("_small/", "_large/");

					if ($this.closest('a').length) return true;

					$template = $("#galleryImageTemplate").tmpl({
						title: $img.attr("title"),
						original: srcOrig,
						large: srcGallery,
						thumb: srcPage,
						style: 'float: '+ fl
					});

					image = $template.find('.image');
					$img.load(function() {
						if ($img.get(0).width != "") image.css('width', $img.get(0).width + "px");
						if ($img.get(0).height != "") image.css('height', $img.get(0).height + "px");
					});
					$img.replaceWith($template);
				});
			},

			getOptions: function() { return opts; },
			getDataset: function() { return dataset; }
		};
	})(jQuery);

	$.wbGallery.init({
		overlayOpacity: 0.8,
		showAnimSettings: { duration: 100, easing: 'linear' },

		fadeOutImage: function($el, cb) {
			if (!$el || !$el.length) return;

			if (!($.browser.msie && $.browser.version < 8)) {
				$el.stop().animate({ left: '+=100', opacity: 0 }, 400, 'swing', cb);
			} else {
				if (cb) cb();
			}
		},
		fadeInImage: function($el, cb) {
			if (!$el || !$el.length) return;

			if (!($.browser.msie && $.browser.version < 8)) {
				$el.stop().animate({ left: '-=100', opacity: 0 }, 0).animate({ left: '+=100', opacity: 1 }, 400, 'swing', cb);
			} else {
				$el.css({opacity: 1}).find('*').css({opacity: 1});
				if (cb) cb();
			}
		},

		largeImageIsBackground: true,
		largeImageTop: -50,
		largeImageLeft: 0
	}, true);

});

$(function() {
	var $lis = $('#menu').children('li'),
		$as = $lis.children('a');

	$as.unbind('click.active').bind('click.active', function() {
		$as.removeClass('activeItem');
		$(this).addClass('activeItem');
	});

	$.changeMenuActive = function() {
		$as.removeClass('activeItem');

		var loc = window.location.toString();
		if		(loc.search('jogteruletek') >= 0)	$as.eq(1).addClass('activeItem');
		else if (loc.search('letoltes')		>= 0)	$as.eq(2).addClass('activeItem');
		else if (loc.search('linkek')		>= 0)	$as.eq(3).addClass('activeItem');
		else if (loc.search('dijazas')		>= 0)	$as.eq(4).addClass('activeItem');
		else if (loc.search('kapcsolat')	>= 0)	$as.eq(5).addClass('activeItem');
		else										$as.eq(0).addClass('activeItem');
	}

	/*if ($.browser.msie && ($.browser.version <= 8)) {
		
		return;
	}*/

	var $sublis = $lis.filter('.menuhover').removeClass('menuhover'),
		$lilis = $sublis.find('li a');

	var hideSubmenu = function($this) {
		$this.children('ul').stop().animate({ opacity: 0 }, 300, 'swing', function() {
			$(this).css({display: 'none'});
			if ($.browser.msie && ($.browser.version < 9)) this.style.removeAttribute('filter');
		});
		if (!$.browser.msie || ($.browser.version > 8)) $lilis.stop().animate({ opacity: 1 }, 100, 'swing');
	}

	$sublis
		.mouseenter(function() {
			$(this).children('ul').stop().css({display: 'block', opacity: 0, left: '150px'}).animate({ left: '160px', opacity: 1 }, 300, 'swing', function() { if ($.browser.msie && ($.browser.version < 9)) this.style.removeAttribute('filter'); });
		})
		.mouseleave(function() {
			hideSubmenu($(this));
		})
		.click(function() { hideSubmenu($(this)); });

	$lilis.mouseenter(function() {
		if (!$.browser.msie || ($.browser.version > 8)) $lilis.stop().not($(this)).animate({ opacity: 0.5 }, 300, 'swing');
		$(this).animate({ opacity: 1 }, 200, 'swing', function() { if ($.browser.msie && ($.browser.version < 9)) this.style.removeAttribute('filter'); });
	});

});

$(function() {
	var $cont = $('#entry_box_container'),
		lock = false;

	var slide = function() {
		if (!lock) {
			var $els = $cont.children();

			$els.eq(0).stop().animate({ opacity: 0 }, 300, 'swing', function() {
				if ($.browser.msie && ($.browser.version < 9)) this.style.removeAttribute('filter');
				$(this).animate({ height: 0 }, 300, 'swing', function() {
					$(this).css({display: 'none'}).appendTo($cont);
					if ($.browser.msie && ($.browser.version < 9)) this.style.removeAttribute('filter');
					$els.eq(2).stop().css({display: 'block', opacity: 0, height: '73px'}).animate({ opacity: 1 }, 300, 'swing', function() { if ($.browser.msie && ($.browser.version < 9)) this.style.removeAttribute('filter'); });
				});
			});
		}

		setTimeout(slide, 8000);
	}

	setTimeout(slide, 8000);

});


$.initDownloads = function() {
	$('#mainContent').find(".downloads_container").click(function(e) {
		e.preventDefault();
		$(this).parent().find('.downloads').slideToggle('fast').prev().toggleClass('opened');
	});
};
