$(document).ready(function(){

	$('#product_comments_block_extra .comments_note').prependTo($('.rate_wrap'));
	$('#product_comments_block_extra').appendTo($('.wrap_buttons').children('.row'));
	var videoPlay = document.getElementById('video-promo-wrap');
	if (videoPlay !== null){
		var posterVideo = $('#video-in').attr('poster');
		if (posterVideo !== undefined){
			$('#video-promo-wrap .poster-video').css('background-image', 'url(' + posterVideo + ')');
		}
		videoPlay.onclick = playPause;
	}
	/*responsive thumbs list on product page*/
		responsiveWidthThumbs();
		$(window).resize(function(){
  			responsiveWidthThumbs();
  			fullWidthVideo();
		});
		function responsiveWidthThumbs(){
			var widthElemThumb = 0;
			var widthThumbList =  $('#thumbs_list').outerWidth();
			if (($(window).width() + widthScrolling)>991){
				widthElemThumb = widthThumbList/3;
			}else if(($(window).width() + widthScrolling)>768){
				widthElemThumb = widthThumbList/4;
			}else if(($(window).width() + widthScrolling)>540){
				widthElemThumb = widthThumbList/4;
			}else{
				widthElemThumb = widthThumbList/3;
			}
			$('#thumbs_list li').css('width',widthElemThumb+'px');
		}

	/*Scroll to top*/
	
	$(window).scroll(function () {
			if ($(this).scrollTop() > 50) {
				$('#back-top').fadeIn();
			} else {
				$('#back-top').fadeOut();
			}
		});
		$("#back-top").fadeOut();
		$('#back-top').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 1000);
			return false;
		});
/*smooth scroll*/
		$('.tp-caption.scroll_down a').bind('click.smoothscroll',function (e) {
			e.preventDefault();
			/*var target = this.hash;*/
				$target = $('#center_column');
			$('html, body').stop().animate({
				'scrollTop': $target.offset().top
			}, 1000, 'swing', function () {

			});
		});


	/*width of a scroll bar*/
			function scrollWidth()
				{
					var div = $('<div>').css({
						position: "absolute",
						top: "0px",
						left: "0px",
						width: "100px",
						height: "100px",
						visibility: "hidden",
						overflow: "scroll"
					});
					
					$('body').eq
					(0).append(div);
					
					var width = div.get(0).offsetWidth - div.get(0).clientWidth;
					
					div.remove();
					
					return width;
				}

				var widthScrolling = scrollWidth();
			
			$(window).resize(function(){
 				addDropDown();
			});

			function addDropDown(){
				if(widthScrolling + $(window).width()<992){
						$('#drop_content_user').css('display','none').addClass('dropdown_links');
				}else{
						$('#drop_content_user').css('display','block').removeClass('dropdown_links');
				}
			}

			setTimeout(function(){ 
				addDropDown();
				fullWidthVideo();
			},500);
	/*Fixed menu on scroll*/

	 var isTouch = function() {
					return $(window).width() < 0 ? true : false;
			};
			//  ========== 
			//  = Scroll inspector = 
			//  ========== 
			var stickyNavbar = function() {
					if (isTouch()) {
							$(window).off("scroll.onlyDesktop");
					} else {
							if(($(window).width() +  widthScrolling) < 992){
								$('#header').removeClass('fixedHeader').css('margin-top','0');
							}
							$navbarTop = $("#topMain").outerHeight();
	
							$(window).on("scroll.onlyDesktop", function() {
									var scrollX = $(window).scrollTop();
									if (scrollX > $navbarTop && ($(window).width() +  widthScrolling) >991) {
											$("#header").addClass('fixedHeader').css('margin-top', '-50px');
									} else {
											$("#header").removeClass('fixedHeader').css('margin-top','0');
									}
							});
					}
			};
			//  ========== 
			//  = Functions which has to be reinitiated when the window size is changed = 
			//  ==========
			var triggeredOnResize = function() {
					// sticky navbar
					stickyNavbar();
			};
			stickyNavbar();
			var fromLastResize;
			// counter in miliseconds
			$(window).resize(function() {
					clearTimeout(fromLastResize);
					fromLastResize = setTimeout(function() {
							triggeredOnResize();
					}, 250);
			});

			//  ========== 
			//  = Last but not the least - trigger the page scroll and resize = 
			//  ========== 
			$(window).trigger("scroll").trigger("resize");

		function fullWidthVideo(){
			var curVideo = $('#video-in');
			var widthVideo = $(curVideo).outerWidth();
			if(scrollWidth() + $(window).width()<1025){
				curVideo.css('height', widthVideo/1.77777778 + 'px');
			}else{
				curVideo.css('height', '');
			}
		}
});
function playPause(){
	var videoPromo = document.getElementById('video-in');
	var videoJquery = $('#video-in');
	if(videoPromo.paused){
		videoPromo.play();
		console.log('play');
		videoJquery.parent().addClass('play').removeClass('pause');
	}
	else{
		videoPromo.pause();
		console.log('pause');
		videoJquery.parent().removeClass('play').addClass('pause');
		}
}