//init page
jQuery(function(){
	initCastomForms();
	initShowBox();
	initCarousel();
	initLightbox();
	initMapHover();
	initImageMaps();
	initSlideshow();
	//classTabs.init();
	initTabs2();
	initSlidePanel();
	initClearInputs();
	initShowDrop();
	initSocialBar();
	initTabs();
	initDropTabs();
	initFormStep();
	initScrollPage();
	initAddClass();
	initHoverProblem();
	initTooltips();
	initNoDownload();
	initDropClose();
	initNavFix();
	initValidation();
});
jQuery(window).load(function(){
	initNavHover();
	initFancyFix();
	initFixPosDrop();
	initVideoSwitch();
});

jQuery(window).resize(initFancyFix);

//if mobile device
var mobileReg = /(ipad|iphone|ipod|android|blackberry|opera mobi)/gi;
var isMobile = mobileReg.test(navigator.userAgent);

//init no download images
function initNoDownload(){
	jQuery('img').attr('oncontextmenu', 'return false');
}

// form validation function
function initValidation() {
    var errorClass = 'text-error';
    var successClass = 'text-success';
    var regEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var regPhone = /^[0-9]+$/;

    jQuery('div.same-form form.send-form1, div.same-form  form.form-validation, div.textwidget  form.form-validation').each(function(){
        var form = $(this);
        var successFlag = true;
        var inputs = form.find('input[type=text]');
        
        // form validation function
        function validateForm() {
            successFlag = true;
            inputs.each(checkField)
            if(!successFlag) {
                return false;
            }else{
				var xhr = jQuery.ajax({
					type:'POST',
					url:form.attr('action'),
					data:form.serialize(),
					dataType:'text',
					error:function() {
						form.parent().removeClass('error-submit').addClass('active');
					},
					success:function (data) {
						form.parent().removeClass('error-submit').addClass('active');
					}
				});
				return false;
			}
        }
        
        // check field
        function checkField(i, obj) {
            var currentObject = $(obj);
            var currentParent = currentObject.parent();
            
            // not empty fields
            if(currentObject.attr('name') == 'name' || currentObject.attr('name') == 'AddressZip_') {
                setState(currentParent, currentObject, (!currentObject.val().length || currentObject.val() == obj.defaultValue))
            }
            // correct email fields
            if(currentObject.attr('name') == 'email') {
                setState(currentParent, currentObject, !regEmail.test(currentObject.val()));
            }
            // correct number fields
            if(currentObject.hasClass('required-number')) {
                setState(currentParent, currentObject, !regPhone.test(currentObject.val()));
            }
            // something selected
            if(currentObject.hasClass('required-select')) {
                setState(currentParent, currentObject, currentObject.get(0).selectedIndex === 0);
            }
        }
        
        // set state
        function setState(hold, field, error) {
            hold.removeClass(errorClass).removeClass(successClass);
            if(error) {
                hold.addClass(errorClass);
				form.parent().addClass('error-submit');
                field.one('focus',function(){hold.removeClass(errorClass).removeClass(successClass)});
                successFlag = false;
            } else {
                hold.addClass(successClass);
            }
        }
        
        // form event handlers
        form.submit(validateForm);
    })
}

//init fancy fix
function initFancyFix(){
	var winW = jQuery('#wrapper').outerWidth();
	if(jQuery('#fancybox-overlay').length){
		jQuery('#fancybox-overlay').css({width: winW});
	}
}

function newsletter_check(f) {
    var re = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
    if (!re.test(f.elements["ne"].value)) {
        jQuery(f).addClass('error-msg');
        return false;
    }
    if (f.elements["ny"] && !f.elements["ny"].checked) {
        alert("<?php echo addslashes($options['privacy_error']); ?>");
        return false;
    }
    return true;
} 

//init drop close
function initDropClose(){
	var nav = jQuery('#nav')
	var drops = nav.find('.drop');
	
	drops.each(function(){
		var drop = jQuery(this);
		var btnClose = drop.find('a.close').hide();
		if(isMobile){
			btnClose.show().bind('touchstart', function(){
				drop.css({opacity: 0, top: '-9999px'});
				drop.parents('li').removeClass('hover');
				return false;
			});
		}
	});
}

//init video switch
function initVideoSwitch(){
	var prevVideo, curVideo = 0;
	jQuery('.tube-video-frame').each(function(){
		var holder = jQuery(this);
		var videoHolder = holder.find('.big-video > .holder');
		videoHolder.hide().eq(curVideo).show();
		var switcher = holder.find('.video-mask > ul > li');
		switcher.each(function(ind){
			jQuery(this).click(function(){
				prevVideo = curVideo;
				curVideo = ind;
				videoHolder.each(function(num){
					if(ind == num){
						videoHolder.hide().eq(num).show();
						var content = videoHolder.eq(prevVideo).html();
						videoHolder.eq(prevVideo).empty().html(content);
					}
				});
				return false;
			});
		});
	});
}

//add class box
function initAddClass(){
	if(jQuery('#sidebar').length){
		jQuery('#sidebar').find('.boxes .box:eq(0)').addClass('box-first');
	}
}

//init tooltips
function initTooltips(){
	var speed = 400;
	var links = jQuery('a.hint, .social-networks ul > li');
	
	var ie = $.browser.msie && $.browser.version < 9;
	links.each(function(){
		var link = jQuery(this);
		var tooltip = link.find('.tooltip, .social-tooltip');
		link.hover(function(){
			if(ie){
				tooltip.css({left: '50%', bottom: '20px'}).stop().animate({bottom: '30px'}, {duration: speed});
			}else{
				tooltip.css({left: '50%', opacity: 0, bottom: '20px'}).stop().animate({opacity: 1, bottom: '30px'}, {duration: speed});
			}
		}, function(){
			if(ie){
				tooltip.stop().animate({bottom: '20px'}, {duration: speed, complete: function(){
					jQuery(this).css({left: '', bottom: ''});
				}});
			}else{
				tooltip.stop().animate({opacity: 0, bottom: '20px'}, {duration: speed, complete: function(){
					jQuery(this).css({opacity: '', left: '', bottom: ''});
				}});
			}
		});
	});
}

//init hover problem
function initHoverProblem(){
	var hold = jQuery('#map-hover');
	var areas = jQuery('#Map area');
	var speed = 400;
	var items = hold.find('>li');
	items.each(function(){
		var item = jQuery(this);
		var imgHover = item.find('img.img-hover').css({opacity: 0});
		item.mouseover(function(){
			imgHover.stop().animate({opacity: 1}, {duration: speed});
		}).mouseout(function(){
			imgHover.stop().animate({opacity: 0}, {duration: speed, complete: function(){item.hide()}});
		});
	});
	areas.each(function(){
		var hoverLi = jQuery('#' + jQuery(this).attr('alt'));
		jQuery(this).mouseenter(function(){
			hoverLi.show();
		});
	});
}

//init scroll page
function initScrollPage(){
	var speed = 650;
	jQuery('.listing, .roster .link').each(function(){
		var nav = jQuery(this);
		var links = nav.find('a');
		links.click(function () {
			elementClick = jQuery(this).attr("href");
			destination = jQuery(elementClick).offset().top;
			jQuery('html, body').animate({scrollTop: destination}, {duration: speed});
			return false;
		});
	});
}

//init drop tabs
function initDropTabs(){
	var activeClass = 'active';
	var animating, speed = 500;
	jQuery('.sub-nav').each(function(){
		var hold = jQuery(this);
		var links = hold.find('a');
		
		links.each(function() {
			var link = jQuery(this);
			var tab = jQuery(link.attr('rel'));
			tab.css({position: 'absolute', left: 0, top: 0});
			if(link.hasClass(activeClass)) {
				tab.css({opacity: 1});
				tab.parent().css({height: tab.height()});
			}else tab.css({opacity: 0}).hide();
			
			link.bind('click', function(){
				if(!animating){
					if(!link.hasClass(activeClass)){
						jQuery(this).addClass(activeClass)
						animating = true;
						links.filter('.' + activeClass).each(function(){
							jQuery(jQuery(this).removeClass(activeClass).attr('rel')).stop().animate({opacity: 0}, {duration: speed, complete: function(){
								jQuery(this).hide();
							}});
							if(jQuery(jQuery(this).removeClass(activeClass).attr('rel')).height() != tab.height()){
								tab.parent().stop().animate({height: tab.height()}, {duration: speed});
							}
						});
						link.addClass(activeClass);
						tab.show().stop().animate({opacity: 1}, {duration: speed, complete: function(){
							var posL = link.offset().left - hold.find('>ul').offset().left;
							hold.find('.backLava').stop().animate({left: posL}, 400);
							animating = false;
						}});
					}else{
						return;
					}
				}
				return false;
			});
		});
	});
}

//init form step
function initFormStep(){
	jQuery('.same-form').each(function(){
		var hold = jQuery(this);
		var select = hold.find('select.select4');
		var box2 = hold.find('.select-box2');
		var box3 = hold.find('.select-box3');
		if(select.val() == 'default') box2.add(box3).hide();
		if(select.val() == 'interest') {
			box2.show();
			box3.hide();
		}
		if(select.val() == 'support'){
			box2.hide();
			box3.show();
		}
		select.change(function(){
			if(select.val() == 'default') box2.add(box3).hide();
			if(select.val() == 'interest') {
				box2.show();
				box3.hide();
			}
			if(select.val() == 'support'){
				box2.hide();
				box3.show();
			}
		});
	});
}

function initTabs(){
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++){
		if (sets[i].className.indexOf("tabset") != -1){
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++){
				if (links[j].className.indexOf("tab") != -1){
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));

					//reset all tabs on start
					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";

					links[j].onclick = function (){
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c){
							//reset all tabs before change
							for (var i = 0; i < this.tabs.length; i++){
								var tab = document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1));
								if (tab){
									tab.style.display = "none";
								}
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}

//init fix position drop
function initFixPosDrop(){
	var hold = jQuery('#nav');
	var items = hold.find('>li');
	items.each(function(){
		if(jQuery(this).is(':has(div)')){
			var drop = jQuery(this).find('.drop');
			drop.css({left: hold.offset().left - jQuery(this).offset().left});
		}
	});
}

//init show drop
function initShowDrop(){
	var hold = jQuery('#nav');
	var items = hold.find('>li');
	var drops = items.find('.drop');
	var speed = 400;
	var ie = jQuery.browser.msie && jQuery.browser.version < 9;
	
	items.each(function(){
		if(jQuery(this).is(':has(div)')){
			var item = jQuery(this);
			var drop = item.find('.drop').css({top: '-9999px'});
			if(isMobile){
				item.bind('touchstart', function(){
					drops.not(drop).stop().animate({opacity: 0}, {duration: speed, complete: function(){
						jQuery(this).css({top: '-9999px', opacity: ''});
					}});
					drop.css({top: '52px', opacity: 0}).stop().animate({opacity: 1}, {duration: speed});
				})
			}else{
				item.mouseenter(function(){
					if(ie){
						drop.css({top: '52px'});
					}else{
						drop.css({top: '52px', opacity: 0}).stop().animate({opacity: 1}, {duration: speed});
					}
				}).mouseleave(function(){
					if(ie){
						drop.css({top: '-9999px'});
					}else{
						drop.stop().animate({opacity: 0}, {duration: speed, complete: function(){
							jQuery(this).css({top: '-9999px', opacity: ''});
						}});
					}
				});
			}
		}
	});
}

//init social bar
function initSocialBar(){
	jQuery('.social-box').each(function(){
		var hold = jQuery(this);
		/* var startLeft = hold.css('left');
		var startTop = hold.css('top'); */
		var leftPos = hold.offset().left;
		var topPos = hold.offset().top;
		var win = jQuery(window);
	
		win.resize(function(){
			hold.css({position: 'absolute', left:'', top:''});
			leftPos = hold.offset().left;	
			reposition();
		});
	
		function reposition(){
			var scrollNow = win.scrollTop();
			if(scrollNow < topPos){
				hold.css({position: 'absolute', left:'', top:''});
			} else {
				hold.css({position: 'fixed', left:leftPos, top:0});
			}		
		}
	
		win.scroll(reposition);
	});
}

//init map hover
function initMapHover(){
	var speed = 400;
	jQuery('.tab-content').each(function(){
		var hold = jQuery(this);
		var items = jQuery('#map-hover1 li, #map-hover2 li, #map-hover3 li');
		var tooltips = items.find('.tooltip-add');
		if(jQuery.browser.msie && jQuery.browser.version < 9){
			items.find('a.img-hover').hide();
			tooltips.hide();
		}else{
			items.find('a.img-hover').css({opacity: 0});
			tooltips.css({opacity: 0});
		}
		var mapItems = jQuery('#Map1 area, #Map2 area, #Map3 area');
		
		mapItems.each(function(){
		var t1, t2;
			var item = '#'+ jQuery(this).attr('alt');
			var newItems = items.not(item);
			var tooltip = jQuery(item).find('.tooltip-add');
			jQuery(this).hover(function(){
				clearTimeout(t1);
				t1 = setTimeout(function(){
					var posT = jQuery(item).offset().top;
					var posL = jQuery(item).offset().left;
					tooltip.appendTo('body').css({top: posT, left: posL});
					if(jQuery.browser.msie && jQuery.browser.version < 9){
						//newItems.find('a.img-hover').show();
						tooltip.show();
					}else{
						//newItems.find('a.img-hover').stop().animate({opacity:1}, {dutation: speed});
						tooltip.stop().animate({opacity:1}, {dutation: speed});
					}
				}, 100);
			}, function(){
				clearTimeout(t1);
				t1 = setTimeout(function(){
					if(jQuery.browser.msie && jQuery.browser.version < 9){
						//newItems.find('a.img-hover').hide();
						tooltip.appendTo(item).css({top:'', left: ''}).hide();
					}else{
						//newItems.find('a.img-hover').stop().animate({opacity:0}, {dutation: speed});
						tooltip.stop().animate({opacity:0}, {dutation: speed, complete:function(){
							jQuery(this).appendTo(item).css({top:'', left: ''})
						}});
					}
				}, 100);
			});
			tooltip.hover(function(){
				if(t1) clearTimeout(t1);
			}, function(){
				if(jQuery.browser.msie && jQuery.browser.version < 9){
					//newItems.find('a.img-hover').hide();
					tooltip.appendTo(item).css({top:'', left: ''}).hide();
				}else{
					//newItems.find('a.img-hover').stop().animate({opacity:0}, {dutation: speed});
					tooltip.stop().animate({opacity:0}, {dutation: speed, complete:function(){
						jQuery(this).appendTo(item).css({top:'', left: ''})
					}});
				}
			});
		});
	});
}

//init nav hover
function initNavHover(){
	var nav = jQuery('#nav');
	var drops = nav.find('div.drop');
	
	drops.each(function(){
		var drop = jQuery(this);
		var parent = drop.parent();
		drop.data('origparent',parent).detach();
	});
	
	// init 1st level lavalamp
	nav.lavaLamp({
		speed: 400
	});
	
	
	drops.each(function(){
		jQuery(this).appendTo(jQuery(this).data('origparent'));
	});
	
	// 2ns level lavalamp
	drops.find('.sub-nav > ul').each(function(){
		var list = jQuery(this);
		list.children().removeClass('noLava');
	});
	jQuery('.product-list').lavaLamp({
		autoReturn: false,
		speed: 400
	});
	jQuery('.intro-menu ul').lavaLamp({
		autoReturn: false,
		speed: 400
	});
}

//init show fade box
function initShowBox(){
	jQuery('.fade-box').fadeBox({
		startBox: '.units',
		btnShow:'a.detail',
		btnClose:'a.close',
		duration:650
	});
	jQuery('.fade-box2').fadeBox({
		startBox: '.benefit-block',
		btnShow:'a.more',
		btnClose:'a.close',
		duration:650
	});
	jQuery('.fade-box3').fadeBox({
		startBox: '.map',
		btnShow:'#map-hover a',
		btnClose:'a.close',
		duration:650
	});
	jQuery('.fade-box4').fadeBox({
		startBox: '.product-holder',
		btnShow:'a.detail',
		btnClose:'a.close',
		duration:650
	});
}

//init carousel
function initCarousel(){
	jQuery('.products, .problem-gallery').scrollGallery({
		sliderHolder:'.mask',
		generatePagination:'.switch-holder',
		duration:650
	});
	jQuery('.tube-video-frame').scrollGallery({
		sliderHolder:'.video-mask',
		generatePagination:'.switch-holder',
		duration:650
	});
	jQuery('.products .mask > ul > li, .problem-gallery .mask > ul > li, .tube-video-frame .video-mask > ul > li ').each(function(){
		var obj = jQuery(this);
		obj.swipe({
			swipe:function(e,dir){
				if(dir == 'left') {
					obj.trigger('nextSlide');
				} else if(dir == 'right') {
					obj.trigger('prevSlide');
				}
			},
			triggerOnTouchEnd : true,
			allowPageScroll:"vertical",
			threshold:20
		});
	});
}

// main page slideshow
function initSlideshow(){
	jQuery('.intro').fadeGallery({
		slideElements:'.gallery li',
		pagerLinks:'.intro-menu a',
		pauseOnHover:true,
		autoRotation:true,
		activeClass:'selectedLava',
		switchTime:6000, // homepage slideshow switch time, ms
		duration:650,
		onChange: function(_this, _slides, _prevIndex, _currentIndex){
			jQuery('.intro-menu ul .backLava').stop().animate({left: (_currentIndex*jQuery('.intro-menu ul .backLava').width())});
		},
		event:'mousemove'
	});
	jQuery('.content-section').fadeGallery({
		slideElements:'.clean-gallery li',
		pagerLinks:'.switch a',
		pauseOnHover:true,
		autoRotation:true,
		switchTime:4000,
		duration:650
	});
	jQuery('.slideshow').fadeGallery({
		slideElements:'ul > li',
		pauseOnHover:true,
		autoRotation:true,
		switchTime:15000,
		autoHeight: true,
		duration:650
	});
	jQuery('#sidebar .box blockquote').fadeGallery({
		slideElements:'> div',
		pauseOnHover:true,
		autoRotation:true,
		switchTime:20000,
		duration:650
	});
	
	jQuery('.clean-gallery > ul > li').each(function(){
		var obj = jQuery(this);
		obj.swipe({
			swipe:function(e,dir){
				if(dir == 'left') {
					obj.trigger('nextslide');
				} else if(dir == 'right') {
					obj.trigger('prevslide');
				}
			},
			triggerOnTouchEnd : true,
			allowPageScroll:"vertical",
			threshold:20
		});
	});
}

//init lightbox
function initLightbox(){
	if(jQuery('.open-lightbox').length){
		jQuery('.open-lightbox:not(.iframe)').fancybox({
			'overlayOpacity' : '0.55',
			'overlayColor' : '#000',
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'easingIn' : 'easeOutBack',
			'easingOut' : 'easeInBack',
			'onComplete' : function(){
				jQuery('img').attr('oncontextmenu', 'return false');
			}
		});
	}
	if(jQuery('a[rel=photos-group]').length){
		jQuery('a[rel=photos-group]').fancybox({
			'overlayOpacity' : '0.55',
			'overlayColor' : '#000',
			'titlePosition' : 'inside',
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'easingIn' : 'easeOutBack',
			'easingOut' : 'easeInBack',
			'onComplete' : function(){
				jQuery('img').attr('oncontextmenu', 'return false');
			}
		});
	}
	jQuery('a.open-lightbox.iframe').each(function(){
		var link = $(this);
		var target = link.attr('href');
		link.click(function(){
			jQuery.fancybox({
				href:target,
				width: parseInt(getUrlAttr(target, 'width')),
				height: parseInt(getUrlAttr(target, 'height')),
				type: 'iframe'
			})
			return false;
		});
	});
	function getUrlAttr(str, name) {
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( str );
		if( results == null ) return ""; else return results[1];
	}
}

//init slide top panel
function initSlidePanel(){
	var speed = 1000;
	jQuery('.header-top').each(function(){
		var hold = jQuery(this);
		var wrapper = jQuery('#wrapper');
		var holdH = hold.height();
		var closeBtn = hold.find('a.close');
		if (!jQuery.cookie("slide")||jQuery.cookie("slide")!='true') {
			hold.show().css({top: -holdH}).stop().animate({top: '0'}, {duration: speed});
			wrapper.stop().animate({paddingTop: holdH}, {duration: speed});
			closeBtn.click(function(){
				hold.stop().animate({top: -holdH}, {duration: speed, complete: function(){
					jQuery(this).hide().removeAttr('style');
					jQuery.cookie("slide","true");
				}});
				wrapper.stop().animate({paddingTop: 0}, {duration: speed});
				return false;
			});
		}
	});
}

//init clear inputs
function initClearInputs(){
	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: true,
		addClassFocus: "focus",
		filterClass: "default"
	});
}

// create imagemaps
function initImageMaps(){
	var imageList = document.getElementsByTagName('img');
	for(var i = 0; i < imageList.length; i++) {
		if(imageList[i].getAttribute('usemap')) {
			new ImageMap({
				image: imageList[i]
			})
		}
	}
}

//init nav fix for mobile
function initNavFix(){
	new touchNav({
		navBlock: 'nav'
	});
}

//navigation accesibility module
function touchNav(options) {
	this.options = {
		mobileReg: /(ipad|iphone|ipod|android|blackberry|iemobile)/gi,
		hoverClass: 'hover',
		followLink: false,
		menuItems: 'li',
		menuOpener: 'a',
		menuDrop: 'div',
		navBlock: null
	}
	for(var p in options) {
		this.options[p] = options[p];
	}
	this.init();
}
touchNav.prototype = {
	init: function() {
		this.isMobile = (this.options.mobileReg).test(navigator.userAgent);
		if(typeof this.options.navBlock === 'string') {
			this.menu = document.getElementById(this.options.navBlock);
		} else if(typeof this.options.navBlock === 'object') {
			this.menu = this.options.navBlock;
		}
		if(this.menu) {
			this.getElements();
			this.addEvents();
		}
	},
	getElements: function() {
		this.menuItems = this.menu.getElementsByTagName(this.options.menuItems);
	},
	hideActiveDropdown: function() {
		if(this.activeParent) {
			for(var i = 0; i < this.menuItems.length; i++) {
				this.removeClass(this.menuItems[i], this.options.hoverClass);
			}
			this.activeParent = null;
		}
	},
	getOpener: function(obj) {
		for(var i = 0; i < obj.childNodes.length; i++) {
			if(obj.childNodes[i].tagName && obj.childNodes[i].tagName.toLowerCase() == this.options.menuOpener.toLowerCase()) {
				return obj.childNodes[i];
			}
		}
		return false;
	},
	getDrop: function(obj) {
		for(var i = 0; i < obj.childNodes.length; i++) {
			if(obj.childNodes[i].tagName && obj.childNodes[i].tagName.toLowerCase() == this.options.menuDrop.toLowerCase()) {
				return obj.childNodes[i];
			}
		}
		return false;
	},
	addEvents: function() {
		// mobile event handlers
		if(this.isMobile) {
			for(var i = 0; i < this.menuItems.length; i++) {
				this.menuItems[i].touchNav = this;
				if(this.getDrop(this.menuItems[i])) {
					this.addHandler(this.getOpener(this.menuItems[i]), 'click', this.bind(this.clickHandler,this.menuItems[i]));
				}
			}
			this.addHandler(document.body, 'click', this.bind(this.outsideHandler, this));
			this.addHandler(document.body, 'touchstart', this.bind(this.outsideHandler, this));
		}
		// desktop event handlers
		else {
			for(var i = 0; i < this.menuItems.length; i++) {
				this.menuItems[i].touchNav = this;
				this.addHandler(this.menuItems[i], 'mouseover', this.mouseoverHandler);
				this.addHandler(this.menuItems[i], 'mouseout', this.mouseoutHandler);
			}
		}
	},
	outsideHandler: function(e) {
		var childFlag = false;
		if(this.activeParent) {
			this.outsideTarget = e.target || e.currentTarget || e.srcElement;
			while (this.outsideTarget.parentNode) {
				if(this.activeParent == this.outsideTarget) {
					childFlag = true;
					break;
				}
				this.outsideTarget = this.outsideTarget.parentNode;
			}
			if(!childFlag) {
				this.hideActiveDropdown();
			}
		}
	},
	mouseoverHandler: function() {
		this.touchNav.addClass(this, this.touchNav.options.hoverClass);
	},
	mouseoutHandler: function() {
		this.touchNav.removeClass(this, this.touchNav.options.hoverClass);
	},
	clickHandler: function(e) {
		// get current dropdown
		var tNav = this.touchNav;
		tNav.currentElement = e.currentTarget || e.srcElement;
		tNav.currentParent = tNav.currentElement.parentNode;

		// hide previous drop (if exists)
		if(tNav.activeParent && !tNav.isParent(tNav.activeParent, tNav.currentParent) && tNav.currentParent != tNav.activeParent) {
			tNav.hideActiveDropdown();
		}

		// handle current drop
		if(tNav.hasClass(tNav.currentParent, tNav.options.hoverClass)) {
			tNav.removeClass(tNav.currentParent, tNav.options.hoverClass);
			if(tNav.options.followLink) {
				window.location.href = tNav.currentElement.href;
			}
		} else {
			tNav.addClass(tNav.currentParent, tNav.options.hoverClass);
			tNav.activeParent = tNav.currentParent;
			return tNav.preventEvent(e);
		}
	},
	preventEvent: function(e) {
		if(!e) e = window.event;
		if(e.preventDefault) e.preventDefault();
		if(e.stopPropagation) e.stopPropagation();
		e.cancelBubble = true;
		return false;
	},
	isParent: function(parent, child) {
		while(child.parentNode) {
			if(child.parentNode == parent) {
				return true;
			}
			child = child.parentNode;
		}
		return false;
	},
	addHandler: function(object, event, handler) {
		if (typeof object.addEventListener != 'undefined') object.addEventListener(event, this.bind(handler,object), false);
		else if (typeof object.attachEvent != 'undefined') object.attachEvent('on' + event, this.bind(handler,object));
	},
	removeHandler: function(object, event, handler) {
		if (typeof object.removeEventListener != 'undefined') object.removeEventListener(event, handler, false);
		else if (typeof object.detachEvent != 'undefined') object.detachEvent('on' + event, handler);
	},
	hasClass: function(obj,cname) {
		return (obj.className ? obj.className.match(new RegExp('(\\s|^)'+cname+'(\\s|$)')) : false);
	},
	addClass: function(obj,cname) {
		if (!this.hasClass(obj,cname)) obj.className += " "+cname;
	},
	removeClass: function(obj,cname) {
		if (this.hasClass(obj,cname)) obj.className=obj.className.replace(new RegExp('(\\s|^)'+cname+'(\\s|$)'),' ');
	},
	bind: function(func, scope){
		return function() {
			return func.apply(scope, arguments);
		}
	}
}

//fade box plugin
jQuery.fn.fadeBox = function(_options){
	var _options = jQuery.extend({
		startBox: '.show-box',
		btnShow:'a.link-show',
		btnClose:'a.link-close',
		duration:650
	},_options);

	return this.each(function(){
		//plugin options
		var _this = jQuery(this);
		var _startBox = jQuery(_options.startBox, _this);
		var _btnShow = jQuery(_options.btnShow, _this);
		var _btnClose = jQuery(_options.btnClose, _this);
		var _duration = _options.duration;
		_btnShow.click(function(){
			var _href = jQuery(this).attr('href').substr(jQuery(this).attr('href').indexOf('#'));
			var _box = jQuery(_href);
			if(jQuery.browser.msie && jQuery.browser.version < 9){
				_startBox.hide();
				_box.css({display: 'block'});
			}else{
				_startBox.stop().animate({opacity:0}, {duration: _duration, complete: function(){
					_box.show().css({opacity:0}).stop().animate({opacity:1}, {duration: _duration});
					jQuery(this).hide();
				}});
			}
			return false;
		});
		_btnClose.click(function(){
			var _href = jQuery(this).attr('href').substr(jQuery(this).attr('href').indexOf('#'));
			var _box = jQuery(_href);
			if(jQuery.browser.msie && jQuery.browser.version < 9){
				_box.hide();
				_startBox.show();
			}else{
				_box.stop().animate({opacity:0}, {duration: _duration, complete: function(){
					_startBox.show().css({opacity:0}).stop().animate({opacity:1}, {duration: _duration});
					jQuery(this).hide();
				}});
			}
			return false;
		});
	});
}

// scrolling gallery plugin
jQuery.fn.scrollGallery = function(_options){
	var _options = jQuery.extend({
		sliderHolder: '>div',
		slider:'>ul',
		slides: '>li',
		pagerLinks:'div.pager a',
		btnPrev:'a.link-prev',
		btnNext:'a.link-next',
		activeClass:'active',
		disabledClass:'disabled',
		generatePagination:'div.pg-holder',
		curNum:'em.scur-num',
		allNum:'em.sall-num',
		circleSlide:true,
		pauseClass:'gallery-paused',
		pauseButton:'none',
		pauseOnHover:true,
		autoRotation:false,
		stopAfterClick:false,
		switchTime:5000,
		duration:650,
		easing:'swing',
		event:'click',
		splitCount:false,
		afterInit:false,
		vertical:false,
		step:false
	},_options);

	return this.each(function(){
		// gallery options
		var _this = jQuery(this);
		var _sliderHolder = jQuery(_options.sliderHolder, _this);
		var _slider = jQuery(_options.slider, _sliderHolder);
		var _slides = jQuery(_options.slides, _slider);
		var _btnPrev = jQuery(_options.btnPrev, _this);
		var _btnNext = jQuery(_options.btnNext, _this);
		var _pagerLinks = jQuery(_options.pagerLinks, _this);
		var _generatePagination = jQuery(_options.generatePagination, _this);
		var _curNum = jQuery(_options.curNum, _this);
		var _allNum = jQuery(_options.allNum, _this);
		var _pauseButton = jQuery(_options.pauseButton, _this);
		var _pauseOnHover = _options.pauseOnHover;
		var _pauseClass = _options.pauseClass;
		var _autoRotation = _options.autoRotation;
		var _activeClass = _options.activeClass;
		var _disabledClass = _options.disabledClass;
		var _easing = _options.easing;
		var _duration = _options.duration;
		var _switchTime = _options.switchTime;
		var _controlEvent = _options.event;
		var _step = _options.step;
		var _vertical = _options.vertical;
		var _circleSlide = _options.circleSlide;
		var _stopAfterClick = _options.stopAfterClick;
		var _afterInit = _options.afterInit;
		var _splitCount = _options.splitCount;

		// gallery init
		if(!_slides.length) return;

		if(_splitCount) {
			var curStep = 0;
			var newSlide = jQuery('<slide>').addClass('split-slide');
			_slides.each(function(){
				newSlide.append(this);
				curStep++;
				if(curStep > _splitCount-1) {
					curStep = 0;
					_slider.append(newSlide);
					newSlide = jQuery('<slide>').addClass('split-slide');
				}
			});
			if(curStep) _slider.append(newSlide);
			_slides = _slider.children();
		}

		var _currentStep = 0;
		var _sumWidth = 0;
		var _sumHeight = 0;
		var _hover = false;
		var _stepWidth;
		var _stepHeight;
		var _stepCount;
		var _offset;
		var _timer;

		_slides.each(function(){
			_sumWidth+=jQuery(this).outerWidth(true);
			_sumHeight+=jQuery(this).outerHeight(true);
		});

		// calculate gallery offset
		function recalcOffsets() {
			if(_vertical) {
				if(_step) {
					_stepHeight = _slides.eq(_currentStep).outerHeight(true);
					_stepCount = Math.ceil((_sumHeight-_sliderHolder.height())/_stepHeight)+1;
					_offset = -_stepHeight*_currentStep;
				} else {
					_stepHeight = _sliderHolder.height();
					_stepCount = Math.ceil(_sumHeight/_stepHeight);
					_offset = -_stepHeight*_currentStep;
					if(_offset < _stepHeight-_sumHeight) _offset = _stepHeight-_sumHeight;
				}
			} else {
				if(_step) {
					_stepWidth = _slides.eq(_currentStep).outerWidth(true)*_step;
					_stepCount = Math.ceil((_sumWidth-_sliderHolder.width())/_stepWidth)+1;
					_offset = -_stepWidth*_currentStep;
					if(_offset < _sliderHolder.width()-_sumWidth) _offset = _sliderHolder.width()-_sumWidth;
				} else {
					_stepWidth = _sliderHolder.width();
					_stepCount = Math.ceil(_sumWidth/_stepWidth);
					_offset = -_stepWidth*_currentStep;
					if(_offset < _stepWidth-_sumWidth) _offset = _stepWidth-_sumWidth;
					if(_sumWidth < _stepWidth) _offset = 0;
				}
			}
		}

		// gallery control
		if(_btnPrev.length) {
			_btnPrev.bind(_controlEvent,function(){
				if(_stopAfterClick) stopAutoSlide();
				prevSlide();
				return false;
			});
		}
		if(_btnNext.length) {
			_btnNext.bind(_controlEvent,function(){
				if(_stopAfterClick) stopAutoSlide();
				nextSlide();
				return false;
			});
		}
		
		_slides.bind('nextSlide', nextSlide);
		_slides.bind('prevSlide', prevSlide);
		
		if(_generatePagination.length) {
			_generatePagination.empty();
			recalcOffsets();
			var _list = jQuery('<ul />');
			for(var i=0; i<_stepCount; i++) jQuery('<li><a href="#">'+(i+1)+'</a></li>').appendTo(_list);
			_list.appendTo(_generatePagination);
			_pagerLinks = _list.children();
		}
		if(_pagerLinks.length) {
			_pagerLinks.each(function(_ind){
				jQuery(this).bind(_controlEvent,function(){
					if(_currentStep != _ind) {
						if(_stopAfterClick) stopAutoSlide();
						_currentStep = _ind;
						switchSlide();
					}
					return false;
				});
			});
		}

		// gallery animation
		function prevSlide() {
			recalcOffsets();
			if(_currentStep > 0) _currentStep--;
			else if(_circleSlide) _currentStep = _stepCount-1;
			switchSlide();
		}
		function nextSlide() {
			recalcOffsets();
			if(_currentStep < _stepCount-1) _currentStep++;
			else if(_circleSlide) _currentStep = 0;
			switchSlide();
		}
		function refreshStatus() {
			if(_pagerLinks.length) _pagerLinks.removeClass(_activeClass).eq(_currentStep).addClass(_activeClass);
			if(!_circleSlide) {
				_btnPrev.removeClass(_disabledClass);
				_btnNext.removeClass(_disabledClass);
				if(_currentStep == 0) _btnPrev.addClass(_disabledClass);
				if(_currentStep == _stepCount-1) _btnNext.addClass(_disabledClass);
			}
			if(_curNum.length) _curNum.text(_currentStep+1);
			if(_allNum.length) _allNum.text(_stepCount);
		}
		function switchSlide() {
			recalcOffsets();
			if(_vertical) _slider.animate({marginTop:_offset},{duration:_duration,queue:false,easing:_easing});
			else _slider.animate({marginLeft:_offset},{duration:_duration,queue:false,easing:_easing});
			refreshStatus();
			autoSlide();
		}

		// autoslide function
		function stopAutoSlide() {
			if(_timer) clearTimeout(_timer);
			_autoRotation = false;
		}
		function autoSlide() {
			if(!_autoRotation || _hover) return;
			if(_timer) clearTimeout(_timer);
			_timer = setTimeout(nextSlide,_switchTime+_duration);
		}
		if(_pauseOnHover) {
			_this.hover(function(){
				_hover = true;
				if(_timer) clearTimeout(_timer);
			},function(){
				_hover = false;
				autoSlide();
			});
		}
		recalcOffsets();
		refreshStatus();
		autoSlide();

		// pause buttton
		if(_pauseButton.length) {
			_pauseButton.click(function(){
				if(_this.hasClass(_pauseClass)) {
					_this.removeClass(_pauseClass);
					_autoRotation = true;
					autoSlide();
				} else {
					_this.addClass(_pauseClass);
					stopAutoSlide();
				}
				return false;
			});
		}

		if(_afterInit && typeof _afterInit === 'function') _afterInit(_this, _slides);
	});
}

// slideshow plugin
jQuery.fn.fadeGallery = function(_options){
	var _options = jQuery.extend({
		slideElements:'div.slideset > div',
		pagerLinks:'div.pager a',
		btnNext:'a.next',
		btnPrev:'a.prev',
		btnPlayPause:'a.play-pause',
		btnPlay:'a.play',
		btnPause:'a.pause',
		pausedClass:'paused',
		disabledClass: 'disabled',
		playClass:'playing',
		activeClass:'active',
		loadingClass:'ajax-loading',
		loadedClass:'slide-loaded',
		dynamicImageLoad:false,
		dynamicImageLoadAttr:'alt',
		currentNum:false,
		allNum:false,
		startSlide:null,
		noCircle:false,
		pauseOnHover:true,
		autoRotation:false,
		autoHeight:false,
		onBeforeFade:false,
		onAfterFade:false,
		onChange:false,
		disableWhileAnimating:false,
		switchTime:3000,
		duration:650,
		event:'click'
	},_options);

	return this.each(function(){
		// gallery options
		if(this.slideshowInit) return; else this.slideshowInit;
		var _this = jQuery(this);
		var _slides = jQuery(_options.slideElements, _this);
		if(this.tagName.toLowerCase() === 'blockquote'){
			_slides = _this.children();
		}
		var _pagerLinks = jQuery(_options.pagerLinks, _this);
		var _btnPrev = jQuery(_options.btnPrev, _this);
		var _btnNext = jQuery(_options.btnNext, _this);
		var _btnPlayPause = jQuery(_options.btnPlayPause, _this);
		var _btnPause = jQuery(_options.btnPause, _this);
		var _btnPlay = jQuery(_options.btnPlay, _this);
		var _pauseOnHover = _options.pauseOnHover;
		var _dynamicImageLoad = _options.dynamicImageLoad;
		var _dynamicImageLoadAttr = _options.dynamicImageLoadAttr;
		var _autoRotation = _options.autoRotation;
		var _activeClass = _options.activeClass;
		var _loadingClass = _options.loadingClass;
		var _loadedClass = _options.loadedClass;
		var _disabledClass = _options.disabledClass;
		var _pausedClass = _options.pausedClass;
		var _playClass = _options.playClass;
		var _autoHeight = _options.autoHeight;
		var _duration = _options.duration;
		var _switchTime = _options.switchTime;
		var _controlEvent = _options.event;
		var _currentNum = (_options.currentNum ? jQuery(_options.currentNum, _this) : false);
		var _allNum = (_options.allNum ? jQuery(_options.allNum, _this) : false);
		var _startSlide = _options.startSlide;
		var _noCycle = _options.noCircle;
		var _onChange = _options.onChange;
		var _onBeforeFade = _options.onBeforeFade;
		var _onAfterFade = _options.onAfterFade;
		var _disableWhileAnimating = _options.disableWhileAnimating;
		// gallery init
		var _anim = false;
		var _hover = false;
		var _prevIndex = 0;
		var _currentIndex = 0;
		var _slideCount = _slides.length;
		var _timer;
		
		if(_slideCount < 2) return;
		_prevIndex = _slides.index(_slides.filter('.'+_activeClass));
		if(_prevIndex < 0) _prevIndex = _currentIndex = 0;
		else _currentIndex = _prevIndex;
		if(_startSlide != null) {
			if(_startSlide == 'random') _prevIndex = _currentIndex = Math.floor(Math.random()*_slideCount);
			else _prevIndex = _currentIndex = parseInt(_startSlide);
		}
		_slides.hide().eq(_currentIndex).show();
		if(_autoRotation) _this.removeClass(_pausedClass).addClass(_playClass);
		else _this.removeClass(_playClass).addClass(_pausedClass);

		// gallery control
		if(_btnPrev.length) {
			_btnPrev.bind(_controlEvent,function(){
				prevSlide();
				return false;
			});
		}
		if(_btnNext.length) {
			_btnNext.bind(_controlEvent,function(){
				nextSlide();
				return false;
			});
		}
		if(_pagerLinks.length) {
			_pagerLinks.each(function(_ind){
				jQuery(this).bind(_controlEvent,function(){
					if(_currentIndex != _ind) {
						if(_disableWhileAnimating && _anim) return;
						_prevIndex = _currentIndex;
						_currentIndex = _ind;
						switchSlide();
					}
					return false;
				});
			});
		}
		
		_slides.bind('nextslide', nextSlide);
		_slides.bind('prevslide', prevSlide);

		// play pause section
		if(_btnPlayPause.length) {
			_btnPlayPause.bind(_controlEvent,function(){
				if(_this.hasClass(_pausedClass)) {
					_this.removeClass(_pausedClass).addClass(_playClass);
					_autoRotation = true;
					autoSlide();
				} else {
					_autoRotation = false;
					if(_timer) clearTimeout(_timer);
					_this.removeClass(_playClass).addClass(_pausedClass);
				}
				return false;
			});
		}
		if(_btnPlay.length) {
			_btnPlay.bind(_controlEvent,function(){
				_this.removeClass(_pausedClass).addClass(_playClass);
				_autoRotation = true;
				autoSlide();
				return false;
			});
		}
		if(_btnPause.length) {
			_btnPause.bind(_controlEvent,function(){
				_autoRotation = false;
				if(_timer) clearTimeout(_timer);
				_this.removeClass(_playClass).addClass(_pausedClass);
				return false;
			});
		}

		// dynamic image loading (swap from ATTRIBUTE)
		function loadSlide(slide) {
			if(!slide.hasClass(_loadingClass) && !slide.hasClass(_loadedClass)) {
				var images = slide.find(_dynamicImageLoad) // pass selector here
				var imagesCount = images.length;
				if(imagesCount) {
					slide.addClass(_loadingClass);
					images.each(function(){
						var img = this;
						img.onload = function(){
							img.loaded = true;
							img.onload = null;
							setTimeout(reCalc,_duration);
						}
						img.setAttribute('src', img.getAttribute(_dynamicImageLoadAttr));
						img.setAttribute(_dynamicImageLoadAttr,'');
					}).css({opacity:0});

					function reCalc() {
						var cnt = 0;
						images.each(function(){
							if(this.loaded) cnt++;
						});
						if(cnt == imagesCount) {
							slide.removeClass(_loadingClass);
							images.animate({opacity:1},{duration:_duration,complete:function(){
								if(jQuery.browser.msie && jQuery.browser.version < 9) jQuery(this).css({opacity:'auto'})
							}});
							slide.addClass(_loadedClass)
						}
					}
				}
			}
		}

		// gallery animation
		function prevSlide() {
			if(_disableWhileAnimating && _anim) return;
			_prevIndex = _currentIndex;
			if(_currentIndex > 0) _currentIndex--;
			else {
				if(_noCycle) return;
				else _currentIndex = _slideCount-1;
			}
			switchSlide();
		}
		function nextSlide() {
			if(_disableWhileAnimating && _anim) return;
			_prevIndex = _currentIndex;
			if(_currentIndex < _slideCount-1) _currentIndex++;
			else {
				if(_noCycle) return;
				else _currentIndex = 0;
			}
			switchSlide();
		}
		function refreshStatus() {
			if(_dynamicImageLoad) loadSlide(_slides.eq(_currentIndex));
			if(_pagerLinks.length) _pagerLinks.parent().removeClass(_activeClass).eq(_currentIndex).addClass(_activeClass);
			if(_currentNum) _currentNum.text(_currentIndex+1);
			if(_allNum) _allNum.text(_slideCount);
			_slides.eq(_prevIndex).removeClass(_activeClass);
			_slides.eq(_currentIndex).addClass(_activeClass);
			if(_noCycle) {
				if(_btnPrev.length) {
					if(_currentIndex == 0) _btnPrev.addClass(_disabledClass);
					else _btnPrev.removeClass(_disabledClass);
				}
				if(_btnNext.length) {
					if(_currentIndex == _slideCount-1) _btnNext.addClass(_disabledClass);
					else _btnNext.removeClass(_disabledClass);
				}
			}
			if(typeof _onChange === 'function') {
				_onChange(_this, _slides, _prevIndex, _currentIndex);
			}
		}
		function switchSlide() {
			_anim = true;
			if(typeof _onBeforeFade === 'function') _onBeforeFade(_this, _slides, _prevIndex, _currentIndex);
			if(jQuery.browser.msie && jQuery.browser.version < 9){
				_slides.eq(_prevIndex).hide();
				_slides.eq(_currentIndex).show();
			}else{
				_slides.eq(_prevIndex).stop().animate({opacity:0}, {queue:false, duration:_duration, complete: function(){
					jQuery(this).css({opacity:1, display: 'none'})
					_anim = false;
				}});
				_slides.eq(_currentIndex).css({opacity:0, display: 'block'}).stop().animate({opacity:1}, {queue:false, duration:_duration, complete: function(){
					if(typeof _onAfterFade === 'function') _onAfterFade(_this, _slides, _prevIndex, _currentIndex);
				}});
			}
			if(_autoHeight) _slides.eq(_currentIndex).parent().animate({height:_slides.eq(_currentIndex).outerHeight(true)},{duration:_duration,queue:false});
			refreshStatus();
			autoSlide();
		}

		// autoslide function
		function autoSlide() {
			if(!_autoRotation || _hover) return;
			if(_timer) clearTimeout(_timer);
			_timer = setTimeout(nextSlide,_switchTime+_duration);
		}
		
		if(_pauseOnHover) {
			_this.hover(function(){
				_hover = true;
				if(_timer) clearTimeout(_timer);
			},function(){
				_hover = false;
				autoSlide();
			});
		}
		refreshStatus();
		autoSlide();
	});
}

// image map module
function ImageMap(opt) {
	this.options = {
		delay: 50,
		image: null,
		hoverClass:'activestate'
	}
	for(var p in opt) {
		if(opt.hasOwnProperty(p)) {
			this.options[p] = opt[p];
		}
	}
	this.init();
}
ImageMap.prototype = {
	init: function() {
		if(typeof this.options.image === 'object') {
			this.getElements();
			this.addHandlers();
		}
	},
	getElements: function() {
		this.mapId = this.options.image.getAttribute('usemap');
		this.mapId = this.mapId.substring(1);
		this.map = document.getElementById(this.mapId);
		if(this.map) {
			this.areas = this.map.getElementsByTagName('area');
		}
	},
	addHandlers: function() {
		if(this.areas) {
			for(var i = 0; i < this.areas.length; i++) {
				(function(inst){
					var timer;
					var area = inst.areas[i];
					var node = document.getElementById(inst.areas[i].alt);
					if(node) {
						area.onmouseover = function() {
							clearTimeout(timer);
							timer = setTimeout(function(){
								inst.addClass(node, inst.options.hoverClass);
							},inst.options.delay)
						}
						area.onmouseout = function() {
							clearTimeout(timer);
							timer = setTimeout(function(){
								inst.removeClass(node, inst.options.hoverClass);
							},inst.options.delay)
						}
						node.onmouseover = function() {
							clearTimeout(timer);
						}
						node.onmouseout = function() {
							clearTimeout(timer);
							timer = setTimeout(function(){
								inst.removeClass(node, inst.options.hoverClass);
							},inst.options.delay)
						}
					}
				})(this);
			}
		}
	},
	hasClass: function(el,cls) {
		return el.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
	},
	addClass: function(el,cls) {
		if (!this.hasClass(el,cls)) el.className += " "+cls;
	},
	removeClass: function(el,cls) {
		if (this.hasClass(el,cls)) {el.className=el.className.replace(new RegExp('(\\s|^)'+cls+'(\\s|$)'),' ');}
	}
}

//clear form fields module
function clearFormFields(o){
	if (o.clearInputs == null) o.clearInputs = true;
	if (o.clearTextareas == null) o.clearTextareas = true;
	if (o.passwordFieldText == null) o.passwordFieldText = false;
	if (o.addClassFocus == null) o.addClassFocus = false;
	if (!o.filter) o.filter = "default";
	if(o.clearInputs) {
		var inputs = document.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++ ) {
			if((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass)) {
				inputs[i].valueHtml = inputs[i].value;
				inputs[i].onfocus = function ()	{
					if(this.valueHtml == this.value) this.value = "";
					if(this.fake) {
						inputsSwap(this, this.previousSibling);
						this.previousSibling.focus();
					}
					if(o.addClassFocus && !this.fake) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				inputs[i].onblur = function () {
					if(this.value == "") {
						this.value = this.valueHtml;
						if(o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
					}
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
				if(o.passwordFieldText && inputs[i].type == "password") {
					var fakeInput = document.createElement("input");
					fakeInput.type = "text";
					fakeInput.value = inputs[i].value;
					fakeInput.className = inputs[i].className;
					fakeInput.fake = true;
					inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
					inputsSwap(inputs[i], null);
				}
			}
		}
	}
	if(o.clearTextareas) {
		var textareas = document.getElementsByTagName("textarea");
		for(var i=0; i<textareas.length; i++) {
			if(textareas[i].className.indexOf(o.filterClass)) {
				textareas[i].valueHtml = textareas[i].value;
				textareas[i].onfocus = function() {
					if(this.value == this.valueHtml) this.value = "";
					if(o.addClassFocus) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				textareas[i].onblur = function() {
					if(this.value == "") this.value = this.valueHtml;
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
			}
		}
	}
	function inputsSwap(el, el2) {
		if(el) el.style.display = "none";
		if(el2) el2.style.display = "inline";
	}
}

// tabs init
function initTabs2(){
	var activeClass = 'active';
	var animating, speed = 600;
	var ie = jQuery.browser.msie && jQuery.browser.version < 9;
	jQuery('ul.product-list').each(function(){
		var nav = jQuery(this);
		var links = nav.find('a.tabs');
		links.each(function(){
			var link = jQuery(this);
			var tab = jQuery(link.attr('href')).css({position: 'absolute', top: 0, left: 0});
			if(ie){
				if(link.hasClass(activeClass)) tab.show();
				else tab.hide();
			}else{
				if(link.hasClass(activeClass)) tab.css({opacity: 1});
				else tab.css({opacity: 0});
			}
			link.mousemove(function(){
				if(!animating){
					if(!link.hasClass(activeClass)){
						animating = true;
						links.filter('.' + activeClass).each(function(){
							if(ie){
								jQuery(jQuery(this).removeClass(activeClass).attr('href')).hide();
							}else{
								jQuery(jQuery(this).removeClass(activeClass).attr('href')).stop().animate({opacity: 0}, {duration: speed});
							}
							
						});
						link.addClass(activeClass);
						if(ie){
							tab.show();
							var posL = link.offset().left - nav.offset().left;
							var elW = link.outerWidth();
							jQuery('.product-list .backLava').stop().animate({left: posL, width: elW}, 400);
							animating = false;
						}else{
							tab.stop().animate({opacity: 1}, {duration: speed, complete: function(){
								animating = false;
								var posL = link.offset().left - nav.offset().left;
								var elW = link.outerWidth();
								jQuery('.product-list .backLava').stop().animate({left: posL, width: elW}, 400);
							}});
						}
					}
				}
			});
		});
	});
}

//classTabs module
var classTabs = {
	hasClass: function(obj,cname) {
		return (obj.className ? obj.className.match(new RegExp('(\\s|^)'+cname+'(\\s|$)')) : false);
	},
	addClass: function (obj,cname) {
		if (!this.hasClass(obj,cname)) {obj.className += " "+cname;this.accurateRecordClass(obj)}
	},
	removeClass: function(obj,cname) {
		if (this.hasClass(obj,cname)) {obj.className=obj.className.replace(new RegExp('(\\s|^)'+cname+'(\\s|$)'),' ');this.accurateRecordClass(obj)}
	},
	accurateRecordClass: function (obj) {
		if (obj.className) obj.className = obj.className.replace(/(\s+)/g, ' ').replace(/(^ | $)/g, '');
	},
	applyCss: function (obj, css){
		for(var key in css) {
			obj.style[key] = css[key];
		}
	},
	applyEvent: function(v,settings) {
		var c = document.getElementById(v.hr);
		if (c) {
			for (var i = 0; i < v.tab.length; i++) {
				this.applyCss(document.getElementById(v.tab[i].hr),settings.cssHide);
				this.removeClass(v.tab[i],settings.activeClass);
				if (settings.addParentClass) {
					this.removeClass(v.tab[i].parent,settings.parentActiveClass);
				}
			}
			this.addClass(v,settings.activeClass);
			if (settings.addParentClass) {
				this.addClass(v.parent,settings.parentActiveClass);
			}
			this.applyCss(c,settings.cssShow);
			return false;
		}
	},
	init: function (o) {
		var settings = {
			addParentClass: false,
			addFirstLast: false,
			addHoverClass: false,
			eventClick: false,
			clickDisabled:true,
			cssShow:{position: 'static',left: 0},
			cssHide:{position: 'absolute',left: '-9999px',top: '-9999px'},
			activeClass: 'active',
			parentActiveClass: 'parentactive',
			firstClass: 'first',
			lastClass: 'last',
			hoverClass: 'hover',
			tagTabMenu: 'ul',
			classTabMenu: 'product-list',
			tagBtnTabMenu: 'a',
			classBtnTabMenu: 'tabs'
		};
		if (typeof(o) == 'object') {
			for(var key in o) if (typeof(settings[key]) == typeof(o[key])) settings[key] = o[key];
		}
		this.sets = document.getElementsByTagName(settings.tagTabMenu);
		for (var i = 0; i < this.sets.length; i++) {
			if (this.hasClass(this.sets[i],settings.classTabMenu)) {
				var tab = [];
				var btn = this.sets[i].getElementsByTagName(settings.tagBtnTabMenu);
				if (btn.length>1 && settings.addFirstLast){
					this.addClass(btn[0].parentNode, settings.firstClass);
					this.addClass(btn[0], settings.firstClass);
					this.addClass(btn[btn.length -1].parentNode, settings.lastClass);
					this.addClass(btn[btn.length -1], settings.lastClass);
				}
				for (var j = 0; j < btn.length; j++) {
					if (settings.addHoverClass){
						btn[j].parentNode.onmouseover = function() {classTabs.addClass(this,settings.hoverClass)}
						btn[j].parentNode.onmouseout = function() {classTabs.removeClass(this,settings.hoverClass)}
					}
					if (this.hasClass(btn[j],settings.classBtnTabMenu)) {
						var _hr = btn[j].href;
						if(_hr.indexOf('#') != -1) {
							_hr = _hr.substr(_hr.indexOf("#") + 1);
							if (_hr.length >0) {
								btn[j].hr = _hr;
								btn[j].parent = btn[j].parentNode;
								tab.push(btn[j]);
								btn[j].tab = tab;
								var c = document.getElementById(_hr);
								if (c) {
									if (this.hasClass(btn[j],settings.activeClass)) {
										this.applyCss(c,settings.cssShow);
										if (settings.addParentClass && !this.hasClass(btn[j].parent,settings.parentActiveClass)) {
											this.addClass(btn[j].parent,settings.parentActiveClass);
										}
									} else {
										this.applyCss(c,settings.cssHide);
									}
								}
								if (settings.eventClick) {
									btn[j].onclick = function () {
										classTabs.applyEvent(this,settings);
										return false;
									}
								} else {
									btn[j].onmouseover = function() {
										classTabs.applyEvent(this,settings);
									}
									if (settings.clickDisabled) {
										btn[j].onclick = function () {return false;}
									}
								}
							}
						}
					}
				}
			}
		}
	}
};

//custom forms
var _selectHeight = 34;

var inputs = new Array();
var selects = new Array();
var labels = new Array();
var radios = new Array();
var radioLabels = new Array();
var checkboxes = new Array();
var checkboxLabels = new Array();
var buttons = new Array();
var selects = new Array();
var all_selects = false;
var active_select = null;
var selectText = "please select";

function is_mac(){
	if (navigator.appVersion.indexOf("Safari") != -1){
		if(!window.getComputedStyle){
			return true;
		}
	}
	
	return false;
}

function initCastomForms(){
	if(!document.getElementById) {return false;}
	getOrigElements();
	separateElements();
	replaceCheckboxes();
	replaceSelects();

	var _selects = document.getElementsByTagName('select');
	var _SelctClassName = [];
	if (_selects){
		for (var i = 0; i < _selects.length; i++){
			if (_selects[i].className != '' && _selects[i].className != 'outtaHere')
				_SelctClassName[i] = ' drop-'+_selects[i].className;
		}
		for (var i = 0; i < _SelctClassName.length; i++){
			var _selectDrop = document.getElementById('optionsDiv'+i);
			if (_selectDrop) {
				if (_SelctClassName[i]) 
					_selectDrop.className += _SelctClassName[i];
			}
		}
	}
}
// getting all the required elements
function getOrigElements(){
	var mass = [];
	for(var _ind = 0,len = inputs.length;_ind < len;_ind++){
		mass[_ind] = inputs[_ind];
	}
	inputs = mass;
	var _frms = document.getElementsByTagName("form");
	for (var nf = 0; nf < _frms.length; nf++){
		if(_frms[nf].className.indexOf("default") == -1){
			var a = document.forms[nf].getElementsByTagName("input");
			for(var nfi = 0; nfi < a.length; nfi++){
				
				inputs.push(a[nfi]);
			}
			var b = document.forms[nf].getElementsByTagName("label");
			for(var nfl = 0; nfl < b.length; nfl++){
				labels.push(b[nfl]);
			}
			var c = document.forms[nf].getElementsByTagName("select");
			for(var nfs = 0; nfs < c.length; nfs++){
				selects.push(c[nfs]);
			}
		}
	}
}

// separating all the elements in their respective arrays
function separateElements(){
	var r = 0; var c = 0; var t = 0; var rl = 0; var cl = 0; var tl = 0; var b = 0;
	for (var q = 0; q < inputs.length; q++){
		if(inputs[q].type == "radio"){
			radios[r] = inputs[q]; ++r;
			for(var w = 0; w < labels.length; w++){
				if((inputs[q].id) && labels[w].htmlFor == inputs[q].id){
					radioLabels[rl] = labels[w];
				}
			}
			++rl;
		}
		if(inputs[q].type == "checkbox" && !jQuery(inputs[q]).hasClass('separate-completed')){
			checkboxes[c] = inputs[q];jQuery(checkboxes[c]).addClass('separate-completed'); ++c;
			for(var w = 0; w < labels.length; w++){
				if((inputs[q].id) && (labels[w].htmlFor == inputs[q].id)){
					checkboxLabels[cl] = labels[w];
				}
			}
			++cl;
		}
		if((inputs[q].type == "submit") || (inputs[q].type == "button")){
			buttons[b] = inputs[q]; ++b;
		}
	}
}
//replacing checkboxes
function replaceCheckboxes(){
	for (var q = 0; q < checkboxes.length; q++){
		checkboxes[q].className += " outtaHere";
		var checkboxArea = document.createElement("div");
		if(checkboxes[q].checked){
			checkboxArea.className = "checkboxAreaChecked";
			if(checkboxLabels[q])
				checkboxLabels[q].className += "checkboxAreaCheckedLabel"
		}else{
			checkboxArea.className = "checkboxArea";
		}
		checkboxArea.id = "myCheckbox" + q;
		checkboxes[q].parentNode.insertBefore(checkboxArea, checkboxes[q]);
		checkboxes[q]._ca = checkboxArea;
		checkboxArea.onclick = checkboxArea.onclick2 = new Function('rechangeCheckboxes('+q+')');
		if (checkboxLabels[q]){
			checkboxLabels[q].onclick = new Function('changeCheckboxes('+q+')');
		}
		
		checkboxes[q].onkeydown = checkEvent;
	}
	return true;
}

//checking checkboxes
function checkCheckboxes(who, action){
	var what = checkboxes[who]._ca;
	if(action == true){
		what.className = "checkboxAreaChecked";
		what.checked = true;
		if(checkboxLabels[who])
			checkboxLabels[who].className += " checkboxAreaCheckedLabel";
	}
	if(action == false){
		what.className = "checkboxArea";
		what.checked = false;
		if(checkboxLabels[who])
			checkboxLabels[who].className = checkboxLabels[who].className.replace("checkboxAreaCheckedLabel", "");
	}
}

//changing checkboxes
function changeCheckboxes(who){
	if(checkboxes[who].checked){
		checkCheckboxes(who, false);
	}else{
		checkCheckboxes(who, true);
	} 
}

//rechanging checkboxes
function rechangeCheckboxes(who){
	var tester = false;
	if(checkboxes[who].checked == true){
		tester = false;
	}else{
		tester = true;
	}
	checkboxes[who].checked = tester;
	checkCheckboxes(who, tester);
}

//check event
function checkEvent(e){
	if(!e) var e = window.event;
	if(e.keyCode == 32) {for (var q = 0; q < checkboxes.length; q++) {if(this == checkboxes[q]) {changeCheckboxes(q);}}} //check if space is pressed
}

function replaceSelects(){
	for(var q = 0; q < selects.length; q++){
		if (!selects[q].replaced && selects[q].offsetWidth && selects[q].className.indexOf("default") == -1){
			selects[q]._number = q;
			//create and build div structure
			var selectArea = document.createElement("div");
			var left = document.createElement("span");
			left.className = "left";
			selectArea.appendChild(left);
			
			var disabled = document.createElement("span");
			disabled.className = "disabled";
			selectArea.appendChild(disabled);
			
			selects[q]._disabled = disabled;
			var center = document.createElement("span");
			var button = document.createElement("a");
			var text = document.createTextNode(selectText);
			center.id = "mySelectText"+q;
			
			var stWidth = selects[q].offsetWidth;
			selectArea.style.width = stWidth + "px";
			if (selects[q].parentNode.className.indexOf("type2") != -1){
				button.href = "javascript:showOptions("+q+",true)";
			}else{
				button.href = "javascript:showOptions("+q+",false)";
			}
			button.className = "selectButton";
			selectArea.className = "selectArea";
			selectArea.className += " " + selects[q].className;
			selectArea.id = "sarea"+q;
			center.className = "center";
			center.appendChild(text);
			selectArea.appendChild(center);
			selectArea.appendChild(button);
			
			//hide the select field
			selects[q].className += " outtaHere";
			//insert select div
			selects[q].parentNode.insertBefore(selectArea, selects[q]);
			//build & place options div

			var optionsDiv = document.createElement("div");
			var optionsListParent = document.createElement("div");
			optionsListParent.className = "select-center";
			var optionsListParent2 = document.createElement("div");
			optionsListParent2.className = "select-center-right";
			var optionsList = document.createElement("ul");
			optionsDiv.innerHTML += "<div class='select-top'><div class='select-top-left'></div><div class='select-top-right'></div></div>";
			optionsListParent.appendChild(optionsListParent2);
			optionsListParent.appendChild(optionsList);
			optionsDiv.appendChild(optionsListParent);
			
			selects[q]._options = optionsList;
			
			optionsDiv.style.width = stWidth + "px";
			optionsDiv._parent = selectArea;
			
			optionsDiv.className = "optionsDivInvisible";
			optionsDiv.id = "optionsDiv"+q;
			
		
			populateSelectOptions(selects[q]);
			optionsDiv.innerHTML += "<div class='select-bottom'><div class='select-bottom-left'></div><div class='select-bottom-right'></div></div>";
			document.getElementsByTagName("body")[0].appendChild(optionsDiv);
			selects[q].replaced = true;
		}
		all_selects = true;
	}
}

//collecting select options
function populateSelectOptions(me){
	me._options.innerHTML = "";
	for(var w = 0; w < me.options.length; w++){
		if(me.options[w].title.indexOf("title") == -1){
			var optionHolder = document.createElement('li');
			var optionLink = document.createElement('a');
			var optionTxt;
			if (me.options[w].title.indexOf('image') != -1){
				optionTxt = document.createElement('img');
				optionSpan = document.createElement('span');
				optionTxt.src = me.options[w].title;
				optionSpan = document.createTextNode(me.options[w].text);
			}else{
				optionTxt = document.createTextNode(me.options[w].text);
			}
			
			optionLink.href = "javascript:showOptions("+me._number+"); selectMe('"+me.id+"',"+w+","+me._number+");";
			if(me.options[w].title.indexOf('image') != -1){
				optionLink.appendChild(optionTxt);
				optionLink.appendChild(optionSpan);
			}else{
				optionLink.appendChild(optionTxt);
			}
			optionHolder.appendChild(optionLink);
			me._options.appendChild(optionHolder);
			//check for pre-selected items
			if(me.options[w].selected){
				selectMe(me.id,w,me._number,true);
			}
		}
		else if(me.options[w].selected)
			selectMe(me.id,w,me._number,true);
	}
	if (me.disabled){
		me._disabled.style.display = "block";
	}else{
		me._disabled.style.display = "none";
	}
}

//selecting me
function selectMe(selectFieldId,linkNo,selectNo,quiet){
	selectField = selects[selectNo];
	for(var k = 0; k < selectField.options.length; k++){
		if(k==linkNo){
			selectField.options[k].selected = true;
		}else{
			selectField.options[k].selected = false;
		}
	}
	
	//show selected option
	textVar = document.getElementById("mySelectText"+selectNo);
	var newText;
	var optionSpan;
	if (selectField.options[linkNo].title.indexOf('image') != -1){
		newText = document.createElement('img');
		newText.src = selectField.options[linkNo].title;
		optionSpan = document.createElement('span');
		optionSpan = document.createTextNode(selectField.options[linkNo].text);
	}else{
		newText = document.createTextNode(selectField.options[linkNo].text);
	}
	if (selectField.options[linkNo].title.indexOf('image') != -1){
		if (textVar.childNodes.length > 1) textVar.removeChild(textVar.childNodes[0]);
		textVar.replaceChild(newText, textVar.childNodes[0]);	
		textVar.appendChild(optionSpan);	
	}else{
		if (textVar.childNodes.length > 1) textVar.removeChild(textVar.childNodes[0]);
		textVar.replaceChild(newText, textVar.childNodes[0]);	
	}
	if (!quiet && all_selects){
		if(typeof selectField.onchange === 'function') {
			selectField.onchange();
		}
		if(window.jQuery && window.jQuery.fn) {
			jQuery(selectField).trigger('change');
		}
	}
}
//showing options
function showOptions(g){
		_elem = document.getElementById("optionsDiv"+g);
		var divArea = document.getElementById("sarea"+g);
		if (active_select && active_select != _elem){
			active_select.className = active_select.className.replace('optionsDivVisible','optionsDivInvisible');
			active_select.style.height = "auto";
			_active.className = _active.className.replace('selectAreaActive','');
		}
		if(_elem.className.indexOf("optionsDivInvisible") != -1) {
			_elem.style.left = "-9999px";
			_elem.style.top = findPosY(divArea) + _selectHeight + 'px';
			_elem.className = _elem.className.replace('optionsDivInvisible','');
			_elem.className += " optionsDivVisible";
			/*if (_elem.offsetHeight > 200)
			{
				_elem.style.height = "200px";
			}*/
			_elem.style.left = findPosX(divArea) + 'px';
			divArea.className += ' selectAreaActive';
			_active = divArea;
			
			active_select = _elem;
			if(document.documentElement){
				document.documentElement.onclick = hideSelectOptions;
			}else{
				window.onclick = hideSelectOptions;
			}
		}
		else if(_elem.className.indexOf("optionsDivVisible") != -1){
			_elem.style.height = "auto";
			_elem.className = _elem.className.replace('optionsDivVisible','');
			_elem.className += " optionsDivInvisible";
			divArea.className = divArea.className.replace('selectAreaActive','');
		}
		
		// for mouseout
		/*_elem.timer = false;
		_elem.onmouseover = function() {
			if (this.timer) clearTimeout(this.timer);
		}
		_elem.onmouseout = function() {
			var _this = this;
			this.timer = setTimeout(function(){
				_this.style.height = "auto";
				_this.className = _this.className.replace('optionsDivVisible','');
				if (_elem.className.indexOf('optionsDivInvisible') == -1)
					_this.className += " optionsDivInvisible";
			},200);
		}*/
}
_active = false;
function hideSelectOptions(e){
	if(active_select){
		if(!e) e = window.event;
		var _target = (e.target || e.srcElement);
		if(isElementBefore(_target,'selectArea') == 0 && isElementBefore(_target,'optionsDiv') == 0){
			active_select.className = active_select.className.replace('optionsDivVisible', '');
			active_select.className = active_select.className.replace('optionsDivInvisible', '');
			active_select.className += " optionsDivInvisible";
			_active.className = _active.className.replace('selectAreaActive','');
			active_select = false;

			if(document.documentElement){
				document.documentElement.onclick = function(){};
			}else{
				window.onclick = null;
			}
		}
	}
}

function isElementBefore(_el,_class){
	var _parent = _el;	
	do{
		_parent = _parent.parentNode;
	}
	while(_parent && _parent.className != null && _parent.className.indexOf(_class) == -1)
	
	if(_parent.className && _parent.className.indexOf(_class) != -1){
		return 1;
	}else{
		return 0;
	}
	
}

function findPosY(obj){
	return jQuery(obj).offset().top;
}
function findPosX(obj){
	return jQuery(obj).offset().left;
}

/**
 * jquery.LavaLamp v1.3.5 - light up your menus with fluid, jQuery powered animations.
 * Requires jQuery v1.2.3 or better from http://jquery.com
 * Tested on jQuery 1.4.4, 1.3.2 and 1.2.6
 * http://nixbox.com/projects/jquery-lavalamp/
 * Source code Copyright (c) 2008, 2009, 2010 Jolyon Terwilliger, jolyon@nixbox.com
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
;(function(d){jQuery.fn.lavaLamp=function(a){function e(g){g=parseInt(g);return isNaN(g)?0:g}a=d.extend({target:"li",container:"",fx:"swing",speed:500,click:function(){return true},startItem:"",includeMargins:false,autoReturn:true,returnDelay:0,setOnClick:true,homeTop:0,homeLeft:0,homeWidth:0,homeHeight:0,returnHome:false,autoResize:false},a||{});if(a.container=="")a.container=a.target;a.autoResize&&d(window).resize(function(){d(a.target+".selectedLava").trigger("mouseenter")});return this.each(function(){function g(c){c||
(c=b);if(!a.includeMargins){i=e(c.css("marginLeft"));j=e(c.css("marginTop"))}c={left:c.position().left+i,top:c.position().top+j,width:c.outerWidth()-l,height:c.outerHeight()-m};f.stop().animate(c,a.speed,a.fx)}d(this).css("position")=="static"&&d(this).css("position","relative");if(a.homeTop||a.homeLeft){var n=d("<"+a.container+' class="homeLava"></'+a.container+">").css({left:a.homeLeft,top:a.homeTop,width:a.homeWidth,height:a.homeHeight,position:"absolute",display:"block"});d(this).prepend(n)}var s=
location.pathname+location.search+location.hash,b,f,k=d(a.target+"[class!=noLava]",this),h,l=0,m=0,p=0,q=0,i=0,j=0;b=d(a.target+".selectedLava",this);if(a.startItem!="")b=k.eq(a.startItem);if((a.homeTop||a.homeLeft)&&b.length<1)b=n;if(b.length<1){var o=0,r;k.each(function(){var c=d("a:first",this).attr("href");if(s.indexOf(c)>-1&&c.length>o){r=d(this);o=c.length}});if(o>0)b=r}if(b.length<1)b=k.eq(0);b=d(b.eq(0).addClass("selectedLava"));k.bind("mouseenter",function(){if(h){clearTimeout(h);h=null}g(d(this))}).click(function(c){if(a.setOnClick){b.removeClass("selectedLava");
b=d(this).addClass("selectedLava")}return a.click.apply(this,[c,this])});f=d("<"+a.container+' class="backLava"><div class="leftLava"></div><div class="bottomLava"></div><div class="cornerLava"></div></'+a.container+">").css({position:"absolute",display:"block",margin:0,padding:0}).prependTo(this);if(a.includeMargins){p=e(b.css("marginTop"))+e(b.css("marginBottom"));q=e(b.css("marginLeft"))+e(b.css("marginRight"))}l=e(f.css("borderLeftWidth"))+e(f.css("borderRightWidth"))+e(f.css("paddingLeft"))+
e(f.css("paddingRight"))-q;m=e(f.css("borderTopWidth"))+e(f.css("borderBottomWidth"))+e(f.css("paddingTop"))+e(f.css("paddingBottom"))-p;if(a.homeTop||a.homeLeft)f.css({left:a.homeLeft,top:a.homeTop,width:a.homeWidth,height:a.homeHeight});else{if(!a.includeMargins){i=e(b.css("marginLeft"));j=e(b.css("marginTop"))}f.css({left:b.position().left+i,top:b.position().top+j,width:b.outerWidth()-l,height:b.outerHeight()-m})}d(this).bind("mouseleave",function(){var c=null;if(a.returnHome)c=n;else if(!a.autoReturn)return true;
if(a.returnDelay){h&&clearTimeout(h);h=setTimeout(function(){g(c)},a.returnDelay)}else g(c);return true})})}})(jQuery);

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

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

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.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 - jQuery.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 jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */
 
 /*
 * FancyBox - jQuery Plugin
 * Simple and fancy lightbox alternative
 *
 * Examples and documentation at: http://fancybox.net
 * 
 * Copyright (c) 2008 - 2010 Janis Skarnelis
 * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
 * 
 * Version: 1.3.4 (11/11/2010)
 * Requires: jQuery v1.3+
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

;(function(b){var m,t,u,f,D,j,E,n,z,A,q=0,e={},o=[],p=0,d={},l=[],G=null,v=new Image,J=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,W=/[^\.]\.(swf)\s*$/i,K,L=1,y=0,s="",r,i,h=false,B=b.extend(b("<div/>")[0],{prop:0}),M=b.browser.msie&&b.browser.version<7&&!window.XMLHttpRequest,N=function(){t.hide();v.onerror=v.onload=null;G&&G.abort();m.empty()},O=function(){if(false===e.onError(o,q,e)){t.hide();h=false}else{e.titleShow=false;e.width="auto";e.height="auto";m.html('<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>');
F()}},I=function(){var a=o[q],c,g,k,C,P,w;N();e=b.extend({},b.fn.fancybox.defaults,typeof b(a).data("fancybox")=="undefined"?e:b(a).data("fancybox"));w=e.onStart(o,q,e);if(w===false)h=false;else{if(typeof w=="object")e=b.extend(e,w);k=e.title||(a.nodeName?b(a).attr("title"):a.title)||"";if(a.nodeName&&!e.orig)e.orig=b(a).children("img:first").length?b(a).children("img:first"):b(a);if(k===""&&e.orig&&e.titleFromAlt)k=e.orig.attr("alt");c=e.href||(a.nodeName?b(a).attr("href"):a.href)||null;if(/^(?:javascript)/i.test(c)||
c=="#")c=null;if(e.type){g=e.type;if(!c)c=e.content}else if(e.content)g="html";else if(c)g=c.match(J)?"image":c.match(W)?"swf":b(a).hasClass("iframe")?"iframe":c.indexOf("#")===0?"inline":"ajax";if(g){if(g=="inline"){a=c.substr(c.indexOf("#"));g=b(a).length>0?"inline":"ajax"}e.type=g;e.href=c;e.title=k;if(e.autoDimensions)if(e.type=="html"||e.type=="inline"||e.type=="ajax"){e.width="auto";e.height="auto"}else e.autoDimensions=false;if(e.modal){e.overlayShow=true;e.hideOnOverlayClick=false;e.hideOnContentClick=
false;e.enableEscapeButton=false;e.showCloseButton=false}e.padding=parseInt(e.padding,10);e.margin=parseInt(e.margin,10);m.css("padding",e.padding+e.margin);b(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change",function(){b(this).replaceWith(j.children())});switch(g){case "html":m.html(e.content);F();break;case "inline":if(b(a).parent().is("#fancybox-content")===true){h=false;break}b('<div class="fancybox-inline-tmp" />').hide().insertBefore(b(a)).bind("fancybox-cleanup",function(){b(this).replaceWith(j.children())}).bind("fancybox-cancel",
function(){b(this).replaceWith(m.children())});b(a).appendTo(m);F();break;case "image":h=false;b.fancybox.showActivity();v=new Image;v.onerror=function(){O()};v.onload=function(){h=true;v.onerror=v.onload=null;e.width=v.width;e.height=v.height;b("<img />").attr({id:"fancybox-img",src:v.src,alt:e.title}).appendTo(m);Q()};v.src=c;break;case "swf":e.scrolling="no";C='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+e.width+'" height="'+e.height+'"><param name="movie" value="'+c+
'"></param>';P="";b.each(e.swf,function(x,H){C+='<param name="'+x+'" value="'+H+'"></param>';P+=" "+x+'="'+H+'"'});C+='<embed src="'+c+'" type="application/x-shockwave-flash" width="'+e.width+'" height="'+e.height+'"'+P+"></embed></object>";m.html(C);F();break;case "ajax":h=false;b.fancybox.showActivity();e.ajax.win=e.ajax.success;G=b.ajax(b.extend({},e.ajax,{url:c,data:e.ajax.data||{},error:function(x){x.status>0&&O()},success:function(x,H,R){if((typeof R=="object"?R:G).status==200){if(typeof e.ajax.win==
"function"){w=e.ajax.win(c,x,H,R);if(w===false){t.hide();return}else if(typeof w=="string"||typeof w=="object")x=w}m.html(x);F()}}}));break;case "iframe":Q()}}else O()}},F=function(){var a=e.width,c=e.height;a=a.toString().indexOf("%")>-1?parseInt((b(window).width()-e.margin*2)*parseFloat(a)/100,10)+"px":a=="auto"?"auto":a+"px";c=c.toString().indexOf("%")>-1?parseInt((b(window).height()-e.margin*2)*parseFloat(c)/100,10)+"px":c=="auto"?"auto":c+"px";m.wrapInner('<div style="width:'+a+";height:"+c+
";overflow: "+(e.scrolling=="auto"?"auto":e.scrolling=="yes"?"scroll":"hidden")+';position:relative;"></div>');e.width=m.width();e.height=m.height();Q()},Q=function(){var a,c;t.hide();if(f.is(":visible")&&false===d.onCleanup(l,p,d)){b.event.trigger("fancybox-cancel");h=false}else{h=true;b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");f.is(":visible")&&d.titlePosition!=="outside"&&f.css("height",f.height());l=o;p=q;d=e;if(d.overlayShow){u.css({"background-color":d.overlayColor,
opacity:d.overlayOpacity,cursor:d.hideOnOverlayClick?"pointer":"auto",height:b(document).height()});if(!u.is(":visible")){M&&b("select:not(#fancybox-tmp select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"});u.show()}}else u.hide();i=X();s=d.title||"";y=0;n.empty().removeAttr("style").removeClass();if(d.titleShow!==false){if(b.isFunction(d.titleFormat))a=d.titleFormat(s,l,p,d);else a=s&&s.length?
d.titlePosition=="float"?'<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">'+s+'</td><td id="fancybox-title-float-right"></td></tr></table>':'<div id="fancybox-title-'+d.titlePosition+'">'+s+"</div>":false;s=a;if(!(!s||s==="")){n.addClass("fancybox-title-"+d.titlePosition).html(s).appendTo("body").show();switch(d.titlePosition){case "inside":n.css({width:i.width-d.padding*2,marginLeft:d.padding,marginRight:d.padding});
y=n.outerHeight(true);n.appendTo(D);i.height+=y;break;case "over":n.css({marginLeft:d.padding,width:i.width-d.padding*2,bottom:d.padding}).appendTo(D);break;case "float":n.css("left",parseInt((n.width()-i.width-40)/2,10)*-1).appendTo(f);break;default:n.css({width:i.width-d.padding*2,paddingLeft:d.padding,paddingRight:d.padding}).appendTo(f)}}}n.hide();if(f.is(":visible")){b(E.add(z).add(A)).hide();a=f.position();r={top:a.top,left:a.left,width:f.width(),height:f.height()};c=r.width==i.width&&r.height==
i.height;j.fadeTo(d.changeFade,0.3,function(){var g=function(){j.html(m.contents()).fadeTo(d.changeFade,1,S)};b.event.trigger("fancybox-change");j.empty().removeAttr("filter").css({"border-width":d.padding,width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2});if(c)g();else{B.prop=0;b(B).animate({prop:1},{duration:d.changeSpeed,easing:d.easingChange,step:T,complete:g})}})}else{f.removeAttr("style");j.css("border-width",d.padding);if(d.transitionIn=="elastic"){r=V();j.html(m.contents());
f.show();if(d.opacity)i.opacity=0;B.prop=0;b(B).animate({prop:1},{duration:d.speedIn,easing:d.easingIn,step:T,complete:S})}else{d.titlePosition=="inside"&&y>0&&n.show();j.css({width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2}).html(m.contents());f.css(i).fadeIn(d.transitionIn=="none"?0:d.speedIn,S)}}}},Y=function(){if(d.enableEscapeButton||d.enableKeyboardNav)b(document).bind("keydown.fb",function(a){if(a.keyCode==27&&d.enableEscapeButton){a.preventDefault();b.fancybox.close()}else if((a.keyCode==
37||a.keyCode==39)&&d.enableKeyboardNav&&a.target.tagName!=="INPUT"&&a.target.tagName!=="TEXTAREA"&&a.target.tagName!=="SELECT"){a.preventDefault();b.fancybox[a.keyCode==37?"prev":"next"]()}});if(d.showNavArrows){if(d.cyclic&&l.length>1||p!==0)z.show();if(d.cyclic&&l.length>1||p!=l.length-1)A.show()}else{z.hide();A.hide()}},S=function(){if(!b.support.opacity){j.get(0).style.removeAttribute("filter");f.get(0).style.removeAttribute("filter")}e.autoDimensions&&j.css("height","auto");f.css("height","auto");
s&&s.length&&n.show();d.showCloseButton&&E.show();Y();d.hideOnContentClick&&j.bind("click",b.fancybox.close);d.hideOnOverlayClick&&u.bind("click",b.fancybox.close);b(window).bind("resize.fb",b.fancybox.resize);d.centerOnScroll&&b(window).bind("scroll.fb",b.fancybox.center);if(d.type=="iframe")b('<iframe id="fancybox-frame" name="fancybox-frame'+(new Date).getTime()+'" frameborder="0" hspace="0" '+(b.browser.msie?'allowtransparency="true""':"")+' scrolling="'+e.scrolling+'" src="'+d.href+'"></iframe>').appendTo(j);
f.show();h=false;b.fancybox.center();d.onComplete(l,p,d);var a,c;if(l.length-1>p){a=l[p+1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}if(p>0){a=l[p-1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}},T=function(a){var c={width:parseInt(r.width+(i.width-r.width)*a,10),height:parseInt(r.height+(i.height-r.height)*a,10),top:parseInt(r.top+(i.top-r.top)*a,10),left:parseInt(r.left+(i.left-r.left)*a,10)};if(typeof i.opacity!=="undefined")c.opacity=a<0.5?0.5:a;f.css(c);
j.css({width:c.width-d.padding*2,height:c.height-y*a-d.padding*2})},U=function(){return[b(window).width()-d.margin*2,b(window).height()-d.margin*2,b(document).scrollLeft()+d.margin,b(document).scrollTop()+d.margin]},X=function(){var a=U(),c={},g=d.autoScale,k=d.padding*2;c.width=d.width.toString().indexOf("%")>-1?parseInt(a[0]*parseFloat(d.width)/100,10):d.width+k;c.height=d.height.toString().indexOf("%")>-1?parseInt(a[1]*parseFloat(d.height)/100,10):d.height+k;if(g&&(c.width>a[0]||c.height>a[1]))if(e.type==
"image"||e.type=="swf"){g=d.width/d.height;if(c.width>a[0]){c.width=a[0];c.height=parseInt((c.width-k)/g+k,10)}if(c.height>a[1]){c.height=a[1];c.width=parseInt((c.height-k)*g+k,10)}}else{c.width=Math.min(c.width,a[0]);c.height=Math.min(c.height,a[1])}c.top=parseInt(Math.max(a[3]-20,a[3]+(a[1]-c.height-40)*0.5),10);c.left=parseInt(Math.max(a[2]-20,a[2]+(a[0]-c.width-40)*0.5),10);return c},V=function(){var a=e.orig?b(e.orig):false,c={};if(a&&a.length){c=a.offset();c.top+=parseInt(a.css("paddingTop"),
10)||0;c.left+=parseInt(a.css("paddingLeft"),10)||0;c.top+=parseInt(a.css("border-top-width"),10)||0;c.left+=parseInt(a.css("border-left-width"),10)||0;c.width=a.width();c.height=a.height();c={width:c.width+d.padding*2,height:c.height+d.padding*2,top:c.top-d.padding-20,left:c.left-d.padding-20}}else{a=U();c={width:d.padding*2,height:d.padding*2,top:parseInt(a[3]+a[1]*0.5,10),left:parseInt(a[2]+a[0]*0.5,10)}}return c},Z=function(){if(t.is(":visible")){b("div",t).css("top",L*-40+"px");L=(L+1)%12}else clearInterval(K)};
b.fn.fancybox=function(a){if(!b(this).length)return this;b(this).data("fancybox",b.extend({},a,b.metadata?b(this).metadata():{})).unbind("click.fb").bind("click.fb",function(c){c.preventDefault();if(!h){h=true;b(this).blur();o=[];q=0;c=b(this).attr("rel")||"";if(!c||c==""||c==="nofollow")o.push(this);else{o=b("a[rel="+c+"], area[rel="+c+"]");q=o.index(this)}I()}});return this};b.fancybox=function(a,c){var g;if(!h){h=true;g=typeof c!=="undefined"?c:{};o=[];q=parseInt(g.index,10)||0;if(b.isArray(a)){for(var k=
0,C=a.length;k<C;k++)if(typeof a[k]=="object")b(a[k]).data("fancybox",b.extend({},g,a[k]));else a[k]=b({}).data("fancybox",b.extend({content:a[k]},g));o=jQuery.merge(o,a)}else{if(typeof a=="object")b(a).data("fancybox",b.extend({},g,a));else a=b({}).data("fancybox",b.extend({content:a},g));o.push(a)}if(q>o.length||q<0)q=0;I()}};b.fancybox.showActivity=function(){clearInterval(K);t.show();K=setInterval(Z,66)};b.fancybox.hideActivity=function(){t.hide()};b.fancybox.next=function(){return b.fancybox.pos(p+
1)};b.fancybox.prev=function(){return b.fancybox.pos(p-1)};b.fancybox.pos=function(a){if(!h){a=parseInt(a);o=l;if(a>-1&&a<l.length){q=a;I()}else if(d.cyclic&&l.length>1){q=a>=l.length?0:l.length-1;I()}}};b.fancybox.cancel=function(){if(!h){h=true;b.event.trigger("fancybox-cancel");N();e.onCancel(o,q,e);h=false}};b.fancybox.close=function(){function a(){u.fadeOut("fast");n.empty().hide();f.hide();b.event.trigger("fancybox-cleanup");j.empty();d.onClosed(l,p,d);l=e=[];p=q=0;d=e={};h=false}if(!(h||f.is(":hidden"))){h=
true;if(d&&false===d.onCleanup(l,p,d))h=false;else{N();b(E.add(z).add(A)).hide();b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");j.find("iframe").attr("src",M&&/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank");d.titlePosition!=="inside"&&n.empty();f.stop();if(d.transitionOut=="elastic"){r=V();var c=f.position();i={top:c.top,left:c.left,width:f.width(),height:f.height()};if(d.opacity)i.opacity=1;n.empty().hide();B.prop=1;
b(B).animate({prop:0},{duration:d.speedOut,easing:d.easingOut,step:T,complete:a})}else f.fadeOut(d.transitionOut=="none"?0:d.speedOut,a)}}};b.fancybox.resize=function(){u.is(":visible")&&u.css("height",b(document).height());b.fancybox.center(true)};b.fancybox.center=function(a){var c,g;if(!h){g=a===true?1:0;c=U();!g&&(f.width()>c[0]||f.height()>c[1])||f.stop().animate({top:parseInt(Math.max(c[3]-20,c[3]+(c[1]-j.height()-40)*0.5-d.padding)),left:parseInt(Math.max(c[2]-20,c[2]+(c[0]-j.width()-40)*0.5-
d.padding))},typeof a=="number"?a:200)}};b.fancybox.init=function(){if(!b("#fancybox-wrap").length){b("body").append(m=b('<div id="fancybox-tmp"></div>'),t=b('<div id="fancybox-loading"><div></div></div>'),u=b('<div id="fancybox-overlay"></div>'),f=b('<div id="fancybox-wrap"></div>'));D=b('<div id="fancybox-outer"></div>').append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>').appendTo(f);
D.append(j=b('<div id="fancybox-content"></div>'),E=b('<a id="fancybox-close"></a>'),n=b('<div id="fancybox-title"></div>'),z=b('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),A=b('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));E.click(b.fancybox.close);t.click(b.fancybox.cancel);z.click(function(a){a.preventDefault();b.fancybox.prev()});A.click(function(a){a.preventDefault();b.fancybox.next()});
b.fn.mousewheel&&f.bind("mousewheel.fb",function(a,c){if(h)a.preventDefault();else if(b(a.target).get(0).clientHeight==0||b(a.target).get(0).scrollHeight===b(a.target).get(0).clientHeight){a.preventDefault();b.fancybox[c>0?"prev":"next"]()}});b.support.opacity||f.addClass("fancybox-ie");if(M){t.addClass("fancybox-ie6");f.addClass("fancybox-ie6");b('<iframe id="fancybox-hide-sel-frame" src="'+(/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank")+'" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(D)}}};
b.fn.fancybox.defaults={padding:10,margin:40,opacity:false,modal:false,cyclic:false,scrolling:"auto",width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.7,overlayColor:"#777",titleShow:true,titlePosition:"float",titleFormat:null,titleFromAlt:false,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",
easingOut:"swing",showCloseButton:true,showNavArrows:true,enableEscapeButton:true,enableKeyboardNav:true,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}};b(document).ready(function(){b.fancybox.init()})})(jQuery);

/*
 * touchSwipe - jQuery Plugin
 * http://plugins.jquery.com/project/touchSwipe
 * http://labs.skinkers.com/touchSwipe/
 *
 * Copyright (c) 2010 Matt Bryson (www.skinkers.com)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 *
 * $version: 1.2.3
 *
 * Changelog
 * $Date: 2010-12-12 (Wed, 12 Dec 2010) $
 * $version: 1.0.0 
 * $version: 1.0.1 - removed multibyte comments
 *
 * $Date: 2011-21-02 (Mon, 21 Feb 2011) $
 * $version: 1.1.0 	- added allowPageScroll property to allow swiping and scrolling of page
 *					- changed handler signatures so one handler can be used for multiple events
 * $Date: 2011-23-02 (Wed, 23 Feb 2011) $
 * $version: 1.2.0 	- added click handler. This is fired if the user simply clicks and does not swipe. The event object and click target are passed to handler.
 *					- If you use the http://code.google.com/p/jquery-ui-for-ipad-and-iphone/ plugin, you can also assign jQuery mouse events to children of a touchSwipe object.
 * $version: 1.2.1 	- removed console log!
 *
 * $version: 1.2.2 	- Fixed bug where scope was not preserved in callback methods. 
 *
 * $Date: 2011-28-04 (Thurs, 28 April 2011) $
 * $version: 1.2.4 	- Changed licence terms to be MIT or GPL inline with jQuery. Added check for support of touch events to stop non compatible browsers erroring.
 *
 * A jQuery plugin to capture left, right, up and down swipes on touch devices.
 * You can capture 2 finger or 1 finger swipes, set the threshold and define either a catch all handler, or individual direction handlers.
 * Options:
 * 		swipe 		Function 	A catch all handler that is triggered for all swipe directions. Handler is passed 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
 * 		swipeLeft	Function 	A handler that is triggered for "left" swipes. Handler is passed 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
 * 		swipeRight	Function 	A handler that is triggered for "right" swipes. Handler is passed 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
 * 		swipeUp		Function 	A handler that is triggered for "up" swipes. Handler is passed 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
 * 		swipeDown	Function 	A handler that is triggered for "down" swipes. Handler is passed 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
 *		swipeStatus Function 	A handler triggered for every phase of the swipe. Handler is passed 4 arguments: event : The original event object, phase:The current swipe face, either "start?, "move?, "end? or "cancel?. direction : The swipe direction, either "up?, "down?, "left " or "right?.distance : The distance of the swipe.
 *		click		Function	A handler triggered when a user just clicks on the item, rather than swipes it. If they do not move, click is triggered, if they do move, it is not.
 *
 * 		fingers 	int 		Default 1. 	The number of fingers to trigger the swipe, 1 or 2.
 * 		threshold 	int  		Default 75.	The number of pixels that the user must move their finger by before it is considered a swipe.
 *		triggerOnTouchEnd Boolean Default true If true, the swipe events are triggered when the touch end event is received (user releases finger).  If false, it will be triggered on reaching the threshold, and then cancel the touch event automatically.
 *		allowPageScroll String Default "auto". How the browser handles page scrolls when the user is swiping on a touchSwipe object. 
 *										"auto" : all undefined swipes will cause the page to scroll in that direction.
 *										"none" : the page will not scroll when user swipes.
 *										"horizontal" : will force page to scroll on horizontal swipes.
 *										"vertical" : will force page to scroll on vertical swipes.
 *
 * This jQuery plugin will only run on devices running Mobile Webkit based browsers (iOS 2.0+, android 2.2+)
 */
;(function($){
	$.fn.swipe = function(options){
		if (!this) return false;
		
		// Default thresholds & swipe functions
		var defaults = {
					
			fingers 		: 1,								// int - The number of fingers to trigger the swipe, 1 or 2. Default is 1.
			threshold 		: 75,								// int - The number of pixels that the user must move their finger by before it is considered a swipe. Default is 75.
			
			swipe 			: null,		// Function - A catch all handler that is triggered for all swipe directions. Accepts 2 arguments, the original event object and the direction of the swipe : "left", "right", "up", "down".
			swipeLeft		: null,		// Function - A handler that is triggered for "left" swipes. Accepts 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
			swipeRight		: null,		// Function - A handler that is triggered for "right" swipes. Accepts 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
			swipeUp			: null,		// Function - A handler that is triggered for "up" swipes. Accepts 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
			swipeDown		: null,		// Function - A handler that is triggered for "down" swipes. Accepts 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
			swipeStatus		: null,		// Function - A handler triggered for every phase of the swipe. Handler is passed 4 arguments: event : The original event object, phase:The current swipe face, either "start?, "move?, "end? or "cancel?. direction : The swipe direction, either "up?, "down?, "left " or "right?.distance : The distance of the swipe.
			click			: null,		// Function	- A handler triggered when a user just clicks on the item, rather than swipes it. If they do not move, click is triggered, if they do move, it is not.
			
			triggerOnTouchEnd : true,	// Boolean, if true, the swipe events are triggered when the touch end event is received (user releases finger).  If false, it will be triggered on reaching the threshold, and then cancel the touch event automatically.
			allowPageScroll : "auto" 	/* How the browser handles page scrolls when the user is swiping on a touchSwipe object. 
											"auto" : all undefined swipes will cause the page to scroll in that direction.
 											"none" : the page will not scroll when user swipes.
 											"horizontal" : will force page to scroll on horizontal swipes.
 											"vertical" : will force page to scroll on vertical swipes.
										*/
		};
		
		//Constants
		var LEFT = "left";
		var RIGHT = "right";
		var UP = "up";
		var DOWN = "down";
		var NONE = "none";
		var HORIZONTAL = "horizontal";
		var VERTICAL = "vertical";
		var AUTO = "auto";
		
		var PHASE_START="start";
		var PHASE_MOVE="move";
		var PHASE_END="end";
		var PHASE_CANCEL="cancel";
		
		var phase="start";
		
		if (options.allowPageScroll==undefined && (options.swipe!=undefined || options.swipeStatus!=undefined))
			options.allowPageScroll=NONE;
		
		if (options)
			$.extend(defaults, options);
		
		/**
		 * Setup each object to detect swipe gestures
		 */
		return this.each(function(){
			var $this = $(this);
			
			var triggerElementID = null; 	// this variable is used to identity the triggering element
			var fingerCount = 0;			// the current number of fingers being used.	
			
			//track mouse points / delta
			var start={x:0, y:0};
			var end={x:0, y:0};
			var delta={x:0, y:0};
			
			
			/**
			* Event handler for a touch start event. 
			* Stops the default click event from triggering and stores where we touched
			*/
			function touchStart(event){
				phase = PHASE_START;
		
				// get the total number of fingers touching the screen
				fingerCount = event.touches.length;
				
				//clear vars..
				distance=0;
				direction=null;
				
				// check the number of fingers is what we are looking for
				if ( fingerCount == defaults.fingers ) {
					// get the coordinates of the touch
					start.x = end.x = event.touches[0].pageX;
					start.y = end.y = event.touches[0].pageY;
					
					if (defaults.swipeStatus)
						triggerHandler(event, phase);
				}else {
					//touch with more/less than the fingers we are looking for
					touchCancel(event);
				}
			}

			/**
			* Event handler for a touch move event. 
			* If we change fingers during move, then cancel the event
			*/
			function touchMove(event) {
				if (phase == PHASE_END || phase == PHASE_CANCEL)
					return;
				
				end.x = event.touches[0].pageX;
				end.y = event.touches[0].pageY;
					
				direction = caluculateDirection();
				fingerCount = event.touches.length;
				
				phase = PHASE_MOVE
				
				//Check if we need to prevent default evnet (page scroll) or not
				validateDefaultEvent(event, direction);
		
				if ( fingerCount == defaults.fingers ){
					distance = caluculateDistance();
					
					if (defaults.swipeStatus)
						triggerHandler(event, phase, direction, distance);
					
					//If we trigger whilst dragging, not on touch end, then calculate now...
					if (!defaults.triggerOnTouchEnd){
						// if the user swiped more than the minimum length, perform the appropriate action
						if ( distance >= defaults.threshold ) {
							phase = PHASE_END;
							triggerHandler(event, phase);
							touchCancel(event); // reset the variables
						}
					}
				} else {
					phase = PHASE_CANCEL;
					triggerHandler(event, phase); 
					touchCancel(event);
				}
			}
			
			/**
			* Event handler for a touch end event. 
			* Calculate the direction and trigger events
			*/
			function touchEnd(event) {
				event.preventDefault();
				
				distance = caluculateDistance();
				direction = caluculateDirection();
						
				if (defaults.triggerOnTouchEnd){
					phase = PHASE_END;
					// check to see if more than one finger was used and that there is an ending coordinate
					if ( fingerCount == defaults.fingers && end.x != 0 ) {
						// if the user swiped more than the minimum length, perform the appropriate action
						if ( distance >= defaults.threshold ) {
							triggerHandler(event, phase);
							touchCancel(event); // reset the variables
						} else {
							phase = PHASE_CANCEL;
							triggerHandler(event, phase); 
							touchCancel(event);
						}	
					} else {
						phase = PHASE_CANCEL;
						triggerHandler(event, phase); 
						touchCancel(event);
					}
				}
				else if (phase == PHASE_MOVE){
					phase = PHASE_CANCEL;
					triggerHandler(event, phase); 
					touchCancel(event);
				}
			}
			
			/**
			* Event handler for a touch cancel event. 
			* Clears current vars
			*/
			function touchCancel(event) {
				// reset the variables back to default values
				fingerCount = 0;
				
				start.x = 0;
				start.y = 0;
				end.x = 0;
				end.y = 0;
				delta.x = 0;
				delta.y = 0;
			}
			
			
			/**
			* Trigger the relevant event handler
			* The handlers are passed the original event, the element that was swiped, and in the case of the catch all handler, the direction that was swiped, "left", "right", "up", or "down"
			*/
			function triggerHandler(event, phase) {
				//update status
				if (defaults.swipeStatus)
					defaults.swipeStatus.call($this,event, phase, direction || null, distance || 0);
				
				
				if (phase == PHASE_CANCEL){
					if (defaults.click && fingerCount==1 && (isNaN(distance) || distance==0))
						defaults.click.call($this,event, event.target);
				}
				
				if (phase == PHASE_END){
					//trigger catch all event handler
					if (defaults.swipe){
						defaults.swipe.call($this,event, direction, distance);
					}
					//trigger direction specific event handlers	
					switch(direction){
						case LEFT :
							if (defaults.swipeLeft)
								defaults.swipeLeft.call($this,event, direction, distance);
							break;
						
						case RIGHT :
							if (defaults.swipeRight)
								defaults.swipeRight.call($this,event, direction, distance);
							break;

						case UP :
							if (defaults.swipeUp)
								defaults.swipeUp.call($this,event, direction, distance);
							break;
						
						case DOWN :	
							if (defaults.swipeDown)
								defaults.swipeDown.call($this,event, direction, distance);
							break;
					}
				}
			}
			
			
			/**
			 * Checks direction of the swipe and the value allowPageScroll to see if we should allow or prevent the default behaviour from occurring.
			 * This will essentially allow page scrolling or not when the user is swiping on a touchSwipe object.
			 */
			function validateDefaultEvent(event, direction){
				if( defaults.allowPageScroll==NONE ){
					event.preventDefault();
				}else {
					var auto=defaults.allowPageScroll==AUTO;
					switch(direction){
						case LEFT :
							if ( (defaults.swipeLeft && auto) || (!auto && defaults.allowPageScroll!=HORIZONTAL))
								event.preventDefault();
							break;
						
						case RIGHT :
							if ( (defaults.swipeRight && auto) || (!auto && defaults.allowPageScroll!=HORIZONTAL))
								event.preventDefault();
							break;

						case UP :
							if ( (defaults.swipeUp && auto) || (!auto && defaults.allowPageScroll!=VERTICAL))
								event.preventDefault();
							break;
						
						case DOWN :	
							if ( (defaults.swipeDown && auto) || (!auto && defaults.allowPageScroll!=VERTICAL))
								event.preventDefault();
							break;
					}
				}
			}
			/**
			* Calcualte the length / distance of the swipe
			*/
			function caluculateDistance(){
				return Math.round(Math.sqrt(Math.pow(end.x - start.x,2) + Math.pow(end.y - start.y,2)));
			}
			
			/**
			* Calcualte the angle of the swipe
			*/
			function caluculateAngle() {
				var X = start.x-end.x;
				var Y = end.y-start.y;
				var r = Math.atan2(Y,X); //radians
				var angle = Math.round(r*180/Math.PI); //degrees
				
				//ensure value is positive
				if (angle < 0) 
					angle = 360 - Math.abs(angle);
					
				return angle;
			}
			
			/**
			* Calcualte the direction of the swipe
			* This will also call caluculateAngle to get the latest angle of swipe
			*/
			function caluculateDirection() {
				var angle = caluculateAngle();
				
				if ( (angle <= 45) && (angle >= 0) ) 
					return LEFT;
				
				else if ( (angle <= 360) && (angle >= 315) )
					return LEFT;
				
				else if ( (angle >= 135) && (angle <= 225) )
					return RIGHT;
				
				else if ( (angle > 45) && (angle < 135) )
					return DOWN;
				
				else
					return UP;
			}
			
			// Add gestures to all swipable areas if supported
			try	{
				this.addEventListener("touchstart", touchStart, false);
				this.addEventListener("touchmove", touchMove, false);
				this.addEventListener("touchend", touchEnd, false);
				this.addEventListener("touchcancel", touchCancel, false);
			}catch(e){
				//touch not supported
			}
				
		});
	};
})(jQuery);

/*!
 * iScroll v4.1.9 ~ Copyright (c) 2011 Matteo Spinelli, http://cubiq.org
 * Released under MIT license, http://cubiq.org/license
 */
;(function(){var p=Math,t=(/webkit/i).test(navigator.appVersion)?"webkit":(/firefox/i).test(navigator.userAgent)?"Moz":"opera" in window?"O":"",j="WebKitCSSMatrix" in window&&"m11" in new WebKitCSSMatrix(),s="ontouchstart" in window,e=t+"Transform" in document.documentElement.style,u=(/android/gi).test(navigator.appVersion),h=(/iphone|ipad/gi).test(navigator.appVersion),c=(/playbook/gi).test(navigator.appVersion),f=h||c,l=(function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(m){return setTimeout(m,1)}})(),k=(function(){return window.cancelRequestAnimationFrame||window.webkitCancelRequestAnimationFrame||window.mozCancelRequestAnimationFrame||window.oCancelRequestAnimationFrame||window.msCancelRequestAnimationFrame||clearTimeout})(),g="onorientationchange" in window?"orientationchange":"resize",b=s?"touchstart":"mousedown",n=s?"touchmove":"mousemove",d=s?"touchend":"mouseup",r=s?"touchcancel":"mouseup",o=t=="Moz"?"DOMMouseScroll":"mousewheel",a="translate"+(j?"3d(":"("),i=j?",0)":")",q=function(w,m){var x=this,y=document,v;x.wrapper=typeof w=="object"?w:y.getElementById(w);x.wrapper.style.overflow="hidden";x.scroller=x.wrapper.children[0];x.options={hScroll:true,vScroll:true,x:0,y:0,bounce:true,bounceLock:false,momentum:true,lockDirection:true,useTransform:true,useTransition:false,topOffset:0,checkDOMChanges:false,hScrollbar:true,vScrollbar:true,fixedScrollbar:u,hideScrollbar:h,fadeScrollbar:h&&j,scrollbarClass:"",zoom:false,zoomMin:1,zoomMax:4,doubleTapZoom:2,wheelAction:"scroll",snap:false,snapThreshold:1,onRefresh:null,onBeforeScrollStart:function(z){z.preventDefault()},onScrollStart:null,onBeforeScrollMove:null,onScrollMove:null,onBeforeScrollEnd:null,onScrollEnd:null,onTouchEnd:null,onDestroy:null,onZoomStart:null,onZoom:null,onZoomEnd:null};if(x.zoom&&u){a="translate(";i=")"}for(v in m){x.options[v]=m[v]}x.x=x.options.x;x.y=x.options.y;x.options.useTransform=e?x.options.useTransform:false;x.options.hScrollbar=x.options.hScroll&&x.options.hScrollbar;x.options.vScrollbar=x.options.vScroll&&x.options.vScrollbar;x.options.zoom=x.options.useTransform&&x.options.zoom;x.options.useTransition=f&&x.options.useTransition;x.scroller.style[t+"TransitionProperty"]=x.options.useTransform?"-"+t.toLowerCase()+"-transform":"top left";x.scroller.style[t+"TransitionDuration"]="0";x.scroller.style[t+"TransformOrigin"]="0 0";if(x.options.useTransition){x.scroller.style[t+"TransitionTimingFunction"]="cubic-bezier(0.33,0.66,0.66,1)"}if(x.options.useTransform){x.scroller.style[t+"Transform"]=a+x.x+"px,"+x.y+"px"+i}else{x.scroller.style.cssText+=";position:absolute;top:"+x.y+"px;left:"+x.x+"px"}if(x.options.useTransition){x.options.fixedScrollbar=true}x.refresh();x._bind(g,window);x._bind(b);if(!s){x._bind("mouseout",x.wrapper);x._bind(o)}if(x.options.checkDOMChanges){x.checkDOMTime=setInterval(function(){x._checkDOMChanges()},500)}};q.prototype={enabled:true,x:0,y:0,steps:[],scale:1,currPageX:0,currPageY:0,pagesX:[],pagesY:[],aniTime:null,wheelZoomCount:0,handleEvent:function(v){var m=this;switch(v.type){case b:if(!s&&v.button!==0){return}m._start(v);break;case n:m._move(v);break;case d:case r:m._end(v);break;case g:m._resize();break;case o:m._wheel(v);break;case"mouseout":m._mouseout(v);break;case"webkitTransitionEnd":m._transitionEnd(v);break}},_checkDOMChanges:function(){if(this.moved||this.zoomed||this.animating||(this.scrollerW==this.scroller.offsetWidth*this.scale&&this.scrollerH==this.scroller.offsetHeight*this.scale)){return}this.refresh()},_scrollbar:function(m){var w=this,x=document,v;if(!w[m+"Scrollbar"]){if(w[m+"ScrollbarWrapper"]){if(e){w[m+"ScrollbarIndicator"].style[t+"Transform"]=""}w[m+"ScrollbarWrapper"].parentNode.removeChild(w[m+"ScrollbarWrapper"]);w[m+"ScrollbarWrapper"]=null;w[m+"ScrollbarIndicator"]=null}return}if(!w[m+"ScrollbarWrapper"]){v=x.createElement("div");if(w.options.scrollbarClass){v.className=w.options.scrollbarClass+m.toUpperCase()}else{v.style.cssText="position:absolute;z-index:100;"+(m=="h"?"height:7px;bottom:1px;left:2px;right:"+(w.vScrollbar?"7":"2")+"px":"width:7px;bottom:"+(w.hScrollbar?"7":"2")+"px;top:2px;right:1px")}v.style.cssText+=";pointer-events:none;-"+t+"-transition-property:opacity;-"+t+"-transition-duration:"+(w.options.fadeScrollbar?"350ms":"0")+";overflow:hidden;opacity:"+(w.options.hideScrollbar?"0":"1");w.wrapper.appendChild(v);w[m+"ScrollbarWrapper"]=v;v=x.createElement("div");if(!w.options.scrollbarClass){v.style.cssText="position:absolute;z-index:100;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);-"+t+"-background-clip:padding-box;-"+t+"-box-sizing:border-box;"+(m=="h"?"height:100%":"width:100%")+";-"+t+"-border-radius:3px;border-radius:3px"}v.style.cssText+=";pointer-events:none;-"+t+"-transition-property:-"+t+"-transform;-"+t+"-transition-timing-function:cubic-bezier(0.33,0.66,0.66,1);-"+t+"-transition-duration:0;-"+t+"-transform:"+a+"0,0"+i;if(w.options.useTransition){v.style.cssText+=";-"+t+"-transition-timing-function:cubic-bezier(0.33,0.66,0.66,1)"}w[m+"ScrollbarWrapper"].appendChild(v);w[m+"ScrollbarIndicator"]=v}if(m=="h"){w.hScrollbarSize=w.hScrollbarWrapper.clientWidth;w.hScrollbarIndicatorSize=p.max(p.round(w.hScrollbarSize*w.hScrollbarSize/w.scrollerW),8);w.hScrollbarIndicator.style.width=w.hScrollbarIndicatorSize+"px";w.hScrollbarMaxScroll=w.hScrollbarSize-w.hScrollbarIndicatorSize;w.hScrollbarProp=w.hScrollbarMaxScroll/w.maxScrollX}else{w.vScrollbarSize=w.vScrollbarWrapper.clientHeight;w.vScrollbarIndicatorSize=p.max(p.round(w.vScrollbarSize*w.vScrollbarSize/w.scrollerH),8);w.vScrollbarIndicator.style.height=w.vScrollbarIndicatorSize+"px";w.vScrollbarMaxScroll=w.vScrollbarSize-w.vScrollbarIndicatorSize;w.vScrollbarProp=w.vScrollbarMaxScroll/w.maxScrollY}w._scrollbarPos(m,true)},_resize:function(){var m=this;setTimeout(function(){m.refresh()},u?200:0)},_pos:function(m,v){m=this.hScroll?m:0;v=this.vScroll?v:0;if(this.options.useTransform){this.scroller.style[t+"Transform"]=a+m+"px,"+v+"px"+i+" scale("+this.scale+")"}else{m=p.round(m);v=p.round(v);this.scroller.style.left=m+"px";this.scroller.style.top=v+"px"}this.x=m;this.y=v;this._scrollbarPos("h");this._scrollbarPos("v")},_scrollbarPos:function(m,x){var w=this,y=m=="h"?w.x:w.y,v;if(!w[m+"Scrollbar"]){return}y=w[m+"ScrollbarProp"]*y;if(y<0){if(!w.options.fixedScrollbar){v=w[m+"ScrollbarIndicatorSize"]+p.round(y*3);if(v<8){v=8}w[m+"ScrollbarIndicator"].style[m=="h"?"width":"height"]=v+"px"}y=0}else{if(y>w[m+"ScrollbarMaxScroll"]){if(!w.options.fixedScrollbar){v=w[m+"ScrollbarIndicatorSize"]-p.round((y-w[m+"ScrollbarMaxScroll"])*3);if(v<8){v=8}w[m+"ScrollbarIndicator"].style[m=="h"?"width":"height"]=v+"px";y=w[m+"ScrollbarMaxScroll"]+(w[m+"ScrollbarIndicatorSize"]-v)}else{y=w[m+"ScrollbarMaxScroll"]}}}w[m+"ScrollbarWrapper"].style[t+"TransitionDelay"]="0";w[m+"ScrollbarWrapper"].style.opacity=x&&w.options.hideScrollbar?"0":"1";w[m+"ScrollbarIndicator"].style[t+"Transform"]=a+(m=="h"?y+"px,0":"0,"+y+"px")+i},_start:function(C){var B=this,v=s?C.touches[0]:C,w,m,D,A,z;if(!B.enabled){return}if(B.options.onBeforeScrollStart){B.options.onBeforeScrollStart.call(B,C)}if(B.options.useTransition||B.options.zoom){B._transitionTime(0)}B.moved=false;B.animating=false;B.zoomed=false;B.distX=0;B.distY=0;B.absDistX=0;B.absDistY=0;B.dirX=0;B.dirY=0;if(B.options.zoom&&s&&C.touches.length>1){A=p.abs(C.touches[0].pageX-C.touches[1].pageX);z=p.abs(C.touches[0].pageY-C.touches[1].pageY);B.touchesDistStart=p.sqrt(A*A+z*z);B.originX=p.abs(C.touches[0].pageX+C.touches[1].pageX-B.wrapperOffsetLeft*2)/2-B.x;B.originY=p.abs(C.touches[0].pageY+C.touches[1].pageY-B.wrapperOffsetTop*2)/2-B.y;if(B.options.onZoomStart){B.options.onZoomStart.call(B,C)}}if(B.options.momentum){if(B.options.useTransform){w=getComputedStyle(B.scroller,null)[t+"Transform"].replace(/[^0-9-.,]/g,"").split(",");m=w[4]*1;D=w[5]*1}else{m=getComputedStyle(B.scroller,null).left.replace(/[^0-9-]/g,"")*1;D=getComputedStyle(B.scroller,null).top.replace(/[^0-9-]/g,"")*1}if(m!=B.x||D!=B.y){if(B.options.useTransition){B._unbind("webkitTransitionEnd")}else{k(B.aniTime)}B.steps=[];B._pos(m,D)}}B.absStartX=B.x;B.absStartY=B.y;B.startX=B.x;B.startY=B.y;B.pointX=v.pageX;B.pointY=v.pageY;B.startTime=C.timeStamp||Date.now();if(B.options.onScrollStart){B.options.onScrollStart.call(B,C)}B._bind(n);B._bind(d);B._bind(r)},_move:function(C){var A=this,D=s?C.touches[0]:C,y=D.pageX-A.pointX,w=D.pageY-A.pointY,m=A.x+y,E=A.y+w,z,x,v,B=C.timeStamp||Date.now();if(A.options.onBeforeScrollMove){A.options.onBeforeScrollMove.call(A,C)}if(A.options.zoom&&s&&C.touches.length>1){z=p.abs(C.touches[0].pageX-C.touches[1].pageX);x=p.abs(C.touches[0].pageY-C.touches[1].pageY);A.touchesDist=p.sqrt(z*z+x*x);A.zoomed=true;v=1/A.touchesDistStart*A.touchesDist*this.scale;if(v<A.options.zoomMin){v=0.5*A.options.zoomMin*Math.pow(2,v/A.options.zoomMin)}else{if(v>A.options.zoomMax){v=2*A.options.zoomMax*Math.pow(0.5,A.options.zoomMax/v)}}A.lastScale=v/this.scale;m=this.originX-this.originX*A.lastScale+this.x,E=this.originY-this.originY*A.lastScale+this.y;this.scroller.style[t+"Transform"]=a+m+"px,"+E+"px"+i+" scale("+v+")";if(A.options.onZoom){A.options.onZoom.call(A,C)}return}A.pointX=D.pageX;A.pointY=D.pageY;if(m>0||m<A.maxScrollX){m=A.options.bounce?A.x+(y/2):m>=0||A.maxScrollX>=0?0:A.maxScrollX}if(E>A.minScrollY||E<A.maxScrollY){E=A.options.bounce?A.y+(w/2):E>=A.minScrollY||A.maxScrollY>=0?A.minScrollY:A.maxScrollY}if(A.absDistX<6&&A.absDistY<6){A.distX+=y;A.distY+=w;A.absDistX=p.abs(A.distX);A.absDistY=p.abs(A.distY);return}if(A.options.lockDirection){if(A.absDistX>A.absDistY+5){E=A.y;w=0}else{if(A.absDistY>A.absDistX+5){m=A.x;y=0}}}A.moved=true;A._pos(m,E);A.dirX=y>0?-1:y<0?1:0;A.dirY=w>0?-1:w<0?1:0;if(B-A.startTime>300){A.startTime=B;A.startX=A.x;A.startY=A.y}if(A.options.onScrollMove){A.options.onScrollMove.call(A,C)}},_end:function(C){if(s&&C.touches.length!=0){return}var A=this,I=s?C.changedTouches[0]:C,D,H,w={dist:0,time:0},m={dist:0,time:0},z=(C.timeStamp||Date.now())-A.startTime,E=A.x,B=A.y,G,F,v,y,x;A._unbind(n);A._unbind(d);A._unbind(r);if(A.options.onBeforeScrollEnd){A.options.onBeforeScrollEnd.call(A,C)}if(A.zoomed){x=A.scale*A.lastScale;x=Math.max(A.options.zoomMin,x);x=Math.min(A.options.zoomMax,x);A.lastScale=x/A.scale;A.scale=x;A.x=A.originX-A.originX*A.lastScale+A.x;A.y=A.originY-A.originY*A.lastScale+A.y;A.scroller.style[t+"TransitionDuration"]="200ms";A.scroller.style[t+"Transform"]=a+A.x+"px,"+A.y+"px"+i+" scale("+A.scale+")";A.zoomed=false;A.refresh();if(A.options.onZoomEnd){A.options.onZoomEnd.call(A,C)}return}if(!A.moved){if(s){if(A.doubleTapTimer&&A.options.zoom){clearTimeout(A.doubleTapTimer);A.doubleTapTimer=null;if(A.options.onZoomStart){A.options.onZoomStart.call(A,C)}A.zoom(A.pointX,A.pointY,A.scale==1?A.options.doubleTapZoom:1);if(A.options.onZoomEnd){setTimeout(function(){A.options.onZoomEnd.call(A,C)},200)}}else{A.doubleTapTimer=setTimeout(function(){A.doubleTapTimer=null;D=I.target;while(D.nodeType!=1){D=D.parentNode}if(D.tagName!="SELECT"&&D.tagName!="INPUT"&&D.tagName!="TEXTAREA"){H=document.createEvent("MouseEvents");H.initMouseEvent("click",true,true,C.view,1,I.screenX,I.screenY,I.clientX,I.clientY,C.ctrlKey,C.altKey,C.shiftKey,C.metaKey,0,null);H._fake=true;D.dispatchEvent(H)}},A.options.zoom?250:0)}}A._resetPos(200);if(A.options.onTouchEnd){A.options.onTouchEnd.call(A,C)}return}if(z<300&&A.options.momentum){w=E?A._momentum(E-A.startX,z,-A.x,A.scrollerW-A.wrapperW+A.x,A.options.bounce?A.wrapperW:0):w;m=B?A._momentum(B-A.startY,z,-A.y,(A.maxScrollY<0?A.scrollerH-A.wrapperH+A.y-A.minScrollY:0),A.options.bounce?A.wrapperH:0):m;E=A.x+w.dist;B=A.y+m.dist;if((A.x>0&&E>0)||(A.x<A.maxScrollX&&E<A.maxScrollX)){w={dist:0,time:0}}if((A.y>A.minScrollY&&B>A.minScrollY)||(A.y<A.maxScrollY&&B<A.maxScrollY)){m={dist:0,time:0}}}if(w.dist||m.dist){v=p.max(p.max(w.time,m.time),10);if(A.options.snap){G=E-A.absStartX;F=B-A.absStartY;if(p.abs(G)<A.options.snapThreshold&&p.abs(F)<A.options.snapThreshold){A.scrollTo(A.absStartX,A.absStartY,200)}else{y=A._snap(E,B);E=y.x;B=y.y;v=p.max(y.time,v)}}A.scrollTo(p.round(E),p.round(B),v);if(A.options.onTouchEnd){A.options.onTouchEnd.call(A,C)}return}if(A.options.snap){G=E-A.absStartX;F=B-A.absStartY;if(p.abs(G)<A.options.snapThreshold&&p.abs(F)<A.options.snapThreshold){A.scrollTo(A.absStartX,A.absStartY,200)}else{y=A._snap(A.x,A.y);if(y.x!=A.x||y.y!=A.y){A.scrollTo(y.x,y.y,y.time)}}if(A.options.onTouchEnd){A.options.onTouchEnd.call(A,C)}return}A._resetPos(200);if(A.options.onTouchEnd){A.options.onTouchEnd.call(A,C)}},_resetPos:function(w){var m=this,x=m.x>=0?0:m.x<m.maxScrollX?m.maxScrollX:m.x,v=m.y>=m.minScrollY||m.maxScrollY>0?m.minScrollY:m.y<m.maxScrollY?m.maxScrollY:m.y;if(x==m.x&&v==m.y){if(m.moved){m.moved=false;if(m.options.onScrollEnd){m.options.onScrollEnd.call(m)}}if(m.hScrollbar&&m.options.hideScrollbar){if(t=="webkit"){m.hScrollbarWrapper.style[t+"TransitionDelay"]="300ms"}m.hScrollbarWrapper.style.opacity="0"}if(m.vScrollbar&&m.options.hideScrollbar){if(t=="webkit"){m.vScrollbarWrapper.style[t+"TransitionDelay"]="300ms"}m.vScrollbarWrapper.style.opacity="0"}return}m.scrollTo(x,v,w||0)},_wheel:function(z){var x=this,y,w,v,m,A;if("wheelDeltaX" in z){y=z.wheelDeltaX/12;w=z.wheelDeltaY/12}else{if("detail" in z){y=w=-z.detail*3}else{y=w=-z.wheelDelta}}if(x.options.wheelAction=="zoom"){A=x.scale*Math.pow(2,1/3*(w?w/Math.abs(w):0));if(A<x.options.zoomMin){A=x.options.zoomMin}if(A>x.options.zoomMax){A=x.options.zoomMax}if(A!=x.scale){if(!x.wheelZoomCount&&x.options.onZoomStart){x.options.onZoomStart.call(x,z)}x.wheelZoomCount++;x.zoom(z.pageX,z.pageY,A,400);setTimeout(function(){x.wheelZoomCount--;if(!x.wheelZoomCount&&x.options.onZoomEnd){x.options.onZoomEnd.call(x,z)}},400)}return}v=x.x+y;m=x.y+w;if(v>0){v=0}else{if(v<x.maxScrollX){v=x.maxScrollX}}if(m>x.minScrollY){m=x.minScrollY}else{if(m<x.maxScrollY){m=x.maxScrollY}}x.scrollTo(v,m,0)},_mouseout:function(v){var m=v.relatedTarget;if(!m){this._end(v);return}while(m=m.parentNode){if(m==this.wrapper){return}}this._end(v)},_transitionEnd:function(v){var m=this;if(v.target!=m.scroller){return}m._unbind("webkitTransitionEnd");m._startAni()},_startAni:function(){var A=this,v=A.x,m=A.y,y=Date.now(),z,x,w;if(A.animating){return}if(!A.steps.length){A._resetPos(400);return}z=A.steps.shift();if(z.x==v&&z.y==m){z.time=0}A.animating=true;A.moved=true;if(A.options.useTransition){A._transitionTime(z.time);A._pos(z.x,z.y);A.animating=false;if(z.time){A._bind("webkitTransitionEnd")}else{A._resetPos(0)}return}w=function(){var B=Date.now(),D,C;if(B>=y+z.time){A._pos(z.x,z.y);A.animating=false;if(A.options.onAnimationEnd){A.options.onAnimationEnd.call(A)}A._startAni();return}B=(B-y)/z.time-1;x=p.sqrt(1-B*B);D=(z.x-v)*x+v;C=(z.y-m)*x+m;A._pos(D,C);if(A.animating){A.aniTime=l(w)}};w()},_transitionTime:function(m){m+="ms";this.scroller.style[t+"TransitionDuration"]=m;if(this.hScrollbar){this.hScrollbarIndicator.style[t+"TransitionDuration"]=m}if(this.vScrollbar){this.vScrollbarIndicator.style[t+"TransitionDuration"]=m}},_momentum:function(B,v,z,m,D){var A=0.0006,w=p.abs(B)/v,x=(w*w)/(2*A),C=0,y=0;if(B>0&&x>z){y=D/(6/(x/w*A));z=z+y;w=w*z/x;x=z}else{if(B<0&&x>m){y=D/(6/(x/w*A));m=m+y;w=w*m/x;x=m}}x=x*(B<0?-1:1);C=w/A;return{dist:x,time:p.round(C)}},_offset:function(m){var w=-m.offsetLeft,v=-m.offsetTop;while(m=m.offsetParent){w-=m.offsetLeft;v-=m.offsetTop}if(m!=this.wrapper){w*=this.scale;v*=this.scale}return{left:w,top:v}},_snap:function(E,D){var B=this,A,z,C,w,v,m;C=B.pagesX.length-1;for(A=0,z=B.pagesX.length;A<z;A++){if(E>=B.pagesX[A]){C=A;break}}if(C==B.currPageX&&C>0&&B.dirX<0){C--}E=B.pagesX[C];v=p.abs(E-B.pagesX[B.currPageX]);v=v?p.abs(B.x-E)/v*500:0;B.currPageX=C;C=B.pagesY.length-1;for(A=0;A<C;A++){if(D>=B.pagesY[A]){C=A;break}}if(C==B.currPageY&&C>0&&B.dirY<0){C--}D=B.pagesY[C];m=p.abs(D-B.pagesY[B.currPageY]);m=m?p.abs(B.y-D)/m*500:0;B.currPageY=C;w=p.round(p.max(v,m))||200;return{x:E,y:D,time:w}},_bind:function(w,v,m){(v||this.scroller).addEventListener(w,this,!!m)},_unbind:function(w,v,m){(v||this.scroller).removeEventListener(w,this,!!m)},destroy:function(){var m=this;m.scroller.style[t+"Transform"]="";m.hScrollbar=false;m.vScrollbar=false;m._scrollbar("h");m._scrollbar("v");m._unbind(g,window);m._unbind(b);m._unbind(n);m._unbind(d);m._unbind(r);if(m.options.hasTouch){m._unbind("mouseout",m.wrapper);m._unbind(o)}if(m.options.useTransition){m._unbind("webkitTransitionEnd")}if(m.options.checkDOMChanges){clearInterval(m.checkDOMTime)}if(m.options.onDestroy){m.options.onDestroy.call(m)}},refresh:function(){var x=this,z,w,m,v,A=0,y=0;if(x.scale<x.options.zoomMin){x.scale=x.options.zoomMin}x.wrapperW=x.wrapper.clientWidth||1;x.wrapperH=x.wrapper.clientHeight||1;x.minScrollY=-x.options.topOffset||0;x.scrollerW=p.round(x.scroller.offsetWidth*x.scale);x.scrollerH=p.round((x.scroller.offsetHeight+x.minScrollY)*x.scale);x.maxScrollX=x.wrapperW-x.scrollerW;x.maxScrollY=x.wrapperH-x.scrollerH+x.minScrollY;x.dirX=0;x.dirY=0;if(x.options.onRefresh){x.options.onRefresh.call(x)}x.hScroll=x.options.hScroll&&x.maxScrollX<0;x.vScroll=x.options.vScroll&&(!x.options.bounceLock&&!x.hScroll||x.scrollerH>x.wrapperH);x.hScrollbar=x.hScroll&&x.options.hScrollbar;x.vScrollbar=x.vScroll&&x.options.vScrollbar&&x.scrollerH>x.wrapperH;z=x._offset(x.wrapper);x.wrapperOffsetLeft=-z.left;x.wrapperOffsetTop=-z.top;if(typeof x.options.snap=="string"){x.pagesX=[];x.pagesY=[];v=x.scroller.querySelectorAll(x.options.snap);for(w=0,m=v.length;w<m;w++){A=x._offset(v[w]);A.left+=x.wrapperOffsetLeft;A.top+=x.wrapperOffsetTop;x.pagesX[w]=A.left<x.maxScrollX?x.maxScrollX:A.left*x.scale;x.pagesY[w]=A.top<x.maxScrollY?x.maxScrollY:A.top*x.scale}}else{if(x.options.snap){x.pagesX=[];while(A>=x.maxScrollX){x.pagesX[y]=A;A=A-x.wrapperW;y++}if(x.maxScrollX%x.wrapperW){x.pagesX[x.pagesX.length]=x.maxScrollX-x.pagesX[x.pagesX.length-1]+x.pagesX[x.pagesX.length-1]}A=0;y=0;x.pagesY=[];while(A>=x.maxScrollY){x.pagesY[y]=A;A=A-x.wrapperH;y++}if(x.maxScrollY%x.wrapperH){x.pagesY[x.pagesY.length]=x.maxScrollY-x.pagesY[x.pagesY.length-1]+x.pagesY[x.pagesY.length-1]}}}x._scrollbar("h");x._scrollbar("v");if(!x.zoomed){x.scroller.style[t+"TransitionDuration"]="0";x._resetPos(200)}},scrollTo:function(m,D,C,B){var A=this,z=m,w,v;A.stop();if(!z.length){z=[{x:m,y:D,time:C,relative:B}]}for(w=0,v=z.length;w<v;w++){if(z[w].relative){z[w].x=A.x-z[w].x;z[w].y=A.y-z[w].y}A.steps.push({x:z[w].x,y:z[w].y,time:z[w].time||0})}A._startAni()},scrollToElement:function(m,w){var v=this,x;m=m.nodeType?m:v.scroller.querySelector(m);if(!m){return}x=v._offset(m);x.left+=v.wrapperOffsetLeft;x.top+=v.wrapperOffsetTop;x.left=x.left>0?0:x.left<v.maxScrollX?v.maxScrollX:x.left;x.top=x.top>v.minScrollY?v.minScrollY:x.top<v.maxScrollY?v.maxScrollY:x.top;w=w===undefined?p.max(p.abs(x.left)*2,p.abs(x.top)*2):w;v.scrollTo(x.left,x.top,w)},scrollToPage:function(w,v,A){var z=this,m,B;if(z.options.onScrollStart){z.options.onScrollStart.call(z)}if(z.options.snap){w=w=="next"?z.currPageX+1:w=="prev"?z.currPageX-1:w;v=v=="next"?z.currPageY+1:v=="prev"?z.currPageY-1:v;w=w<0?0:w>z.pagesX.length-1?z.pagesX.length-1:w;v=v<0?0:v>z.pagesY.length-1?z.pagesY.length-1:v;z.currPageX=w;z.currPageY=v;m=z.pagesX[w];B=z.pagesY[v]}else{m=-z.wrapperW*w;B=-z.wrapperH*v;if(m<z.maxScrollX){m=z.maxScrollX}if(B<z.maxScrollY){B=z.maxScrollY}}z.scrollTo(m,B,A||400)},disable:function(){this.stop();this._resetPos(0);this.enabled=false;this._unbind(n);this._unbind(d);this._unbind(r)},enable:function(){this.enabled=true},stop:function(){if(this.options.useTransition){this._unbind("webkitTransitionEnd")}else{k(this.aniTime)}this.steps=[];this.moved=false;this.animating=false},zoom:function(m,B,A,z){var v=this,w=A/v.scale;if(!v.options.useTransform){return}v.zoomed=true;z=z===undefined?200:z;m=m-v.wrapperOffsetLeft-v.x;B=B-v.wrapperOffsetTop-v.y;v.x=m-m*w+v.x;v.y=B-B*w+v.y;v.scale=A;v.refresh();v.x=v.x>0?0:v.x<v.maxScrollX?v.maxScrollX:v.x;v.y=v.y>v.minScrollY?v.minScrollY:v.y<v.maxScrollY?v.maxScrollY:v.y;v.scroller.style[t+"TransitionDuration"]=z+"ms";v.scroller.style[t+"Transform"]=a+v.x+"px,"+v.y+"px"+i+" scale("+A+")";v.zoomed=false},isReady:function(){return !this.moved&&!this.zoomed&&!this.animating}};if(typeof exports!=="undefined"){exports.iScroll=q}else{window.iScroll=q}})();
/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
