text: // page init
  jQuery(function(){
  	"use strict";
  
  	initTabs();
  	initFitVids();
  	initMobileNav();
  	initSameHeight();
  	initNumCounter();
  	initParallaxBg();
  	initStickyHeader();
  	initHasDropClasses();
  	initCountDown();
  	initAnimatedProgressbars();
  	initJqureyAnimation();
  	initGoToTopScroll();
  	initPieCharts();
  	initSlickSlider();
  });
  jQuery(window).on('load', function() {
  	"use strict";
  	
  	initPreLoader();
  	initMarquee();
  	initIsotope();
  	initLightbox();
  	initAjaxLoad();
  	initGoogleMap();
  	initFlexSlider();
  	initOwlSlider();
  	initVimeoPlayer();
  	initAudioPlayer();
  	initVideoPlayer();
  	initYoutubePlayer();
  	initStyleChanger();
  	initIsotopControl();
  	initBackgroundResize();
  	initFlickrPhotos();
      initFormValidation();
  	initGoToTop();
  	initAccordion();
  	initCustomForms();
  	initNavRemoveClass();
  	jQuery('input, textarea').placeholder();
  	initInstagramPics('2311561473.1677ed0.4e364b1ee1664889b061b4bb21612abe', ' e37e5979509b44cb811a8be2b1067f11');
  	initAnchors();
  });
  
  jQuery(window).scroll(function() {
  	initPieCharts();
  	initGoToTopScroll();
  	initAnimatedProgressbars();
  });
  
  function initSlickSlider() {
      jQuery('.beans-slider').each(function() {
      	var item = jQuery(this);
      	var btnPrev = item.find('.btn-prev');
      	var btnNext = item.find('.btn-next');
      	var slider = item.find('.beans-slideset');
      	var pagination = item.find('.beans-pagination');
  
      	slider.slick({
      		arrows: (btnPrev.length > 0) && (btnNext.length > 0) ? true : false,
      		dots: pagination.length > 0 ? true : false,
      		pauseOnHover: true,
      		autoplay: true,
      		//CAMBIA EL DELAY DEL CARRUSEL
      		autoplaySpeed: 9000,
      		speed: 800
      	});
  
      	pagination.remove();
      	btnPrev.remove();
      	btnNext.remove();
      });
  
      jQuery('.beans-stepslider').each(function() {
      	var item = jQuery(this);
      	var btnPrev = item.find('.btn-prev');
      	var btnNext = item.find('.btn-next');
      	var slider = item.find('.beans-slideset');
      	var pagination = item.find('.beans-pagination');
  
      	slider.slick({
      		arrows: (btnPrev.length > 0) && (btnNext.length > 0) ? true : false,
      		dots: pagination.length > 0 ? true : false,
      		slidesToShow: 1,
      		mobileFirst: true,
      		autoplay: true,
      		responsive: [
      			{
      				breakpoint: 767,
      				settings: {
      					slidesToShow: 2
      				}
      			}, {
  					breakpoint: 1024,
      				settings: {
      					slidesToShow: 4
      				}    				
      			}
      		]
      	});
  
      	if(item.parents('.blog-section , .finest-chef').length > 0) {
      		slider.slick('unslick');
  	    	slider.slick({
  	    		arrows: (btnPrev.length > 0) && (btnNext.length > 0) ? true : false,
  	    		dots: pagination.length > 0 ? true : false,
      			autoplay: true,
  	    		slidesToShow: 1,
  	    		mobileFirst: true,
  	    		responsive: [
  	    			{
  	    				breakpoint: 768,
  	    				settings: {
  	    					slidesToShow: 2
  	    				}
  	    			}, {
  						breakpoint: 1024,
  	    				settings: {
  	    					slidesToShow: 3
  	    				}    				
  	    			}
  	    		]
  	    	});
      	}
  
      	if(item.parents('.related-shop').length > 0) {
      		slider.slick('unslick');
  	    	slider.slick({
  	    		arrows: (btnPrev.length > 0) && (btnNext.length > 0) ? true : false,
  	    		dots: pagination.length > 0 ? true : false,
      			autoplay: true,
      			speed: 1200,
      			autoplaySpeed: 4000,
  	    		slidesToShow: 1
  	    	});
      	}
  
      	pagination.remove();
      	btnPrev.remove();
      	btnNext.remove();
      });
  
      jQuery('.beans-fadeslider').each(function() {
      	var item = jQuery(this);
      	var btnPrev = item.find('.btn-prev');
      	var btnNext = item.find('.btn-next');
      	var slider = item.find('.slideset');
      	var pagination = item.find('.beans-pagination');
  
      	slider.slick({
      		arrows: (btnPrev.length > 0) && (btnNext.length > 0) ? true : false,
      		dots: pagination.length > 0 ? true : false,
      		pauseOnHover: false,
      		autoplay: true,
      		fade: true,
      		speed: 800
      	});
  
      	pagination.remove();
      	btnPrev.remove();
      	btnNext.remove();
      });
  
      jQuery('.beans-stepslider2').each(function() {
      	var item = jQuery(this);
      	var slider = item.find('.beans-slideset');
  
      	slider.slick({
      		asNavFor: '.beans-pagination ul',
      		pauseOnHover: false,
      		arrows: false,
      		speed: 800
      	});
      });
  
      jQuery('.beans-pagination').each(function() {
      	var item = jQuery(this);
      	var btnPrev = item.find('.btn-prev');
      	var btnNext = item.find('.btn-next');
      	var slider = item.find('ul');
  
      	slider.slick({
      		arrows: (btnPrev.length > 0) && (btnNext.length > 0) ? true : false,
      		asNavFor: '.beans-stepslider2 .beans-slideset',
      		focusOnSelect: true,
      		slidesToShow: 1,
      		mobileFirst: true,
      		autoplay: false,
      		responsive: [
      			{
      				breakpoint: 767,
      				settings: {
      					slidesToShow: 2
      				}
      			}, {
  					breakpoint: 1024,
      				settings: {
      					slidesToShow: 4
      				}    				
      			}
      		]
      	});
      });
  }
  
  
  // NavRemoveClass init
  function initNavRemoveClass() {
  	jQuery("#nav .smoothanchor").click(function(){
  		if (jQuery("body").hasClass("mainnav-active")) {
  			setTimeout(function() { 
  			jQuery("body").removeClass("mainnav-active");}, 1000);
  		}
  	});
  }
  
  
  // FlexSlider init
  function initFlexSlider() {
  	jQuery('.flexslider').flexslider({
  		animation: "slide"
  	});
  }
  
  // OwlSlider init
  function initOwlSlider() {
  	jQuery('#owl-example').owlCarousel({
  		autoPlay: true
  	});
  }
  // sticky header init
  function initStickyHeader() {
  	var win = jQuery(window),
  		stickyClass = 'fixed-position';
  
  	jQuery('#header').each(function() {
  		var header = jQuery(this);
  		var headerOffset = header.offset().top || 0;
  		var flag = true;
  
  		function scrollHandler() {
  			if (win.scrollTop() > headerOffset) {
  				if (flag){
  					flag = false;
  					header.addClass(stickyClass);
  				}
  			} else {
  				if (!flag) {
  					flag = true;
  					header.removeClass(stickyClass);
  				}
  			}
  
  			ResponsiveHelper.addRange({
  				'..767': {
  					on: function() {
  						header.removeClass(stickyClass);
  					}
  				}
  			});
  		}
  
  		scrollHandler();
  		win.on('scroll resize orientationchange', scrollHandler);
  	});
  }
  
  // instagram photos init
  function initInstagramPics(instaToken, instaID) {
  	var instaBox = jQuery('.instagram-photos');
  
  	jQuery.fn.spectragram.accessData = {
  		accessToken: instaToken,
  		clientID: instaID
  	};
  
  	instaBox.each(function() {
  		var item = jQuery(this);
  		var userName = item.attr('data-user');
  		var limit = item.attr('data-count') ? Number(item.attr('data-count')) : 8;
  
  		item.spectragram('getPopular',{
  			max: limit,
  			size: 'medium',
  			wrapEachWith: ' '
  		});
  	});
  }
  
  // animation init
  function initJqureyAnimation() {
  	var sections = jQuery('[data-animate]');
  	var	pageBody = jQuery('body');
  
  	sections.each(function() {
  		var item = jQuery(this);
  		var delay = item.attr('data-delay') ? Number(item.attr('data-delay')) + 500 : 500;
  		var animation = item.attr('data-animate');
  
  		if(!item.hasClass('animated')) {
  			item.addClass('not-animated');
  			item.appear(function () {
  				setTimeout(function() {
  					item.removeClass('not-animated').addClass(animation + ' animated');
  				}, delay);
  			},{accX: 0, accY: -120},'easeInCubic');
  		}
  	});
  }
  
  // flickr feed init
  function initFlickrPhotos() {
  	var flickrBox = jQuery('.flickr-feed');
  
  	flickrBox.each(function() {
  		var item = jQuery(this);
  		var feedType = item.attr('data-type');
  
  		item.jflickrfeed({
  			feedapi: feedType === 'group' ? 'groups_pool.gne' : feedType,
  			limit: Number(item.attr('data-count')) || 8,
  			qstrings: {
  				id: item.attr('data-id')
  			},
  			itemTemplate: '<a href="{{image_b}}" title="{{title}}" rel="lightbox">' + '<img src="{{image_s}}" alt="{{title}}" />' + '</a>'
  		});
  	});
  }
  
  // animate pie charts init
  function initPieCharts() {
  	if(typeof jQuery.fn.easyPieChart != 'undefined'){
  		jQuery(".pie-chart:in-viewport").each(function() {
  			var item = jQuery(this);
  			var dimension = item.attr("data-barSize");
  
  			item.css({
  				'height': dimension,
  				'width': dimension,
  				'line-height': dimension + 'px'
  			});
  			
  			item.easyPieChart({
  				animate: 2000,
  				lineCap: "square",
  				lineWidth: item.attr("data-lineWidth"),
  				size: dimension,
  				barColor: item.attr("data-barColor"),
  				trackColor: item.attr("data-trackColor"),
  				scaleColor: "transparent",
  				onStep: function(from, to, percent) {
  					jQuery(this.el).find('.pie-chart-percent span').text(Math.round(from));
  				}
  			});
  		});
  	}
  }
  
  // progressbars init
  function initAnimatedProgressbars() {
  	jQuery(".progress-bar .progress-bar-outer:in-viewport").each(function() {
  		var item = jQuery(this);
  		var percent = item.attr('data-width');
  		var animationSpeed = 2500;
  		var flag = false;
  
  		if(!flag) {
  			item.animate({
  				width: percent + "%"
  			}, animationSpeed);
  
  			flag = true;
  		}
  	});
  }
  
  // count down init
  function initCountDown() {
  	var newDate = new Date(2016, 1, 30);
  	
  	jQuery('#countdown').countdown({until: newDate});
  }
  
  // counter init
  function initNumCounter() {
  	var counters = jQuery('.counter');
  	var pageBody = jQuery('body');
  
  	counters.each(function() {
  		var item = jQuery(this);
  		var isComma = item.find('span').attr('data-comma');
  
  		item.appear(function() {
  			if(isComma) {
  				item.find('span').countTo({
  					formatter: function (value, options) {
  						value = value.toFixed(options.decimals);
  						value = value.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  						return value;
  					}
  				});
  			} else {
  				item.find('span').countTo();
  			}
  		});
  	});
  }
  
  // go to top init
  function initGoToTop() {
  	var linkTop = jQuery('#gotoTop');
  	var animationSpeed = 600;
  	
  	linkTop.click(function(e) {
  		e.preventDefault();
  		
  		jQuery('body,html').stop(true).animate({
  			scrollTop: 0
  		}, animationSpeed);
  	});
  }
  
  // go to top scroll init
  function initGoToTopScroll() {
  	var linkTop = jQuery('#gotoTop'),
  		win = jQuery(window);
  	
  	if(win.scrollTop() > 0) {
  		linkTop.fadeIn();
  	} else {
  		linkTop.fadeOut();
  	}
  }
  
  // PreLoader init
  function initPreLoader() {
  	jQuery('#pre-loader').delay(1200).fadeOut();
  }
  
  // AudioPlayer init
  function initAudioPlayer() {
  	jQuery('audio').mediaelementplayer();
  }
  
  // VimeoPlayer init
  function initVimeoPlayer() {
  	var vimeoHolder = jQuery('.vimeo-area');
  
  	vimeoHolder.each(function(index, item) {
  		var container = jQuery(item);
  		var vimeoBox = container.find('.vimeo');
  		var iframe = jQuery('#player1')[0];
  		var player = $f(iframe);
  		var button = container.find('.btn-play');
  		var activeClass = 'playing';
  
  		window.setTimeout(function() {
  			vimeoBox.css({
  				visibility: 'visible'
  			});
  		}, 2000);
  
  		player.addEvent('ready', function() {
  			player.api('setVolume', 0);
  			button.on('click', function(e) {
  				e.preventDefault();
  
  				if(button.hasClass(activeClass)) {
  					player.api('pause');
  					button.removeClass(activeClass);
  				} else {
  					player.api('play');
  					button.addClass(activeClass);
  				}
  			});
  		});
  	});
  }
  
  // initVideoPlayer init
  function initVideoPlayer() {
  	jQuery('.video-area').each(function() {
  		var container = jQuery(this);
  		var player = container.find('video').mediaelementplayer().get(0);
  		var button = container.find('.btn-play');
  		var activeClass = 'playing';
  		
  		
  		if(container.hasClass('mute')) {
  		   player.setVolume(0);
  		}
  		button.on('click', function(e) {
  			e.preventDefault();
  			
  			if(button.hasClass(activeClass)) {
  				player.pause();
  				button.removeClass(activeClass);
  			} else {
  				player.play();
  				button.addClass(activeClass);
  			}
  		});
  	});
  }
  
  // GoogleMap init
  function initGoogleMap() {
  	jQuery('.map').googleMapAPI({
  		marker: 'images/logoMARKER.png',
  		mapInfoContent: '.map-info',
  		streetViewControl: false,
  		mapTypeControl: false,
  		scrollwheel: false,
  		panControl: false,
  		zoomControl: false
  	});
  }
  
  //  Custom variables for isotop
  function initIsotopControl() {
  	var isotopeHolder = jQuery('#work'),
  		win = jQuery(window);
  
  	isotopeHolder.isotope({transitionDuration: '0.75s'});
  
  	setTimeout(function() {
  		isotopeHolder.isotope('layout');
  	}, 100);
  
  	jQuery('#work-filter a').click(function(e){
  		e.preventDefault();
  		
  		jQuery('#work-filter li').removeClass('active');
  		jQuery(this).parent('li').addClass('active');
  		var selector = jQuery(this).attr('data-filter');
  		isotopeHolder.isotope({ filter: selector });
  	});
  
  	jQuery('#work-shuffle').click(function() {
  		isotopeHolder.isotope('updateSortData').isotope({
  			sortBy: 'random'
  		});
  	});
  
  	win.resize(function() {
  		isotopeHolder.isotope('layout');
  	});
  }
  
  // style changer
  function initStyleChanger() {
  	var element = jQuery('#style-changer');
  
  	if(element) {
  		$.ajax({
  			url: element.attr('data-src'),
  			type: 'get',
  			dataType: 'text',
  			success: function(data) {
  				var newContent = jQuery('<div>', {
  					html: data
  				});
  
  				newContent.appendTo(element);
  				jQuery('body').mobileNav({
  					hideOnClickOutside: false,
  					menuActiveClass: 'changer-active',
  					menuOpener: '.changer-opener'
  				});
  				jQuery('body').mobileNav({
  					hideOnClickOutside: false,
  					menuActiveClass: 'boxed-v',
  					menuOpener: '.boxed-link, .btn2',
  					onInit: function() {
  						initIsotopControl();
  						initBackgroundResize();
  					},
  					onHide: function() {
  						initIsotopControl();
  						initBackgroundResize();
  					}
  				});
  				
  				var sheet,
  					darkSheet,
  					sheetName,
  					darkSheetName = 'dark',
  					sheetAdded = false,
  					darkStylesAdded = false;
  
  				jQuery('.list-color li').each(function() {
  					var item = jQuery(this),
  						link = item.find('a').eq(0);
  
  					link.on('click', function(e) {
  						e.preventDefault();
  						sheetName = item.attr('class');
  
  						if(!sheetAdded) {
  							sheet = jQuery('<link>').attr('rel','stylesheet')
  										.attr('type','text/css')
  										.attr('href', 'css/color/' + sheetName + '.css')
  										.appendTo('head');
  
  							sheetAdded = true;
  						} else {
  							sheet.attr('href', 'css/color/' + sheetName + '.css');
  						}
  					});
  				});
  				jQuery('.list-bg-color li').each(function() {
  					var body = jQuery('body'),
  						item = jQuery(this),
  						link = item.find('a').eq(0);
  										 
  					link.on('click', function(e) {
  						e.preventDefault();
  						
  						body.removeClass('dark');
  						if(link.hasClass('dark')) {
  							if(!body.hasClass('dark')) {
  								body.addClass('dark');
  							}
  						}
  					});
  				});
  			}
  		});
  	}
  }
  
  // initialize smooth anchor links
  function initAnchors() {
  	new SmoothScroll({
  		anchorLinks: 'a[href^="#"].smoothanchor',
  		extraOffset: 66,
  		activeClasses: 'parent'
  	});
  }
  
  // content tabs init
  function initTabs() {
  	jQuery('ul.beans-tabset').contentTabs({
  		addToParent: true,
  		tabLinks: 'a'
  	});
  	jQuery('ul.tabset').contentTabs({
  		addToParent: true,
  		tabLinks: 'a'
  	});
  	jQuery('ul.tabset-onepage').contentTabs({
  		addToParent: true,
  		tabLinks: 'a'
  	});
  }
  
  // Isotope init
  function initIsotope() {
  	jQuery('#masonry-container').isotope({
  		itemSelector: '.item',
  		transitionDuration: '0.6s',
  		masonry: {
  			columnWidth: 2,
  			gutter: 0,
  			isResizable: false
  		}
  	});
  }
  
  // init youtube background player
  function initYoutubePlayer() {
  	jQuery(".youtube_bg_video").each(function() {
  		var player = jQuery(this),
  			btnPlay = player.closest('.video-section').find('.play-icon'),
  			videoPlaying = false;
  			player.YTPlayer();
  
  		btnPlay.on('click', function(e) {
  			e.preventDefault();
  			if(videoPlaying) {
  				player.pauseYTP();
  				btnPlay.removeClass('video-playing').addClass('video-pause');
  				videoPlaying = false;
  			} else {
  				player.playYTP();
  				btnPlay.removeClass('video-pause').addClass('video-playing');
  				videoPlaying = true;
  			}
  		});
  	});
  }
  
  // handle flexible video size
  function initFitVids() {
  	jQuery('.vimeo').fitVids();
  	jQuery('.video-area').fitVids();
  }
  
  // align blocks height
  function initSameHeight() {
  	setSameHeight({
  		holder: '.same-block',
  		elements: '.same-column',
  		flexible: true,
  		multiLine: true,
  		biggestHeight: true
  	});
  }
  
  // ajax load init
  function initAjaxLoad(){
  	jQuery('.ajax-area').ajaxPopup({
  		button: '.btn-load',
  		ajaxHold: '#ajax-holder',
  		appendToBody: false,
  		attr: 'href',
  	 	animSpeed: 500,
  	 	onChange: function(){
  	 		//initCycleCarousel();
  	 		initBackgroundResize();
  	 	}
  	});
  }
  
  // mobile menu init
  function initMobileNav() {
  	jQuery('body').mobileNav({
  		hideOnClickOutside: true,
  		menuActiveClass: 'sidenav-active',
  		menuOpener: '.menu-opener , .btn-close',
  		menuDrop: '.menu-nav'
  	});
  	jQuery('body').mobileNav({
  		hideOnClickOutside: false,
  		menuActiveClass: 'search-active',
  		menuOpener: '.search-opener , .close-btn'
  	});
  	jQuery('body').mobileNav({
  		hideOnClickOutside: false,
  		menuActiveClass: 'user-active',
  		menuOpener: '.user-opener , .close-btn2'
  	});
  	jQuery('body').mobileNav({
  		hideOnClickOutside: true,
  		menuActiveClass: 'mainnav-active',
  		menuOpener: '.nav-opener',
  		menuDrop: '.sidemenu-photo, .nav-holder'
  	});
  	jQuery('body').mobileNav({
  		hideOnClickOutside: true,
  		menuActiveClass: 'mainnav-active',
  		menuOpener: '.main-navopener2',
  		menuDrop: '.main-menu'
  	});
  	jQuery('body').mobileNav({
  		hideOnClickOutside: true,
  		menuActiveClass: 'nav-active',
  		menuOpener: '.portfolio-nav-opener',
  		menuDrop: '.sidenav-port'
  	});
  }
  
  // dropdown classes
  function initHasDropClasses() {
  	var dropClassName = 'has-drop',
  		megaDropClassName = 'has-mega-drop';
  
  	jQuery('#nav li').each(function(index, item) {
  		var container = jQuery(item),
  			link = container.find('a'),
  			drop = container.find('.drop'),
  			megaDrop = container.find('.mega-drop');
  
  		if(drop.length) {
  			container.addClass(dropClassName);
  		}
  
  		if(megaDrop.length) {
  			container.addClass(megaDropClassName);
  		}
  	});
  }
  
  // initialize Parallax background
  function initParallaxBg() {
  	jQuery('.parallax-holder').parallaxBG({
  		parent: '.parallax-frame',
  		image: 'img',
  		parallaxOffset: 100,
  		fallbackFunc: initBgStretch
  	});
  }
  
  // stretch background to fill blocks
  function initBackgroundResize() {
  	jQuery('.stretch').each(function() {
  		ImageStretcher.add({
  			container: this,
  			image: 'img'
  		});
  	});
  }
  
  // running line init
  function initMarquee() {
  	jQuery('.line-box').marquee({
  		line: '.line',
  		animSpeed: 50
  	});
  }
  
  // initialize custom form elements
  function initCustomForms() {
  	//jcf.replaceAll();
  }
  
  // fancybox modal popup init
  function initLightbox() {
  	jQuery('a.lightbox, a[rel*="lightbox"]').fancybox({
  		padding: 0,
  		loop: false,
  		helpers: {
  			overlay: {
  				css: {background: 'rgba(0, 0, 0, 0.35)'}
  			}
  		},
  		afterLoad: function(current, previous) {
  			// handle custom close button in inline modal
  			if(current.href.indexOf('#') === 0) {
  				jQuery(current.href).find('a.close').off('click.fb').on('click.fb', function(e){
  					e.preventDefault();
  					jQuery.fancybox.close();
  				});
  			}
  		}
  	});
  }
  
  // accordion menu init
  function initAccordion() {
  	jQuery('.blog-accordion').slideAccordion({
  		opener: 'a.opener',
  		slider: '.blog-slide',
  		animSpeed: 300
  	});
  	jQuery('.beans-accordion').slideAccordion({
  		opener: 'a.opener',
  		slider: '.beans-slide',
  		animSpeed: 300
  	});
  }
  
  // form validation init
  function initFormValidation() {
  	//if submit button is clicked
  	$('#submit,#submit2').click(function () {
  
          //Get the data from all the fields
          var name = $('input[name=name]');
          var email = $('input[name=email]');
          var website = $('input[name=website]');
          var comment = $('textarea[name=comment]');
          var returnError = false;
  
          //Simple validation to make sure user entered something
          //Add your own error checking here with JS, but also do some error checking with PHP.
          //If error found, add hightlight class to the text field
          if (name.val()=='') {
              name.addClass('error');
              returnError = true;
          } else name.removeClass('error');
  
          if (email.val()=='') {
              email.addClass('error');
              returnError = true;
          } else email.removeClass('error');
  
          if (comment.val()=='') {
              comment.addClass('error');
              returnError = true;
          } else comment.removeClass('error');
  
          // Highlight all error fields, then quit.
          if(returnError == true) {
              return false;	
          }
  
          //organize the data
          var data = 'name=' + name.val() + '&email=' + email.val() + '&website=' + website.val() + '&comment='  + encodeURIComponent(comment.val());
  
          //disabled all the text fields
          $('.text').attr('disabled','true');
  
          //show the loading sign
          $('.loading').show();
  
          //start the ajax
          $.ajax({
              //this is the php file that processes the data and sends email
              url: "inc/process.php",	
  
              //GET method is used
              type: "GET",
  
              //pass the data	
              data: data,	
  
              //Do not cache the page
              cache: false,
  
              //success
              success: function (html) {	
              //if process.php returned 1/true (send mail success)
                  if (html==1) {	
                  //hide the form
                  $('.email-form').fadeOut('slow');	
  
                  //show the success message
                  $('.done-massage').fadeIn('slow');
  
                  //if process.php returned 0/false (send mail failed)
                  } else alert('Sorry, unexpected error. Please try again later.');	
              }	
          });
  
          //cancel the submit button default behaviours
          return false;
  	});
  	//if submit button is clicked
  	$('#form-submit').click(function () {
  
          //Get the data from all the fields
          var name = $('input[name=name]');
          var email = $('input[name=email]');
          var purchase = $('input[name=purchase]');
          var profile = $('input[name=profile]');
          var comment = $('textarea[name=comment]');
          var returnError = false;
  
          //Simple validation to make sure user entered something
          //Add your own error checking here with JS, but also do some error checking with PHP.
          //If error found, add hightlight class to the text field
          if (name.val()=='') {
              name.addClass('error');
              returnError = true;
          } else name.removeClass('error');
  
          if (email.val()=='') {
              email.addClass('error');
              returnError = true;
          } else email.removeClass('error');
  
          if (purchase.val()=='') {
              purchase.addClass('error');
              returnError = true;
          } else purchase.removeClass('error');
  
          if (profile.val()=='') {
              profile.addClass('error');
              returnError = true;
          } else profile.removeClass('error');
  
          if (comment.val()=='') {
              comment.addClass('error');
              returnError = true;
          } else comment.removeClass('error');
  
          // Highlight all error fields, then quit.
          if(returnError == true) {
              return false;	
          }
  
          //organize the data
          var data = 'name=' + name.val() + '&email=' + email.val() + '&purchase=' + purchase.val() + '&profile=' + profile.val() + '&website=' + website.val() + '&comment='  + encodeURIComponent(comment.val());
  
          //disabled all the text fields
          $('.form-control').attr('disabled','true');
  
          //show the loading sign
          $('.loading').show();
  
          //start the ajax
          $.ajax({
              //this is the php file that processes the data and sends email
              url: "inc/process2.php",	
  
              //GET method is used
              type: "GET",
  
              //pass the data	
              data: data,	
  
              //Do not cache the page
              cache: false,
  
              //success
              success: function (html) {	
              //if process.php returned 1/true (send mail success)
                  if (html==1) {	
                  //hide the form
                  $('.email-form').fadeOut('slow');	
  
                  //show the success message
                  $('.done-massage').fadeIn('slow');
  
                  //if process.php returned 0/false (send mail failed)
                  } else alert('Sorry, unexpected error. Please try again later.');	
              }	
          });
  
          //cancel the submit button default behaviours
          return false;
  	});
  }
  
  
  /*
   * Simple Mobile Navigation
   */
  ;(function($) {
  	function MobileNav(options) {
  		this.options = $.extend({
  			container: null,
  			hideOnClickOutside: false,
  			menuActiveClass: 'nav-active',
  			menuOpener: '.nav-opener',
  			menuDrop: '.nav-drop',
  			toggleEvent: 'click',
  			outsideClickEvent: 'click touchstart pointerdown MSPointerDown'
  		}, options);
  		this.initStructure();
  		this.attachEvents();
  	}
  	MobileNav.prototype = {
  		initStructure: function() {
  			this.page = $('html');
  			this.container = $(this.options.container);
  			this.opener = this.container.find(this.options.menuOpener);
  			this.drop = this.container.find(this.options.menuDrop);
  		},
  		attachEvents: function() {
  			var self = this;
  
  			if(activateResizeHandler) {
  				activateResizeHandler();
  				activateResizeHandler = null;
  			}
  
  			this.outsideClickHandler = function(e) {
  				if(self.isOpened()) {
  					var target = $(e.target);
  					if(!target.closest(self.opener).length && !target.closest(self.drop).length) {
  						self.hide();
  					}
  				}
  			};
  
  			this.openerClickHandler = function(e) {
  				e.preventDefault();
  				self.toggle();
  			};
  
  			this.opener.on(this.options.toggleEvent, this.openerClickHandler);
  		},
  		isOpened: function() {
  			return this.container.hasClass(this.options.menuActiveClass);
  		},
  		show: function() {
  			this.container.addClass(this.options.menuActiveClass);
  			if(this.options.hideOnClickOutside) {
  				this.page.on(this.options.outsideClickEvent, this.outsideClickHandler);
  			}
  			this.makeCallback('onInit', this);
  		},
  		hide: function() {
  			this.container.removeClass(this.options.menuActiveClass);
  			if(this.options.hideOnClickOutside) {
  				this.page.off(this.options.outsideClickEvent, this.outsideClickHandler);
  			}
  			this.makeCallback('onHide', this);
  		},
  		toggle: function() {
  			if(this.isOpened()) {
  				this.hide();
  			} else {
  				this.show();
  			}
  		},
  		makeCallback: function(name) {
  			if(typeof this.options[name] === 'function') {
  				var args = Array.prototype.slice.call(arguments);
  				args.shift();
  				this.options[name].apply(this, args);
  			}
  		},
  		destroy: function() {
  			this.container.removeClass(this.options.menuActiveClass);
  			this.opener.off(this.options.toggleEvent, this.clickHandler);
  			this.page.off(this.options.outsideClickEvent, this.outsideClickHandler);
  		}
  	};
  
  	var activateResizeHandler = function() {
  		var win = $(window),
  			doc = $('html'),
  			resizeClass = 'resize-active',
  			flag, timer;
  		var removeClassHandler = function() {
  			flag = false;
  			doc.removeClass(resizeClass);
  		};
  		var resizeHandler = function() {
  			if(!flag) {
  				flag = true;
  				doc.addClass(resizeClass);
  			}
  			clearTimeout(timer);
  			timer = setTimeout(removeClassHandler, 500);
  		};
  		win.on('resize orientationchange', resizeHandler);
  	};
  
  	$.fn.mobileNav = function(options) {
  		return this.each(function() {
  			var params = $.extend({}, options, {container: this}),
  				instance = new MobileNav(params);
  			$.data(this, 'MobileNav', instance);
  		});
  	};
  }(jQuery));
  
  /*! http://mths.be/placeholder v2.0.7 by @mathias */
  ;(function(window, document, $) {
  
  	// Opera Mini v7 doesn’t support placeholder although its DOM seems to indicate so
  	var isOperaMini = Object.prototype.toString.call(window.operamini) == '[object OperaMini]';
  	var isInputSupported = 'placeholder' in document.createElement('input') && !isOperaMini;
  	var isTextareaSupported = 'placeholder' in document.createElement('textarea') && !isOperaMini;
  	var prototype = $.fn;
  	var valHooks = $.valHooks;
  	var propHooks = $.propHooks;
  	var hooks;
  	var placeholder;
  
  	if (isInputSupported && isTextareaSupported) {
  
  		placeholder = prototype.placeholder = function() {
  			return this;
  		};
  
  		placeholder.input = placeholder.textarea = true;
  
  	} else {
  
  		placeholder = prototype.placeholder = function() {
  			var $this = this;
  			$this
  				.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
  				.not('.placeholder')
  				.bind({
  					'focus.placeholder': clearPlaceholder,
  					'blur.placeholder': setPlaceholder
  				})
  				.data('placeholder-enabled', true)
  				.trigger('blur.placeholder');
  			return $this;
  		};
  
  		placeholder.input = isInputSupported;
  		placeholder.textarea = isTextareaSupported;
  
  		hooks = {
  			'get': function(element) {
  				var $element = $(element);
  
  				var $passwordInput = $element.data('placeholder-password');
  				if ($passwordInput) {
  					return $passwordInput[0].value;
  				}
  
  				return $element.data('placeholder-enabled') && $element.hasClass('placeholder') ? '' : element.value;
  			},
  			'set': function(element, value) {
  				var $element = $(element);
  
  				var $passwordInput = $element.data('placeholder-password');
  				if ($passwordInput) {
  					return $passwordInput[0].value = value;
  				}
  
  				if (!$element.data('placeholder-enabled')) {
  					return element.value = value;
  				}
  				if (value == '') {
  					element.value = value;
  					// Issue #56: Setting the placeholder causes problems if the element continues to have focus.
  					if (element != safeActiveElement()) {
  						// We can't use `triggerHandler` here because of dummy text/password inputs :(
  						setPlaceholder.call(element);
  					}
  				} else if ($element.hasClass('placeholder')) {
  					clearPlaceholder.call(element, true, value) || (element.value = value);
  				} else {
  					element.value = value;
  				}
  				// `set` can not return `undefined`; see http://jsapi.info/jquery/1.7.1/val#L2363
  				return $element;
  			}
  		};
  
  		if (!isInputSupported) {
  			valHooks.input = hooks;
  			propHooks.value = hooks;
  		}
  		if (!isTextareaSupported) {
  			valHooks.textarea = hooks;
  			propHooks.value = hooks;
  		}
  
  		$(function() {
  			// Look for forms
  			$(document).delegate('form', 'submit.placeholder', function() {
  				// Clear the placeholder values so they don't get submitted
  				var $inputs = $('.placeholder', this).each(clearPlaceholder);
  				setTimeout(function() {
  					$inputs.each(setPlaceholder);
  				}, 10);
  			});
  		});
  
  		// Clear placeholder values upon page reload
  		$(window).bind('beforeunload.placeholder', function() {
  			$('.placeholder').each(function() {
  				this.value = '';
  			});
  		});
  
  	}
  
  	function args(elem) {
  		// Return an object of element attributes
  		var newAttrs = {};
  		var rinlinejQuery = /^jQuery\d+$/;
  		$.each(elem.attributes, function(i, attr) {
  			if (attr.specified && !rinlinejQuery.test(attr.name)) {
  				newAttrs[attr.name] = attr.value;
  			}
  		});
  		return newAttrs;
  	}
  
  	function clearPlaceholder(event, value) {
  		var input = this;
  		var $input = $(input);
  		if (input.value == $input.attr('placeholder') && $input.hasClass('placeholder')) {
  			if ($input.data('placeholder-password')) {
  				$input = $input.hide().next().show().attr('id', $input.removeAttr('id').data('placeholder-id'));
  				// If `clearPlaceholder` was called from `$.valHooks.input.set`
  				if (event === true) {
  					return $input[0].value = value;
  				}
  				$input.focus();
  			} else {
  				input.value = '';
  				$input.removeClass('placeholder');
  				input == safeActiveElement() && input.select();
  			}
  		}
  	}
  
  	function setPlaceholder() {
  		var $replacement;
  		var input = this;
  		var $input = $(input);
  		var id = this.id;
  		if (input.value == '') {
  			if (input.type == 'password') {
  				if (!$input.data('placeholder-textinput')) {
  					try {
  						$replacement = $input.clone().attr({ 'type': 'text' });
  					} catch(e) {
  						$replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' }));
  					}
  					$replacement
  						.removeAttr('name')
  						.data({
  							'placeholder-password': $input,
  							'placeholder-id': id
  						})
  						.bind('focus.placeholder', clearPlaceholder);
  					$input
  						.data({
  							'placeholder-textinput': $replacement,
  							'placeholder-id': id
  						})
  						.before($replacement);
  				}
  				$input = $input.removeAttr('id').hide().prev().attr('id', id).show();
  				// Note: `$input[0] != input` now!
  			}
  			$input.addClass('placeholder');
  			$input[0].value = $input.attr('placeholder');
  		} else {
  			$input.removeClass('placeholder');
  		}
  	}
  
  	function safeActiveElement() {
  		// Avoid IE9 `document.activeElement` of death
  		// https://github.com/mathiasbynens/jquery-placeholder/pull/99
  		try {
  			return document.activeElement;
  		} catch (err) {}
  	}
  
  }(this, document, jQuery));
  
  ;(function($){
  	function ParallaxBG(opt) {
  		this.options = $.extend({
  			parent: '.bg-frame',
  			image: 'img',
  			parallaxOffset: 100,
  			fallbackFunc: function() {}
  		}, opt);
  		this.init();
  	}
  	ParallaxBG.prototype = {
  		init: function() {
  			if(this.options.holder) {
  				if(typeof this.options.fallbackFunc == 'function' && (oldIe || isTouchDevice)) {
  					this.options.fallbackFunc();
  					return;
  				}
  				this.getStructure();
  				this.attachEvents();
  			}
  		},
  		getStructure: function() {
  			this.holder = $(this.options.holder);
  			this.parent = this.holder.find(this.options.parent);
  			this.holderHeight = this.holder.height();
  			this.holderOffset = this.holder.offset().top;
  
  			// generate bg
  			this.image = this.parent.find(this.options.image).eq(0).css({visibility: 'hidden'});
  			this.imageRatio = this.image.attr('width')/this.image.attr('height') || this.image.width()/this.image.height();
  
  			this.parent.css({
  				backgroundImage: 'url('+this.image.attr('src')+')',
  				backgroundRepeat: 'no-repeat',
  				backgroundAttachment: 'fixed'
  			});
  
  			this.win = $(window);
  			this.winHeight = this.win.height();
  			this.winWidth = this.win.width();
  			this.winScroll = this.win.scrollTop();
  			this.bgHeight = this.winHeight + this.options.parallaxOffset;
  		},
  		attachEvents: function() {
  			var self = this;
  			this.bindHandlers(['scrollLayout']);
  			this.bindHandlers(['resizeLayout']);
  			this.win.bind('scroll', this.scrollLayout).bind('resize load', this.resizeLayout);
  
  			// fix load problem
  			setTimeout(function() {
  				self.resizeLayout();
  				self.win.trigger('scroll');
  			}, 500);
  		},
  		resizeLayout: function() {
  			// get dimensions
  			this.winHeight = this.win.height();
  			this.winWidth = this.win.width();
  			this.holderHeight = this.holder.height();
  			this.holderOffset = this.holder.offset().top;
  			
  			this.blockHeight = this.winHeight + this.options.parallaxOffset;
  			this.currentTop = Math.max(0, this.blockHeight - this.holderHeight);
  
  			// get parallax ratio and image ratio state
  			this.parallaxRatio = this.win.width()/(this.winHeight + this.options.parallaxOffset);
  			this.ratioState = this.imageRatio <= this.parallaxRatio;
  			
  			if(this.ratioState) {
  				this.bgWidth = this.winWidth;
  				this.bgHeight = this.bgWidth/this.imageRatio;
  			} else {
  				this.bgWidth = 'auto';
  				this.bgHeight = this.winHeight + this.options.parallaxOffset;
  			}
  
  			this.parent.css({
  				paddingBottom: this.currentTop,
  				backgroundSize: this.bgWidth != 'auto' ? this.bgWidth +'px '+this.bgHeight+'px' : this.bgWidth +' '+this.bgHeight+'px'
  			});
  			this.scrollLayout();
  		},
  		scrollLayout: function() {
  			this.winScroll = this.win.scrollTop();
  			this.offsetPercentage = Math.max(0, Math.min((this.winScroll + this.winHeight - this.holderOffset)/(this.winHeight + this.holderHeight), 1)).toFixed(4);
  
  			if(!!this.ratioState) {
  				var curPos = '50% ' + ((-parseFloat(this.offsetPercentage)*this.options.parallaxOffset) - (this.bgHeight - this.winHeight)/2)+'px';
  			} else {
  				var curPos = '50% ' + (-parseFloat(this.offsetPercentage)*this.options.parallaxOffset)+'px';
  			}
  
  			this.parent.css({backgroundPosition: curPos});
  		},
  		bindHandlers: function(handlersList) {
  			var self = this;
  			$.each(handlersList, function(index, handler) {
  				var origHandler = self[handler];
  				self[handler] = function() {
  					return origHandler.apply(self, arguments);
  				};
  			});
  		}
  	};
  
  	// detect device type
  	var isTouchDevice = /MSIE 10.*Touch/.test(navigator.userAgent) || ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch;
  	var oldIe = window.attachEvent && !window.addEventListener;
  
  	// jquery parallax plugin
  	$.fn.parallaxBG = function(opt){
  		return this.each(function(){
  			new ParallaxBG($.extend(opt,{holder:this}));
  		});
  	};
  }(jQuery));
  
  // background stretching
  function initBgStretch() {
  	jQuery('.bg-frame').each(function() {
  		var holder = jQuery(this);
  		var image = holder.find('img');
  		jQuery(window).bind('load resize', function() {
  			var settings = getProportions(getDimensions(image, holder));
  			resizeAll(image, settings);	
  		});
  	});
  
  	function getProportions(dimensions) {
  		var ratio = dimensions.ratio || (dimensions.elementWidth / dimensions.elementHeight);
  		var slideWidth = dimensions.maskWidth, slideHeight = slideWidth / ratio;
  		if(slideHeight < dimensions.maskHeight) {
  			slideHeight = dimensions.maskHeight;
  			slideWidth = slideHeight * ratio;
  		}
  		return {
  			width: slideWidth,
  			height: slideHeight,
  			top: (dimensions.maskHeight - slideHeight) / 2,
  			left: (dimensions.maskWidth - slideWidth) / 2
  		}
  	}
  	
  	function getDimensions(img, block) {
  		img.css({
  			height: '',
  			left: '',
  			top: '',
  			width: ''
  		});
  		return {
  			ratio: img.width()/img.height(),
  			maskWidth: block.width(),
  			maskHeight: block.outerHeight(true)
  		};
  	}
  
  	function resizeAll(img, obj) {
  		img.css({
  			height: obj.height,
  			left: obj.left,
  			top: obj.top,
  			width: obj.width
  		});
  	}
  }
  
  
  /*
   * Image Stretch module
   */
  var ImageStretcher = {
  	getDimensions: function(data) {
  		// calculate element coords to fit in mask
  		var ratio = data.imageRatio || (data.imageWidth / data.imageHeight),
  			slideWidth = data.maskWidth,
  			slideHeight = slideWidth / ratio;
  
  		if(slideHeight < data.maskHeight) {
  			slideHeight = data.maskHeight;
  			slideWidth = slideHeight * ratio;
  		}
  		return {
  			width: slideWidth,
  			height: slideHeight,
  			top: (data.maskHeight - slideHeight) / 2,
  			left: (data.maskWidth - slideWidth) / 2
  		};
  	},
  	getRatio: function(image) {
  		if(image.prop('naturalWidth')) {
  			return image.prop('naturalWidth') / image.prop('naturalHeight');
  		} else {
  			var img = new Image();
  			img.src = image.prop('src');
  			return img.width / img.height;
  		}
  	},
  	imageLoaded: function(image, callback) {
  		var self = this;
  		var loadHandler = function() {
  			callback.call(self);
  		};
  		if(image.prop('complete')) {
  			loadHandler();
  		} else {
  			image.one('load', loadHandler);
  		}
  	},
  	resizeHandler: function() {
  		var self = this;
  		jQuery.each(this.imgList, function(index, item) {
  			if(item.image.prop('complete')) {
  				self.resizeImage(item.image, item.container);
  			}
  		});
  	},
  	resizeImage: function(image, container) {
  		this.imageLoaded(image, function() {
  			var styles = this.getDimensions({
  				imageRatio: this.getRatio(image),
  				maskWidth: container.width(),
  				maskHeight: container.height()
  			});
  			image.css({
  				width: styles.width,
  				height: styles.height,
  				marginTop: styles.top,
  				marginLeft: styles.left
  			});
  		});
  	},
  	add: function(options) {
  		var container = jQuery(options.container ? options.container : window),
  			image = typeof options.image === 'string' ? container.find(options.image) : jQuery(options.image);
  
  		// resize image
  		this.resizeImage(image, container);
  
  		// add resize handler once if needed
  		if(!this.win) {
  			this.resizeHandler = jQuery.proxy(this.resizeHandler, this);
  			this.imgList = [];
  			this.win = jQuery(window);
  			this.win.on('resize orientationchange', this.resizeHandler);
  		}
  
  		// store item in collection
  		this.imgList.push({
  			container: container,
  			image: image
  		});
  	}
  };
  
  /*!
   * JavaScript Custom Forms
   *
   * Copyright 2014-2015 PSD2HTML - http://psd2html.com/jcf
   * Released under the MIT license (LICENSE.txt)
   *
   * Version: 1.1.3
   */
  ;(function(root, factory) {
  	'use strict';
  	if (typeof define === 'function' && define.amd) {
  		define(['jquery'], factory);
  	} else if (typeof exports === 'object') {
  		module.exports = factory(require('jquery'));
  	} else {
  		root.jcf = factory(jQuery);
  	}
  }
  (this, function($) {
  	'use strict';
  
  	// define version
  	var version = '1.1.3';
  
  	// private variables
  	var customInstances = [];
  
  	// default global options
  	var commonOptions = {
  		optionsKey: 'jcf',
  		dataKey: 'jcf-instance',
  		rtlClass: 'jcf-rtl',
  		focusClass: 'jcf-focus',
  		pressedClass: 'jcf-pressed',
  		disabledClass: 'jcf-disabled',
  		hiddenClass: 'jcf-hidden',
  		resetAppearanceClass: 'jcf-reset-appearance',
  		unselectableClass: 'jcf-unselectable'
  	};
  
  	// detect device type
  	var isTouchDevice = ('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch,
  		isWinPhoneDevice = /Windows Phone/.test(navigator.userAgent);
  	commonOptions.isMobileDevice = !!(isTouchDevice || isWinPhoneDevice);
  
  	// create global stylesheet if custom forms are used
  	var createStyleSheet = function() {
  		var styleTag = $('<style>').appendTo('head'),
  			styleSheet = styleTag.prop('sheet') || styleTag.prop('styleSheet');
  
  		// crossbrowser style handling
  		var addCSSRule = function(selector, rules, index) {
  			if (styleSheet.insertRule) {
  				styleSheet.insertRule(selector + '{' + rules + '}', index);
  			} else {
  				styleSheet.addRule(selector, rules, index);
  			}
  		};
  
  		// add special rules
  		addCSSRule('.' + commonOptions.hiddenClass, 'position:absolute !important;left:-9999px !important;height:1px !important;width:1px !important;margin:0 !important;border-width:0 !important;-webkit-appearance:none;-moz-appearance:none;appearance:none');
  		addCSSRule('.' + commonOptions.rtlClass + ' .' + commonOptions.hiddenClass, 'right:-9999px !important; left: auto !important');
  		addCSSRule('.' + commonOptions.unselectableClass, '-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-tap-highlight-color: rgba(0,0,0,0);');
  		addCSSRule('.' + commonOptions.resetAppearanceClass, 'background: none; border: none; -webkit-appearance: none; appearance: none; opacity: 0; filter: alpha(opacity=0);');
  
  		// detect rtl pages
  		var html = $('html'), body = $('body');
  		if (html.css('direction') === 'rtl' || body.css('direction') === 'rtl') {
  			html.addClass(commonOptions.rtlClass);
  		}
  
  		// handle form reset event
  		html.on('reset', function() {
  			setTimeout(function() {
  				api.refreshAll();
  			}, 0);
  		});
  
  		// mark stylesheet as created
  		commonOptions.styleSheetCreated = true;
  	};
  
  	// simplified pointer events handler
  	(function() {
  		var pointerEventsSupported = navigator.pointerEnabled || navigator.msPointerEnabled,
  			touchEventsSupported = ('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch,
  			eventList, eventMap = {}, eventPrefix = 'jcf-';
  
  		// detect events to attach
  		if (pointerEventsSupported) {
  			eventList = {
  				pointerover: navigator.pointerEnabled ? 'pointerover' : 'MSPointerOver',
  				pointerdown: navigator.pointerEnabled ? 'pointerdown' : 'MSPointerDown',
  				pointermove: navigator.pointerEnabled ? 'pointermove' : 'MSPointerMove',
  				pointerup: navigator.pointerEnabled ? 'pointerup' : 'MSPointerUp'
  			};
  		} else {
  			eventList = {
  				pointerover: 'mouseover',
  				pointerdown: 'mousedown' + (touchEventsSupported ? ' touchstart' : ''),
  				pointermove: 'mousemove' + (touchEventsSupported ? ' touchmove' : ''),
  				pointerup: 'mouseup' + (touchEventsSupported ? ' touchend' : '')
  			};
  		}
  
  		// create event map
  		$.each(eventList, function(targetEventName, fakeEventList) {
  			$.each(fakeEventList.split(' '), function(index, fakeEventName) {
  				eventMap[fakeEventName] = targetEventName;
  			});
  		});
  
  		// jQuery event hooks
  		$.each(eventList, function(eventName, eventHandlers) {
  			eventHandlers = eventHandlers.split(' ');
  			$.event.special[eventPrefix + eventName] = {
  				setup: function() {
  					var self = this;
  					$.each(eventHandlers, function(index, fallbackEvent) {
  						if (self.addEventListener) self.addEventListener(fallbackEvent, fixEvent, false);
  						else self['on' + fallbackEvent] = fixEvent;
  					});
  				},
  				teardown: function() {
  					var self = this;
  					$.each(eventHandlers, function(index, fallbackEvent) {
  						if (self.addEventListener) self.removeEventListener(fallbackEvent, fixEvent, false);
  						else self['on' + fallbackEvent] = null;
  					});
  				}
  			};
  		});
  
  		// check that mouse event are not simulated by mobile browsers
  		var lastTouch = null;
  		var mouseEventSimulated = function(e) {
  			var dx = Math.abs(e.pageX - lastTouch.x),
  				dy = Math.abs(e.pageY - lastTouch.y),
  				rangeDistance = 25;
  
  			if (dx <= rangeDistance && dy <= rangeDistance) {
  				return true;
  			}
  		};
  
  		// normalize event
  		var fixEvent = function(e) {
  			var origEvent = e || window.event,
  				touchEventData = null,
  				targetEventName = eventMap[origEvent.type];
  
  			e = $.event.fix(origEvent);
  			e.type = eventPrefix + targetEventName;
  
  			if (origEvent.pointerType) {
  				switch (origEvent.pointerType) {
  					case 2: e.pointerType = 'touch'; break;
  					case 3: e.pointerType = 'pen'; break;
  					case 4: e.pointerType = 'mouse'; break;
  					default: e.pointerType = origEvent.pointerType;
  				}
  			} else {
  				e.pointerType = origEvent.type.substr(0, 5); // "mouse" or "touch" word length
  			}
  
  			if (!e.pageX && !e.pageY) {
  				touchEventData = origEvent.changedTouches ? origEvent.changedTouches[0] : origEvent;
  				e.pageX = touchEventData.pageX;
  				e.pageY = touchEventData.pageY;
  			}
  
  			if (origEvent.type === 'touchend') {
  				lastTouch = { x: e.pageX, y: e.pageY };
  			}
  			if (e.pointerType === 'mouse' && lastTouch && mouseEventSimulated(e)) {
  				return;
  			} else {
  				return ($.event.dispatch || $.event.handle).call(this, e);
  			}
  		};
  	}());
  
  	// custom mousewheel/trackpad handler
  	(function() {
  		var wheelEvents = ('onwheel' in document || document.documentMode >= 9 ? 'wheel' : 'mousewheel DOMMouseScroll').split(' '),
  			shimEventName = 'jcf-mousewheel';
  
  		$.event.special[shimEventName] = {
  			setup: function() {
  				var self = this;
  				$.each(wheelEvents, function(index, fallbackEvent) {
  					if (self.addEventListener) self.addEventListener(fallbackEvent, fixEvent, false);
  					else self['on' + fallbackEvent] = fixEvent;
  				});
  			},
  			teardown: function() {
  				var self = this;
  				$.each(wheelEvents, function(index, fallbackEvent) {
  					if (self.addEventListener) self.removeEventListener(fallbackEvent, fixEvent, false);
  					else self['on' + fallbackEvent] = null;
  				});
  			}
  		};
  
  		var fixEvent = function(e) {
  			var origEvent = e || window.event;
  			e = $.event.fix(origEvent);
  			e.type = shimEventName;
  
  			// old wheel events handler
  			if ('detail'      in origEvent) { e.deltaY = -origEvent.detail;      }
  			if ('wheelDelta'  in origEvent) { e.deltaY = -origEvent.wheelDelta;  }
  			if ('wheelDeltaY' in origEvent) { e.deltaY = -origEvent.wheelDeltaY; }
  			if ('wheelDeltaX' in origEvent) { e.deltaX = -origEvent.wheelDeltaX; }
  
  			// modern wheel event handler
  			if ('deltaY' in origEvent) {
  				e.deltaY = origEvent.deltaY;
  			}
  			if ('deltaX' in origEvent) {
  				e.deltaX = origEvent.deltaX;
  			}
  
  			// handle deltaMode for mouse wheel
  			e.delta = e.deltaY || e.deltaX;
  			if (origEvent.deltaMode === 1) {
  				var lineHeight = 16;
  				e.delta *= lineHeight;
  				e.deltaY *= lineHeight;
  				e.deltaX *= lineHeight;
  			}
  
  			return ($.event.dispatch || $.event.handle).call(this, e);
  		};
  	}());
  
  	// extra module methods
  	var moduleMixin = {
  		// provide function for firing native events
  		fireNativeEvent: function(elements, eventName) {
  			$(elements).each(function() {
  				var element = this, eventObject;
  				if (element.dispatchEvent) {
  					eventObject = document.createEvent('HTMLEvents');
  					eventObject.initEvent(eventName, true, true);
  					element.dispatchEvent(eventObject);
  				} else if (document.createEventObject) {
  					eventObject = document.createEventObject();
  					eventObject.target = element;
  					element.fireEvent('on' + eventName, eventObject);
  				}
  			});
  		},
  		// bind event handlers for module instance (functions beggining with "on")
  		bindHandlers: function() {
  			var self = this;
  			$.each(self, function(propName, propValue) {
  				if (propName.indexOf('on') === 0 && $.isFunction(propValue)) {
  					// dont use $.proxy here because it doesn't create unique handler
  					self[propName] = function() {
  						return propValue.apply(self, arguments);
  					};
  				}
  			});
  		}
  	};
  
  	// public API
  	var api = {
  		version: version,
  		modules: {},
  		getOptions: function() {
  			return $.extend({}, commonOptions);
  		},
  		setOptions: function(moduleName, moduleOptions) {
  			if (arguments.length > 1) {
  				// set module options
  				if (this.modules[moduleName]) {
  					$.extend(this.modules[moduleName].prototype.options, moduleOptions);
  				}
  			} else {
  				// set common options
  				$.extend(commonOptions, moduleName);
  			}
  		},
  		addModule: function(proto) {
  			// add module to list
  			var Module = function(options) {
  				// save instance to collection
  				if (!options.element.data(commonOptions.dataKey)) {
  					options.element.data(commonOptions.dataKey, this);
  				}
  				customInstances.push(this);
  
  				// save options
  				this.options = $.extend({}, commonOptions, this.options, getInlineOptions(options.element), options);
  
  				// bind event handlers to instance
  				this.bindHandlers();
  
  				// call constructor
  				this.init.apply(this, arguments);
  			};
  
  			// parse options from HTML attribute
  			var getInlineOptions = function(element) {
  				var dataOptions = element.data(commonOptions.optionsKey),
  					attrOptions = element.attr(commonOptions.optionsKey);
  
  				if (dataOptions) {
  					return dataOptions;
  				} else if (attrOptions) {
  					try {
  						return $.parseJSON(attrOptions);
  					} catch (e) {
  						// ignore invalid attributes
  					}
  				}
  			};
  
  			// set proto as prototype for new module
  			Module.prototype = proto;
  
  			// add mixin methods to module proto
  			$.extend(proto, moduleMixin);
  			if (proto.plugins) {
  				$.each(proto.plugins, function(pluginName, plugin) {
  					$.extend(plugin.prototype, moduleMixin);
  				});
  			}
  
  			// override destroy method
  			var originalDestroy = Module.prototype.destroy;
  			Module.prototype.destroy = function() {
  				this.options.element.removeData(this.options.dataKey);
  
  				for (var i = customInstances.length - 1; i >= 0; i--) {
  					if (customInstances[i] === this) {
  						customInstances.splice(i, 1);
  						break;
  					}
  				}
  
  				if (originalDestroy) {
  					originalDestroy.apply(this, arguments);
  				}
  			};
  
  			// save module to list
  			this.modules[proto.name] = Module;
  		},
  		getInstance: function(element) {
  			return $(element).data(commonOptions.dataKey);
  		},
  		replace: function(elements, moduleName, customOptions) {
  			var self = this,
  				instance;
  
  			if (!commonOptions.styleSheetCreated) {
  				createStyleSheet();
  			}
  
  			$(elements).each(function() {
  				var moduleOptions,
  					element = $(this);
  
  				instance = element.data(commonOptions.dataKey);
  				if (instance) {
  					instance.refresh();
  				} else {
  					if (!moduleName) {
  						$.each(self.modules, function(currentModuleName, module) {
  							if (module.prototype.matchElement.call(module.prototype, element)) {
  								moduleName = currentModuleName;
  								return false;
  							}
  						});
  					}
  					if (moduleName) {
  						moduleOptions = $.extend({ element: element }, customOptions);
  						instance = new self.modules[moduleName](moduleOptions);
  					}
  				}
  			});
  			return instance;
  		},
  		refresh: function(elements) {
  			$(elements).each(function() {
  				var instance = $(this).data(commonOptions.dataKey);
  				if (instance) {
  					instance.refresh();
  				}
  			});
  		},
  		destroy: function(elements) {
  			$(elements).each(function() {
  				var instance = $(this).data(commonOptions.dataKey);
  				if (instance) {
  					instance.destroy();
  				}
  			});
  		},
  		replaceAll: function(context) {
  			var self = this;
  			$.each(this.modules, function(moduleName, module) {
  				$(module.prototype.selector, context).each(function() {
  					if (this.className.indexOf('jcf-ignore') < 0) {
  						self.replace(this, moduleName);
  					}
  				});
  			});
  		},
  		refreshAll: function(context) {
  			if (context) {
  				$.each(this.modules, function(moduleName, module) {
  					$(module.prototype.selector, context).each(function() {
  						var instance = $(this).data(commonOptions.dataKey);
  						if (instance) {
  							instance.refresh();
  						}
  					});
  				});
  			} else {
  				for (var i = customInstances.length - 1; i >= 0; i--) {
  					customInstances[i].refresh();
  				}
  			}
  		},
  		destroyAll: function(context) {
  			if (context) {
  				$.each(this.modules, function(moduleName, module) {
  					$(module.prototype.selector, context).each(function(index, element) {
  						var instance = $(element).data(commonOptions.dataKey);
  						if (instance) {
  							instance.destroy();
  						}
  					});
  				});
  			} else {
  				while (customInstances.length) {
  					customInstances[0].destroy();
  				}
  			}
  		}
  	};
  
  	// always export API to the global window object
  	window.jcf = api;
  
  	return api;
  }));
  
  /*!
   * JavaScript Custom Forms : Scrollbar Module
   *
   * Copyright 2014-2015 PSD2HTML - http://psd2html.com/jcf
   * Released under the MIT license (LICENSE.txt)
   *
   * Version: 1.1.3
   */
  ;(function($, window) {
  	'use strict';
  
  	jcf.addModule({
  		name: 'Scrollable',
  		selector: '.jcf-scrollable',
  		plugins: {
  			ScrollBar: ScrollBar
  		},
  		options: {
  			mouseWheelStep: 150,
  			handleResize: true,
  			alwaysShowScrollbars: false,
  			alwaysPreventMouseWheel: false,
  			scrollAreaStructure: '<div class="jcf-scrollable-wrapper"></div>'
  		},
  		matchElement: function(element) {
  			return element.is('.jcf-scrollable');
  		},
  		init: function() {
  			this.initStructure();
  			this.attachEvents();
  			this.rebuildScrollbars();
  		},
  		initStructure: function() {
  			// prepare structure
  			this.doc = $(document);
  			this.win = $(window);
  			this.realElement = $(this.options.element);
  			this.scrollWrapper = $(this.options.scrollAreaStructure).insertAfter(this.realElement);
  
  			// set initial styles
  			this.scrollWrapper.css('position', 'relative');
  			this.realElement.css('overflow', 'hidden');
  			this.vBarEdge = 0;
  		},
  		attachEvents: function() {
  			// create scrollbars
  			var self = this;
  			this.vBar = new ScrollBar({
  				holder: this.scrollWrapper,
  				vertical: true,
  				onScroll: function(scrollTop) {
  					self.realElement.scrollTop(scrollTop);
  				}
  			});
  			this.hBar = new ScrollBar({
  				holder: this.scrollWrapper,
  				vertical: false,
  				onScroll: function(scrollLeft) {
  					self.realElement.scrollLeft(scrollLeft);
  				}
  			});
  
  			// add event handlers
  			this.realElement.on('scroll', this.onScroll);
  			if (this.options.handleResize) {
  				this.win.on('resize orientationchange load', this.onResize);
  			}
  
  			// add pointer/wheel event handlers
  			this.realElement.on('jcf-mousewheel', this.onMouseWheel);
  			this.realElement.on('jcf-pointerdown', this.onTouchBody);
  		},
  		onScroll: function() {
  			this.redrawScrollbars();
  		},
  		onResize: function() {
  			// do not rebuild scrollbars if form field is in focus
  			if (!$(document.activeElement).is(':input')) {
  				this.rebuildScrollbars();
  			}
  		},
  		onTouchBody: function(e) {
  			if (e.pointerType === 'touch') {
  				this.touchData = {
  					scrollTop: this.realElement.scrollTop(),
  					scrollLeft: this.realElement.scrollLeft(),
  					left: e.pageX,
  					top: e.pageY
  				};
  				this.doc.on({
  					'jcf-pointermove': this.onMoveBody,
  					'jcf-pointerup': this.onReleaseBody
  				});
  			}
  		},
  		onMoveBody: function(e) {
  			var targetScrollTop,
  				targetScrollLeft,
  				verticalScrollAllowed = this.verticalScrollActive,
  				horizontalScrollAllowed = this.horizontalScrollActive;
  
  			if (e.pointerType === 'touch') {
  				targetScrollTop = this.touchData.scrollTop - e.pageY + this.touchData.top;
  				targetScrollLeft = this.touchData.scrollLeft - e.pageX + this.touchData.left;
  
  				// check that scrolling is ended and release outer scrolling
  				if (this.verticalScrollActive && (targetScrollTop < 0 || targetScrollTop > this.vBar.maxValue)) {
  					verticalScrollAllowed = false;
  				}
  				if (this.horizontalScrollActive && (targetScrollLeft < 0 || targetScrollLeft > this.hBar.maxValue)) {
  					horizontalScrollAllowed = false;
  				}
  
  				this.realElement.scrollTop(targetScrollTop);
  				this.realElement.scrollLeft(targetScrollLeft);
  
  				if (verticalScrollAllowed || horizontalScrollAllowed) {
  					e.preventDefault();
  				} else {
  					this.onReleaseBody(e);
  				}
  			}
  		},
  		onReleaseBody: function(e) {
  			if (e.pointerType === 'touch') {
  				delete this.touchData;
  				this.doc.off({
  					'jcf-pointermove': this.onMoveBody,
  					'jcf-pointerup': this.onReleaseBody
  				});
  			}
  		},
  		onMouseWheel: function(e) {
  			var currentScrollTop = this.realElement.scrollTop(),
  				currentScrollLeft = this.realElement.scrollLeft(),
  				maxScrollTop = this.realElement.prop('scrollHeight') - this.embeddedDimensions.innerHeight,
  				maxScrollLeft = this.realElement.prop('scrollWidth') - this.embeddedDimensions.innerWidth,
  				extraLeft, extraTop, preventFlag;
  
  			// check edge cases
  			if (!this.options.alwaysPreventMouseWheel) {
  				if (this.verticalScrollActive && e.deltaY) {
  					if (!(currentScrollTop <= 0 && e.deltaY < 0) && !(currentScrollTop >= maxScrollTop && e.deltaY > 0)) {
  						preventFlag = true;
  					}
  				}
  				if (this.horizontalScrollActive && e.deltaX) {
  					if (!(currentScrollLeft <= 0 && e.deltaX < 0) && !(currentScrollLeft >= maxScrollLeft && e.deltaX > 0)) {
  						preventFlag = true;
  					}
  				}
  				if (!this.verticalScrollActive && !this.horizontalScrollActive) {
  					return;
  				}
  			}
  
  			// prevent default action and scroll item
  			if (preventFlag || this.options.alwaysPreventMouseWheel) {
  				e.preventDefault();
  			} else {
  				return;
  			}
  
  			extraLeft = e.deltaX / 100 * this.options.mouseWheelStep;
  			extraTop = e.deltaY / 100 * this.options.mouseWheelStep;
  
  			this.realElement.scrollTop(currentScrollTop + extraTop);
  			this.realElement.scrollLeft(currentScrollLeft + extraLeft);
  		},
  		setScrollBarEdge: function(edgeSize) {
  			this.vBarEdge = edgeSize || 0;
  			this.redrawScrollbars();
  		},
  		saveElementDimensions: function() {
  			this.savedDimensions = {
  				top: this.realElement.width(),
  				left: this.realElement.height()
  			};
  			return this;
  		},
  		restoreElementDimensions: function() {
  			if (this.savedDimensions) {
  				this.realElement.css({
  					width: this.savedDimensions.width,
  					height: this.savedDimensions.height
  				});
  			}
  			return this;
  		},
  		saveScrollOffsets: function() {
  			this.savedOffsets = {
  				top: this.realElement.scrollTop(),
  				left: this.realElement.scrollLeft()
  			};
  			return this;
  		},
  		restoreScrollOffsets: function() {
  			if (this.savedOffsets) {
  				this.realElement.scrollTop(this.savedOffsets.top);
  				this.realElement.scrollLeft(this.savedOffsets.left);
  			}
  			return this;
  		},
  		getContainerDimensions: function() {
  			// save current styles
  			var desiredDimensions,
  				currentStyles,
  				currentHeight,
  				currentWidth;
  
  			if (this.isModifiedStyles) {
  				desiredDimensions = {
  					width: this.realElement.innerWidth() + this.vBar.getThickness(),
  					height: this.realElement.innerHeight() + this.hBar.getThickness()
  				};
  			} else {
  				// unwrap real element and measure it according to CSS
  				this.saveElementDimensions().saveScrollOffsets();
  				this.realElement.insertAfter(this.scrollWrapper);
  				this.scrollWrapper.detach();
  
  				// measure element
  				currentStyles = this.realElement.prop('style');
  				currentWidth = parseFloat(currentStyles.width);
  				currentHeight = parseFloat(currentStyles.height);
  
  				// reset styles if needed
  				if (this.embeddedDimensions && currentWidth && currentHeight) {
  					this.isModifiedStyles |= (currentWidth !== this.embeddedDimensions.width || currentHeight !== this.embeddedDimensions.height);
  					this.realElement.css({
  						overflow: '',
  						width: '',
  						height: ''
  					});
  				}
  
  				// calculate desired dimensions for real element
  				desiredDimensions = {
  					width: this.realElement.outerWidth(),
  					height: this.realElement.outerHeight()
  				};
  
  				// restore structure and original scroll offsets
  				this.scrollWrapper.insertAfter(this.realElement);
  				this.realElement.css('overflow', 'hidden').prependTo(this.scrollWrapper);
  				this.restoreElementDimensions().restoreScrollOffsets();
  			}
  
  			return desiredDimensions;
  		},
  		getEmbeddedDimensions: function(dimensions) {
  			// handle scrollbars cropping
  			var fakeBarWidth = this.vBar.getThickness(),
  				fakeBarHeight = this.hBar.getThickness(),
  				paddingWidth = this.realElement.outerWidth() - this.realElement.width(),
  				paddingHeight = this.realElement.outerHeight() - this.realElement.height(),
  				resultDimensions;
  
  			if (this.options.alwaysShowScrollbars) {
  				// simply return dimensions without custom scrollbars
  				this.verticalScrollActive = true;
  				this.horizontalScrollActive = true;
  				resultDimensions = {
  					innerWidth: dimensions.width - fakeBarWidth,
  					innerHeight: dimensions.height - fakeBarHeight
  				};
  			} else {
  				// detect when to display each scrollbar
  				this.saveElementDimensions();
  				this.verticalScrollActive = false;
  				this.horizontalScrollActive = false;
  
  				// fill container with full size
  				this.realElement.css({
  					width: dimensions.width - paddingWidth,
  					height: dimensions.height - paddingHeight
  				});
  
  				this.horizontalScrollActive = this.realElement.prop('scrollWidth') > this.containerDimensions.width;
  				this.verticalScrollActive = this.realElement.prop('scrollHeight') > this.containerDimensions.height;
  
  				this.restoreElementDimensions();
  				resultDimensions = {
  					innerWidth: dimensions.width - (this.verticalScrollActive ? fakeBarWidth : 0),
  					innerHeight: dimensions.height - (this.horizontalScrollActive ? fakeBarHeight : 0)
  				};
  			}
  			$.extend(resultDimensions, {
  				width: resultDimensions.innerWidth - paddingWidth,
  				height: resultDimensions.innerHeight - paddingHeight
  			});
  			return resultDimensions;
  		},
  		rebuildScrollbars: function() {
  			// resize wrapper according to real element styles
  			this.containerDimensions = this.getContainerDimensions();
  			this.embeddedDimensions = this.getEmbeddedDimensions(this.containerDimensions);
  
  			// resize wrapper to desired dimensions
  			this.scrollWrapper.css({
  				width: this.containerDimensions.width,
  				height: this.containerDimensions.height
  			});
  
  			// resize element inside wrapper excluding scrollbar size
  			this.realElement.css({
  				overflow: 'hidden',
  				width: this.embeddedDimensions.width,
  				height: this.embeddedDimensions.height
  			});
  
  			// redraw scrollbar offset
  			this.redrawScrollbars();
  		},
  		redrawScrollbars: function() {
  			var viewSize, maxScrollValue;
  
  			// redraw vertical scrollbar
  			if (this.verticalScrollActive) {
  				viewSize = this.vBarEdge ? this.containerDimensions.height - this.vBarEdge : this.embeddedDimensions.innerHeight;
  				maxScrollValue = Math.max(this.realElement.prop('offsetHeight'), this.realElement.prop('scrollHeight')) - this.vBarEdge;
  
  				this.vBar.show().setMaxValue(maxScrollValue - viewSize).setRatio(viewSize / maxScrollValue).setSize(viewSize);
  				this.vBar.setValue(this.realElement.scrollTop());
  			} else {
  				this.vBar.hide();
  			}
  
  			// redraw horizontal scrollbar
  			if (this.horizontalScrollActive) {
  				viewSize = this.embeddedDimensions.innerWidth;
  				maxScrollValue = this.realElement.prop('scrollWidth');
  
  				if (maxScrollValue === viewSize) {
  					this.horizontalScrollActive = false;
  				}
  				this.hBar.show().setMaxValue(maxScrollValue - viewSize).setRatio(viewSize / maxScrollValue).setSize(viewSize);
  				this.hBar.setValue(this.realElement.scrollLeft());
  			} else {
  				this.hBar.hide();
  			}
  
  			// set "touch-action" style rule
  			var touchAction = '';
  			if (this.verticalScrollActive && this.horizontalScrollActive) {
  				touchAction = 'none';
  			} else if (this.verticalScrollActive) {
  				touchAction = 'pan-x';
  			} else if (this.horizontalScrollActive) {
  				touchAction = 'pan-y';
  			}
  			this.realElement.css('touchAction', touchAction);
  		},
  		refresh: function() {
  			this.rebuildScrollbars();
  		},
  		destroy: function() {
  			// remove event listeners
  			this.win.off('resize orientationchange load', this.onResize);
  			this.realElement.off({
  				'jcf-mousewheel': this.onMouseWheel,
  				'jcf-pointerdown': this.onTouchBody
  			});
  			this.doc.off({
  				'jcf-pointermove': this.onMoveBody,
  				'jcf-pointerup': this.onReleaseBody
  			});
  
  			// restore structure
  			this.saveScrollOffsets();
  			this.vBar.destroy();
  			this.hBar.destroy();
  			this.realElement.insertAfter(this.scrollWrapper).css({
  				touchAction: '',
  				overflow: '',
  				width: '',
  				height: ''
  			});
  			this.scrollWrapper.remove();
  			this.restoreScrollOffsets();
  		}
  	});
  
  	// custom scrollbar
  	function ScrollBar(options) {
  		this.options = $.extend({
  			holder: null,
  			vertical: true,
  			inactiveClass: 'jcf-inactive',
  			verticalClass: 'jcf-scrollbar-vertical',
  			horizontalClass: 'jcf-scrollbar-horizontal',
  			scrollbarStructure: '<div class="jcf-scrollbar"><div class="jcf-scrollbar-dec"></div><div class="jcf-scrollbar-slider"><div class="jcf-scrollbar-handle"></div></div><div class="jcf-scrollbar-inc"></div></div>',
  			btnDecSelector: '.jcf-scrollbar-dec',
  			btnIncSelector: '.jcf-scrollbar-inc',
  			sliderSelector: '.jcf-scrollbar-slider',
  			handleSelector: '.jcf-scrollbar-handle',
  			scrollInterval: 300,
  			scrollStep: 400 // px/sec
  		}, options);
  		this.init();
  	}
  	$.extend(ScrollBar.prototype, {
  		init: function() {
  			this.initStructure();
  			this.attachEvents();
  		},
  		initStructure: function() {
  			// define proporties
  			this.doc = $(document);
  			this.isVertical = !!this.options.vertical;
  			this.sizeProperty = this.isVertical ? 'height' : 'width';
  			this.fullSizeProperty = this.isVertical ? 'outerHeight' : 'outerWidth';
  			this.invertedSizeProperty = this.isVertical ? 'width' : 'height';
  			this.thicknessMeasureMethod = 'outer' + this.invertedSizeProperty.charAt(0).toUpperCase() + this.invertedSizeProperty.substr(1);
  			this.offsetProperty = this.isVertical ? 'top' : 'left';
  			this.offsetEventProperty = this.isVertical ? 'pageY' : 'pageX';
  
  			// initialize variables
  			this.value = this.options.value || 0;
  			this.maxValue = this.options.maxValue || 0;
  			this.currentSliderSize = 0;
  			this.handleSize = 0;
  
  			// find elements
  			this.holder = $(this.options.holder);
  			this.scrollbar = $(this.options.scrollbarStructure).appendTo(this.holder);
  			this.btnDec = this.scrollbar.find(this.options.btnDecSelector);
  			this.btnInc = this.scrollbar.find(this.options.btnIncSelector);
  			this.slider = this.scrollbar.find(this.options.sliderSelector);
  			this.handle = this.slider.find(this.options.handleSelector);
  
  			// set initial styles
  			this.scrollbar.addClass(this.isVertical ? this.options.verticalClass : this.options.horizontalClass).css({
  				touchAction: this.isVertical ? 'pan-x' : 'pan-y',
  				position: 'absolute'
  			});
  			this.slider.css({
  				position: 'relative'
  			});
  			this.handle.css({
  				touchAction: 'none',
  				position: 'absolute'
  			});
  		},
  		attachEvents: function() {
  			this.bindHandlers();
  			this.handle.on('jcf-pointerdown', this.onHandlePress);
  			this.slider.add(this.btnDec).add(this.btnInc).on('jcf-pointerdown', this.onButtonPress);
  		},
  		onHandlePress: function(e) {
  			if (e.pointerType === 'mouse' && e.button > 1) {
  				return;
  			} else {
  				e.preventDefault();
  				this.handleDragActive = true;
  				this.sliderOffset = this.slider.offset()[this.offsetProperty];
  				this.innerHandleOffset = e[this.offsetEventProperty] - this.handle.offset()[this.offsetProperty];
  
  				this.doc.on('jcf-pointermove', this.onHandleDrag);
  				this.doc.on('jcf-pointerup', this.onHandleRelease);
  			}
  		},
  		onHandleDrag: function(e) {
  			e.preventDefault();
  			this.calcOffset = e[this.offsetEventProperty] - this.sliderOffset - this.innerHandleOffset;
  			this.setValue(this.calcOffset / (this.currentSliderSize - this.handleSize) * this.maxValue);
  			this.triggerScrollEvent(this.value);
  		},
  		onHandleRelease: function() {
  			this.handleDragActive = false;
  			this.doc.off('jcf-pointermove', this.onHandleDrag);
  			this.doc.off('jcf-pointerup', this.onHandleRelease);
  		},
  		onButtonPress: function(e) {
  			var direction, clickOffset;
  			if (e.pointerType === 'mouse' && e.button > 1) {
  				return;
  			} else {
  				e.preventDefault();
  				if (!this.handleDragActive) {
  					if (this.slider.is(e.currentTarget)) {
  						// slider pressed
  						direction = this.handle.offset()[this.offsetProperty] > e[this.offsetEventProperty] ? -1 : 1;
  						clickOffset = e[this.offsetEventProperty] - this.slider.offset()[this.offsetProperty];
  						this.startPageScrolling(direction, clickOffset);
  					} else {
  						// scrollbar buttons pressed
  						direction = this.btnDec.is(e.currentTarget) ? -1 : 1;
  						this.startSmoothScrolling(direction);
  					}
  					this.doc.on('jcf-pointerup', this.onButtonRelease);
  				}
  			}
  		},
  		onButtonRelease: function() {
  			this.stopPageScrolling();
  			this.stopSmoothScrolling();
  			this.doc.off('jcf-pointerup', this.onButtonRelease);
  		},
  		startPageScrolling: function(direction, clickOffset) {
  			var self = this,
  				stepValue = direction * self.currentSize;
  
  			// limit checker
  			var isFinishedScrolling = function() {
  				var handleTop = (self.value / self.maxValue) * (self.currentSliderSize - self.handleSize);
  
  				if (direction > 0) {
  					return handleTop + self.handleSize >= clickOffset;
  				} else {
  					return handleTop <= clickOffset;
  				}
  			};
  
  			// scroll by page when track is pressed
  			var doPageScroll = function() {
  				self.value += stepValue;
  				self.setValue(self.value);
  				self.triggerScrollEvent(self.value);
  
  				if (isFinishedScrolling()) {
  					clearInterval(self.pageScrollTimer);
  				}
  			};
  
  			// start scrolling
  			this.pageScrollTimer = setInterval(doPageScroll, this.options.scrollInterval);
  			doPageScroll();
  		},
  		stopPageScrolling: function() {
  			clearInterval(this.pageScrollTimer);
  		},
  		startSmoothScrolling: function(direction) {
  			var self = this, dt;
  			this.stopSmoothScrolling();
  
  			// simple animation functions
  			var raf = window.requestAnimationFrame || function(func) {
  				setTimeout(func, 16);
  			};
  			var getTimestamp = function() {
  				return Date.now ? Date.now() : new Date().getTime();
  			};
  
  			// set animation limit
  			var isFinishedScrolling = function() {
  				if (direction > 0) {
  					return self.value >= self.maxValue;
  				} else {
  					return self.value <= 0;
  				}
  			};
  
  			// animation step
  			var doScrollAnimation = function() {
  				var stepValue = (getTimestamp() - dt) / 1000 * self.options.scrollStep;
  
  				if (self.smoothScrollActive) {
  					self.value += stepValue * direction;
  					self.setValue(self.value);
  					self.triggerScrollEvent(self.value);
  
  					if (!isFinishedScrolling()) {
  						dt = getTimestamp();
  						raf(doScrollAnimation);
  					}
  				}
  			};
  
  			// start animation
  			self.smoothScrollActive = true;
  			dt = getTimestamp();
  			raf(doScrollAnimation);
  		},
  		stopSmoothScrolling: function() {
  			this.smoothScrollActive = false;
  		},
  		triggerScrollEvent: function(scrollValue) {
  			if (this.options.onScroll) {
  				this.options.onScroll(scrollValue);
  			}
  		},
  		getThickness: function() {
  			return this.scrollbar[this.thicknessMeasureMethod]();
  		},
  		setSize: function(size) {
  			// resize scrollbar
  			var btnDecSize = this.btnDec[this.fullSizeProperty](),
  				btnIncSize = this.btnInc[this.fullSizeProperty]();
  
  			// resize slider
  			this.currentSize = size;
  			this.currentSliderSize = size - btnDecSize - btnIncSize;
  			this.scrollbar.css(this.sizeProperty, size);
  			this.slider.css(this.sizeProperty, this.currentSliderSize);
  			this.currentSliderSize = this.slider[this.sizeProperty]();
  
  			// resize handle
  			this.handleSize = Math.round(this.currentSliderSize * this.ratio);
  			this.handle.css(this.sizeProperty, this.handleSize);
  			this.handleSize = this.handle[this.fullSizeProperty]();
  
  			return this;
  		},
  		setRatio: function(ratio) {
  			this.ratio = ratio;
  			return this;
  		},
  		setMaxValue: function(maxValue) {
  			this.maxValue = maxValue;
  			this.setValue(Math.min(this.value, this.maxValue));
  			return this;
  		},
  		setValue: function(value) {
  			this.value = value;
  			if (this.value < 0) {
  				this.value = 0;
  			} else if (this.value > this.maxValue) {
  				this.value = this.maxValue;
  			}
  			this.refresh();
  		},
  		setPosition: function(styles) {
  			this.scrollbar.css(styles);
  			return this;
  		},
  		hide: function() {
  			this.scrollbar.detach();
  			return this;
  		},
  		show: function() {
  			this.scrollbar.appendTo(this.holder);
  			return this;
  		},
  		refresh: function() {
  			// recalculate handle position
  			if (this.value === 0 || this.maxValue === 0) {
  				this.calcOffset = 0;
  			} else {
  				this.calcOffset = (this.value / this.maxValue) * (this.currentSliderSize - this.handleSize);
  			}
  			this.handle.css(this.offsetProperty, this.calcOffset);
  
  			// toggle inactive classes
  			this.btnDec.toggleClass(this.options.inactiveClass, this.value === 0);
  			this.btnInc.toggleClass(this.options.inactiveClass, this.value === this.maxValue);
  			this.scrollbar.toggleClass(this.options.inactiveClass, this.maxValue === 0);
  		},
  		destroy: function() {
  			// remove event handlers and scrollbar block itself
  			this.btnDec.add(this.btnInc).off('jcf-pointerdown', this.onButtonPress);
  			this.handle.off('jcf-pointerdown', this.onHandlePress);
  			this.doc.off('jcf-pointermove', this.onHandleDrag);
  			this.doc.off('jcf-pointerup', this.onHandleRelease);
  			this.doc.off('jcf-pointerup', this.onButtonRelease);
  			this.stopSmoothScrolling();
  			this.stopPageScrolling();
  			this.scrollbar.remove();
  		}
  	});
  
  }(jQuery, this));
  
  /*!
   * JavaScript Custom Forms : Number Module
   *
   * Copyright 2014-2015 PSD2HTML - http://psd2html.com/jcf
   * Released under the MIT license (LICENSE.txt)
   *
   * Version: 1.1.3
   */
  ;(function($) {
  	'use strict';
  
  	jcf.addModule({
  		name: 'Number',
  		selector: 'input[type="number"]',
  		options: {
  			realElementClass: 'jcf-real-element',
  			fakeStructure: '<span class="jcf-number"><span class="jcf-btn-inc"></span><span class="jcf-btn-dec"></span></span>',
  			btnIncSelector: '.jcf-btn-inc',
  			btnDecSelector: '.jcf-btn-dec',
  			pressInterval: 150
  		},
  		matchElement: function(element) {
  			return element.is(this.selector);
  		},
  		init: function() {
  			this.initStructure();
  			this.attachEvents();
  			this.refresh();
  		},
  		initStructure: function() {
  			this.page = $('html');
  			this.realElement = $(this.options.element).addClass(this.options.realElementClass);
  			this.fakeElement = $(this.options.fakeStructure).insertBefore(this.realElement).prepend(this.realElement);
  			this.btnDec = this.fakeElement.find(this.options.btnDecSelector);
  			this.btnInc = this.fakeElement.find(this.options.btnIncSelector);
  
  			// set initial values
  			this.initialValue = parseFloat(this.realElement.val()) || 0;
  			this.minValue = parseFloat(this.realElement.attr('min'));
  			this.maxValue = parseFloat(this.realElement.attr('max'));
  			this.stepValue = parseFloat(this.realElement.attr('step')) || 1;
  
  			// check attribute values
  			this.minValue = isNaN(this.minValue) ? -Infinity : this.minValue;
  			this.maxValue = isNaN(this.maxValue) ? Infinity : this.maxValue;
  
  			// handle range
  			if (isFinite(this.maxValue)) {
  				this.maxValue -= (this.maxValue - this.minValue) % this.stepValue;
  			}
  		},
  		attachEvents: function() {
  			this.realElement.on({
  				focus: this.onFocus
  			});
  			this.btnDec.add(this.btnInc).on('jcf-pointerdown', this.onBtnPress);
  		},
  		onBtnPress: function(e) {
  			var self = this,
  				increment;
  
  			if (!this.realElement.is(':disabled')) {
  				increment = this.btnInc.is(e.currentTarget);
  
  				self.step(increment);
  				clearInterval(this.stepTimer);
  				this.stepTimer = setInterval(function() {
  					self.step(increment);
  				}, this.options.pressInterval);
  
  				this.page.on('jcf-pointerup', this.onBtnRelease);
  			}
  		},
  		onBtnRelease: function() {
  			clearInterval(this.stepTimer);
  			this.page.off('jcf-pointerup', this.onBtnRelease);
  		},
  		onFocus: function() {
  			this.fakeElement.addClass(this.options.focusClass);
  			this.realElement.on({
  				blur: this.onBlur,
  				keydown: this.onKeyPress
  			});
  		},
  		onBlur: function() {
  			this.fakeElement.removeClass(this.options.focusClass);
  			this.realElement.off({
  				blur: this.onBlur,
  				keydown: this.onKeyPress
  			});
  		},
  		onKeyPress: function(e) {
  			if (e.which === 38 || e.which === 40) {
  				e.preventDefault();
  				this.step(e.which === 38);
  			}
  		},
  		step: function(increment) {
  			var originalValue = parseFloat(this.realElement.val()),
  				newValue = originalValue || 0,
  				addValue = this.stepValue * (increment ? 1 : -1),
  				edgeNumber = isFinite(this.minValue) ? this.minValue : this.initialValue - Math.abs(newValue * this.stepValue),
  				diff = Math.abs(edgeNumber - newValue) % this.stepValue;
  
  			// handle step diff
  			if (diff) {
  				if (increment) {
  					newValue += addValue - diff;
  				} else {
  					newValue -= diff;
  				}
  			} else {
  				newValue += addValue;
  			}
  
  			// handle min/max limits
  			if (newValue < this.minValue) {
  				newValue = this.minValue;
  			} else if (newValue > this.maxValue) {
  				newValue = this.maxValue;
  			}
  
  			// update value in real input if its changed
  			if (newValue !== originalValue) {
  				this.realElement.val(newValue).trigger('change');
  				this.refresh();
  			}
  		},
  		refresh: function() {
  			var isDisabled = this.realElement.is(':disabled'),
  				currentValue = parseFloat(this.realElement.val());
  
  			// handle disabled state
  			this.fakeElement.toggleClass(this.options.disabledClass, isDisabled);
  
  			// refresh button classes
  			this.btnDec.toggleClass(this.options.disabledClass, currentValue === this.minValue);
  			this.btnInc.toggleClass(this.options.disabledClass, currentValue === this.maxValue);
  		},
  		destroy: function() {
  			// restore original structure
  			this.realElement.removeClass(this.options.realElementClass).insertBefore(this.fakeElement);
  			this.fakeElement.remove();
  			clearInterval(this.stepTimer);
  
  			// remove event handlers
  			this.page.off('jcf-pointerup', this.onBtnRelease);
  			this.realElement.off({
  				keydown: this.onKeyPress,
  				focus: this.onFocus,
  				blur: this.onBlur
  			});
  		}
  	});
  
  }(jQuery));
  
  /*!
   * JavaScript Custom Forms : Range Module
   *
   * Copyright 2014-2015 PSD2HTML - http://psd2html.com/jcf
   * Released under the MIT license (LICENSE.txt)
   *
   * Version: 1.1.3
   */
  ;(function($) {
  	'use strict';
  
  	jcf.addModule({
  		name: 'Range',
  		selector: 'input[type="range"]',
  		options: {
  			realElementClass: 'jcf-real-element',
  			fakeStructure: '<span class="jcf-range"><span class="jcf-range-wrapper"><span class="jcf-range-track"><span class="jcf-range-handle"></span></span></span></span>',
  			dataListMark: '<span class="jcf-range-mark"></span>',
  			rangeDisplayWrapper: '<span class="jcf-range-display-wrapper"></span>',
  			rangeDisplay: '<span class="jcf-range-display"></span>',
  			handleSelector: '.jcf-range-handle',
  			trackSelector: '.jcf-range-track',
  			activeHandleClass: 'jcf-active-handle',
  			verticalClass: 'jcf-vertical',
  			orientation: 'horizontal',
  			range: false, // or "min", "max", "all"
  			dragHandleCenter: true,
  			snapToMarks: true,
  			snapRadius: 5
  		},
  		matchElement: function(element) {
  			return element.is(this.selector);
  		},
  		init: function() {
  			this.initStructure();
  			this.attachEvents();
  			this.refresh();
  		},
  		initStructure: function() {
  			this.page = $('html');
  			this.realElement = $(this.options.element).addClass(this.options.hiddenClass);
  			this.fakeElement = $(this.options.fakeStructure).insertBefore(this.realElement).prepend(this.realElement);
  			this.track = this.fakeElement.find(this.options.trackSelector);
  			this.trackHolder = this.track.parent();
  			this.handle = this.fakeElement.find(this.options.handleSelector);
  			this.createdHandleCount = 0;
  			this.activeDragHandleIndex = 0;
  			this.isMultiple = this.realElement.prop('multiple') || typeof this.realElement.attr('multiple') === 'string';
  			this.values = this.isMultiple ? this.realElement.attr('value').split(',') : [this.realElement.val()];
  			this.handleCount = this.isMultiple ? this.values.length : 1;
  
  			// create range display
  			this.rangeDisplayWrapper = $(this.options.rangeDisplayWrapper).insertBefore(this.track);
  			if (this.options.range === 'min' || this.options.range === 'all') {
  				this.rangeMin = $(this.options.rangeDisplay).addClass('jcf-range-min').prependTo(this.rangeDisplayWrapper);
  			}
  			if (this.options.range === 'max' || this.options.range === 'all') {
  				this.rangeMax = $(this.options.rangeDisplay).addClass('jcf-range-max').prependTo(this.rangeDisplayWrapper);
  			}
  
  			// clone handles if needed
  			while (this.createdHandleCount < this.handleCount) {
  				this.createdHandleCount++;
  				this.handle.clone().addClass('jcf-index-' + this.createdHandleCount).insertBefore(this.handle);
  
  				// create mid ranges
  				if (this.createdHandleCount > 1) {
  					if (!this.rangeMid) {
  						this.rangeMid = $();
  					}
  					this.rangeMid = this.rangeMid.add($(this.options.rangeDisplay).addClass('jcf-range-mid').prependTo(this.rangeDisplayWrapper));
  				}
  			}
  
  			// grab all handles
  			this.handle.detach();
  			this.handle = null;
  			this.handles = this.fakeElement.find(this.options.handleSelector);
  			this.handles.eq(0).addClass(this.options.activeHandleClass);
  
  			// handle orientation
  			this.isVertical = (this.options.orientation === 'vertical');
  			this.directionProperty = this.isVertical ? 'top' : 'left';
  			this.offsetProperty = this.isVertical ? 'bottom' : 'left';
  			this.eventProperty = this.isVertical ? 'pageY' : 'pageX';
  			this.sizeProperty = this.isVertical ? 'height' : 'width';
  			this.sizeMethod = this.isVertical ? 'innerHeight' : 'innerWidth';
  			this.fakeElement.css('touchAction', this.isVertical ? 'pan-x' : 'pan-y');
  			if (this.isVertical) {
  				this.fakeElement.addClass(this.options.verticalClass);
  			}
  
  			// set initial values
  			this.minValue = parseFloat(this.realElement.attr('min'));
  			this.maxValue = parseFloat(this.realElement.attr('max'));
  			this.stepValue = parseFloat(this.realElement.attr('step')) || 1;
  
  			// check attribute values
  			this.minValue = isNaN(this.minValue) ? 0 : this.minValue;
  			this.maxValue = isNaN(this.maxValue) ? 100 : this.maxValue;
  
  			// handle range
  			if (this.stepValue !== 1) {
  				this.maxValue -= (this.maxValue - this.minValue) % this.stepValue;
  			}
  			this.stepsCount = (this.maxValue - this.minValue) / this.stepValue;
  			this.createDataList();
  		},
  		attachEvents: function() {
  			this.realElement.on({
  				focus: this.onFocus
  			});
  			this.trackHolder.on('jcf-pointerdown', this.onTrackPress);
  			this.handles.on('jcf-pointerdown', this.onHandlePress);
  		},
  		createDataList: function() {
  			var self = this,
  				dataValues = [],
  				dataListId = this.realElement.attr('list');
  
  			if (dataListId) {
  				$('#' + dataListId).find('option').each(function() {
  					var itemValue = parseFloat(this.value || this.innerHTML),
  						mark, markOffset;
  
  					if (!isNaN(itemValue)) {
  						markOffset = self.valueToOffset(itemValue);
  						dataValues.push({
  							value: itemValue,
  							offset: markOffset
  						});
  						mark = $(self.options.dataListMark).text(itemValue).attr({
  							'data-mark-value': itemValue
  						}).css(self.offsetProperty, markOffset + '%').appendTo(self.track);
  					}
  				});
  				if (dataValues.length) {
  					self.dataValues = dataValues;
  				}
  			}
  		},
  		getDragHandleRange: function(handleIndex) {
  			// calculate range for slider with multiple handles
  			var minStep = -Infinity,
  				maxStep = Infinity;
  
  			if (handleIndex > 0) {
  				minStep = this.valueToStepIndex(this.values[handleIndex - 1]);
  			}
  			if (handleIndex < this.handleCount - 1) {
  				maxStep = this.valueToStepIndex(this.values[handleIndex + 1]);
  			}
  
  			return {
  				minStepIndex: minStep,
  				maxStepIndex: maxStep
  			};
  		},
  		getNearestHandle: function(percent) {
  			// handle vertical sliders
  			if (this.isVertical) {
  				percent = 1 - percent;
  			}
  
  			// detect closest handle when track is pressed
  			var closestHandle = this.handles.eq(0),
  				closestDistance = Infinity,
  				self = this;
  
  			if (this.handleCount > 1) {
  				this.handles.each(function() {
  					var handleOffset = parseFloat(this.style[self.offsetProperty]) / 100,
  						handleDistance = Math.abs(handleOffset - percent);
  
  					if (handleDistance < closestDistance) {
  						closestDistance = handleDistance;
  						closestHandle = $(this);
  					}
  				});
  			}
  			return closestHandle;
  		},
  		onTrackPress: function(e) {
  			var trackSize, trackOffset, innerOffset;
  
  			e.preventDefault();
  			if (!this.realElement.is(':disabled') && !this.activeDragHandle) {
  				trackSize = this.track[this.sizeMethod]();
  				trackOffset = this.track.offset()[this.directionProperty];
  				this.activeDragHandle = this.getNearestHandle((e[this.eventProperty] - trackOffset) / this.trackHolder[this.sizeMethod]());
  				this.activeDragHandleIndex = this.handles.index(this.activeDragHandle);
  				this.handles.removeClass(this.options.activeHandleClass).eq(this.activeDragHandleIndex).addClass(this.options.activeHandleClass);
  				innerOffset = this.activeDragHandle[this.sizeMethod]() / 2;
  
  				this.dragData = {
  					trackSize: trackSize,
  					innerOffset: innerOffset,
  					trackOffset: trackOffset,
  					min: trackOffset,
  					max: trackOffset + trackSize
  				};
  				this.page.on({
  					'jcf-pointermove': this.onHandleMove,
  					'jcf-pointerup': this.onHandleRelease
  				});
  
  				if (e.pointerType === 'mouse') {
  					this.realElement.focus();
  				}
  
  				this.onHandleMove(e);
  			}
  		},
  		onHandlePress: function(e) {
  			var trackSize, trackOffset, innerOffset;
  
  			e.preventDefault();
  			if (!this.realElement.is(':disabled') && !this.activeDragHandle) {
  				this.activeDragHandle = $(e.currentTarget);
  				this.activeDragHandleIndex = this.handles.index(this.activeDragHandle);
  				this.handles.removeClass(this.options.activeHandleClass).eq(this.activeDragHandleIndex).addClass(this.options.activeHandleClass);
  				trackSize = this.track[this.sizeMethod]();
  				trackOffset = this.track.offset()[this.directionProperty];
  				innerOffset = this.options.dragHandleCenter ? this.activeDragHandle[this.sizeMethod]() / 2 : e[this.eventProperty] - this.handle.offset()[this.directionProperty];
  
  				this.dragData = {
  					trackSize: trackSize,
  					innerOffset: innerOffset,
  					trackOffset: trackOffset,
  					min: trackOffset,
  					max: trackOffset + trackSize
  				};
  				this.page.on({
  					'jcf-pointermove': this.onHandleMove,
  					'jcf-pointerup': this.onHandleRelease
  				});
  
  				if (e.pointerType === 'mouse') {
  					this.realElement.focus();
  				}
  			}
  		},
  		onHandleMove: function(e) {
  			var self = this,
  				newOffset, dragPercent, stepIndex, valuePercent, handleDragRange;
  
  			// calculate offset
  			if (this.isVertical) {
  				newOffset = this.dragData.max + (this.dragData.min - e[this.eventProperty]) - this.dragData.innerOffset;
  			} else {
  				newOffset = e[this.eventProperty] - this.dragData.innerOffset;
  			}
  
  			// fit in range
  			if (newOffset < this.dragData.min) {
  				newOffset = this.dragData.min;
  			} else if (newOffset > this.dragData.max) {
  				newOffset = this.dragData.max;
  			}
  
  			e.preventDefault();
  			if (this.options.snapToMarks && this.dataValues) {
  				// snap handle to marks
  				var dragOffset = newOffset - this.dragData.trackOffset;
  				dragPercent = (newOffset - this.dragData.trackOffset) / this.dragData.trackSize * 100;
  
  				$.each(this.dataValues, function(index, item) {
  					var markOffset = item.offset / 100 * self.dragData.trackSize,
  						markMin = markOffset - self.options.snapRadius,
  						markMax = markOffset + self.options.snapRadius;
  
  					if (dragOffset >= markMin && dragOffset <= markMax) {
  						dragPercent = item.offset;
  						return false;
  					}
  				});
  			} else {
  				// snap handle to steps
  				dragPercent = (newOffset - this.dragData.trackOffset) / this.dragData.trackSize * 100;
  			}
  
  			// move handle only in range
  			stepIndex = Math.round(dragPercent * this.stepsCount / 100);
  			if (this.handleCount > 1) {
  				handleDragRange = this.getDragHandleRange(this.activeDragHandleIndex);
  				if (stepIndex < handleDragRange.minStepIndex) {
  					stepIndex = Math.max(handleDragRange.minStepIndex, stepIndex);
  				} else if (stepIndex > handleDragRange.maxStepIndex) {
  					stepIndex = Math.min(handleDragRange.maxStepIndex, stepIndex);
  				}
  			}
  			valuePercent = stepIndex * (100 / this.stepsCount);
  
  			if (this.dragData.stepIndex !== stepIndex) {
  				this.dragData.stepIndex = stepIndex;
  				this.dragData.offset = valuePercent;
  				this.activeDragHandle.css(this.offsetProperty, this.dragData.offset + '%');
  
  				// update value(s) and trigger "input" event
  				this.values[this.activeDragHandleIndex] = '' + this.stepIndexToValue(stepIndex);
  				this.updateValues();
  				this.realElement.trigger('input');
  			}
  		},
  		onHandleRelease: function() {
  			var newValue;
  			if (typeof this.dragData.offset === 'number') {
  				newValue = this.stepIndexToValue(this.dragData.stepIndex);
  				this.realElement.val(newValue).trigger('change');
  			}
  
  			this.page.off({
  				'jcf-pointermove': this.onHandleMove,
  				'jcf-pointerup': this.onHandleRelease
  			});
  			delete this.activeDragHandle;
  			delete this.dragData;
  		},
  		onFocus: function() {
  			if (!this.fakeElement.hasClass(this.options.focusClass)) {
  				this.fakeElement.addClass(this.options.focusClass);
  				this.realElement.on({
  					blur: this.onBlur,
  					keydown: this.onKeyPress
  				});
  			}
  		},
  		onBlur: function() {
  			this.fakeElement.removeClass(this.options.focusClass);
  			this.realElement.off({
  				blur: this.onBlur,
  				keydown: this.onKeyPress
  			});
  		},
  		onKeyPress: function(e) {
  			var incValue = (e.which === 38 || e.which === 39),
  				decValue = (e.which === 37 || e.which === 40);
  
  			// handle TAB key in slider with multiple handles
  			if (e.which === 9 && this.handleCount > 1) {
  				if (e.shiftKey && this.activeDragHandleIndex > 0) {
  					this.activeDragHandleIndex--;
  				} else if (!e.shiftKey && this.activeDragHandleIndex < this.handleCount - 1) {
  					this.activeDragHandleIndex++;
  				} else {
  					return;
  				}
  				e.preventDefault();
  				this.handles.removeClass(this.options.activeHandleClass).eq(this.activeDragHandleIndex).addClass(this.options.activeHandleClass);
  			}
  
  			// handle cursor keys
  			if (decValue || incValue) {
  				e.preventDefault();
  				this.step(incValue ? this.stepValue : -this.stepValue);
  			}
  		},
  		updateValues: function() {
  			var value = this.values.join(',');
  			if (this.values.length > 1) {
  				this.realElement.prop('valueLow', this.values[0]);
  				this.realElement.prop('valueHigh', this.values[this.values.length - 1]);
  				this.realElement.val(value);
  
  				// if browser does not accept multiple values set only one
  				if (this.realElement.val() !== value) {
  					this.realElement.val(this.values[this.values.length - 1]);
  				}
  			} else {
  				this.realElement.val(value);
  			}
  
  			this.updateRanges();
  		},
  		updateRanges: function() {
  			// update display ranges
  			var self = this,
  				handle;
  
  			if (this.rangeMin) {
  				handle = this.handles[0];
  				this.rangeMin.css(this.offsetProperty, 0).css(this.sizeProperty, handle.style[this.offsetProperty]);
  			}
  			if (this.rangeMax) {
  				handle = this.handles[this.handles.length - 1];
  				this.rangeMax.css(this.offsetProperty, handle.style[this.offsetProperty]).css(this.sizeProperty, 100 - parseFloat(handle.style[this.offsetProperty]) + '%');
  			}
  			if (this.rangeMid) {
  				this.handles.each(function(index, curHandle) {
  					var prevHandle, midBox;
  					if (index > 0) {
  						prevHandle = self.handles[index - 1];
  						midBox = self.rangeMid[index - 1];
  						midBox.style[self.offsetProperty] = prevHandle.style[self.offsetProperty];
  						midBox.style[self.sizeProperty] = parseFloat(curHandle.style[self.offsetProperty]) - parseFloat(prevHandle.style[self.offsetProperty]) + '%';
  					}
  				});
  			}
  		},
  		step: function(changeValue) {
  			var originalValue = parseFloat(this.values[this.activeDragHandleIndex || 0]),
  				newValue = originalValue,
  				minValue = this.minValue,
  				maxValue = this.maxValue;
  
  			if (isNaN(originalValue)) {
  				newValue = 0;
  			}
  
  			newValue += changeValue;
  
  			if (this.handleCount > 1) {
  				if (this.activeDragHandleIndex > 0) {
  					minValue = parseFloat(this.values[this.activeDragHandleIndex - 1]);
  				}
  				if (this.activeDragHandleIndex < this.handleCount - 1) {
  					maxValue = parseFloat(this.values[this.activeDragHandleIndex + 1]);
  				}
  			}
  
  			if (newValue > maxValue) {
  				newValue = maxValue;
  			} else if (newValue < minValue) {
  				newValue = minValue;
  			}
  
  			if (newValue !== originalValue) {
  				this.values[this.activeDragHandleIndex || 0] = '' + newValue;
  				this.updateValues();
  				this.realElement.trigger('input').trigger('change');
  				this.setSliderValue(this.values);
  			}
  		},
  		valueToStepIndex: function(value) {
  			return (value - this.minValue) / this.stepValue;
  		},
  		stepIndexToValue: function(stepIndex) {
  			return this.minValue + this.stepValue * stepIndex;
  		},
  		valueToOffset: function(value) {
  			var range = this.maxValue - this.minValue,
  				percent = (value - this.minValue) / range;
  
  			return percent * 100;
  		},
  		getSliderValue: function() {
  			return $.map(this.values, function(value) {
  				return parseFloat(value) || 0;
  			});
  		},
  		setSliderValue: function(values) {
  			// set handle position accordion according to value
  			var self = this;
  			this.handles.each(function(index, handle) {
  				handle.style[self.offsetProperty] = self.valueToOffset(values[index]) + '%';
  			});
  		},
  		refresh: function() {
  			// handle disabled state
  			var isDisabled = this.realElement.is(':disabled');
  			this.fakeElement.toggleClass(this.options.disabledClass, isDisabled);
  
  			// refresh handle position according to current value
  			this.setSliderValue(this.getSliderValue());
  			this.updateRanges();
  		},
  		destroy: function() {
  			this.realElement.removeClass(this.options.hiddenClass).insertBefore(this.fakeElement);
  			this.fakeElement.remove();
  
  			this.realElement.off({
  				keydown: this.onKeyPress,
  				focus: this.onFocus,
  				blur: this.onBlur
  			});
  		}
  	});
  
  }(jQuery));
  
  
  /*
   * jQuery SlideMenu plugin
   */
  ;(function($){
  	function AjaxPopup(options){
  		this.options = $.extend({
  			holder: null,
  			button: '.btn-more',
  			holderBox: 'body',
  			ajaxHold: '#ajax-holder',
  			appendToBody: false,
  			attr: 'href',
  			animSpeed: 500
  		}, options);
  
  		this.init();
  	}
  	AjaxPopup.prototype = {
  		init: function(){
  			this.findElements();
  			this.makeCallback('onInit', this);
  			this.attachEvents();
  		},
  		findElements: function(){
  			this.holder = jQuery(this.options.holder);
  			this.button = this.holder.find(this.options.button);
  			this.ajaxHold = this.holder.find(this.options.ajaxHold);
  
  		},
  		attachEvents: function(){
  			var self = this;
  			this.clickHandler = function(e){
  				e.preventDefault();
  				var attr = self.button.attr(self.options.attr);
  				if(attr != '#'){
  					e.preventDefault();
  					self.ajaxLoad(attr).done(function(data){
  						var content = jQuery(data).filter('.blogs-block').css({opacity: 0});
  						var btnAjax = jQuery(data).filter('.btn-load');
  
  						if(self.options.appendToBody) content.appendTo(jQuery(self.options.holderBox));
  						else content.appendTo(self.ajaxHold);
  
  						if(btnAjax.length) self.button.attr('href', btnAjax.attr('href')); 
  						else self.button.hide();
  					
  						content.stop().animate({opacity: 1}, self.options.animSpeed);
  						self.makeCallback('onChange', self);
  					});
  				}
  			};
  			this.button.on('click', this.clickHandler);
  		},
  		ajaxLoad: function(url){
  			var d = jQuery.Deferred();
  			jQuery.ajax({
  				url: url,
  				type: 'get',
  				cache: false,
  				dataType: "html",
  				success: function(data){
  					d.resolve(data);
  				},
  				error: function(jqXHR, textStatus, errorThrown){
  					d.reject(jqXHR, textStatus, errorThrown);
  				}
  			});
  			return d;
  		},
  		makeCallback: function(name) {
  			if(typeof this.options[name] === 'function') {
  				var args = Array.prototype.slice.call(arguments);
  					args.shift();
  					this.options[name].apply(this, args);
  				}
  			}
  		};
  
  	$.fn.ajaxPopup = function(options){
  		return this.each(function(){
  			$(this).data('AjaxPopup', new AjaxPopup($.extend(options, {holder:this})));
  		});
  	};
  })(jQuery);
  
  /*
   * jQuery Accordion plugin
   */
  ;(function($){
  	$.fn.slideAccordion = function(opt){
  		// default options
  		var options = $.extend({
  			addClassBeforeAnimation: false,
  			allowClickWhenExpanded: false,
  			activeClass:'active',
  			opener:'.opener',
  			slider:'.slide',
  			animSpeed: 300,
  			collapsible:true,
  			event:'click'
  		},opt);
  
  		return this.each(function(){
  			// options
  			var accordion = $(this);
  			var items = accordion.find(':has('+options.slider+')');
  
  			items.each(function(){
  				var item = $(this);
  				var opener = item.find(options.opener);
  				var slider = item.find(options.slider);
  				opener.bind(options.event, function(e){
  					if(!slider.is(':animated')) {
  						if(item.hasClass(options.activeClass)) {
  							if(options.allowClickWhenExpanded) {
  								return;
  							} else if(options.collapsible) {
  								slider.slideUp(options.animSpeed, function(){
  									hideSlide(slider);
  									item.removeClass(options.activeClass);
  								});
  							}
  						} else {
  							// show active
  							var levelItems = item.siblings('.'+options.activeClass);
  							var sliderElements = levelItems.find(options.slider);
  							item.addClass(options.activeClass);
  							showSlide(slider).hide().slideDown(options.animSpeed);
  						
  							// collapse others
  							sliderElements.slideUp(options.animSpeed, function(){
  								levelItems.removeClass(options.activeClass);
  								hideSlide(sliderElements);
  							});
  						}
  					}
  					e.preventDefault();
  				});
  				if(item.hasClass(options.activeClass)) showSlide(slider); else hideSlide(slider);
  			});
  		});
  	};
  
  	// accordion slide visibility
  	var showSlide = function(slide) {
  		return slide.css({position:'', top: '', left: '', width: '' });
  	};
  	var hideSlide = function(slide) {
  		return slide.show().css({position:'absolute', top: -9999, left: -9999, width: slide.width() });
  	};
  }(jQuery));
  
  /*
   * jQuery <marquee> plugin
   */
  ;(function($){
  	function Marquee(options) {
  		this.options = $.extend({
  			holder: null,
  			handleFlexible: true,
  			pauseOnHover: true,
  			hoverClass: 'hover',
  			direction: 'left',
  			cloneClass: 'cloned',
  			mask: null,
  			line: '>*',
  			items: '>*',
  			animSpeed: 10, // px per second
  			initialDelay: 0
  		}, options);
  		this.init();
  	}
  	Marquee.prototype = {
  		init: function() {
  			if(this.options.holder) {
  				this.initStructure();
  				this.attachEvents();
  			}
  		},
  		initStructure: function() {
  			// find elements
  			this.holder = $(this.options.holder);
  			this.mask = this.options.mask ? this.holder.find(this.options.mask) : this.holder,
  			this.line = this.mask.find(this.options.line),
  			this.items = this.line.find(this.options.items).css({'float':'left'});
  			this.direction = (this.options.direction === 'left') ? -1 : 1;
  			this.recalculateDimensions();
  
  			// prepare structure
  			this.cloneItems = this.items.clone().addClass(this.options.cloneClass).appendTo(this.line);
  			if(this.itemWidth >= this.maskWidth) {
  				this.activeLine = true;
  				this.offset = (this.direction === -1 ? 0 : this.maxOffset);
  			} else {
  				this.activeLine = false;
  				this.cloneItems.hide();
  				this.offset = 0;
  			}
  			this.line.css({
  				width: this.itemWidth * 2,
  				marginLeft: this.offset
  			});
  		},
  		attachEvents: function() {
  			// flexible layout handling
  			var self = this;
  			if(this.options.handleFlexible) {
  				this.resizeHandler = function() {
  					self.recalculateDimensions();
  					if(self.itemWidth < self.maskWidth) {
  						self.activeLine = false;
  						self.cloneItems.hide();
  						self.stopMoving();
  						self.offset = 0;
  						self.line.css({marginLeft: self.offset});
  					} else {
  						self.activeLine = true;
  						self.cloneItems.show();
  						self.startMoving();
  					}
  				};
  				$(window).bind('resize orientationchange', this.resizeHandler);
  			}
  
  			// pause on hover
  			if(this.options.pauseOnHover) {
  				this.hoverHandler = function() {
  					self.stopMoving();
  					self.holder.addClass(self.options.hoverClass);
  				};
  				this.leaveHandler = function() {
  					self.startMoving();
  					self.holder.removeClass(self.options.hoverClass);
  				};
  				this.holder.bind({ mouseenter: this.hoverHandler, mouseleave: this.leaveHandler });
  			}
  
  			// initial delay
  			setTimeout(function(){
  				self.initialFlag = true;
  				self.startMoving();
  			}, self.options.initialDelay || 1);
  		},
  		recalculateDimensions: function() {
  			// calculate block dimensions
  			var self = this;
  			this.maskWidth = this.mask.width();
  			this.itemWidth = 1;
  			this.items.each(function(){
  				self.itemWidth += $(this).outerWidth(true);
  			});
  			this.maxOffset = -this.itemWidth;
  		},
  		startMoving: function() {
  			// start animation
  			var self = this;
  			if(self.activeLine && self.initialFlag) {
  				var targetOffset = (self.direction < 0 ? self.maxOffset : 0);
  
  				self.offset = parseInt(self.line.css('marginLeft'), 10) || 0;
  				self.line.stop().animate({
  					marginLeft: targetOffset
  				}, {
  					duration: Math.abs(1000 * (self.offset - targetOffset) / self.options.animSpeed),
  					easing: 'linear',
  					complete: function() {
  						self.offset = (self.direction < 0 ? 0 : self.maxOffset);
  						self.line.css({marginLeft: self.offset});
  						self.startMoving();
  					}
  				});
  			}
  		},
  		stopMoving: function() {
  			// stop animation
  			this.line.stop();
  		},
  		destroy: function() {
  			this.stopMoving();
  			this.cloneItems.remove();
  			this.items.css({'float':''});
  			this.line.css({marginLeft:'',width:''});
  			this.holder.removeClass(this.options.hoverClass);
  			this.holder.unbind('mouseenter', this.hoverHandler);
  			this.holder.unbind('mouseleave', this.leaveHandler);
  			$(window).unbind('resize orientationchange', this.resizeHandler);
  		}
  	};
  
  	// jQuery plugin interface
  	$.fn.marquee = function(opt) {
  		return this.each(function() {
  			jQuery(this).data('Marquee', new Marquee($.extend(opt, {holder: this})));
  		});
  	};
  }(jQuery));
  
  // set same height for blocks
  function setSameHeight(opt) {
  	// default options
  	var options = {
  		holder: null,
  		skipClass: 'same-height-ignore',
  		leftEdgeClass: 'same-height-left',
  		rightEdgeClass: 'same-height-right',
  		elements: '>*',
  		flexible: false,
  		multiLine: false,
  		useMinHeight: false,
  		biggestHeight: false
  	};
  	for(var p in opt) {
  		if(opt.hasOwnProperty(p)) {
  			options[p] = opt[p];
  		}
  	}
  
  	// init script
  	if(options.holder) {
  		var holders = lib.queryElementsBySelector(options.holder);
  		lib.each(holders, function(ind, curHolder){
  			var curElements = [], resizeTimer, postResizeTimer;
  			var tmpElements = lib.queryElementsBySelector(options.elements, curHolder);
  
  			// get resize elements
  			for(var i = 0; i < tmpElements.length; i++) {
  				if(!lib.hasClass(tmpElements[i], options.skipClass)) {
  					curElements.push(tmpElements[i]);
  				}
  			}
  			if(!curElements.length) return;
  
  			// resize handler
  			function doResize() {
  				for(var i = 0; i < curElements.length; i++) {
  					curElements[i].style[options.useMinHeight && SameHeight.supportMinHeight ? 'minHeight' : 'height'] = '';
  				}
  
  				if(options.multiLine) {
  					// resize elements row by row
  					SameHeight.resizeElementsByRows(curElements, options);
  				} else {
  					// resize elements by holder
  					SameHeight.setSize(curElements, curHolder, options);
  				}
  			}
  			doResize();
  
  			// handle flexible layout / font resize
  			function flexibleResizeHandler() {
  				clearTimeout(resizeTimer);
  				resizeTimer = setTimeout(function(){
  					doResize();
  					clearTimeout(postResizeTimer);
  					postResizeTimer = setTimeout(doResize, 100);
  				},1);
  			}
  			if(options.flexible) {
  				addEvent(window, 'resize', flexibleResizeHandler);
  				addEvent(window, 'orientationchange', flexibleResizeHandler);
  				FontResizeEvent.onChange(flexibleResizeHandler);
  			}
  			// handle complete page load including images and fonts
  			addEvent(window, 'load', flexibleResizeHandler);
  		});
  	}
  
  	// event handler helper functions
  	function addEvent(object, event, handler) {
  		if(object.addEventListener) object.addEventListener(event, handler, false);
  		else if(object.attachEvent) object.attachEvent('on'+event, handler);
  	}
  }
  
  /*
   * SameHeight helper module
   */
  SameHeight = {
  	supportMinHeight: typeof document.documentElement.style.maxHeight !== 'undefined', // detect css min-height support
  	setSize: function(boxes, parent, options) {
  		var calcHeight, holderHeight = typeof parent === 'number' ? parent : this.getHeight(parent);
  
  		for(var i = 0; i < boxes.length; i++) {
  			var box = boxes[i];
  			var depthDiffHeight = 0;
  			var isBorderBox = this.isBorderBox(box);
  			lib.removeClass(box, options.leftEdgeClass);
  			lib.removeClass(box, options.rightEdgeClass);
  
  			if(typeof parent != 'number') {
  				var tmpParent = box.parentNode;
  				while(tmpParent != parent) {
  					depthDiffHeight += this.getOuterHeight(tmpParent) - this.getHeight(tmpParent);
  					tmpParent = tmpParent.parentNode;
  				}
  			}
  			calcHeight = holderHeight - depthDiffHeight;
  			calcHeight -= isBorderBox ? 0 : this.getOuterHeight(box) - this.getHeight(box);
  			if(calcHeight > 0) {
  				box.style[options.useMinHeight && this.supportMinHeight ? 'minHeight' : 'height'] = calcHeight + 'px';
  			}
  		}
  
  		lib.addClass(boxes[0], options.leftEdgeClass);
  		lib.addClass(boxes[boxes.length - 1], options.rightEdgeClass);
  		return calcHeight;
  	},
  	getOffset: function(obj) {
  		if (obj.getBoundingClientRect) {
  			var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
  			var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  			var clientLeft = document.documentElement.clientLeft || document.body.clientLeft || 0;
  			var clientTop = document.documentElement.clientTop || document.body.clientTop || 0;
  			return {
  				top:Math.round(obj.getBoundingClientRect().top + scrollTop - clientTop),
  				left:Math.round(obj.getBoundingClientRect().left + scrollLeft - clientLeft)
  			};
  		} else {
  			var posLeft = 0, posTop = 0;
  			while (obj.offsetParent) {posLeft += obj.offsetLeft; posTop += obj.offsetTop; obj = obj.offsetParent;}
  			return {top:posTop,left:posLeft};
  		}
  	},
  	getStyle: function(el, prop) {
  		if (document.defaultView && document.defaultView.getComputedStyle) {
  			return document.defaultView.getComputedStyle(el, null)[prop];
  		} else if (el.currentStyle) {
  			return el.currentStyle[prop];
  		} else {
  			return el.style[prop];
  		}
  	},
  	getStylesTotal: function(obj) {
  		var sum = 0;
  		for(var i = 1; i < arguments.length; i++) {
  			var val = parseFloat(this.getStyle(obj, arguments[i]));
  			if(!isNaN(val)) {
  				sum += val;
  			}
  		}
  		return sum;
  	},
  	getHeight: function(obj) {
  		return obj.offsetHeight - this.getStylesTotal(obj, 'borderTopWidth', 'borderBottomWidth', 'paddingTop', 'paddingBottom');
  	},
  	getOuterHeight: function(obj) {
  		return obj.offsetHeight;
  	},
  	isBorderBox: function(obj) {
  		var f = this.getStyle, styleValue = f(obj, 'boxSizing') || f(obj, 'WebkitBoxSizing') || f(obj, 'MozBoxSizing');
  		return styleValue === 'border-box';
  	},
  	resizeElementsByRows: function(boxes, options) {
  		var currentRow = [], maxHeight, maxCalcHeight = 0, firstOffset = this.getOffset(boxes[0]).top;
  		for(var i = 0; i < boxes.length; i++) {
  			if(this.getOffset(boxes[i]).top === firstOffset) {
  				currentRow.push(boxes[i]);
  			} else {
  				maxHeight = this.getMaxHeight(currentRow);
  				maxCalcHeight = Math.max(maxCalcHeight, this.setSize(currentRow, maxHeight, options));
  				firstOffset = this.getOffset(boxes[i]).top;
  				currentRow = [boxes[i]];
  			}
  		}
  		if(currentRow.length) {
  			maxHeight = this.getMaxHeight(currentRow);
  			maxCalcHeight = Math.max(maxCalcHeight, this.setSize(currentRow, maxHeight, options));
  		}
  		if(options.biggestHeight) {
  			for(i = 0; i < boxes.length; i++) {
  				boxes[i].style[options.useMinHeight && this.supportMinHeight ? 'minHeight' : 'height'] = maxCalcHeight + 'px';
  			}
  		}
  	},
  	getMaxHeight: function(boxes) {
  		var maxHeight = 0;
  		for(var i = 0; i < boxes.length; i++) {
  			maxHeight = Math.max(maxHeight, this.getOuterHeight(boxes[i]));
  		}
  		return maxHeight;
  	}
  };
  
  /*
   * FontResize Event
   */
  FontResizeEvent = (function(window,document){
  	var randomID = 'font-resize-frame-' + Math.floor(Math.random() * 1000);
  	var resizeFrame = document.createElement('iframe');
  	resizeFrame.id = randomID; resizeFrame.className = 'font-resize-helper';
  	resizeFrame.style.cssText = 'position:absolute;width:100em;height:10px;top:-9999px;left:-9999px;border-width:0';
  
  	// wait for page load
  	function onPageReady() {
  		document.body.appendChild(resizeFrame);
  
  		// use native IE resize event if possible
  		if (/MSIE (6|7|8)/.test(navigator.userAgent)) {
  			resizeFrame.onresize = function() {
  				window.FontResizeEvent.trigger(resizeFrame.offsetWidth / 100);
  			};
  		}
  		// use script inside the iframe to detect resize for other browsers
  		else {
  			var doc = resizeFrame.contentWindow.document;
  			doc.open();
  			doc.write('<scri' + 'pt>window.onload = function(){var em = parent.document.getElementById("' + randomID + '");window.onresize = function(){if(parent.FontResizeEvent){parent.FontResizeEvent.trigger(em.offsetWidth / 100);}}};</scri' + 'pt>');
  			doc.close();
  		}
  	}
  	if(window.addEventListener) window.addEventListener('load', onPageReady, false);
  	else if(window.attachEvent) window.attachEvent('onload', onPageReady);
  
  	// public interface
  	var callbacks = [];
  	return {
  		onChange: function(f) {
  			if(typeof f === 'function') {
  				callbacks.push(f);
  			}
  		},
  		trigger: function(em) {
  			for(var i = 0; i < callbacks.length; i++) {
  				callbacks[i](em);
  			}
  		}
  	};
  }(this, document));
  
  /*
   * Utility module
   */
  lib = {
  	hasClass: function(el,cls) {
  		return el && el.className ? el.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')) : false;
  	},
  	addClass: function(el,cls) {
  		if (el && !this.hasClass(el,cls)) el.className += " "+cls;
  	},
  	removeClass: function(el,cls) {
  		if (el && this.hasClass(el,cls)) {el.className=el.className.replace(new RegExp('(\\s|^)'+cls+'(\\s|$)'),' ');}
  	},
  	extend: function(obj) {
  		for(var i = 1; i < arguments.length; i++) {
  			for(var p in arguments[i]) {
  				if(arguments[i].hasOwnProperty(p)) {
  					obj[p] = arguments[i][p];
  				}
  			}
  		}
  		return obj;
  	},
  	each: function(obj, callback) {
  		var property, len;
  		if(typeof obj.length === 'number') {
  			for(property = 0, len = obj.length; property < len; property++) {
  				if(callback.call(obj[property], property, obj[property]) === false) {
  					break;
  				}
  			}
  		} else {
  			for(property in obj) {
  				if(obj.hasOwnProperty(property)) {
  					if(callback.call(obj[property], property, obj[property]) === false) {
  						break;
  					}
  				}
  			}
  		}
  	},
  	event: (function() {
  		var fixEvent = function(e) {
  			e = e || window.event;
  			if(e.isFixed) return e; else e.isFixed = true;
  			if(!e.target) e.target = e.srcElement;
  			e.preventDefault = e.preventDefault || function() {this.returnValue = false;};
  			e.stopPropagation = e.stopPropagation || function() {this.cancelBubble = true;};
  			return e;
  		};
  		return {
  			add: function(elem, event, handler) {
  				if(!elem.events) {
  					elem.events = {};
  					elem.handle = function(e) {
  						var ret, handlers = elem.events[e.type];
  						e = fixEvent(e);
  						for(var i = 0, len = handlers.length; i < len; i++) {
  							if(handlers[i]) {
  								ret = handlers[i].call(elem, e);
  								if(ret === false) {
  									e.preventDefault();
  									e.stopPropagation();
  								}
  							}
  						}
  					};
  				}
  				if(!elem.events[event]) {
  					elem.events[event] = [];
  					if(elem.addEventListener) elem.addEventListener(event, elem.handle, false);
  					else if(elem.attachEvent) elem.attachEvent('on'+event, elem.handle);
  				}
  				elem.events[event].push(handler);
  			},
  			remove: function(elem, event, handler) {
  				var handlers = elem.events[event];
  				for(var i = handlers.length - 1; i >= 0; i--) {
  					if(handlers[i] === handler) {
  						handlers.splice(i,1);
  					}
  				}
  				if(!handlers.length) {
  					delete elem.events[event];
  					if(elem.removeEventListener) elem.removeEventListener(event, elem.handle, false);
  					else if(elem.detachEvent) elem.detachEvent('on'+event, elem.handle);
  				}
  			}
  		};
  	}()),
  	queryElementsBySelector: function(selector, scope) {
  		scope = scope || document;
  		if(!selector) return [];
  		if(selector === '>*') return scope.children;
  		if(typeof document.querySelectorAll === 'function') {
  			return scope.querySelectorAll(selector);
  		}
  		var selectors = selector.split(',');
  		var resultList = [];
  		for(var s = 0; s < selectors.length; s++) {
  			var currentContext = [scope || document];
  			var tokens = selectors[s].replace(/^\s+/,'').replace(/\s+$/,'').split(' ');
  			for (var i = 0; i < tokens.length; i++) {
  				token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');
  				if (token.indexOf('#') > -1) {
  					var bits = token.split('#'), tagName = bits[0], id = bits[1];
  					var element = document.getElementById(id);
  					if (element && tagName && element.nodeName.toLowerCase() != tagName) {
  						return [];
  					}
  					currentContext = element ? [element] : [];
  					continue;
  				}
  				if (token.indexOf('.') > -1) {
  					var bits = token.split('.'), tagName = bits[0] || '*', className = bits[1], found = [], foundCount = 0;
  					for (var h = 0; h < currentContext.length; h++) {
  						var elements;
  						if (tagName == '*') {
  							elements = currentContext[h].getElementsByTagName('*');
  						} else {
  							elements = currentContext[h].getElementsByTagName(tagName);
  						}
  						for (var j = 0; j < elements.length; j++) {
  							found[foundCount++] = elements[j];
  						}
  					}
  					currentContext = [];
  					var currentContextIndex = 0;
  					for (var k = 0; k < found.length; k++) {
  						if (found[k].className && found[k].className.match(new RegExp('(\\s|^)'+className+'(\\s|$)'))) {
  							currentContext[currentContextIndex++] = found[k];
  						}
  					}
  					continue;
  				}
  				if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
  					var tagName = RegExp.$1 || '*', attrName = RegExp.$2, attrOperator = RegExp.$3, attrValue = RegExp.$4;
  					if(attrName.toLowerCase() == 'for' && this.browser.msie && this.browser.version < 8) {
  						attrName = 'htmlFor';
  					}
  					var found = [], foundCount = 0;
  					for (var h = 0; h < currentContext.length; h++) {
  						var elements;
  						if (tagName == '*') {
  							elements = currentContext[h].getElementsByTagName('*');
  						} else {
  							elements = currentContext[h].getElementsByTagName(tagName);
  						}
  						for (var j = 0; elements[j]; j++) {
  							found[foundCount++] = elements[j];
  						}
  					}
  					currentContext = [];
  					var currentContextIndex = 0, checkFunction;
  					switch (attrOperator) {
  						case '=': checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue) }; break;
  						case '~': checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('(\\s|^)'+attrValue+'(\\s|$)'))) }; break;
  						case '|': checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))) }; break;
  						case '^': checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0) }; break;
  						case '$': checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length) }; break;
  						case '*': checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1) }; break;
  						default : checkFunction = function(e) { return e.getAttribute(attrName) };
  					}
  					currentContext = [];
  					var currentContextIndex = 0;
  					for (var k = 0; k < found.length; k++) {
  						if (checkFunction(found[k])) {
  							currentContext[currentContextIndex++] = found[k];
  						}
  					}
  					continue;
  				}
  				tagName = token;
  				var found = [], foundCount = 0;
  				for (var h = 0; h < currentContext.length; h++) {
  					var elements = currentContext[h].getElementsByTagName(tagName);
  					for (var j = 0; j < elements.length; j++) {
  						found[foundCount++] = elements[j];
  					}
  				}
  				currentContext = found;
  			}
  			resultList = [].concat(resultList,currentContext);
  		}
  		return resultList;
  	},
  	trim: function (str) {
  		return str.replace(/^\s+/, '').replace(/\s+$/, '');
  	},
  	bind: function(f, scope, forceArgs){
  		return function() {return f.apply(scope, typeof forceArgs !== 'undefined' ? [forceArgs] : arguments);};
  	}
  };
  
  // DOM ready handler
  function bindReady(handler){
  	var called = false;
  	var ready = function() {
  		if (called) return;
  		called = true;
  		handler();
  	};
  	if (document.addEventListener) {
  		document.addEventListener('DOMContentLoaded', ready, false);
  	} else if (document.attachEvent) {
  		if (document.documentElement.doScroll && window == window.top) {
  			var tryScroll = function(){
  				if (called) return;
  				if (!document.body) return;
  				try {
  					document.documentElement.doScroll('left');
  					ready();
  				} catch(e) {
  					setTimeout(tryScroll, 0);
  				}
  			};
  			tryScroll();
  		}
  		document.attachEvent('onreadystatechange', function(){
  			if (document.readyState === 'complete') {
  				ready();
  			}
  		});
  	}
  	if (window.addEventListener) window.addEventListener('load', ready, false);
  	else if (window.attachEvent) window.attachEvent('onload', ready);
  }
  
  
  /*
   * jQuery Tabs plugin
   */
  ;(function($){
  	$.fn.contentTabs = function(o){
  		// default options
  		var options = $.extend({
  			activeClass:'active',
  			addToParent:false,
  			autoHeight:false,
  			autoRotate:false,
  			checkHash:false,
  			animSpeed:400,
  			switchTime:3000,
  			effect: 'none', // "fade", "slide"
  			tabLinks:'a',
  			attrib:'href',
  			event:'click'
  		},o);
  
  		return this.each(function(){
  			var tabset = $(this), tabs = $();
  			var tabLinks = tabset.find(options.tabLinks);
  			var tabLinksParents = tabLinks.parent();
  			var prevActiveLink = tabLinks.eq(0), currentTab, animating;
  			var tabHolder;
  
  			// handle location hash
  			if(options.checkHash && tabLinks.filter('[' + options.attrib + '="' + location.hash + '"]').length) {
  				(options.addToParent ? tabLinksParents : tabLinks).removeClass(options.activeClass);
  				setTimeout(function() {
  					window.scrollTo(0,0);
  				},1);
  			}
  
  			// init tabLinks
  			tabLinks.each(function(){
  				var link = $(this);
  				var href = link.attr(options.attrib);
  				var parent = link.parent();
  				href = href.substr(href.lastIndexOf('#'));
  
  				// get elements
  				var tab = $(href).hide().addClass(tabHiddenClass);
  				tabs = tabs.add(tab);
  				link.data('cparent', parent);
  				link.data('ctab', tab);
  
  				// find tab holder
  				if(!tabHolder && tab.length) {
  					tabHolder = tab.parent();
  				}
  
  				// show only active tab
  				var classOwner = options.addToParent ? parent : link;
  				if(classOwner.hasClass(options.activeClass) || (options.checkHash && location.hash === href)) {
  					classOwner.addClass(options.activeClass);
  					prevActiveLink = link; currentTab = tab;
  					tab.removeClass(tabHiddenClass).width('');
  					contentTabsEffect[options.effect].show({tab:tab, fast:true});
  				} else {
  					var tabWidth = tab.width();
  					if(tabWidth) {
  						tab.width(tabWidth);
  					}
  					tab.addClass(tabHiddenClass);
  				}
  
  				// event handler
  				link.bind(options.event, function(e){
  					if(link != prevActiveLink && !animating) {
  						switchTab(prevActiveLink, link);
  						prevActiveLink = link;
  					}
  				});
  				if(options.attrib === 'href') {
  					link.bind('click', function(e){
  						e.preventDefault();
  					});
  				}
  			});
  
  			// tab switch function
  			function switchTab(oldLink, newLink) {
  				animating = true;
  				var oldTab = oldLink.data('ctab');
  				var newTab = newLink.data('ctab');
  				prevActiveLink = newLink;
  				currentTab = newTab;
  
  				// refresh pagination links
  				(options.addToParent ? tabLinksParents : tabLinks).removeClass(options.activeClass);
  				(options.addToParent ? newLink.data('cparent') : newLink).addClass(options.activeClass);
  
  				// hide old tab
  				resizeHolder(oldTab, true);
  				contentTabsEffect[options.effect].hide({
  					speed: options.animSpeed,
  					tab:oldTab,
  					complete: function() {
  						// show current tab
  						resizeHolder(newTab.removeClass(tabHiddenClass).width(''));
  						contentTabsEffect[options.effect].show({
  							speed: options.animSpeed,
  							tab:newTab,
  							complete: function() {
  								if(!oldTab.is(newTab)) {
  									oldTab.width(oldTab.width()).addClass(tabHiddenClass);
  								}
  								animating = false;
  								resizeHolder(newTab, false);
  								autoRotate();
  								$(window).trigger('resize');
  							}
  						});
  					}
  				});
  			}
  
  			// holder auto height
  			function resizeHolder(block, state) {
  				var curBlock = block && block.length ? block : currentTab;
  				if(options.autoHeight && curBlock) {
  					tabHolder.stop();
  					if(state === false) {
  						tabHolder.css({height:''});
  					} else {
  						var origStyles = curBlock.attr('style');
  						curBlock.show().css({width:curBlock.width()});
  						var tabHeight = curBlock.outerHeight(true);
  						if(!origStyles) curBlock.removeAttr('style'); else curBlock.attr('style', origStyles);
  						if(state === true) {
  							tabHolder.css({height: tabHeight});
  						} else {
  							tabHolder.animate({height: tabHeight}, {duration: options.animSpeed});
  						}
  					}
  				}
  			}
  			if(options.autoHeight) {
  				$(window).bind('resize orientationchange', function(){
  					tabs.not(currentTab).removeClass(tabHiddenClass).show().each(function(){
  						var tab = jQuery(this), tabWidth = tab.css({width:''}).width();
  						if(tabWidth) {
  							tab.width(tabWidth);
  						}
  					}).hide().addClass(tabHiddenClass);
  
  					resizeHolder(currentTab, false);
  				});
  			}
  
  			// autorotation handling
  			var rotationTimer;
  			function nextTab() {
  				var activeItem = (options.addToParent ? tabLinksParents : tabLinks).filter('.' + options.activeClass);
  				var activeIndex = (options.addToParent ? tabLinksParents : tabLinks).index(activeItem);
  				var newLink = tabLinks.eq(activeIndex < tabLinks.length - 1 ? activeIndex + 1 : 0);
  				prevActiveLink = tabLinks.eq(activeIndex);
  				switchTab(prevActiveLink, newLink);
  			}
  			function autoRotate() {
  				if(options.autoRotate && tabLinks.length > 1) {
  					clearTimeout(rotationTimer);
  					rotationTimer = setTimeout(function() {
  						if(!animating) {
  							nextTab();
  						} else {
  							autoRotate();
  						}
  					}, options.switchTime);
  				}
  			}
  			autoRotate();
  		});
  	};
  
  	// add stylesheet for tabs on DOMReady
  	var tabHiddenClass = 'js-tab-hidden';
  	(function() {
  		var tabStyleSheet = $('<style type="text/css">')[0];
  		var tabStyleRule = '.'+tabHiddenClass;
  		tabStyleRule += '{position:absolute !important;left:-9999px !important;top:-9999px !important;display:block !important}';
  		if (tabStyleSheet.styleSheet) {
  			tabStyleSheet.styleSheet.cssText = tabStyleRule;
  		} else {
  			tabStyleSheet.appendChild(document.createTextNode(tabStyleRule));
  		}
  		$('head').append(tabStyleSheet);
  	}());
  
  	// tab switch effects
  	var contentTabsEffect = {
  		none: {
  			show: function(o) {
  				o.tab.css({display:'block'});
  				if(o.complete) o.complete();
  			},
  			hide: function(o) {
  				o.tab.css({display:'none'});
  				if(o.complete) o.complete();
  			}
  		},
  		fade: {
  			show: function(o) {
  				if(o.fast) o.speed = 1;
  				o.tab.fadeIn(o.speed);
  				if(o.complete) setTimeout(o.complete, o.speed);
  			},
  			hide: function(o) {
  				if(o.fast) o.speed = 1;
  				o.tab.fadeOut(o.speed);
  				if(o.complete) setTimeout(o.complete, o.speed);
  			}
  		},
  		slide: {
  			show: function(o) {
  				var tabHeight = o.tab.show().css({width:o.tab.width()}).outerHeight(true);
  				var tmpWrap = $('<div class="effect-div">').insertBefore(o.tab).append(o.tab);
  				tmpWrap.css({width:'100%', overflow:'hidden', position:'relative'}); o.tab.css({marginTop:-tabHeight,display:'block'});
  				if(o.fast) o.speed = 1;
  				o.tab.animate({marginTop: 0}, {duration: o.speed, complete: function(){
  					o.tab.css({marginTop: '', width: ''}).insertBefore(tmpWrap);
  					tmpWrap.remove();
  					if(o.complete) o.complete();
  				}});
  			},
  			hide: function(o) {
  				var tabHeight = o.tab.show().css({width:o.tab.width()}).outerHeight(true);
  				var tmpWrap = $('<div class="effect-div">').insertBefore(o.tab).append(o.tab);
  				tmpWrap.css({width:'100%', overflow:'hidden', position:'relative'});
  
  				if(o.fast) o.speed = 1;
  				o.tab.animate({marginTop: -tabHeight}, {duration: o.speed, complete: function(){
  					o.tab.css({display:'none', marginTop:'', width:''}).insertBefore(tmpWrap);
  					tmpWrap.remove();
  					if(o.complete) o.complete();
  				}});
  			}
  		}
  	};
  }(jQuery));
  
  
  /*!
   * JavaScript Custom Forms : Select Module
   *
   * Copyright 2014 PSD2HTML (http://psd2html.com)
   * Released under the MIT license (LICENSE.txt)
   * 
   * Version: 1.0.0
   */
  ;(function($, window) {
  	'use strict';
  
  	jcf.addModule({
  		name: 'Select',
  		selector: 'select',
  		options: {
  			element: null
  		},
  		plugins: {
  			ListBox: ListBox,
  			ComboBox: ComboBox,
  			SelectList: SelectList
  		},
  		matchElement: function(element) {
  			return element.is('select');
  		},
  		init: function() {
  			this.element = $(this.options.element);
  			this.createInstance();
  		},
  		isListBox: function() {
  			return this.element.is('[size]:not([jcf-size]), [multiple]');
  		},
  		createInstance: function() {
  			if(this.instance) {
  				this.instance.destroy();
  			}
  			if(this.isListBox()) {
  				this.instance = new ListBox(this.options);
  			} else {
  				this.instance = new ComboBox(this.options);
  			}
  		},
  		refresh: function() {
  			var typeMismatch = (this.isListBox() && this.instance instanceof ComboBox) ||
  								(!this.isListBox() && this.instance instanceof ListBox);
  
  			if(typeMismatch) {
  				this.createInstance();
  			} else {
  				this.instance.refresh();
  			}
  		},
  		destroy: function() {
  			this.instance.destroy();
  		}
  	});
  
  	// combobox module
  	function ComboBox(options) {
  		this.options = $.extend({
  			wrapNative: true,
  			wrapNativeOnMobile: true,
  			fakeDropInBody: true,
  			useCustomScroll: true,
  			flipDropToFit: true,
  			maxVisibleItems: 10,
  			fakeAreaStructure: '<span class="jcf-select"><span class="jcf-select-text"></span><span class="jcf-select-opener"></span></span>',
  			fakeDropStructure: '<div class="jcf-select-drop"><div class="jcf-select-drop-content"></div></div>',
  			optionClassPrefix: 'jcf-option-',
  			selectClassPrefix: 'jcf-select-',
  			dropContentSelector: '.jcf-select-drop-content',
  			selectTextSelector: '.jcf-select-text',
  			dropActiveClass: 'jcf-drop-active',
  			flipDropClass: 'jcf-drop-flipped'
  		}, options);
  		this.init();
  	}
  	$.extend(ComboBox.prototype, {
  		init: function(options) {
  			this.initStructure();
  			this.bindHandlers();
  			this.attachEvents();
  			this.refresh();
  		},
  		initStructure: function() {
  			// prepare structure
  			this.win = $(window);
  			this.doc = $(document);
  			this.realElement = $(this.options.element);
  			this.fakeElement = $(this.options.fakeAreaStructure).insertAfter(this.realElement);
  			this.selectTextContainer = this.fakeElement.find(this.options.selectTextSelector);
  			this.selectText = $('<span></span>').appendTo(this.selectTextContainer);
  			makeUnselectable(this.fakeElement);
  
  			// copy classes from original select
  			this.fakeElement.addClass(getPrefixedClasses(this.realElement.prop('className'), this.options.selectClassPrefix));
  
  			// detect device type and dropdown behavior
  			if(this.options.isMobileDevice && this.options.wrapNativeOnMobile && !this.options.wrapNative) {
  				this.options.wrapNative = true;
  			}
  
  			if(this.options.wrapNative) {
  				// wrap native select inside fake block
  				this.realElement.prependTo(this.fakeElement).css({
  					position: 'absolute',
  					height: '100%',
  					width: '100%'
  				}).addClass(this.options.resetAppearanceClass);
  			} else {
  				// just hide native select
  				this.realElement.addClass(this.options.hiddenClass);
  				this.fakeElement.attr('title', this.realElement.attr('title'));
  				this.fakeDropTarget = this.options.fakeDropInBody ? $('body') : this.fakeElement;
  			}
  		},
  		attachEvents: function() {
  			// delayed refresh handler
  			var self = this;
  			this.delayedRefresh = function() {
  				setTimeout(function() {
  					self.refresh();
  					if(self.list) {
  						self.list.refresh();
  					}
  				}, 1);
  			};
  
  			// native dropdown event handlers
  			if(this.options.wrapNative) {
  				this.realElement.on({
  					focus: this.onFocus,
  					change: this.onChange,
  					click: this.onChange,
  					keydown: this.onChange
  				});
  			} else {
  				// custom dropdown event handlers
  				this.realElement.on({
  					focus: this.onFocus,
  					change: this.onChange,
  					keydown: this.onKeyDown
  				});
  				this.fakeElement.on({
  					'jcf-pointerdown': this.onSelectAreaPress
  				});
  			}
  		},
  		onKeyDown: function(e) {
  			if(e.which === 13) {
  				this.toggleDropdown();
  			} else {
  				this.delayedRefresh();
  			}
  		},
  		onChange: function() {
  			this.refresh();
  		},
  		onFocus: function() {
  			if(!this.pressedFlag || !this.focusedFlag) {
  				this.fakeElement.addClass(this.options.focusClass);
  				this.realElement.on('blur', this.onBlur);
  				this.toggleListMode(true);
  				this.focusedFlag = true;
  			}
  		},
  		onBlur: function() {
  			if(!this.pressedFlag) {
  				this.fakeElement.removeClass(this.options.focusClass);
  				this.realElement.off('blur', this.onBlur);
  				this.toggleListMode(false);
  				this.focusedFlag = false;
  			}
  		},
  		onResize: function() {
  			if(this.dropActive) {
  				this.hideDropdown();
  			}
  		},
  		onSelectDropPress: function() {
  			this.pressedFlag = true;	
  		},
  		onSelectDropRelease: function(e, pointerEvent) {
  			this.pressedFlag = false;
  			if(pointerEvent.pointerType === 'mouse') {
  				this.realElement.focus();
  			}
  		},
  		onSelectAreaPress: function(e) {
  			// skip click if drop inside fake element or real select is disabled
  			var dropClickedInsideFakeElement = !this.options.fakeDropInBody && $(e.target).closest(this.dropdown).length;
  			if(dropClickedInsideFakeElement || e.button > 1 || this.realElement.is(':disabled')) {
  				return;
  			}
  
  			// toggle dropdown visibility
  			this.toggleDropdown();
  
  			// misc handlers
  			if(!this.focusedFlag) {
  				if(e.pointerType === 'mouse') {
  					this.realElement.focus();
  				} else {
  					this.onFocus(e);
  				}
  			}
  			this.pressedFlag = true;
  			this.fakeElement.addClass(this.options.pressedClass);
  			this.doc.on('jcf-pointerup', this.onSelectAreaRelease);
  		},
  		onSelectAreaRelease: function(e) {
  			if(this.focusedFlag && e.pointerType === 'mouse') {
  				this.realElement.focus();
  			}
  			this.pressedFlag = false;
  			this.fakeElement.removeClass(this.options.pressedClass);
  			this.doc.off('jcf-pointerup', this.onSelectAreaRelease);
  		},
  		onOutsideClick: function(e) {
  			var target = $(e.target),
  				clickedInsideSelect = target.closest(this.fakeElement).length || target.closest(this.dropdown).length;
  
  			if(!clickedInsideSelect) {
  				this.hideDropdown();
  			}
  		},
  		onSelect: function() {
  			this.hideDropdown();
  			this.refresh();
  			this.fireNativeEvent(this.realElement, 'change');
  		},
  		toggleListMode: function(state) {
  			if(!this.options.wrapNative) {
  				if(state) {
  					// temporary change select to list to avoid appearing of native dropdown
  					this.realElement.attr({
  						size: 4,
  						'jcf-size': ''
  					});
  				} else {
  					// restore select from list mode to dropdown select
  					if(!this.options.wrapNative) {
  						this.realElement.removeAttr('size jcf-size');
  					}
  				}
  			}
  		},
  		createDropdown: function() {
  			// destroy previous dropdown if needed
  			if(this.dropdown) {
  				this.list.destroy();
  				this.dropdown.remove();
  			}
  
  			// create new drop container
  			this.dropdown = $(this.options.fakeDropStructure).appendTo(this.fakeDropTarget);
  			this.dropdown.addClass(getPrefixedClasses(this.realElement.prop('className'), this.options.selectClassPrefix));
  			makeUnselectable(this.dropdown);
  
  			// set initial styles for dropdown in body
  			if(this.options.fakeDropInBody) {
  				this.dropdown.css({
  					position: 'absolute',
  					top: -9999
  				});
  			}
  
  			// create new select list instance
  			this.list = new SelectList({
  				useHoverClass: true,
  				handleResize: false,
  				alwaysPreventMouseWheel: true,
  				maxVisibleItems: this.options.maxVisibleItems,
  				useCustomScroll: this.options.useCustomScroll,
  				holder: this.dropdown.find(this.options.dropContentSelector),
  				element: this.realElement
  			});
  			$(this.list).on({
  				select: this.onSelect,
  				press: this.onSelectDropPress,
  				release: this.onSelectDropRelease
  			});
  		},
  		repositionDropdown: function() {
  			var selectOffset = this.fakeElement.offset(),
  				selectWidth = this.fakeElement.outerWidth(),
  				selectHeight = this.fakeElement.outerHeight(),
  				dropHeight = this.dropdown.outerHeight(),
  				winScrollTop = this.win.scrollTop(),
  				winHeight = this.win.height(),
  				calcTop, calcLeft, bodyOffset, needFlipDrop = false;
  
  			// check flip drop position
  			if(selectOffset.top + selectHeight + dropHeight > winScrollTop + winHeight && selectOffset.top - dropHeight > winScrollTop) {
  				needFlipDrop = true;
  			}
  
  			if(this.options.fakeDropInBody) {
  				bodyOffset = this.fakeDropTarget.css('position') !== 'static' ? this.fakeDropTarget.offset().top : 0;
  				if(this.options.flipDropToFit && needFlipDrop) {
  					// calculate flipped dropdown position
  					calcLeft = selectOffset.left;
  					calcTop = selectOffset.top - dropHeight - bodyOffset;
  				} else {
  					// calculate default drop position
  					calcLeft = selectOffset.left;
  					calcTop = selectOffset.top + selectHeight - bodyOffset;
  				}
  
  				// update drop styles
  				this.dropdown.css({
  					width: selectWidth,
  					left: calcLeft,
  					top: calcTop
  				});
  			}
  
  			// refresh flipped class
  			this.dropdown.add(this.fakeElement).toggleClass(this.options.flipDropClass, this.options.flipDropToFit && needFlipDrop);
  		},
  		showDropdown: function() {
  			// create options list if not created
  			if(!this.dropdown) {
  				this.createDropdown();
  			}
  
  			// show dropdown
  			this.dropActive = true;
  			this.dropdown.appendTo(this.fakeDropTarget);
  			this.fakeElement.addClass(this.options.dropActiveClass);
  			this.refreshSelectedText();
  			this.repositionDropdown();
  			this.list.setScrollTop(this.savedScrollTop);
  			this.list.refresh();
  
  			// add temporary event handlers
  			this.win.on('resize', this.onResize);
  			this.doc.on('jcf-pointerdown', this.onOutsideClick);
  		},
  		hideDropdown: function() {
  			if(this.dropdown) {
  				this.savedScrollTop = this.list.getScrollTop();
  				this.fakeElement.removeClass(this.options.dropActiveClass + ' ' + this.options.flipDropClass);
  				this.dropdown.removeClass(this.options.flipDropClass).detach();
  				this.doc.off('jcf-pointerdown', this.onOutsideClick);
  				this.win.off('resize', this.onResize);
  				this.dropActive = false;
  			}
  		},
  		toggleDropdown: function() {
  			if(this.dropActive) {
  				this.hideDropdown();
  			} else {
  				this.showDropdown();
  			}
  		},
  		refreshSelectedText: function() {
  			// redraw selected area
  			var selectedIndex = this.realElement.prop('selectedIndex'),
  				selectedOption = this.realElement.prop('options')[selectedIndex],
  				selectedOptionImage = selectedOption.getAttribute('data-image'),
  				selectedOptionClasses,
  				selectedFakeElement;
  
  			if(this.currentSelectedText !== selectedOption.innerHTML || this.currentSelectedImage !== selectedOptionImage) {
  				selectedOptionClasses = getPrefixedClasses(selectedOption.className, this.options.optionClassPrefix);
  				this.selectText.attr('class', selectedOptionClasses).html(selectedOption.innerHTML);
  
  				if(selectedOptionImage) {
  					if(!this.selectImage) {
  						this.selectImage = $('<img>').prependTo(this.selectTextContainer).hide();
  					}
  					this.selectImage.attr('src', selectedOptionImage).show();
  				} else if(this.selectImage) {
  					this.selectImage.hide();
  				}
  
  				this.currentSelectedText = selectedOption.innerHTML;
  				this.currentSelectedImage = selectedOptionImage;
  			}
  		},
  		refresh: function() {
  			// refresh fake select visibility
  			if(this.realElement.prop('style').display === 'none') {
  				this.fakeElement.hide();
  			} else {
  				this.fakeElement.show();
  			}
  
  			// refresh selected text
  			this.refreshSelectedText();
  
  			// handle disabled state
  			this.fakeElement.toggleClass(this.options.disabledClass, this.realElement.is(':disabled'));
  		},	
  		destroy: function() {
  			// restore structure
  			if(this.options.wrapNative) {
  				this.realElement.insertBefore(this.fakeElement).css({
  					position: '',
  					height: '',
  					width: ''
  				}).removeClass(this.options.resetAppearanceClass);
  			} else {
  				this.realElement.removeClass(this.options.hiddenClass);
  				if(this.realElement.is('[jcf-size]')) {
  					this.realElement.removeAttr('size jcf-size');
  				}
  			}
  
  			// removing element will also remove its event handlers
  			this.fakeElement.remove();
  
  			// remove other event handlers
  			this.doc.off('jcf-pointerup', this.onSelectAreaRelease);
  			this.realElement.off({
  				focus: this.onFocus
  			});
  		}
  	});
  
  	// listbox module
  	function ListBox(options) {
  		this.options = $.extend({
  			wrapNative: true,
  			useCustomScroll: true,
  			fakeStructure: '<span class="jcf-list-box"><span class="jcf-list-wrapper"></span></span>',
  			selectClassPrefix: 'jcf-select-',
  			listHolder: '.jcf-list-wrapper'
  		}, options);
  		this.init();
  	}
  	$.extend(ListBox.prototype, {
  		init: function(options) {
  			this.bindHandlers();
  			this.initStructure();
  			this.attachEvents();
  		},
  		initStructure: function() {
  			var self = this;
  			this.realElement = $(this.options.element);
  			this.fakeElement = $(this.options.fakeStructure).insertAfter(this.realElement);
  			this.listHolder = this.fakeElement.find(this.options.listHolder);
  			makeUnselectable(this.fakeElement);
  
  			// copy classes from original select
  			this.fakeElement.addClass(getPrefixedClasses(this.realElement.prop('className'), this.options.selectClassPrefix));
  			this.realElement.addClass(this.options.hiddenClass);
  
  			this.list = new SelectList({
  				useCustomScroll: this.options.useCustomScroll,
  				holder: this.listHolder,
  				selectOnClick: false,
  				element: this.realElement
  			});
  		},
  		attachEvents: function() {
  			// delayed refresh handler
  			var self = this;
  			this.delayedRefresh = function() {
  				clearTimeout(self.refreshTimer);
  				self.refreshTimer = setTimeout(function() {
  					self.refresh();
  				}, 1);
  			};
  
  			// other event handlers
  			this.realElement.on({
  				focus: this.onFocus,
  				click: this.delayedRefresh,
  				keydown: this.delayedRefresh
  			});
  
  			// select list event handlers
  			$(this.list).on({
  				select: this.onSelect,
  				press: this.onFakeOptionsPress,
  				release: this.onFakeOptionsRelease
  			});
  		},
  		onFakeOptionsPress: function(e, pointerEvent) {
  			this.pressedFlag = true;
  			if(pointerEvent.pointerType === 'mouse') {
  				this.realElement.focus();
  			}
  		},
  		onFakeOptionsRelease: function(e, pointerEvent) {
  			this.pressedFlag = false;
  			if(pointerEvent.pointerType === 'mouse') {
  				this.realElement.focus();
  			}
  		},
  		onSelect: function() {
  			this.fireNativeEvent(this.realElement, 'change');
  			this.fireNativeEvent(this.realElement, 'click');
  		},
  		onFocus: function() {
  			if(!this.pressedFlag || !this.focusedFlag) {
  				this.fakeElement.addClass(this.options.focusClass);
  				this.realElement.on('blur', this.onBlur);
  				this.focusedFlag = true;
  			}
  		},
  		onBlur: function() {
  			if(!this.pressedFlag) {
  				this.fakeElement.removeClass(this.options.focusClass);
  				this.realElement.off('blur', this.onBlur);
  				this.focusedFlag = false;
  			}
  		},
  		refresh: function() {
  			this.fakeElement.toggleClass(this.options.disabledClass, this.realElement.is(':disabled'));
  			this.list.refresh();
  		},
  		destroy: function() {
  			this.list.destroy();
  			this.realElement.insertBefore(this.fakeElement).removeClass(this.options.hiddenClass);
  			this.fakeElement.remove();
  		}
  	});
  
  	// options list module
  	function SelectList(options) {
  		this.options = $.extend({
  			holder: null,
  			maxVisibleItems: 10,
  			selectOnClick: true,
  			useHoverClass: false,
  			useCustomScroll: false,
  			handleResize: true,
  			alwaysPreventMouseWheel: false,
  			indexAttribute: 'data-index',
  			cloneClassPrefix: 'jcf-option-',
  			containerStructure: '<span class="jcf-list"><span class="jcf-list-content"></span></span>',
  			containerSelector: '.jcf-list-content',
  			captionClass: 'jcf-optgroup-caption',
  			disabledClass: 'jcf-disabled',
  			optionClass: 'jcf-option',
  			groupClass: 'jcf-optgroup',
  			hoverClass: 'jcf-hover',
  			selectedClass: 'jcf-selected',
  			scrollClass: 'jcf-scroll-active'
  		}, options);
  		this.init();
  	}
  	$.extend(SelectList.prototype, {
  		init: function() {
  			this.initStructure();
  			this.refreshSelectedClass();
  			this.attachEvents();
  		},
  		initStructure: function() {
  			this.element = $(this.options.element);
  			this.indexSelector = '[' + this.options.indexAttribute + ']';
  			this.container = $(this.options.containerStructure).appendTo(this.options.holder);
  			this.listHolder = this.container.find(this.options.containerSelector);
  			this.lastClickedIndex = this.element.prop('selectedIndex');
  			this.rebuildList();
  		},
  		attachEvents: function() {
  			this.bindHandlers();
  			this.listHolder.on('jcf-pointerdown', this.indexSelector, this.onItemPress);
  			this.listHolder.on('jcf-pointerdown', this.onPress);
  
  			if(this.options.useHoverClass) {
  				this.listHolder.on('jcf-pointerover', this.indexSelector, this.onHoverItem);
  			}
  		},
  		onPress: function(e) {
  			$(this).trigger('press', e);
  			this.listHolder.on('jcf-pointerup', this.onRelease);
  		},
  		onRelease: function(e) {
  			$(this).trigger('release', e);
  			this.listHolder.off('jcf-pointerup', this.onRelease);
  		},
  		onHoverItem: function(e) {
  			var hoverIndex = parseFloat(e.currentTarget.getAttribute(this.options.indexAttribute));
  			this.fakeOptions.removeClass(this.options.hoverClass).eq(hoverIndex).addClass(this.options.hoverClass);
  		},
  		onItemPress: function(e) {
  			if(e.pointerType === 'touch' || this.options.selectOnClick) {
  				// select option after "click"
  				this.tmpListOffsetTop = this.list.offset().top;
  				this.listHolder.on('jcf-pointerup', this.indexSelector, this.onItemRelease);
  			} else {
  				// select option immediately
  				this.onSelectItem(e);
  			}
  		},
  		onItemRelease: function(e) {
  			// remove event handlers and temporary data
  			this.listHolder.off('jcf-pointerup', this.indexSelector, this.onItemRelease);
  
  			// simulate item selection
  			if(this.tmpListOffsetTop === this.list.offset().top) {
  				this.listHolder.on('click', this.indexSelector, this.onSelectItem);
  			}
  			delete this.tmpListOffsetTop;
  		},
  		onSelectItem: function(e) {
  			var clickedIndex = parseFloat(e.currentTarget.getAttribute(this.options.indexAttribute)),
  				range;
  
  			// remove click event handler
  			this.listHolder.off('click', this.indexSelector, this.onSelectItem);
  
  			// ignore clicks on disabled options
  			if(e.button > 1 || this.realOptions[clickedIndex].disabled) {
  				return;
  			}
  
  			if(this.element.prop('multiple')) {
  				if(e.metaKey || e.ctrlKey || e.pointerType === 'touch') {
  					// if CTRL/CMD pressed or touch devices - toggle selected option
  					this.realOptions[clickedIndex].selected = !this.realOptions[clickedIndex].selected;
  				} else if(e.shiftKey) {
  					// if SHIFT pressed - update selection
  					range = [this.lastClickedIndex, clickedIndex].sort(function(a, b){
  						return a - b;
  					});
  					this.realOptions.each(function(index, option) {
  						option.selected = (index >= range[0] && index <= range[1]);
  					});
  				} else {
  					// set single selected index
  					this.element.prop('selectedIndex', clickedIndex);
  				}
  			} else {
  				this.element.prop('selectedIndex', clickedIndex);
  			}
  
  			// save last clicked option
  			if(!e.shiftKey) {
  				this.lastClickedIndex = clickedIndex;
  			}
  
  			// refresh classes
  			this.refreshSelectedClass();
  
  			// scroll to active item in desktop browsers
  			if(e.pointerType === 'mouse') {
  				this.scrollToActiveOption();
  			}
  
  			// make callback when item selected
  			$(this).trigger('select');
  		},
  		rebuildList: function() {
  			// rebuild options
  			var self = this,
  				rootElement = this.element[0];
  
  			// recursively create fake options
  			this.storedSelectHTML = rootElement.innerHTML;
  			this.optionIndex = 0;
  			this.list = $(this.createOptionsList(rootElement));
  			this.listHolder.empty().append(this.list);
  			this.realOptions = this.element.find('option');
  			this.fakeOptions = this.list.find(this.indexSelector);
  			this.fakeListItems = this.list.find('.' + this.options.captionClass + ',' + this.indexSelector);
  			delete this.optionIndex;
  
  			// detect max visible items
  			var maxCount = this.options.maxVisibleItems,
  				sizeValue = this.element.prop('size');
  			if(sizeValue > 1) {
  				maxCount = sizeValue;
  			}
  
  			// handle scrollbar
  			var needScrollBar = this.fakeOptions.length > maxCount;
  			this.container.toggleClass(this.options.scrollClass, needScrollBar);
  			if(needScrollBar) {
  				// change max-height
  				this.listHolder.css({
  					maxHeight: this.getOverflowHeight(maxCount),
  					overflow: 'auto'
  				});
  
  				if(this.options.useCustomScroll && jcf.modules.Scrollable) {
  					// add custom scrollbar if specified in options
  					jcf.replace(this.listHolder, 'Scrollable', {
  						handleResize: this.options.handleResize,
  						alwaysPreventMouseWheel: this.options.alwaysPreventMouseWheel
  					});
  					return;
  				}
  			}
  
  			// disable edge wheel scrolling
  			if(this.options.alwaysPreventMouseWheel) {
  				this.preventWheelHandler = function(e) {
  					var currentScrollTop = self.listHolder.scrollTop(),
  						maxScrollTop = self.listHolder.prop('scrollHeight') - self.listHolder.innerHeight(),
  						maxScrollLeft = self.listHolder.prop('scrollWidth') - self.listHolder.innerWidth();
  
  					// check edge cases
  					if((currentScrollTop <= 0 && e.deltaY < 0) || (currentScrollTop >= maxScrollTop && e.deltaY > 0)) {
  						e.preventDefault();
  					}
  				};
  				this.listHolder.on('jcf-mousewheel', this.preventWheelHandler);
  			}
  		},
  		refreshSelectedClass: function() {
  			var self = this,
  				selectedItem,
  				isMultiple = this.element.prop('multiple'),
  				selectedIndex = this.element.prop('selectedIndex');
  
  			if(isMultiple) {
  				this.realOptions.each(function(index, option) {
  					self.fakeOptions.eq(index).toggleClass(self.options.selectedClass, !!option.selected);
  				});
  			} else {
  				this.fakeOptions.removeClass(this.options.selectedClass + ' ' + this.options.hoverClass);
  				selectedItem = this.fakeOptions.eq(selectedIndex).addClass(this.options.selectedClass);
  				if(this.options.useHoverClass) {
  					selectedItem.addClass(this.options.hoverClass);
  				}
  			}
  		},
  		scrollToActiveOption: function() {
  			// scroll to target option
  			var targetOffset = this.getActiveOptionOffset();
  			this.listHolder.prop('scrollTop', targetOffset);
  		},
  		getSelectedIndexRange: function() {
  			var firstSelected = -1, lastSelected = -1;
  			this.realOptions.each(function(index, option) {
  				if(option.selected) {
  					if(firstSelected < 0) {
  						firstSelected = index;
  					}
  					lastSelected = index;
  				}
  			});
  			return [firstSelected, lastSelected];
  		},
  		getChangedSelectedIndex: function() {
  			var selectedIndex = this.element.prop('selectedIndex'),
  				targetIndex;
  
  			if(this.element.prop('multiple')) {
  				// multiple selects handling
  				if(!this.previousRange) {
  					this.previousRange = [selectedIndex, selectedIndex];
  				}
  				this.currentRange = this.getSelectedIndexRange();
  				targetIndex = this.currentRange[this.currentRange[0] !== this.previousRange[0] ? 0 : 1];
  				this.previousRange = this.currentRange;
  				return targetIndex;
  			} else {
  				// single choice selects handling
  				return selectedIndex;
  			}
  		},
  		getActiveOptionOffset: function() {
  			// calc values
  			var dropHeight = this.listHolder.height(),
  				dropScrollTop = this.listHolder.prop('scrollTop'),
  				currentIndex = this.getChangedSelectedIndex(),
  				fakeOption = this.fakeOptions.eq(currentIndex),
  				fakeOptionOffset = fakeOption.offset().top - this.list.offset().top,
  				fakeOptionHeight = fakeOption.innerHeight();
  
  			// scroll list
  			if(fakeOptionOffset + fakeOptionHeight >= dropScrollTop + dropHeight) {
  				// scroll down (always scroll to option)
  				return fakeOptionOffset - dropHeight + fakeOptionHeight;
  			} else if(fakeOptionOffset < dropScrollTop) {
  				// scroll up to option
  				return fakeOptionOffset;
  			}
  		},
  		getOverflowHeight: function(sizeValue) {
  			var item = this.fakeListItems.eq(sizeValue - 1),
  				listOffset = this.list.offset().top,
  				itemOffset = item.offset().top,
  				itemHeight = item.innerHeight();
  
  			return itemOffset + itemHeight - listOffset;
  		},
  		getScrollTop: function() {
  			return this.listHolder.scrollTop();
  		},
  		setScrollTop: function(value) {
  			this.listHolder.scrollTop(value);
  		},
  		createOption: function(option) {
  			var newOption = document.createElement('span');
  			newOption.className = this.options.optionClass;
  			newOption.innerHTML = option.innerHTML;
  			newOption.setAttribute(this.options.indexAttribute, this.optionIndex++);
  
  			var optionImage, optionImageSrc = option.getAttribute('data-image');
  			if(optionImageSrc) {
  				optionImage = document.createElement('img');
  				optionImage.src = optionImageSrc;
  				newOption.insertBefore(optionImage, newOption.childNodes[0]);
  			}
  			if(option.disabled) {
  				newOption.className += ' ' + this.options.disabledClass;
  			}
  			if(option.className) {
  				newOption.className += ' ' + getPrefixedClasses(option.className, this.options.cloneClassPrefix);
  			}
  			return newOption;
  		},
  		createOptGroup: function(optgroup) {
  			var optGroupContainer = document.createElement('span'),
  				optGroupName = optgroup.getAttribute('label'),
  				optGroupCaption, optGroupList;
  
  			// create caption
  			optGroupCaption = document.createElement('span');
  			optGroupCaption.className = this.options.captionClass;
  			optGroupCaption.innerHTML = optGroupName;
  			optGroupContainer.appendChild(optGroupCaption);
  
  			// create list of options
  			if(optgroup.children.length) {
  				optGroupList = this.createOptionsList(optgroup);
  				optGroupContainer.appendChild(optGroupList);
  			}
  
  			optGroupContainer.className = this.options.groupClass;
  			return optGroupContainer;
  		},
  		createOptionContainer: function() {
  			var optionContainer = document.createElement('li');
  			return optionContainer;
  		},
  		createOptionsList: function(container) {
  			var self = this,
  				list = document.createElement('ul');
  
  			$.each(container.children, function(index, currentNode) {
  				var item = self.createOptionContainer(currentNode),
  					newNode;
  
  				switch(currentNode.tagName.toLowerCase()) {
  					case 'option': newNode = self.createOption(currentNode); break;
  					case 'optgroup': newNode = self.createOptGroup(currentNode); break;
  				}
  				list.appendChild(item).appendChild(newNode);
  			});
  			return list;
  		},
  		refresh: function() {
  			// check for select innerHTML changes
  			if(this.storedSelectHTML !== this.element.prop('innerHTML')) {
  				this.rebuildList();
  			}
  
  			// refresh custom scrollbar
  			var scrollInstance = jcf.getInstance(this.listHolder);
  			if(scrollInstance) {
  				scrollInstance.refresh();
  			}
  
  			// scroll active option into view
  			this.scrollToActiveOption();
  
  			// refresh selectes classes
  			this.refreshSelectedClass();
  		},
  		destroy: function() {
  			this.listHolder.off('jcf-mousewheel', this.preventWheelHandler);
  			this.listHolder.off('jcf-pointerdown', this.indexSelector, this.onSelectItem);
  			this.listHolder.off('jcf-pointerover', this.indexSelector, this.onHoverItem);
  			this.listHolder.off('jcf-pointerdown', this.onPress);
  		}
  	});
  
  	// helper functions
  	var getPrefixedClasses = function(className, prefixToAdd) {
  		return className ? className.replace(/[\s]*([\S]+)+[\s]*/gi, prefixToAdd + '$1 ') : '';
  	};
  	var makeUnselectable = (function() {
  		var unselectableClass = jcf.getOptions().unselectableClass;
  		function preventHandler(e) {
  			e.preventDefault();
  		}
  		return function(node) {
  			node.addClass(unselectableClass).on('selectstart', preventHandler);
  		};
  	}());
  
  }(jQuery, this));
  
  
  /*!* SmoothScroll module*/
   
  ;(function($, exports) {
  	// private variables
  	var page,
  		win = $(window),
  		activeBlock, activeWheelHandler,
  		wheelEvents = ('onwheel' in document || document.documentMode >= 9 ? 'wheel' : 'mousewheel DOMMouseScroll');
  
  	// animation handlers
  	function scrollTo(offset, options, callback) {
  		// initialize variables
  		var scrollBlock;
  		if (document.body) {
  			if (typeof options === 'number') {
  				options = { duration: options };
  			} else {
  				options = options || {};
  			}
  			page = page || $('html, body');
  			scrollBlock = options.container || page;
  		} else {
  			return;
  		}
  
  		// treat single number as scrollTop
  		if (typeof offset === 'number') {
  			offset = { top: offset };
  		}
  
  		// handle mousewheel/trackpad while animation is active
  		if (activeBlock && activeWheelHandler) {
  			activeBlock.off(wheelEvents, activeWheelHandler);
  		}
  		if (options.wheelBehavior && options.wheelBehavior !== 'none') {
  			activeWheelHandler = function(e) {
  				if (options.wheelBehavior === 'stop') {
  					scrollBlock.off(wheelEvents, activeWheelHandler);
  					scrollBlock.stop();
  				} else if (options.wheelBehavior === 'ignore') {
  					e.preventDefault();
  				}
  			};
  			activeBlock = scrollBlock.on(wheelEvents, activeWheelHandler);
  		}
  
  		// start scrolling animation
  		scrollBlock.stop().animate({
  			scrollLeft: offset.left,
  			scrollTop: offset.top
  		}, options.duration, function() {
  			if (activeWheelHandler) {
  				scrollBlock.off(wheelEvents, activeWheelHandler);
  			}
  			if ($.isFunction(callback)) {
  				callback();
  			}
  		});
  	}
  
  	// smooth scroll contstructor
  	function SmoothScroll(options) {
  		this.options = $.extend({
  			anchorLinks: 'a[href^="#"]',	// selector or jQuery object
  			container: null,		// specify container for scrolling (default - whole page)
  			extraOffset: null,		// function or fixed number
  			activeClasses: null,	// null, "link", "parent"
  			easing: 'swing',		// easing of scrolling
  			animMode: 'duration',	// or "speed" mode
  			animDuration: 800,		// total duration for scroll (any distance)
  			animSpeed: 1500,		// pixels per second
  			anchorActiveClass: 'active',
  			sectionActiveClass: 'section-active',
  			wheelBehavior: 'stop', // "stop", "ignore" or "none"
  			useNativeAnchorScrolling: false // do not handle click in devices with native smooth scrolling
  		}, options);
  		this.init();
  	}
  	SmoothScroll.prototype = {
  		init: function() {
  			this.initStructure();
  			this.attachEvents();
  		},
  		initStructure: function() {
  			this.container = this.options.container ? $(this.options.container) : $('html,body');
  			this.scrollContainer = this.options.container ? this.container : win;
  			this.anchorLinks = $(this.options.anchorLinks);
  		},
  		getAnchorTarget: function(link) {
  			// get target block from link href
  			var targetId = $(link).attr('href');
  			return $(targetId.length > 1 ? targetId : 'html');
  		},
  		getTargetOffset: function(block) {
  			// get target offset
  			var blockOffset = block.offset().top;
  			if (this.options.container) {
  				blockOffset -= this.container.offset().top - this.container.prop('scrollTop');
  			}
  
  			// handle extra offset
  			if (typeof this.options.extraOffset === 'number') {
  				blockOffset -= this.options.extraOffset;
  			} else if (typeof this.options.extraOffset === 'function') {
  				blockOffset -= this.options.extraOffset(block);
  			}
  			return { top: blockOffset };
  		},
  		attachEvents: function() {
  			var self = this;
  
  			// handle active classes
  			if (this.options.activeClasses) {
  				// cache structure
  				this.anchorData = [];
  				this.anchorLinks.each(function() {
  					var link = jQuery(this),
  						targetBlock = self.getAnchorTarget(link),
  						anchorDataItem;
  
  					$.each(self.anchorData, function(index, item) {
  						if (item.block[0] === targetBlock[0]) {
  							anchorDataItem = item;
  						}
  					});
  
  					if (anchorDataItem) {
  						anchorDataItem.link = anchorDataItem.link.add(link);
  					} else {
  						self.anchorData.push({
  							link: link,
  							block: targetBlock
  						});
  					}
  				});
  
  				// add additional event handlers
  				this.resizeHandler = function() {
  					self.recalculateOffsets();
  				};
  				this.scrollHandler = function() {
  					self.refreshActiveClass();
  				};
  
  				this.recalculateOffsets();
  				this.scrollContainer.on('scroll', this.scrollHandler);
  				win.on('resize', this.resizeHandler);
  			}
  
  			// handle click event
  			this.clickHandler = function(e) {
  				self.onClick(e);
  			};
  			if (!this.options.useNativeAnchorScrolling) {
  				this.anchorLinks.on('click', this.clickHandler);
  			}
  		},
  		recalculateOffsets: function() {
  			var self = this;
  			$.each(this.anchorData, function(index, data) {
  				data.offset = self.getTargetOffset(data.block);
  				data.height = data.block.outerHeight();
  			});
  			this.refreshActiveClass();
  		},
  		refreshActiveClass: function() {
  			var self = this,
  				foundFlag = false,
  				containerHeight = this.container.prop('scrollHeight'),
  				viewPortHeight = this.scrollContainer.height(),
  				scrollTop = this.options.container ? this.container.prop('scrollTop') : win.scrollTop();
  
  			// user function instead of default handler
  			if (this.options.customScrollHandler) {
  				this.options.customScrollHandler.call(this, scrollTop, this.anchorData);
  				return;
  			}
  
  			// sort anchor data by offsets
  			this.anchorData.sort(function(a, b) {
  				return a.offset.top - b.offset.top;
  			});
  			function toggleActiveClass(anchor, block, state) {
  				anchor.toggleClass(self.options.anchorActiveClass, state);
  				block.toggleClass(self.options.sectionActiveClass, state);
  			}
  
  			// default active class handler
  			$.each(this.anchorData, function(index) {
  				var reverseIndex = self.anchorData.length - index - 1,
  					data = self.anchorData[reverseIndex],
  					anchorElement = (self.options.activeClasses === 'parent' ? data.link.parent() : data.link);
  
  				if (scrollTop >= containerHeight - viewPortHeight) {
  					// handle last section
  					if (reverseIndex === self.anchorData.length - 1) {
  						toggleActiveClass(anchorElement, data.block, true);
  					} else {
  						toggleActiveClass(anchorElement, data.block, false);
  					}
  				} else {
  					// handle other sections
  					if (!foundFlag && (scrollTop >= data.offset.top - 1 || reverseIndex === 0)) {
  						foundFlag = true;
  						toggleActiveClass(anchorElement, data.block, true);
  					} else {
  						toggleActiveClass(anchorElement, data.block, false);
  					}
  				}
  			});
  		},
  		calculateScrollDuration: function(offset) {
  			var distance;
  			if (this.options.animMode === 'speed') {
  				distance = Math.abs(this.scrollContainer.scrollTop() - offset.top);
  				return (distance / this.options.animSpeed) * 1000;
  			} else {
  				return this.options.animDuration;
  			}
  		},
  		onClick: function(e) {
  			var targetBlock = this.getAnchorTarget(e.currentTarget),
  				targetOffset = this.getTargetOffset(targetBlock);
  
  			e.preventDefault();
  			scrollTo(targetOffset, {
  				container: this.container,
  				wheelBehavior: this.options.wheelBehavior,
  				duration: this.calculateScrollDuration(targetOffset)
  			});
  		},
  		destroy: function() {
  			if (this.options.activeClasses) {
  				win.off('resize', this.resizeHandler);
  				this.scrollContainer.off('scroll', this.scrollHandler);
  			}
  			this.anchorLinks.off('click', this.clickHandler);
  		}
  	};
  
  	// public API
  	$.extend(SmoothScroll, {
  		scrollTo: function(blockOrOffset, durationOrOptions, callback) {
  			scrollTo(blockOrOffset, durationOrOptions, callback);
  		}
  	});
  
  	// export module
  	exports.SmoothScroll = SmoothScroll;
  }(jQuery, this));
  
  /*!
   * Google Map module
   */
  
  ;(function($) {
  	function GoogleMapAPI(options) {
  		this.options = $.extend({
  			mapTypeId: google.maps.MapTypeId.ROADMAP
  		}, options);
  		this.init();
  	}
  
  	GoogleMapAPI.prototype = {
  		init: function() {
  			this.findStructure();
  			this.getInfoWindowContent();
  			this.createMap();
  			this.createMarker();
  			this.createInfoWindow();
  		},
  
  		findStructure: function() {
  			this.container = $(this.options.container);
  			this.lat = parseFloat(this.container.attr('data-lat'));
  			this.lng = parseFloat(this.container.attr('data-lng'));
  			this.coords = new google.maps.LatLng(this.lat, this.lng);
  			this.zoom = parseInt(this.container.attr('data-zoom'));
  			this.infoWindowContent = this.container.find('.map-info');
  			this.mapOptions = {
  				mapTypeId: this.options.mapTypeId,
  				panControl: this.options.panControl,
  				zoomControl: this.options.zoomControl,
  				streetViewControl: this.options.streetViewControl,
  				mapTypeControl: this.options.mapTypeControl,
  				center: this.coords,
  				scrollwheel: this.options.scrollwheel,
  				zoom: this.zoom
  			};
  		},
  
  		getInfoWindowContent: function() {
  			this.infoWindowContent = this.container.find(this.options.mapInfoContent);
  		},
  
  		createMap: function() {
  			this.map = new google.maps.Map(this.container.get(0), this.mapOptions);
  		},
  
  		createMarker: function() {
  			this.marker = new google.maps.Marker({
  				icon: this.options.marker,
  				position: this.coords
  			});
  
  			this.marker.setMap(this.map);
  		},
  
  		createInfoWindow: function() {
  			var self = this;
  			this.infoWindow = new google.maps.InfoWindow({
  				content: this.infoWindowContent.get(0)
  			});
  			this.marker.addListener('click', function() {
  				self.infoWindow.open(self.map, self.marker);
  			})
  		}
  	};
  
  	$.fn.googleMapAPI = function(opt) {
  		return this.each(function() {
  			$(this).data('GoogleMapAPI', new GoogleMapAPI($.extend(opt, {container: this})));
  		});
  	};
  }(jQuery));
  
  /*
   * Responsive Layout helper
   */
  ResponsiveHelper = (function($){
  	// init variables
  	var handlers = [],
  		prevWinWidth,
  		win = $(window),
  		nativeMatchMedia = false;
  
  	// detect match media support
  	if(window.matchMedia) {
  		if(window.Window && window.matchMedia === Window.prototype.matchMedia) {
  			nativeMatchMedia = true;
  		} else if(window.matchMedia.toString().indexOf('native') > -1) {
  			nativeMatchMedia = true;
  		}
  	}
  
  	// prepare resize handler
  	function resizeHandler() {
  		var winWidth = win.width();
  		if(winWidth !== prevWinWidth) {
  			prevWinWidth = winWidth;
  
  			// loop through range groups
  			$.each(handlers, function(index, rangeObject){
  				// disable current active area if needed
  				$.each(rangeObject.data, function(property, item) {
  					if(item.currentActive && !matchRange(item.range[0], item.range[1])) {
  						item.currentActive = false;
  						if(typeof item.disableCallback === 'function') {
  							item.disableCallback();
  						}
  					}
  				});
  
  				// enable areas that match current width
  				$.each(rangeObject.data, function(property, item) {
  					if(!item.currentActive && matchRange(item.range[0], item.range[1])) {
  						// make callback
  						item.currentActive = true;
  						if(typeof item.enableCallback === 'function') {
  							item.enableCallback();
  						}
  					}
  				});
  			});
  		}
  	}
  	win.bind('load resize orientationchange', resizeHandler);
  
  	// test range
  	function matchRange(r1, r2) {
  		var mediaQueryString = '';
  		if(r1 > 0) {
  			mediaQueryString += '(min-width: ' + r1 + 'px)';
  		}
  		if(r2 < Infinity) {
  			mediaQueryString += (mediaQueryString ? ' and ' : '') + '(max-width: ' + r2 + 'px)';	
  		}
  		return matchQuery(mediaQueryString, r1, r2);
  	}
  
  	// media query function
  	function matchQuery(query, r1, r2) {
  		if(window.matchMedia && nativeMatchMedia) {
  			return matchMedia(query).matches;
  		} else if(window.styleMedia) {
  			return styleMedia.matchMedium(query);
  		} else if(window.media) {
  			return media.matchMedium(query);
  		} else {
  			return prevWinWidth >= r1 && prevWinWidth <= r2;
  		}
  	}
  
  	// range parser
  	function parseRange(rangeStr) {
  		var rangeData = rangeStr.split('..');
  		var x1 = parseInt(rangeData[0], 10) || -Infinity;
  		var x2 = parseInt(rangeData[1], 10) || Infinity;
  		return [x1, x2].sort(function(a, b){
  			return a - b;
  		});
  	}
  
  	// export public functions
  	return {
  		addRange: function(ranges) {
  			// parse data and add items to collection
  			var result = {data:{}};
  			$.each(ranges, function(property, data){
  				result.data[property] = {
  					range: parseRange(property),
  					enableCallback: data.on,
  					disableCallback: data.off
  				};
  			});
  			handlers.push(result);
  
  			// call resizeHandler to recalculate all events
  			prevWinWidth = null;
  			resizeHandler();
  		}
  	};
  }(jQuery));
  
  