var clf_container = 'clf'; var clf_markup = '' + '
'+ '
'+ '

More

'+ '
'; // Create css and container document.writeln(''); document.writeln('
'); // Include libraries if missing if ((typeof Prototype=='undefined')) document.writeln(''); if ((typeof Effect=='undefined')) document.writeln(''); function addonload(func) { if (typeof window.addEventListener != 'undefined') { window.addEventListener('load', func, false); } else if (typeof window.attachEvent != "undefined") { // IE window.attachEvent('onload', func ); } else { if (window.onload != null) { // maintain any other onload events var oldOnload = window.onload; window.onload = function (e) { oldOnload(e); func(); }; } else { window.onload = func; } } } // Onload javascript (basically waits for prototype to be loaded) var clfloader = function() { var CLFMenu = Class.create({ timeout : null, initialize: function(container, options){ // Ensure container exists if (!$(container)) { throw(container+" doesn't exist!"); return false; } // Override default options this.options = Object.extend({ duration: 0.5, hoverDuration : 2, toggleHeight: 35 }, options || {}); // Get move distances this.moveDown = $(container).getHeight() - this.options.toggleHeight; this.moveUp = this.moveDown * -1; this.moveLeft = $(container).positionedOffset()[0]; // Elements this.toggle = $(container).down(0).next(0).down(0); this.container = $(container); // Menu Toggle - watch for mouse overs Event.observe(container, 'mouseover', function(){ clearTimeout(this.timeout); }.bind(this)); // Menu Toggle - watch for mouse outs Event.observe(container, 'mouseout', function(){ this.timeout = setTimeout(this.activate.bind(this,'close'),this.options.hoverDuration*1000); }.bind(this)); // Toggle Dropdown animation Event.observe(this.toggle, 'click', this.activate.bind(this,'toggle'), false); // Initial State $(this.container).setStyle({ top: this.moveUp + 'px', visibility: 'visible' }); }, activate: function(action) { // Do this if the menu is open (down) if ( ($(this.toggle).hasClassName('opened')) && ((action=='close') || (action=='toggle')) ) { new Effect.Move (this.container, { duration: this.options.duration, x: 0, y: this.moveUp, afterFinish: function(){ $(this.toggle).href = '#more-open'; $(this.toggle).addClassName('closed'); $(this.toggle).removeClassName('opened'); }.bind(this) }); } // Do this if the menu is closed (up) else if ( ($(this.toggle).hasClassName('closed')) && ((action=='open') || (action=='toggle')) ) { new Effect.Move (this.container, { duration: this.options.duration, x: 0, y: this.moveDown, afterFinish: function(){ $(this.toggle).href = '#more-close'; $(this.toggle).addClassName('opened'); $(this.toggle).removeClassName('closed'); }.bind(this) }); } } }); var CLFSearch = Class.create({ initialize: function(field){ // Ensure container exists if (!$(field)) { return false; } this.field = $(field); this.defaultValue = $F(this.field); // Clear field on click Event.observe(this.field, "click", function(){ if ($F(this.field)==this.defaultValue) { $(this.field).clear(); } }.bind(this)); // Restore field's default text when empty Event.observe(this.field, "blur", function(){ if (!$(this.field).present()) { $(this.field).setValue(this.defaultValue); } }.bind(this)); } }); // Track links! function gaCLFLinks(container) { // Ensure container exists if (!$(container)) { return false; } // Ensure Google Analytics exists if ((typeof _gat=='undefined')) { return false; } // Create tracker var clfTracker = _gat._getTracker("UA-84069-34"); // calgarystampede.com tracker (not cs.calgarystampede.com) // Track links $$('#'+container+' a').each( function(link) { Event.observe(link, "click", function() { var currentPage = window.location.host + window.location.pathname; var clickedLink = link.href.substring(7); // remove http:// // Replace hash with a slash and weed out any double slashies clickedLink = clickedLink.replace('#','/'); clickedLink = clickedLink.replace('//','/'); // Strip page from url if just tracking the more-open or more-close button if (/more-open/.test(clickedLink)) { clickedLink = 'more-open'; } if (/more-close/.test(clickedLink)) { clickedLink = 'more-close'; } // Track on GA under /clf_click clfTracker._trackPageview('/clf_click/__to-'+ clickedLink + '__from-' + currentPage); }.bind(link)); }); } // Last step, fill in the hooks! if ($(clf_container)) { $(clf_container).update(clf_markup); new CLFMenu("clfmenu"); new CLFSearch("search"); gaCLFLinks("clf"); } } addonload(clfloader);