var yearoffsets = new Array(); var maxwidth = new Number(); var _scrollinc = 400; var _expon = false; var imgarray = new Array(); $(document).ready(function () { maxwidth = $("#timeline").width(); $(".tyear").find('span').each(function () { var pos = $(this).position(); var txt = $(this).text(); if(!yearoffsets[txt]){ yearoffsets[txt] = pos.left; } }); $(".ti").each(function () { if($(this).attr('i') != undefined){ var itm = new Object(); itm.img = $(this).attr('i'); itm.target = $(this).find('.i:first'); itm.alt = $(this).find('.i:first').text(); var pos = $(this).position(); itm.left = pos.left; imgarray.push(itm); } $(this).click(function () { var date = $(this).attr('d'); var ext = $(this).find('.exp:first').text(); var pos = $(this).position(); scrolldecide(pos.left); if($(this).attr('i') != undefined){ $("#pp_img").html('' + $(this).find('.i:first').text() + ''); } else { $("#pp_img").html(''); } var hazrsrc = false; var hazint = false; if($(this).find('div.rsrc').find('a:first').text() != ''){ hazrsrc = true; var rsfill = 'Resources'; $(this).find('div.rsrc').find('a').each(function () { var linka = $(this).attr('href') + '" target="links"'; if(linka.indexOf('http://') == -1){ linka = $(this).attr('href') + '"'; } rsfill += ''; }); $("#pp_intv").html(ifill); $("#pp_intv").show(); } else { $("#pp_intv").hide(); } if(hazint && !hazrsrc){ $("#pp_intv").removeClass('interviews').addClass('interviews_single'); } if(hazint && hazrsrc){ $("#pp_intv").removeClass('interviews_single').addClass('interviews'); $("#pp_rsrc").removeClass('resources_single').addClass('resources'); } if(hazrsrc && !hazint){ $("#pp_rsrc").removeClass('resources').addClass('resources_single'); } if(!hazrsrc && !hazint){ $("#pp_linea").hide(); } else { $("#pp_linea").show(); } $("#pp_dat").text($(this).attr('d')); $("#pp_bod").html($(this).find('.exp:first').html()); $("#pp_tit").text($(this).find('.t:first').text()); $("#cronexpand").css({ 'opacity':1, 'margin-left': (($("#timeline_outer").width() / 2) - 280) + 'px' }); $("#cronexpand").fadeIn(); _expon = true; }); }); $("#scrollleft").hide(); $("#scrollright").click(function () { scrollleft(); }); $("#scrollleft").click(function () { scrollright(); }); $(document).keydown(function (eve){ if(eve.which == 27){ if(_expon){ boxclose(); } } if(eve.which == 37){ scrollright(); } if(eve.which == 39){ scrollleft(); } }); if(_ismobile){ $("#timeline_outer").swipe({ swipeLeft: function () { scrollright(); }, swipeRight: function () { scrollleft(); } }); } if(window.location.href.indexOf('#') != -1){ var dat = window.location.href.substring(window.location.href.indexOf('#')+1, window.location.href.length); dat = decodeURIComponent(dat); if(yearoffsets[dat]){ scrolltoyear(dat); } } else { imgupdate(0); } }); $(window).resize(function () { var curpos_start = $("#timeline").position(); var curpos = curpos_start.left; imgupdate(curpos); }); function boxclose () { $("#cronexpand").fadeOut(); _expon = false; } function scrollright () { var curpos_start = $("#timeline").position(); var curpos = 0 - curpos_start.left; scrollcore(curpos - _scrollinc); } function scrollleft () { var curpos_start = $("#timeline").position(); var curpos = 0 - curpos_start.left; scrollcore(curpos + _scrollinc); } function scrolldecide (target) { target = 0 - target; var curwidth = $("#timeline_outer").width(); var curpos_start = $("#timeline").position(); var curpos = curpos_start.left; if(target > curpos){ scrollcore(0 - target); } else { if((target - 220) < (curpos - curwidth)){ scrollcore(0 - (target + (curwidth - 500))); } } } function imgupdate (target) { target = 0 - target; leftcheck = target; var curwidth = $("#timeline_outer").width(); var newarray = new Array(); for(var x = 0; x < imgarray.length; x++){ if((imgarray[x].left > (leftcheck - 100)) && (imgarray[x].left < (leftcheck + curwidth))){ imgarray[x].target.html('' + imgarray[x].alt + ''); } else { newarray.push(imgarray[x]); } } imgarray = newarray; } function scrolltoyear (yeartarget) { if(_expon){ boxclose(); } scrollcore(yearoffsets[yeartarget]); } function scrollcore (target) { var curpos_start = $("#timeline").position(); var curpos = curpos_start.left; var curwidth = $("#timeline_outer").width(); var scrollpoint = 100 - target; if((0 - scrollpoint) > (maxwidth - curwidth)){ scrollpoint = (0 - (maxwidth - curwidth)); $("#scrollright").hide(); } else { $("#scrollright").show(); } if(scrollpoint > 0){ scrollpoint = 0; } $("#timeline").stop(); $("#timeline").animate({ 'left': scrollpoint + 'px' }); imgupdate(scrollpoint); if(scrollpoint > -200){ $("#scrollleft").hide(); } else { $("#scrollleft").show(); } }