(function(jQuery){var cache=[];jQuery.preLoadImages=function(){var args_len=arguments.length;for(var i=args_len;i--;){var cacheImage=document.createElement('img');cacheImage.src=arguments[i];cache.push(cacheImage)}}})(jQuery);jQuery(document).ready(function(){var id=0,feedxml,ko=new Date(),time=ko.getTime(),promoBox=jQuery('#promoBoxjq .promoBoxWrapperjq'),promoButtons=jQuery('.promobutton',promoBox),timer
function fadeInPromo(pid){if(pid>=feedxml.length)return false;var promo=jQuery(feedxml[pid]);promoBox.animate({opacity:0},500,function(){var newURL,vid=jQuery('video_id',promo).text();if(vid.length>0){newURL=MPORA.globalVars.video_base_url+'watch/'+vid+'/'}else newURL=jQuery('link_url',promo).text();newURL+='?utm_source='+MPORA.globalVars.interest_url+'-front&utm_medium=Promo&utm_term='+MPORA.globalVars.interest_url+'&utm_content='+jQuery('title_url',promo).text()+'&utm_campaign=Promo';if(newURL.length>0){promoBox.attr('href',newURL)}else promoBox.removeAttr('href');promoBox.find('h2 span').text(jQuery('title',promo).text());promoBox.find('p').text(jQuery('text',promo).text());var imageURL=jQuery('image_filename',promo).text();promoBox.css('backgroundImage','url('+imageURL+')').animate({opacity:1},500)})}
function cyclePromos(){clearTimeout(timer);id++;if(id>=feedxml.length)id=0;fadeInPromo(id);timer=setTimeout(cyclePromos,6000)};promoBox.hover(function(){clearTimeout(timer);promoButtons.stop(true,true).fadeIn('fast')},function(){timer=setTimeout(cyclePromos,6000);promoButtons.stop(true,true).fadeOut('fast')});promoButtons.click(function(e){e.preventDefault();if(jQuery(this).attr('id')=='prev'){id--;if(id<0)id=feedxml.length-1}else{id++;if(id>=feedxml.length)id=0};fadeInPromo(id);return false});jQuery.ajax({url:promoUrl+MPORA.globalVars.lang+'/stamp/'+time,type:"GET",dataType:'xml',success:function(xml){feedxml=jQuery(xml).children('promos').children('item');if(feedxml.length>1){var preloadImage;feedxml.each(function(){preloadImage=jQuery('image_filename',this).text();preloadImage=preloadImage.replace(/ /g,'%20');jQuery('image_filename',this).text(preloadImage);jQuery.preLoadImages(preloadImage)});timer=setTimeout(cyclePromos,6000)}}});jQuery(promoBox).click(function(){if(jQuery(this).attr('href')>'')window.location.href=jQuery(this).attr('href')})});
