﻿
$(function(){$("#mainOverlay").hide();overlayHoverEffect();addCloseToVideoOverlay();sliderVideoForIpad();stopVideoPlaybackWhenSlided();if($('.slidewrap').size()>0){carousel=$('.slidewrap').carousel({slider:'.slider',slide:'.slide',slideHed:'.slidehed',nextSlide:'.next',prevSlide:'.prev',autoNav:true,addPagination:false,addNav:false});$(".slidewrap, a.next, a.prev, .slidecontrols").hover(function(){autoRotatingBlocked=true;},function(){autoRotatingBlocked=false;});var next=$('a.next');var prev=$('a.prev');var slidesTotal=$('.slidewrap .slide').length;currentSlideIndex=0;autoRotatingBlocked=false;next.click(function(){autoRotatingBlocked=true;if(currentSlideIndex+1==slidesTotal){clickItToIndex(prev,0);}else{currentSlideIndex++;}
$(".video .overlay").show("slow");togleThumbnailOnSlideChange();});prev.click(function(){autoRotatingBlocked=true;if(currentSlideIndex==0){clickItToIndex(next,slidesTotal-1);}else{currentSlideIndex--;}
$(".video .overlay").show("slow");togleThumbnailOnSlideChange();});}
setTimeout(function(){autoRotate()},3000);});function clickItToIndex(it,index){if(index!=$(".slide").index($(".carousel-active-slide"))){it.click();if(getInternetExplorerVersion()==7||/Opera/.test(navigator.userAgent)){var timeout=350;}else{var timeout=3;}
setTimeout(function(){clickItToIndex(it,index);},timeout);}else{autoRotatingBlocked=false;currentSlideIndex=index;}}
function autoRotate(){if(!autoRotatingBlocked){$("a.next").click();$(".video .overlay").show("slow");autoRotatingBlocked=false;}
setTimeout(function(){autoRotate();},3000);}
$(window).load(function(){placeOverlay();placeOverlay('.overlay h2');setModulesContainerHeight();});function equalizeHeight(selector){var elements=$(selector);for(var i=0;i<elements.length;i+=3){var heights=jQuery.map(elements,function(element,index){return $(element).height();});var max_height=Math.max.apply(null,heights);$(elements).each(function(h_index,element){$(element).height(max_height);});}}
function reduceSlideshowTop(){$('.slideshow .overlay').each(function(i,element){$(element).css('top',parseInt($(element).css('top'),10)+5);});}
function placeOverlay(selector){if(selector){equalizeHeight(selector);elements=$(selector);elements.each(function(i,element){var offset=$(element).closest("a, .video").outerHeight()-$(element).outerHeight();$(element).parent().css('top',offset-6);});}else{elements=$('.overlay');elements.each(function(i,element){var offset=$(element).closest("a, .video").outerHeight();$(element).css('top',offset-6);});}
reduceSlideshowTop();}
function lifting(elm){if(!elm.hasClass("lifted")){current_overlay=elm.find(".overlay")
current_overlay_offset=current_overlay.css('top');var new_offset=elm.closest("a, .video").outerHeight()-current_overlay.outerHeight();current_overlay.stop().animate({top:new_offset},{queue:true,duration:500});elm.addClass("lifted");}}
function unlifting(elm){if(elm.hasClass("lifted")){current_overlay.stop().animate({top:current_overlay_offset},{queue:true,duration:500,complete:function(){$(this).closest("a, .video").removeClass("lifted")}});}}
function overlayHoverEffect(){var links=$('.box > a .overlay, .slide > a .overlay, .video .overlay').parent();if(navigator.platform=="iPad"){for(var i=0;i<links.length;i++){links[i].addEventListener('touchstart',function(event){if(($(this).find("p").size()>0)&&!$(this).hasClass("lifted")){for(var j=0;j<links.length;j++){unlifting($(links[j]));}
event.preventDefault();lifting($(this));}},false);links[i].addEventListener('touchmove',function(){unlifting($(this));},false);}}else{links.hover(function(){lifting($(this));},function(){unlifting($(this));});}}
function setModulesContainerHeight(){var containerHeight=0;$('.box').each(function(h_index,element){if($(element).css('left')=="0px"){containerHeight+=$(element).outerHeight();}
$('.modules-container').css('height',containerHeight);});$('.FooterArea').show();$('.overlay').css('visibility','visible');}
function onYouTubePlayerReady(playerId){}
function stopVideoPlaybackWhenSlided(){if(!/MSIE(\d+\.\d+);/.test(navigator.userAgent)){if($('.slide.video').size()>0){$("a.next, a.prev").click(function(){for(index in array_with_youtube_players_ids){try{eval(array_with_youtube_players_ids[index]).pauseVideo();}
catch(Error){}}});}}}
function getInternetExplorerVersion()
{var rv=-1;if(navigator.appName=='Microsoft Internet Explorer')
{var ua=navigator.userAgent;var re=new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");if(re.exec(ua)!=null)
rv=parseFloat(RegExp.$1);}
return rv;}
function addCloseToVideoOverlay(){var overlays=$('.video .overlay')
overlays.append("<span class=\"close\">x</span>");$(".close").click(function(){$(this).closest('.overlay').hide();});}
function sliderVideoForIpad(){if(navigator.platform=="iPad"){var videos=$('.slideshow').find('.video').find('object');videos.closest('.video').addClass('ipad').prepend(function(index,html){return'<img src="'+getScreen($(this).find('param[name=movie]').attr('value'),'big')+'" alt="" /><span class="ipadPlay">&nbsp;</span>'}).click(function(){$(this).children('img').hide();$(this).children('.ipadPlay').hide();$(this).children('object').show();currentPlayerId=$(this).children('object').find('embed').attr('id');setTimeout(function(){eval(currentPlayerId).playVideo()},600);});videos.hide();}}
function togleThumbnailOnSlideChange(){if(navigator.platform=="iPad"){$('.slideshow').find('.video').find('object').hide();$('.slideshow').find('.video').find('img').show();$('.slideshow').find('.video').find('.ipadPlay').show();}}
function getScreen(url,size){if(url===null){return"";}
size=(size===null)?"big":size;var vid;var results;var from="";var to="";from=url.indexOf('/v/');to=url.indexOf('?ver');vid=url.substring(from+3,to);if(size=="small"){return"http://img.youtube.com/vi/"+vid+"/2.jpg";}else{return"http://img.youtube.com/vi/"+vid+"/0.jpg";}}
