function i_set_status(new_status) { expireDate = new Date(); expireDate.setTime(expireDate.getTime() + (1000 * 60 * 60 * 24 * 365)); expireStr = expireDate.toGMTString(); document.cookie="crgs_infobox_disable=" + ((new_status)?"0":"1") + ";expires=" + expireStr; document.location.reload(); } var i_feeds = new Array(); i_feeds.push( new Array("popular_feeds","uk") ); i_feeds.push( new Array("popular_feeds","world") ); i_feeds.push( new Array("popular_feeds","sport") ); i_feeds.push( new Array("popular_feeds","business") ); i_feeds.push( new Array("popular_feeds","technology") ); i_feeds.push( new Array("popular_feeds","on_this_day") ); i_feeds.push( new Array("popular_feeds","strange_news") ); /* write infobox */ document.write("
 
 
 
"); /* xmlhttprequest object */ var i_req; /* array of stories for this feed. each element is an array: [title, description, link] */ var i_stories; /* index of the current story */ var i_story; /* time to keep each story active */ var i_story_length = 10000; /* various timeouts for fading animation and waiting for new story */ var i_story_timeout, i_fade_in_timeout, i_fade_out_timeout; /* current opacity of the text, 0 = transparent, 1 = opaque */ var i_opacity = 0; function i_go() { window.location = i_stories[i_story][2]; } /* change to different feed */ function i_change_feed(category, name) { /* clearing timeouts stops the script going insane */ window.clearTimeout(i_story_timeout); window.clearTimeout(i_fade_in_timeout); window.clearTimeout(i_fade_out_timeout); /* write a cookie so the page remembers which tab should be active by default make the cookie expire in a year's time */ expireDate = new Date(); expireDate.setTime(expireDate.getTime() + (1000 * 60 * 60 * 24 * 365)); expireStr = expireDate.toGMTString(); document.cookie = "crgsonline_infobox_tab=" + category + ":" + name + ";expires=" + expireStr; /* display loading message */ document.getElementById("i_ui_body_inner").innerHTML = "Loading feed...
 "; /* send an http request */ i_get_feed(category, name); /* update the tab display */ for(i_i = 0; i_i < i_feeds.length; i_i++) { i_thiscat = i_feeds[i_i][0]; i_thisname = i_feeds[i_i][1]; document.getElementById("i_ui_tab_" + i_thiscat + "_" + i_thisname).className = ((i_thiscat == category && i_thisname == name) ? "i_ui_tab_on" : "i_ui_tab"); } } /* request feed from server */ function i_get_feed(category, name) { /* get time in milliseconds since epoch to prevent caching of feed.php */ uncache = (new Date()).getTime().toString(); href = "/infobox/feed.php?category=" + category + "&name=" + name + "&uncache=" + uncache; /* everything except IE on Windows */ if (window.XMLHttpRequest) { i_req = new XMLHttpRequest(); i_req.onreadystatechange = i_got_feed; i_req.open("GET", href, true); i_req.send(null); } /* IE on windows */ else if (window.ActiveXObject) { i_req = new ActiveXObject("Microsoft.XMLHTTP"); if (i_req) { i_req.onreadystatechange = i_got_feed; i_req.open("GET", href, true); i_req.send(); } } } /* http request for feed complete */ function i_got_feed() { /* readyState == 4 indicates transfer is complete. 200 is the http code for "OK" */ if(i_req.readyState == 4 && i_req.status == 200) { /* each story is separated by a newline */ data_in = i_req.responseText.split("\n"); var numstories = 0; i_stories = new Array(); for(idx=0;idx= i_stories.length) { new_idx = 0; } i_change_story(new_idx); } /* change story index */ function i_change_story(story_idx) { /* clear timeouts to prevent script going insane */ window.clearTimeout(i_story_timeout); window.clearTimeout(i_fade_in_timeout); window.clearTimeout(i_fade_out_timeout); /* update variables and fade out the old story */ i_story = story_idx; i_change_opacity(1); i_fade_out(); } /* ready to change story - finished fading out the old one */ function i_change_story_ready() { /* clear timeouts */ window.clearTimeout(i_story_timeout); window.clearTimeout(i_fade_in_timeout); window.clearTimeout(i_fade_out_timeout); if(i_story >= i_stories.length) { return; } /* write new story to i_ui_body_inner */ document.getElementById("i_ui_body_inner").innerHTML = "" + i_stories[i_story][0] + "
" + i_stories[i_story][1] + "
"; // document.getElementById("i_ui_body_inner").innerHTML = "" + i_stories[i_story][0] + "
" + i_stories[i_story][1] + ""; /* fade in this new story */ i_fade_in(); /* work out what the index of the next story will be */ new_idx = i_story + 1; if(new_idx >= i_stories.length) { new_idx = 0; } /* set a timeout for the next story */ i_story_timeout = window.setTimeout("i_change_story(" + new_idx + ")", i_story_length); } /* fade out a story */ function i_fade_out() { /* reduce opacity - can't be less than 0 */ i_opacity -= 0.1; if(i_opacity < 0) i_opacity = 0; i_change_opacity(); /* finished fading out so we're ready to change the story */ if(i_opacity <= 0) { i_fade_out_timeout = window.setTimeout("i_change_story_ready()", 30); } /* or keep fading out a bit more */ else { i_fade_out_timeout = window.setTimeout("i_fade_out()", 30); } } /* fade in a story */ function i_fade_in() { /* increase opacity - can't be greater than 1 */ i_opacity += 0.1; if(i_opacity > 1) i_opacity = 1; i_change_opacity(); /* do nothing if we're finished fading in - kept the IF statement in case you want to do something here */ if(i_opacity >= 1) { } /* keep going if we haven't finished yet */ else { i_fade_in_timeout = window.setTimeout("i_fade_in()", 30); } } /* change opacity */ var i_colours=new Array("#D8E5F8","#C8D8E8","#B8C8D8","#A8B8C8","#98A8B8","#788898","#586878","#384858","#283848","#182838","#000000"); function i_change_opacity(new_opacity) { /* everything except IE */ //document.getElementById("i_ui_body_table").style.opacity = i_opacity; /* IE */ //window.status = i_opacity + " = " + parseInt((i_opacity*10)) + " = " + i_colours[(i_opacity*10)]; document.getElementById("i_ui_link").style.color = i_colours[ parseInt((i_opacity*10)) ]; //document.getElementById("i_ui_body_table").style.filter = "alpha(opacity=" + (i_opacity*100) + ")"; } /* open customisation window */ function i_customise() { i_opened = window.open("/infobox/customise.php","i_customise_win","width=400,height=500,scrollbars=yes"); if(!i_opened) { /* open standalone version of window.open() blocked */ window.location = "/infobox/customise.php?s=1"; } } /* if the user does actually have feeds then write a startup function that will load the zeroth feed, or, if they have a cookie set, their own chosen feed (as long as it exists) */ if(i_feeds.length > 0) { window.onload=function() { /* do we want to load the zeroth feed */ i_load_default = true; /* find a cookie */ if(document.cookie.toString().indexOf("crgsonline_infobox_tab") != -1) { infoStr = document.cookie.toString().split("crgsonline_infobox_tab=")[1].split(";")[0]; infoStr = infoStr.split(":"); fcategory = infoStr[0]; fname = infoStr[1]; /* go through the user's feeds, check the feed in the cookie still exists */ for(i=0;i