/* File: js/hub.js, Ratio: 18% */

var frontPageIntId;var frontPageTimerId;var currFrontPageId;var nextFrontPageId;var prevFrontPageId;var frontPageDelay=7000;var totalsRefresh=10000;var totalsRefreshInterval;function frontPageTimerStart(){if(!nextFrontPageId||nextFrontPageId.length==0){nextFrontPageId=$('#frontPageMenu a').first().attr('id');}
frontPageTimerStop();frontPageIntId=setInterval("selectEntry(nextFrontPageId)",frontPageDelay);}
function frontPageTimerStop(){clearInterval(frontPageIntId);}
function selectEntry(entryName){if(entryName=='nextFrontPage'){entryName=nextFrontPageId;}else if(entryName=='prevFrontPage'){entryName=prevFrontPageId;}
var btn=$('#frontPageMenu').find('#'+entryName);var win=$('#frontPageList').find('.'+entryName);prevFrontPageId=btn.closest('li').prev().find('a').attr('id');if(!prevFrontPageId){prevFrontPageId=btn.closest('ul').find('li a').last().attr('id');}
currFrontPageId=entryName;if(btn.closest('li').next('li').length>0){nextFrontPageId=btn.closest('li').next('li').find('a').attr('id');}else{nextFrontPageId=btn.closest('ul').find('li a').first().attr('id');}
if(win.length>0){$('#frontPageList').scrollTo(win,{duration:100});}
$('#frontPageMenu').find('a').removeClass('sel');if(btn.length>0){btn.addClass('sel');}};jQuery.fn.clickEntry=function(entryName){frontPageTimerStop();frontPageTimerId=setTimeout("frontPageTimerStart()",15000);selectEntry($(this).attr('id'));};function vCenterLargeMenu(){$('.hubLargeMenu').each(function(){var _currH=$(this).parent().height();var _parentH=$(this).closest('.hubTop').height();if(_currH<_parentH){$(this).parent().css('margin-top',(_parentH-_currH)/2);}});};var scrollReverse=false;var scrollInit=false;var scrollRate=2;var scrollObj;$.fn.partnersScroll=function(){var _self=$(this),_dst=scrollReverse?0:'max',_rate=scrollRate/100,_winWidth=_self.innerWidth(),_scrollWidth=_self.find('table:first').innerWidth()-_winWidth,_left=_self.scrollLeft(),_afterPause=_winWidth/_rate/2,_distance=scrollReverse?_left:_scrollWidth-_left,_dur=_distance/_rate;var msg='Scroll Distance: '+_scrollWidth+'px\n';msg+='Scroll Position: '+_left+'px\n';msg+='Direction: '+(scrollReverse?'Left':'Right')+'\n';msg+='Distance: '+_distance+"px = Rate: "+_rate+" * Time: "+(_dur/1000)+"s\n";msg+='Window Width: '+_winWidth+'\n';if(_dur<1){_dur=0;}
_self.scrollTo(_dst,_dur,{axis:'x',easing:'linear',onAfter:function(){scrollReverse=scrollReverse?false:true;setTimeout("scrollObj.partnersScroll()",_afterPause);}});if(!scrollInit){scrollObj=_self;_self.hover(function(){_self.addClass('hover').partnersScrollStop();},function(){_self.removeClass('hover').partnersScroll();});scrollInit=true;}}
$.fn.partnersScrollStop=function(){var buffer=10;$(this).stop(true,false).scrollTo((scrollReverse?'-=':'+=')+buffer+'px',250);};$.fn.animateHighlight=function(highlightColor,duration){var highlightBg=highlightColor||"#FFFF9C";var animateMs=duration||"fast";var originalBg=this.css("background-color");if(!originalBg||originalBg==highlightBg){originalBg="#FFFFFF";}
$(this).css("backgroundColor",highlightBg).animate({backgroundColor:originalBg},animateMs,null,function(){jQuery(this).css("backgroundColor",originalBg);});};function hubTotalsInit(){if(hubId){var $totalsUrl="/ajax/hubs/front_page_stats/"+hubId;var $intervalCounter=0;if(cityId){$totalsUrl+="/"+cityId;}
setInterval(function(){var $container=$('.hubTotalHorizontal');$intervalCounter++;$.ajax({url:$totalsUrl,isModified:true,success:function($text){$container.replaceWith($text).animateHighlight();}});},totalsRefresh);}}
$(document).ready(function(){vCenterLargeMenu();$('.partnerScroll').partnersScroll();$('#frontPageList').children('div').wrap('<td>');$('#frontPageList').wrapInner('<table cellspacing="30"><tr>');$('#frontPageList')._scrollable();$('#frontPageMenu a').click(function(){$(this).clickEntry();});$('#frontPageMenu').css('left',function(){return $(this).parent().width()/2-$(this).width()/2});selectEntry('entry0');$preview=$('.frontPagePreview .dimensions');$box=$('.frontPagePreview .frontPageWindow');if($preview.length>0&&$box.length>0){$preview.html('<strong>Dimensions: '+$box.width()+"px X "+$box.height()+"px</strong>");}else{$('#frontPageHolder').hover(frontPageTimerStop,frontPageTimerStart);frontPageTimerStart();}
hubTotalsInit();});
