var video_touchsensibility=10;var video_fadingTime=600;var video_touchstartx;var video_touchstarty;$(document).ready(function(){if(!areVideosPresent()){return;}if(isHTML5()){showVideo();showImageContainer();showImage();}else{showVideo();hideImageContainer();hideImage();}addListeners();processSpecificBrowsers();});function isTouchDevice(){return"ontouchstart" in window;}function isHTML5(){var $video=getVideo()[0];
if($video){return typeof $video.pause=="function";}else{return false;}}function isAndroid3(){var ua=navigator.userAgent.toLowerCase();if(ua){return ua.indexOf("android 3")>-1;}else{return false;}}function isIoS(){var ua=navigator.userAgent.toLowerCase();return ua.indexOf("ipad")>-1||ua.indexOf("iphone")>-1||ua.indexOf("ipod")>-1;}function processSpecificBrowsers(){if(isIoS()){jwplayer("myjwplayer").onComplete(restartJwPlayerVideo);
}}function addListeners(){var $image=getImage();var $container=getImageContainer();var $video=getVideo();if(isTouchDevice()){$image.bind("touchstart",touchStart);$image.bind("touchend",touchImageEnd);$container.bind("touchstart",touchStart);$container.bind("touchend",touchContainerEnd);$video.bind("touchstart",touchStart);$video.bind("touchend",touchVideoEnd);$(".detail-gallery-carrousel a").each(function(){$(this).bind("touchstart",touchStart);
});$(".detail-gallery-carrousel a").each(function(){$(this).bind("touchend",touchThumbEnd);});}else{$image.hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");}).click(function(e){showVideo();showBackgroundAndFadeIntoVideo();});$container.click(containerClickHandler);$video.click(pauseVideo);$(".detail-gallery-carrousel a").click(thumbnailClickHandler);}$video.bind("ended",onVideoPlaybackEnded);
$video.bind("play",onVideoPlaybackStarted);$video.bind("pause",onVideoPaused);$video.bind("error",onVideoError);}function containerClickHandler(){if(isVideoPaused()&&getVideo()[0].currentTime>0.1){resumeVideo();}return true;}function thumbnailClickHandler(){if(isJwplayerVideo()){restartJwPlayerVideo();}else{if(isYoutubeVideo()){stopYoutubeVideo();}else{if(isHTML5()){stopVideo();}else{var flash=getFlashMovieObject("flash-moodplayer");
if(flash[0]&&typeof flash[0].reset=="function"){flash[0].reset();}}}}return true;}function getVisibleProductGallery(){return $("#product-gallery div.product-gallery-part:visible");}function areVideosPresent(){return $("#product-detail .media-button").length>0;}function getVideo(){return $("#video_mood");}function getImageContainer(){return $(".product-gallery-part .video-container .image-container");
}function getImage(){return getImageContainer().find(".bg-image");}function touchStart(event){event=event.originalEvent;if(event.changedTouches.length==1){var touch=event.touches[0];if(touch){video_touchstartx=touch.pageX;video_touchstarty=touch.pageY;}}return true;}function touchImageEnd(event){event=event.originalEvent;if(isTouchClick(event)){showBackgroundAndFadeIntoVideo();}return false;}function touchContainerEnd(event){event=event.originalEvent;
if(isTouchClick(event)){resumeVideo();}return true;}function touchVideoEnd(event){event=event.originalEvent;if(isTouchClick(event)){pauseVideo();}return true;}function touchThumbEnd(event){event=event.originalEvent;if(isTouchClick(event)){thumbnailClickHandler();}return true;}function isTouchClick(event){if(event.changedTouches.length==1){var touch=event.changedTouches[0];return(Math.abs(video_touchstartx-touch.pageX)<video_touchsensibility)&&(Math.abs(video_touchstarty-touch.pageY)<video_touchsensibility);
}else{return false;}}function getFlashMovieObject(movieName){return $("#"+movieName);}function showBackgroundAndFadeIntoVideo(){fadeOutImage(playVideo);}function fadeOutImage(callback){if(isTouchDevice()){hidePlayButton();hideImageContainer();if(callback){callback();}}else{hidePlayButton();getImageContainer().fadeOut(video_fadingTime,callback);}}function fadeInImage(callback){hideImageContainer();getImageContainer().fadeIn(video_fadingTime,callback);
}function showPlayButtonAndImage(){showPlayButton();showImage();}function showPlayButton(){var $button=getImageContainer().find(".btn-play-video");$button.show();}function hidePlayButton(){var $button=getImageContainer().find(".btn-play-video");$button.hide();}function removePlayButton(){var $button=getImageContainer().find(".btn-play-video");$button.remove();}function showImageContainer(){getImageContainer().show();
}function hideImageContainer(){getImageContainer().hide();}function showImage(){getImage().show();}function hideImage(){getImage().hide();}function hideVideo(){getVideo().hide();}function showVideo(){getVideo().css("display","inline");}function playVideo(){if(isHTML5()){getVideo()[0].play();}else{var flash=getFlashMovieObject("flash-moodplayer");flash[0].play();}}function pauseVideo(){getVideo()[0].pause();
}function resetVideo(){try{if(getVideo()[0].readyState>0){getVideo()[0].currentTime=0.1;}}catch(e){}}function resumeVideo(){getVideo()[0].play();}function stopVideo(){pauseVideo();resetVideo();onVideoPlaybackEnded();}function isVideoPaused(){return getVideo()[0].paused;}function isJwplayerVideo(){var product_gallery=getVisibleProductGallery();return product_gallery.find("#myjwplayer_wrapper").is(":visible")||product_gallery.find("div#myjwplayer").is(":visible");
}function restartJwPlayerVideo(){var product_gallery=getVisibleProductGallery();var parent=product_gallery.find("#myjwplayer_wrapper").parent();$("#myjwplayer_wrapper").remove();parent.append('<div id="myjwplayer"></div>');jwinitplayer();if(isIoS()){jwplayer("myjwplayer").onComplete(restartJwPlayerVideo);}}function isYoutubeVideo(){var product_gallery=getVisibleProductGallery();return product_gallery.find("iframe.youtube_video").length>0;
}function stopYoutubeVideo(){var product_gallery=getVisibleProductGallery();var iframe=product_gallery.find("> iframe");var src=iframe.attr("src");iframe.attr("src",src);}function onVideoPlaybackStarted(){hideImageContainer();hideImage();hidePlayButton();showVideo();return true;}function onVideoPaused(){showImageContainer();showPlayButton();hideImage();return true;}function onVideoPlaybackEnded(){fadeInImage(showPlayButtonAndImage);
return true;}function onVideoError(e){}
