;(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,{		
		"_ajaxSlider":{
			spinner:false,
			minSleep:300,
			show: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)
						if(th.attr('href')!='#')
							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,
					url=holder.data('url')
				holder.find('*').remove()
				if(opt.spinner)
					opt.sParent.append(opt.spinner.fadeIn())
				setTimeout(function(){
					holder.load(url,{},function(){
						opt.spinner.fadeOut(function(){$(this).detach()})
						opt.animationCallback.call(holder,opt)
					})
				},opt.minSleep)
				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
					})
				if(opt.spinner)
					opt.spinner=$(opt.spinner),
					opt.sParent=opt.spinner.parent()
				if(opt.show!==false)
					opt.pags.eq(opt.show).addClass(opt.pagActiveCl).siblings().removeClass(opt.pagActiveCl),
					opt.changeFu($('a',opt.pags.eq(opt.show)))					
				holder.data({opt:opt})
			}
		},
		"_spinnerGallery":{
			spinnerURL:false,
			fader:false,
			spinner:false,
			pagination:false,
			pagArea:'>a',
			pagEv:'click',
			navLinks:'a[rel=spinnerGallery]',
			spinnerClassName:'_spinner',
			faderClassName:'_fader',
			currentCl:false,
			blocked:false,
			showEv:'_show',
			minSleep:400,
			faderOpacity:.6,
			faderColor:'#fff',
			css:{position:'absolute',left:0,top:0,right:0,bottom:0,zIndex:9999},
			pagFu:function(){
				var opt=this,
					pags=opt.pags=$(opt.pagination)
				pags.parent()
					.delegate(opt.pagination+(opt.pagArea?' '+opt.pagArea:''),opt.pagEv,function(){
						var th=$(this),
							li=opt.pagArea?th.praParent('li'):th
						if(opt.currentCl)
							if(li.is('.'+opt.currentCl))
								return false
							else
								opt.pags.removeClass(opt.currentCl),
								li.addClass(opt.currentCl),
								opt.showFu(th.attr('href'))
						else
							opt.showFu(th.attr('href'))
						return false
					})
			},
			showFu:function(data){
				var opt=this
				if(!opt.blocked)
					opt.fader
						.appendTo(opt.holder)
						.stop()
						.animate({
							opacity:opt.faderOpacity
								 },{
								duration:opt.minSleep/2,
								complete:function(){
								opt.outOfSpace
									.load(function(){
										opt.pic.attr({src:this.src})
										setTimeout(function(){
											opt.hideFu()
											},opt.minSleep)
										})
										.attr({src:data})
									}
								}),
					opt.spinner
						.appendTo(opt.holder),
					opt.blocked=true
			},
			hideFu:function(){
				var opt=this
				opt.spinner.detach()
				opt.fader.stop().animate({
										opacity:0
										 },{
										duration:opt.minSleep/2,
										complete:function(){											
											opt.fader.detach()
											opt.blocked=false
										}
								})
			},
			init:function(opt){
				var holder=opt.holder=this,
					pic=opt.pic=$('img',holder),
					outOfSpace=opt.outOfSpace=$('<img>')
				opt.fader=$('<div>')
							.css(opt.css)
							.css({
								backgroundColor:opt.faderColor,
								opacity:0
							})
				opt.spinner=$('<div>')
							.css(opt.css)
							.css({
								 background:'url('+opt.spinnerURL+') 50% 50% no-repeat'
							})
				if(!opt.spinnerURL)
					return this
				if(holder.css('position')!='absolute')
					holder.css({position:'relative'})
				holder.bind(opt.showEv,function(e,data){
					opt.showFu(data)
					return false
				})
				if(opt.pagination)
					opt.pagFu()
			}
		},
		"_shadowBox":{
			showEv:'click',
			faderCl:'_fader',
			fader:true,
			method:'inline',
			easing:'',
			duration:600,
			faderCSS:{
				position:'fixed',
				left:0,
				top:0,
				bottom:0,
				right:0,
				zIndex:9999,
				opacity:.7,
				background:'#000'
			},
			boxCSS:{
				position:'fixed',
				left:'50%',
				top:'50%',
				zIndex:9999
			},
			preFu:function(){
				var opt=this,
					box=opt.box=$('<div id="_box">')
						.css(opt.boxCSS)
				if(opt.fader)
					opt.fader=$('<div>'),
					opt.fader
						.css(opt.faderCSS)
			},
			changeFu:function(){
				var opt=this,
					url=opt.holder.attr('href'),
					tmp,
					width=~(tmp=url.indexOf('width'))?url.slice(tmp,url.indexOf('&',tmp)).replace('width=',''):'auto',
					height=~(tmp=url.indexOf('height'))?url.slice(tmp,url.indexOf('&',tmp)).replace('height=',''):'auto'
				if(opt.method=='flash')					
					opt.box
						.empty()
						.flashembed(url)
					opt.box						
						.width(width)
						.height(height)
						.css({
							marginLeft:-width/2,
							marginTop:-height/2
							})
				opt.showFu()
			},
			showFu:function(){
				var opt=this
				opt.fader
					.unbind(opt.showEv)
					.bind(opt.showEv,function(){
						opt.hideFu()
					})
					.css({opacity:0})
					.appendTo('body')
					.stop()
					.animate({
							opacity:opt.faderOpacity
							},{
							duration:opt.duration,
							easing:opt.easing,
							complete:function(){
								opt.box.appendTo('body')
							}
							})
			},
			hideFu:function(){
				var opt=this
				opt.box.remove()
				opt.fader.remove()
			},
			init:function(opt){
				var holder=opt.holder=this
				opt.faderOpacity=opt.faderCSS.opacity
				opt.method=holder.attr('rel')
				opt.preFu()
				holder
					.bind(opt.showEv,function(){
						opt.changeFu()
						return false
					})
			}
		}
	})
	
	//jQuery methods
	$.fn.extend({
		"_bgSlider":function(opt){
			return _fw.apply(this,['_bgSlider',opt])
		},
		"_ajaxSlider":function(opt){
			return _fw.apply(this,['_ajaxSlider',opt])
		},
		"_spinnerGallery":function(opt){
			return _fw.apply(this,['_spinnerGallery',opt])
		},
		"_shadowBox":function(opt){
			return _fw.apply(this,['_shadowBox',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
		},
		waitLoading: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
}
