

(function($) {
	function styleSupport( prop ) {
		var vendorProp, supportedProp,
				capProp = prop.charAt( 0 ).toUpperCase() + prop.slice( 1 ),
				prefixes = [ "Moz", "Webkit", "O", "ms" ],
				div = document.createElement( "div" );

		if (prop in div.style) {
			supportedProp = prop;
		} else {
			for (var i=0; i<prefixes.length; i++) {
				vendorProp = prefixes[i] + capProp;
				if (vendorProp in div.style) {
					supportedProp = vendorProp;
					break;
				}
			}
		}
		
		div = null;
		$.support[prop] = supportedProp;
		return supportedProp;
	}

	var backgroundSize = styleSupport("backgroundSize");
	if (backgroundSize && backgroundSize !== "backgroundSize") {
		$.cssHooks.backgroundSize = {
			get: function(elem, computed, extra) {
				return $.css(elem, backgroundSize);
			},
			set: function( elem, value) {
				elem.style[ backgroundSize ] = value;
			}
		}
	}
})(jQuery);

function cl (el, descr) {
	console.log(el, descr);
}

var $wnd;
var is_touch = 'ontouchstart' in window;
var css_transitions  = true;

function load_page(callback) {
	var loader_H = $wnd.height()-$('#footer').outerHeight()-$('#footer-social').outerHeight();
	// if (!document.location.hash) 
		$('#loading-section').css('height', loader_H); 
	// else $('#loading-section').css('display', 'none');
	$('#footer').css('margin-top', loader_H);
	$(document).on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', '.fullscreen-slider', function() {
		set_fslider_height(this);
	});
	$(document).on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', '#loading-section', function() {
		$('#loading-section').remove();
	});

	$wnd.on('load', function() {
		// cl('onload');
		$('body').addClass('page-loaded');
		$('#title-page').fadeIn(650);
		$('#footer').css('margin-top', '');
		callback();
	})
}

jQuery(document).ready(function($) {

	$wnd = $(window);
	
	if (is_touch) {
		$('body').addClass('touch');
	}

	$('#header-menu-toggle').on('click', function() {
		$('body').toggleClass('header-nav-open');
		$(this).toggleClass('opened');
		return false;
	});

	$('.nav-close').on('click', function() {
		$('body').removeClass('header-nav-open');
		window.setTimeout(function(){$('#header-menu-toggle').removeClass('opened');}, 400);
		return false;
	});


	$('.footer-like').on('click', function() {
		$('.footer-share-popup').fadeOut('fast');
		$('.footer-like-popup').fadeToggle('fast');
		return false;
	});
	$('.footer-share').on('click', function() {
		$('.footer-like-popup').fadeOut('fast');
		$('.footer-share-popup').fadeToggle('fast');
		return false;
	});

	$('#moveTop').on('click', function(){
		if (navigator.userAgent.match(/(iPod|iPhone|iPad|Android)/)){
			window.scrollTo(0, 0);
		}else{
			$('html,body').animate({scrollTop: 0}, 650);
		}
		return false
	});	
	
	
});