;(function($,undefined){
	var _timer=[],
		_fw=window._fw=function(){
			var argms=arguments
			this.each(function(){
				var th=$(this)					
				for(var i=0,opt={};i<argms.length;i++)
					if(typeof argms[i]==typeof '')
						if(_fw[argms[i]]!=undefined)
							$.extend(opt,_fw[argms[i]]),
							th.data(argms[i],opt)
						else
							void(0)//coming soon ajax script loader
					else
						if(typeof argms[i]==typeof {})
							$.extend(opt,argms[i])
				if(th.data('opt'))
					$.extend(opt,th.data('opt'))
				opt.init.call(th,opt)
			})			
			return this
		}
		
	//modules
	_fw=$.extend(_fw,{
		"_bgSlider":{
			slideshow:false,
			duration:1500,
			easing:'',
			preload:false,
			pagination:false,
			pagActiveCl:'current',
			pagEv:'click',
			pagArea:'a',
			current:0,
			method:'fit',
			altCSS:{},
			padding:0,
			preload:false,
			spinner:false,
			minSpinnerWait:150,
			preloadFu:function(){
				var opt=this,
					img=$('<img>')
							.css({position:'absolute',left:'-999%'})
							.appendTo('body'),
					num=opt.images.length
				;(function(){
					if(num)
						img	.load(arguments.callee)
							.attr({src:opt.images[--num]})
					else
						img.remove()					
				})()
			},
			pagsFu:function(){
				var opt=this,
					pags=opt.pags=$(opt.pagination+' li')
				if(!opt.images)
					opt.images=[],
					pags.each(function(i){
						opt.images.push($('a',this).attr('href'))
					})
				pags.find(opt.pagArea).each(function(i){
					$(this).data({num:i})
				})
				pags.parent()
					.delegate(opt.pagination+':not(.'+opt.pagActiveCl+')'+(opt.pagArea?' '+opt.pagArea:''),opt.pagEv,function(){
						var th=$(this)
						opt.changeFu(th.data('num'))
						opt.pags.not(th.praParent('li').addClass(opt.pagActiveCl)).removeClass(opt.pagActiveCl)						
						return false
					})
			},
			preFu:function(){
				var opt=this
				opt.img
					.css({
						position:'absolute',
						left:0,
						top:0
						})
					.css(opt.altCSS)
					.attr({src:opt.images[opt.current]})
					.load(function(){
						opt.img.data({width:opt.img.width(),height:opt.img.height()})
						opt.resizeFu()
					})
				opt.holder
					.css({
						position:'fixed',
						left:0,
						right:0,
						top:0,
						bottom:0,
						zIndex:-1
						})
					.append(opt.img)
				if(opt.spinner)
					opt.spinner.hide()
			},
			resizeFu:function(){
				var opt=this,
					img=opt.img,
					w=img.data('width'),
					h=img.data('height'),
					l=img.css('left'),
					t=img.css('top'),
					bw=document.body.offsetWidth-opt.padding,
					bh=document.body.offsetHeight,
					k=(img.data('width'))/img.data('height')
				if(opt.method=='fit')
					if(bw/bh<k)
						img.width('auto').height(bh).css({top:t,left:l})
					else
						img.width(bw).height('auto').css({top:t,left:l})
				else
					if(!(bw/bh<k))
						img.width('auto').height(bh).css({top:t,left:l})
					else
						img.width(bw).height('auto').css({top:t,left:l})
					
			},
			changeFu:function(n){
				var opt=this
				opt.showFu(opt.images[n])
			},
			showFu:function(src){
				var opt=this,
					clone=opt.clone=opt.img.clone()
				clone
					.css({
						 opacity:0,
						 left:0,
						 top:0
						 })
					.appendTo(opt.holder)
					.load(function(){
						opt.holder.find('>*').stop()						
						setTimeout(function(){
							opt.spinner.hide()
							clone
								.data({
									width:this.offsetWidth,
									height:this.offsetHeight
									})
								.stop()
								.animate({
										opacity:1
										},{
										duration:opt.duration,
										easing:opt.easing,
										complete:function(){
											var tmp=opt.holder.find('img')
											opt.img=$(this)
											tmp.not(tmp.last()).remove()
											opt.resizeFu()
										}
										})
						},opt.minSpinnerWait)
					})
					.attr({src:src})
					opt.spinner.show()
			},
			init:function(opt){
				var holder=opt.holder=this,
					img=opt.img=$('<img>')
				if(opt.pagination)
					opt.pagsFu()
				if(opt.spinner)
					opt.spinner=$(opt.spinner)
				opt.preFu()
				if(opt.preload)
					opt.preloadFu()
				if(opt.method=='fit')
					$(window).resize(function(){
						opt.resizeFu()
					})
				holder.data({opt:opt})
			}
		},
		"_ajaxSlider":{
			spinner:false,
			navLinks:'a[rel=nav]',
			pagArea:'>a',
			pagActiveCl:'active',
			pagEv:'click',
			pagRefreshEv:'_pagRefresh',
			showEv:'_show',
			changeEv:'_change',
			pagination:false,
			prevEv:'_prev',
			nextEv:'_next',
			nextBu:false,
			prevBu:false,
			animationCallback:function(){},
			pagFu:function(){
				var opt=this,
					pags=opt.pags=$(opt.pagination)
				pags.parent()
					.delegate(opt.pagination+':not(.'+opt.pagActiveCl+')'+(opt.pagArea?' '+opt.pagArea:''),opt.pagEv,function(){
						var th=$(this)
						pags.removeClass(opt.pagActiveCl)
						th.praParent('li').addClass(opt.pagActiveCl)
						opt.changeFu(th)
						return false
					})
					.delegate(opt.pagination+'.'+opt.pagActiveCl+(opt.pagArea?' '+opt.pagArea:''),opt.pagEv,function(e){
						return false
					})
				opt.holder.trigger(opt.pagRefreshEv)
			},
			changeFu:function(data){
				var opt=this,
					url=data.attr('href')
				opt.holder.data({url:url})
				opt.showFu()
				opt.holder.trigger(opt.changeEv)
			},
			nextFu:function(){
				var opt=this,
					act=opt.act=opt.pags.parent().find('.'+opt.pagActiveCl),
					next=act.next()
				if(next.length)
					opt.pags.removeClass(opt.pagActiveCl),
					next.addClass(opt.pagActiveCl),
					opt.changeFu(opt.pagArea?next.find(opt.pagArea):next),
					opt.holder.trigger(opt.pagRefreshEv)
				else
					opt.pags.removeClass(opt.pagActiveCl),
					opt.act=opt.pags.eq(0).addClass(opt.pagActiveCl),
					opt.changeFu(opt.pagArea?opt.act.find(opt.pagArea):opt.act),
					opt.holder.trigger(opt.pagRefreshEv)
			},
			prevFu:function(){
				var opt=this,
					act=opt.act=opt.pags.parent().find('.'+opt.pagActiveCl),
					next=act.prev()
				if(next.length)
					opt.pags.removeClass(opt.pagActiveCl),
					opt.act=next.addClass(opt.pagActiveCl),
					opt.changeFu(opt.pagArea?next.find(opt.pagArea):next),
					opt.holder.trigger(opt.pagRefreshEv)
				else
					opt.pags.removeClass(opt.pagActiveCl),
					opt.act=opt.pags.eq(-1).addClass(opt.pagActiveCl),
					opt.changeFu(opt.pagArea?opt.act.find(opt.pagArea):opt.act),
					opt.holder.trigger(opt.pagRefreshEv)
			},
			showFu:function(){
				var opt=this,
					holder=opt.holder,
					spinner=$(opt.spinner),
					url=holder.data('url')
				holder.find('*').remove()
				holder.append(spinner)				
				holder.load(url,{},function(){
					spinner.remove()
					opt.animationCallback.call(holder,opt)
				})
				holder.trigger(opt.showEv,url)
			},
			init:function(opt){
				var holder=opt.holder=this,
					tmp
				if(opt.pagination)	
					opt.pagFu()
				if(opt.navLinks)
					$(opt.navLinks).live(opt.pagEv,function(){
						var th=$(this),
							tmp
						if((tmp=th.data('opt'))!=undefined&&tmp.clearPags)
							$(opt.pagination).removeClass(opt.pagActiveCl)
						opt.changeFu(th)
						return false
					})
				holder
					.bind(opt.nextEv,function(){
						opt.nextFu()
					})
					.bind(opt.prevEv,function(){
						opt.prevFu()
					})
				if(opt.nextBu)
					opt.nextBu=$(opt.nextBu),
					opt.nextBu.bind('click',function(){
						opt.nextFu()
						return false
					})
				if(opt.prevBu)
					opt.prevBu=$(opt.prevBu),
					opt.prevBu.bind('click',function(){
						opt.prevFu()
						return false
					})
				holder.data({opt:opt})
			}
		},
		"_forms":{
			target:'input[type=text],input[type=password],input[type=tel],input[type=email],textarea',
			buttons:'a[rel=reset],a[rel=submit]',
			event:'click',
			init:function(opt){
				var form=opt.form=this,
					inputs=opt.inputs=$(opt.target,form)
				inputs.each(function(){
					var th=$(this)
					th.data({defValue:th.attr('value')})
					th
						.bind('focus',function(){
							if(th.attr('value')==th.data('defValue'))
								th.attr({value:''})
						})
						.bind('blur',function(){
							if(th.attr('value')=='')
								th.attr({value:th.data('defValue')})
						})					
				})
				$(opt.buttons,form).each(function(){
					var th=$(this)
					th.bind(opt.event,function(){											   
						form.attr(this.rel).call(form[0])
						return false
					})
				})
			}
		}
	})
	
	//jQuery methods
	$.fn.extend({
		"_bgSlider":function(opt){
			return _fw.apply(this,['_bgSlider',opt])
		},
		"_ajaxSlider":function(opt){
			return _fw.apply(this,['_ajaxSlider',opt])
		},
		"_forms":function(opt){
			return _fw.apply(this,['_forms',opt])
		}
	})
	
	

})(jQuery)

//Helpers
;(function($){
	$.fn.extend({
		praParent:function(expr,fu){
			var th=this,
				test=function(o){
					var i,
						tf=true
					if(fu)
						fu.call(o)
					if(typeof expr===typeof '')
						return o.is(expr)
					if(typeof expr===typeof {}){
						for(i in expr)
							tf=!!any(o.css(i),expr[i].split(' '))
						return tf
					}
				}
			if(!th.length)return false
			while(th=th.parent())
				if(test(th))
					break
				else
					if(th.is('html'))
						return false
			return th
		},
		waitImgLoad:function(fn){
			var th=this,
				img=$('img',this),
				num=img.length
			img.each(function(){
				if(!this.complete)
					$(this).load(function(){
						if(!--num)
							fn.call(th)
					})					
				else
					if(!--num)
						fn.call(th)
			})
			return this
		},
		popUp:function(){
			this.each(function(){
				var th=$(this),
					pos=th.praParent({position:'relative absolute'}).getPos()
				if(!th.hasClass('_popuped'))
					th
						.data({
							  _popUpParent:th.parent(),
							  left:th.attr('offsetLeft'),
							  top:th.css('offsetLeft')
							 })
						.css({
							zIndex:9000,
							position:'absolute',
							left:pos.x+th.data('left'),
							top:pos.y+th.data('top')
							})
						.appendTo('body')
						.addClass('_popuped')
			})
			return this
		},
		pushBack:function(){
			this.each(function(){
				var th=$(this)
				th.appendTo(th.data('_popUpParent'))
				th.css({
					  left:th.data('left'),
					  top:th.data('top')
					  })
				th.removeClass('_popuped')
			})			
			return this
		},
		getPos:function(){
			var ret
			this.each(function(){
				var r={x:0,y:0},
					o=this
				while(o){
					r.x+=o.offsetLeft
					r.y+=o.offsetTop
					o=o.offsetParent
				}
				ret=r
			})
			return ret
		}

	})
})(jQuery)
//jquery.drift.js
;(function($){
	$.fn.extend({
		drift:function(opt){
			opt=$.extend({
				fullScreenClass:'_fs',
				functer:function(pc){
					var th=$(this)
					th.css({
						left:th.data('stX')+pc.x*th.data('dX')+'px',
						top:th.data('stY')+pc.y*th.data('dY')+'px'
					},'fast')
				}, 
				minWidth:0,
				minHeight:0,
				maxWidth:0,
				maxHeight:0
			},opt)
			
			var th=$(this),body=$(document.body),callee=arguments.callee
				maw=opt.maxWidth||parseInt(body.css('max-width')),
				miw=opt.minWidth||parseInt(body.css('min-width')),
				mah=opt.maxHeight||parseInt(body.css('max-height')),
				mih=opt.minHeight||parseInt(body.css('min-height')),
				dw=maw-miw,
				dh=mah-mih
				
			if(!(maw&&mah&&miw&&mih))return false
			
			th.each(function(){
				var tmp={left:this.offsetLeft,top:this.offsetTop},
					delta=function(a,b){return a<b?b-a:a-b}
				$(this)
					.data({stX:tmp.left,stY:tmp.top})
					.addClass(opt.fullScreenClass)
					.data({dX:delta(tmp.left,this.offsetLeft),dY:delta(tmp.top,this.offsetTop)})
					.removeClass(opt.fullScreenClass)
					.css({position:'absolute',left:tmp.left+'px',top:tmp.top+'px'})
			})
			
			$(window).bind('resize load',function(){
				th.each(function(){
					var x=(body.width()-miw)/dw,
						y=(body.height()-mih)/dh
					opt.functer.call(this,{
						x:x>0?x:0,
						y:y>0?y:0
					})
				})
			})
		}
	})	
})(jQuery)

function clone(obj){
	if(!obj||typeof obj!=typeof {})
		return obj
	if(obj instanceof Array)
		return [].concat(obj)
	var tmp=new obj.constructor(),
		i
	for(i in obj)
		if(obj.hasOwnProperty(i))
			tmp[i]=clone(obj[i])
	return tmp
}

function any(inp,vrs){
	var ret=false
	if(arguments.length>2)
		vrs=$.extend([],arguments),
		vrs.shift()
	for(var i=0;i<vrs.length;i++)
		if(inp==vrs[i])
			ret=vrs[i]
	return ret
}
