var viewportW=0;var viewportH=0;var documentH=0;var sectionYcords=[];var tabXcords=[];var highestTab="";var lowestTab="";var highlowTabDiff=0;var distYMoved=0;var currentPage="";var currentDirection="";var disableActions=0;var disableResize=0;var isTriggered=0;var fullURL="";var page="";var currentPage="";var imageDirs=[{'dir':'/wp-content/themes/philosophy/images/background/7/'},{'dir':'/wp-content/themes/philosophy/images/background/8/'},{'dir':'/wp-content/themes/philosophy/images/background/1/'},{'dir':'/wp-content/themes/philosophy/images/background/6/'},{'dir':'/wp-content/themes/philosophy/images/background/5/'}];var currentBGImage=0;var bgimages=[{'name':'bg_4-3_1024x768.jpg','height':'768','width':'1024'},{'name':'bg_16-9_1366x768.jpg','height':'768','width':'1366'},{'name':'bg_5-8_1280x800.jpg','height':'800','width':'1280'},{'name':'bg_4-3_1152x864.jpg','height':'864','width':'1152'},{'name':'bg_16-10_1440x900.jpg','height':'900','width':'1440'},{'name':'bg_5-4_1280x1024.jpg','height':'1024','width':'1280'},{'name':'bg_16-10_1680x1050.jpg','height':'1050','width':'1680'},{'name':'bg_16-9_1920x1080.jpg','height':'1080','width':'1920'},{'name':'bg_4-3_1600x1200.jpg','height':'1200','width':'1600'},{'name':'bg_16-10_1920x1200.jpg','height':'1200','width':'1920'},{'name':'bg_16-9_2560x1440.jpg','height':'1440','width':'2560'},{'name':'bg_16-10_2560x1600.jpg','height':'1600','width':'2560'}];var currentBGName="";var images4Gallery=[];var currentGalleryImage="";var galleryInit=0;$(document).ready(function(){currentPageOn();loadInSectnTabs();loadInViewPortSizeAndDocHeight();centerTabs();suitableBackground();doChecks(1);$("a.tablinks, ul#smallnav a:not(a[rel='external'])").click(function(){letsAnimate(this);return false;});$(window).resize(function(){resizeFunctions();});$("#twitterfeedcontainer >a").click(function(event){openCloseTwitterBox(event);});$(".tpfollow div.navi.up").click(function(){moveUpDownTwitterfeed("up");});$(".tpfollow div.navi.down").click(function(){moveUpDownTwitterfeed("down");});});function changeBGImage(){disableResize=1;currentBGImage++;if(currentBGImage==imageDirs.length){currentBGImage=0;}
$('<img />').attr('src',imageDirs[currentBGImage].dir+currentBGName).load(function(){$("div#bg2").css('background-image','url('+imageDirs[currentBGImage].dir+currentBGName+')');$("div#bg2").fadeIn(1000);$("div#bg1").fadeOut(1000,function(){$("div#bg1").css('background-image','url('+imageDirs[currentBGImage].dir+currentBGName+')');$("div#bg1").show();$("div#bg2").hide();disableResize=0;});});}
function letsAnimate(url,reanimate){if(disableActions==1){return;}else{disableActions=1;}
fullURL=url;var urlData=parseURL(fullURL);var urlsplit=[];urlsplit=urlData.path.split('/');page=urlsplit[1];if(page==currentPage&&reanimate!=1){disableActions=0;return;}
if(!pparray[page]){page="404";}
_gaq.push(['_trackPageview','/'+page]);doChecks(0);$("div#content").hide(pparray[currentPage]['content']['e'],{direction:pparray[currentPage]['content']['d']},1000,function(){currentPage=page;for(var pageOn in pparray[page]['positions']){var positionToMoveTo=pparray[page]['positions'][pageOn]['x'];if(page==pageOn){$("div#tab"+pparray[page]['positions'][pageOn]['id']+" a").addClass('selected');}else{$("div#tab"+pparray[page]['positions'][pageOn]['id']+" a").removeClass('selected');}
if(page==pageOn){$("div#section"+pparray[page]['positions'][pageOn]['id']).addClass('selectedsec');}else{$("div#section"+pparray[page]['positions'][pageOn]['id']).removeClass('selectedsec');}
if(pparray[page]['positions'][pageOn]['d']==0){$("div#section"+pparray[page]['positions'][pageOn]['id']).hide();}
$("div#section"+pparray[page]['positions'][pageOn]['id']).css("z-index",pparray[page]['positions'][pageOn]['z']);$("div#section"+pparray[page]['positions'][pageOn]['id']).animate({left:''+positionToMoveTo+''},1000,function(){if(isTriggered==1){return;}else{isTriggered=1;}
$("div#content").css({"top":pparray[page]['content']['y']+distYMoved,"left":pparray[page]['content']['x'],"width":pparray[page]['content']['w']});if(pparray[page]['content']['b']==0){$("div#content").removeClass('withbg');}else{$("div#content").addClass('withbg');}
if(pparray[page]['content']['a']==0){$("div#tab"+pparray[page]['positions'][page]['id']+" a.tablinks").before("<img class='loading' src='/wp-content/themes/philosophy/images/ajax-loader.gif' alt='Loading - Please Wait' title='Loading - Please Wait' />");}
$.post(fullURL,{ajaxrequest:"1"},function(data){$("div#content").html(data);$("img.loading").remove();doChecks(1);$("div#content").show(pparray[currentPage]['content']['e'],{direction:pparray[page]['content']['d']},1000,function(){disableActions=0;isTriggered=0;changeBGImage();resizeFunctions();});});});}});}
function resizeFunctions(){if(disableActions==1||disableResize==1){return;}
loadInViewPortSizeAndDocHeight();centerTabs();suitableBackground();}
function loadInViewPortSizeAndDocHeight()
{viewportW=$(window).width();viewportH=$(window).height();documentH=$(document).height();}
function centerTabs()
{var tabdisttop=Math.floor((viewportH-highlowTabDiff)/2);if(tabdisttop<0){tabdisttop=0;}
var actualtabtopdist=parseInt($("div#"+highestTab).css('top'));var difffromtop=tabdisttop-actualtabtopdist;distYMoved+=difffromtop;$("div.tabs, div#content").each(function(){var newTop=(parseInt($(this).css('top'))+difffromtop)+"px";$(this).css('top',newTop);});}
function loadInSectnTabs()
{var highestvariable=0;var lowestvariable=9999;$("div.tabs").each(function(){tabXcords[this.id.replace("tab","")]=parseInt($(this).css('top'));if(parseInt($(this).css('top'))>highestvariable&&this.id!="tab8")
{highestvariable=parseInt($(this).css('top'));lowestTab=this.id;}
if(parseInt($(this).css('top'))<lowestvariable&&this.id!="tab8")
{lowestvariable=parseInt($(this).css('top'));highestTab=this.id;}});$("div.sections").each(function(){sectionYcords[this.id.replace("section","")]=parseInt($(this).css('left'));});highlowTabDiff=highestvariable-lowestvariable+parseInt($("div#tab0").css('height'));}
function suitableBackground()
{for(var i=0;i<bgimages.length;i++)
{if(bgimages[i].height>=documentH&&bgimages[i].width>=viewportW)
{$("div#bg1").css('background-image','url('+imageDirs[currentBGImage].dir+bgimages[i].name+')');currentBGName=bgimages[i].name;break;}}}
function currentPageOn(){currentPage=window.location['pathname'];var urlsplit=[];urlsplit=currentPage.split('/');currentPage=urlsplit[1];if(currentPage==""){currentPage="home";}}
function doChecks(check){$('a[rel="external"]').attr("target","_blank");if(currentPage=="photos"){setupPhotoPage(check);}
if(currentPage=="palmares"){setupPalmares(check);}
if(currentPage=="news"){if(check==1){$("div.wp-pagenavi a").click(function(){letsAnimate(this,1);return false;});}else{$("div.wp-pagenavi a").unbind('click');}}}
function setupPalmares(check){if(check==1){$("span.palyear").mouseenter(function(){$("span.palyear").removeClass("selected");$(this).addClass("selected");$("table.palmares").addClass("hide");var newtableid="palt-"+this.id.replace("pal-","");$("table#"+newtableid).removeClass("hide");});}else{$("span.palyear").unbind('mouseenter');}}
function setupPhotoPage(check){if(check==1){$("img.galleryimg").each(function(){images4Gallery[images4Gallery.length]=this.id.replace("photo-","");});$("img.galleryimg").mouseenter(function(){var id=this.id.replace("photo-","");$("div#photod-"+id).show();});$("img.galleryimg").mouseleave(function(){var id=this.id.replace("photo-","");$("div#photod-"+id).hide();});$("img.galleryimg").click(function(){initializeGallery(this.id.replace("photo-",""));return false;});$("a#startGallery").click(function(){initializeGallery($("img.galleryimg:first").attr('id').replace("photo-",""));return false;});}else{images4Gallery=[];$("img.galleryimg").unbind('mouseenter');$("img.galleryimg").unbind('mouseleave');$("img.galleryimg").unbind('click');$("a#startGallery").unbind('click');}}
function parseURL(url){var a=document.createElement('a');a.href=url;return{source:url,protocol:a.protocol.replace(':',''),host:a.hostname,port:a.port,query:a.search,params:(function(){var ret={},seg=a.search.replace(/^\?/,'').split('&'),len=seg.length,i=0,s;for(;i<len;i++){if(!seg[i]){continue;}
s=seg[i].split('=');ret[s[0]]=s[1];}
return ret;})(),file:(a.pathname.match(/\/([^\/?#]+)$/i)||[,''])[1],hash:a.hash.replace('#',''),path:a.pathname.replace(/^([^\/])/,'/$1'),relative:(a.href.match(/tps?:\/\/[^\/]+(.+)/)||[,''])[1],segments:a.pathname.replace(/^\//,'').split('/')};}
function initializeGallery(startingID){if(galleryInit==1){return;}else{galleryInit=1;}
for(var i=0;i<images4Gallery.length;i++){if(images4Gallery[i]==startingID){currentGalleryImage=i;}}
$("div#content").append('<div id="galleryGO">&nbsp;</div>');$("div#galleryGO").height($("#content").height()-10);$("div#galleryGO").fadeTo("slow",0.8,function(){$("div#content").append('<div id="galleryContainer"></div>');$("div#galleryContainer").append('<div id="galleryIMGContainer"></div>');$("div#galleryContainer").append('<div id="closegallery" class="galleryButton">CLOSE</div>');$("div#content").append('<div id="galleryFootContainer">Image <span id="galcount">0</span> of <span id="galcounttotal">'+images4Gallery.length+'</span></div>');$("div#galleryFootContainer").append('<div id="nextgallery" class="galleryButton">NEXT</div><div id="prevgallery" class="galleryButton">PREV</div>');$("div#galleryContainer").fadeIn("slow",function(){$("div#nextgallery").click(function(){moveToNextImage('next');});$("div#prevgallery").click(function(){moveToNextImage('previous');});loadGalleryImage();});});}
function loadGalleryImage(){var imageURL=$("a#photol-"+images4Gallery[currentGalleryImage]).attr('href');var imageTitle=$("div#photod-"+images4Gallery[currentGalleryImage]+" p.phototitle").text();$('<img />').attr({'id':'galleryImage','src':imageURL,'alt':imageTitle,'title':imageTitle}).load(function(){$('div#galleryIMGContainer').append($(this));$(this).fadeIn("slow",function(){$("div#photod-"+images4Gallery[currentGalleryImage]).show();$("span#galcount").text(''+(currentGalleryImage+1)+'');$("div#galleryFootContainer").show("blind",{},500);$("div#closegallery").click(function(){closeGallery();});});});}
function moveToNextImage(direction){$("div#closegallery").unbind('click');$("div#photod-"+images4Gallery[currentGalleryImage]).hide();$("div#galleryFootContainer").hide("blind",{},500,function(){$("img#galleryImage").fadeOut("slow",function(){$("img#galleryImage").remove();if(direction=="next"){currentGalleryImage+=1;}else{currentGalleryImage-=1;}
if(currentGalleryImage>=images4Gallery.length){currentGalleryImage=0;}
if(currentGalleryImage<0){currentGalleryImage=images4Gallery.length-1;}
galleryInit=0;loadGalleryImage();});});}
function closeGallery(){$("div#nextgallery, div#prevgallery, div#closegallery").unbind('click');$("div#photod-"+images4Gallery[currentGalleryImage]).hide();$("div#galleryFootContainer").hide("blind",{},500,function(){$("div#galleryContainer").fadeOut("slow",function(){$("div#galleryGO").fadeOut("slow",function(){$("div#galleryGO").remove();$("div#galleryContainer").remove();$("div#galleryFootContainer").remove();galleryInit=0;});});});}
var tp_open_close_state=false;var tp_running=false;function openCloseTwitterBox(event){event.preventDefault();if(true===tp_running){return}else{tp_running=true;}
if(false===tp_open_close_state){tp_open_close_state=true;$(".tpfeed .tploading").show();$("#tweetspanel").show("slide",{direction:"down"},250,function(){$.getJSON('http://twitter.com/statuses/user_timeline.json?screen_name=MarkCavendish&count=10&callback=?',function(data){$(".tpfeed .tploading").hide("slide",{direction:"down"},250,function(){$.each(data,function(key,val){var text=parseTwitter(val);var date=parseTwitterDate(val.created_at);$('.tpfeed').append('<div class="item tptweet">'+text+'<span class="tpdate">'+date+'</span></div>');});loadInTweets();});});});}else{tp_open_close_state=false;$("#tweetspanel").hide("slide",{direction:"down"},250,function(){$("div.item.tptweet").remove();$(".navi.up, .navi.down").hide();tp_running=false;});}}
function loadInTweets(){$("div.item.tptweet:lt(3)").show("slide",{direction:"down"},250,function(){loadButtons();tp_running=false;});}
function loadButtons(){var count=$("div.item.tptweet").length;var index=$('div.item.tptweet').index($('div.item.tptweet:visible'));if(0<index){$(".navi.up").show();}else{$(".navi.up").hide();}
if((count-3)>index){$(".navi.down").show();}else{$(".navi.down").hide();}}
function moveUpDownTwitterfeed(direction){if(true===tp_running){return}else{tp_running=true;}
var index=$('div.item.tptweet').index($('div.item.tptweet:visible'));if("up"==direction){$('div.item.tptweet:eq('+(index+2)+')').hide("slide",{direction:"down"},250,function(){$('div.item.tptweet:eq('+(index-1)+')').show("slide",{direction:"up"},250,function(){loadButtons();tp_running=false;});});}else if("down"==direction){$('div.item.tptweet:eq('+index+')').hide("slide",{direction:"up"},250,function(){$('div.item.tptweet:eq('+(index+3)+')').show("slide",{direction:"down"},250,function(){loadButtons();tp_running=false;});});}else{tp_running=false;}}
function parseTwitter(tweet){var text=tweet.text.toString().replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,'<a href="$1">$1</a>').replace(/(^|\s)@(\w+)/,'<a href="http://www.twitter.com/$2">@$2</a>').replace(/[#]+[A-Za-z0-9-_]+/ig,function(t){var tag=t.replace("#","%23");return t.link("http://search.twitter.com/search?q="+tag);});return text;}
function parseTwitterDate(tdate){var system_date=new Date(Date.parse(tdate));var user_date=new Date();if(K.ie){system_date=Date.parse(tdate.replace(/( \+)/,' UTC$1'))}
var diff=Math.floor((user_date-system_date)/1000);if(diff<=1){return"just now";}
if(diff<20){return diff+" seconds ago";}
if(diff<40){return"half a minute ago";}
if(diff<60){return"less than a minute ago";}
if(diff<=90){return"one minute ago";}
if(diff<=3540){return Math.round(diff/60)+" minutes ago";}
if(diff<=5400){return"1 hour ago";}
if(diff<=86400){return Math.round(diff/3600)+" hours ago";}
if(diff<=129600){return"1 day ago";}
if(diff<604800){return Math.round(diff/86400)+" days ago";}
if(diff<=777600){return"1 week ago";}
return"on "+system_date;}
var K=function(){var a=navigator.userAgent;return{ie:a.match(/MSIE\s([^;]*)/)}}();
