/* * Javascript implementations for WhatAMan 2008 website * (c) Papercut Media. No reproduction without permission. Feel free to ask. * Author: Patrick Pittman * Date: October 2007 * Version: 1.0 * Requires: Prototype.js framework, ufo.js for flash loading, Dreamgirl on the other end for AJAXy JSON communication */ var Cookie = { set: function(name, value, daysToExpire) { var expire = ''; if (daysToExpire != undefined) { var d = new Date(); d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire))); expire = '; expires=' + d.toGMTString(); } return (document.cookie = escape(name) + '=' + escape(value || '') + expire); }, get: function(name) { // alert(document.cookie.inspect()); var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)')); return (cookie ? unescape(cookie[2]) : null); }, erase: function(name) { var cookie = Cookie.get(name) || true; Cookie.set(name, '', -1); return cookie; }, accept: function() { if (typeof navigator.cookieEnabled == 'boolean') { return navigator.cookieEnabled; } Cookie.set('_test', '1'); return (Cookie.erase('_test') === '1'); } }; var baseHref = "http://www.awesomearts.com/"; var siteBaseRel = "/"; var ajaxBase = baseHref + "js/ajax/"; function Papercut() { this.loaderlock = false; this.baseHref = "http://www.awesomearts.com/"; this.ajaxBase = this.baseHref+"js/ajax/"; this.ajaxProgress = document.createElement('img'); this.ajaxProgress.src = this.baseHref+"images/icons/ajax-loader.gif"; this.anchors = $H({}); } Papercut.prototype.init = function(e) { Element.extend(document.body); this.setupFeatureItem(); fixIEPNG(); if ($('infoTab')) { this.setupTabs(); } $$('.festivalContainer').each(function(el) { Papercut.clickBox(el); }); this.clickBox('featureItemContainer'); if ($('MailingList_Email')) { var emailwords = "enter your email address here"; if ($('MailingList_Email').value=='') { $('MailingList_Email').value = emailwords; } $('MailingList_Email').observe('focus',function(e){ if (this.value==emailwords) { this.value = ''; } }); $('MailingList_Email').observe('blur',function(e){ if (this.value=='') { this.value = emailwords; } }); } if (!document.location.href.match('login') && !document.body.hasClassName('editmode')) { } } Papercut.prototype.clickBox = function(myEl) { if ($(myEl)) { $(myEl).observe('click',function(e) { el = Event.findElement(e).up('div').down('a'); // alert(el.inspect()); e.stop(); if (el) { document.location.href = el.href; } }); $(myEl).observe('mouseover',function(e) { Event.element(e).setStyle({cursor: 'pointer'}); } ); } } Papercut.prototype.watchAnchors = function() { new PeriodicalExecuter(function() { Papercut.parseAnchor(); }, 0.2); } Papercut.prototype.getAnchorReqs = function() { var reqUri = document.location.href; reqAnchor = reqUri.lastIndexOf('#'); if (reqAnchor) { return reqUri.substr((reqAnchor + 1),reqUri.length).split('::'); } } Papercut.prototype.parseAnchor = function() { var reqState = this.getAnchorReqs(); // alert(reqState); if (reqState) { for (var i = 0; i < reqState.length; i++) { if (reqState[i].match("=")) { var reqString = reqState[i].split("="); reqArg = reqString[0]; reqVal = reqString[1]; } else { reqArg = reqState[i]; reqVal = null; } if (!this.anchors) { this.anchors = new Hash(); } switch(reqArg) { case "t" : this.anchors.set("t",reqVal); showTab(reqVal,'tab'); break; } } } } Papercut.prototype.writeAnchors = function(href) { if (this.anchors) { var anchorstring = new Array(); this.anchors.each(function(anchor) { if (anchor.value) { anchorstring.push(anchor.key+"="+anchor.value); } }); return this.stripAnchors(href)+"#"+anchorstring.join("::"); } else { return href; } } Papercut.prototype.stripAnchors = function(href) { // strip existing anchors reqAnchor = href.lastIndexOf('#'); if (reqAnchor > 0) { return href.substr(0,reqAnchor); } else { return href; } } Papercut.prototype.addAnchor = function(anchors) { if (Papercut.anchors) { anchors.each(function(anchor) { Papercut.anchors.set(anchor.key,anchor.value); }); } else { Papercut.anchors = anchors; } } var getURLVal = function(key, url, default_) { if (default_==null) default_=""; key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); reg = "[\\?&]"+key+"=([^&#]*)"; var regex = new RegExp(reg); if(url == null) url = window.location.href; var qs = regex.exec(url); if(qs == null) return default_; else return qs[1]; } var lastItem = null; var activeItem = null; Papercut.prototype.setupFeatureItem = function() { if ($('featureList')) { firstActive = $('featureList').firstDescendant('li'); if (!lastItem) { activeItem = getURLVal('FeatureItemID',firstActive.down('a').href); } else { activeItem = lastItem; } // alert(activeItem); var slider; slider = new PeriodicalExecuter(function(slide){ url = ajaxBase+'getFeatureItem/getNext/'+parseInt(activeItem); // alert(url); new Ajax.Updater('featureItemContainer', url,{ onSuccess: function(transport,json) { // alert(json.lastID); if (json.lastID) { activeItem = json.lastID; } // alert('bah'); } }); },10); $('featureList').observe('click',function(e) { thisElement = e.findElement('A'); e.stop(); if (slider) { slider.stop(); } thisItem = getURLVal('FeatureItemID',thisElement.href); req = ajaxBase+'getFeatureItem/'+parseInt(thisItem); lastItem = parseInt(thisItem); activeItem = lastItem; //alert(thisItem); //alert(req); new Ajax.Updater('featureItemContainer', req); }); } } Papercut.prototype.setupTabs = function() { this.watchAnchors(); var targetHeight = 0; var liHeight = 0; if ($$('.tabHeader').length) { lastLi = $$('.tabHeader').last(); if (lastLi){ dlOffset = lastLi.offsetTop + lastLi.getHeight(); // alert(dlOffset); - 32 $$('.tabHeader').each(function(el) { myDL = el.down('div'); myHeight = myDL.getHeight(); myDL.setStyle({top : dlOffset+"px"}); if (myHeight > targetHeight) { targetHeight = myHeight; } myLiHeight = el.getHeight(); if (myLiHeight > liHeight) { liHeight = myLiHeight; } Event.observe(el.down('span'),'click',function(e) { tab = /\d+$/i.exec(Event.element(e).up('li').id); Papercut.anchors.set('t',tab); document.location.href = Papercut.writeAnchors(document.location.href); showTab(tab,'tab'); } ); Event.observe(el.down('span'),'mouseover',function(e) { Event.element(e).setStyle({cursor: 'pointer'}); } ); }); targetHeight = targetHeight + liHeight +15; $('infoTab').setStyle({ height: targetHeight+"px", paddingBottom : liHeight+"px" }); if (Papercut.anchors.get('t')) { thisTab = Papercut.anchors.get('t'); } else { thisTab = 1; } // alert(thisTab); showTab(thisTab,'tab'); } } } showTab = function (i, prefix) { var i = i; $$('.'+prefix+'Header').each(function(el) { myTid = /\d+$/i.exec(el.id); if (parseInt(myTid) == i) { if (!el.hasClassName('active')) { el.addClassName('active'); Effect.Appear($(prefix+'Content'+i),{duration: 0.3}); } } else { el.removeClassName('active'); } }); // $(prefix+'Content'+i).show(); // $(prefix+'Content'+i).show(); } function cleanupFP9IELeaks() { __flash_unloadHandler = function() {}; __flash_savedUnloadHandler = function() {}; } function fixIEPNG() { var version = parseFloat(navigator.appVersion.split('MSIE')[1]); if ((version >= 5.5) && (document.body.filters)) { for(var i=0; i" img.outerHTML = strNewHTML i = i-1 } } } } function initPapercut() { if (window.initPapercutGallery) { initPapercutGallery(); }/* if (curvyCorners.init) { curvyCorners.init(); }*/ Papercut.init(); } var Papercut = new Papercut(); document.observe('dom:loaded',initPapercut);