var searcharea; document.addEventListener('DOMContentLoaded', function() { // This allows for more than one search element per page... $$('.searchForm').each(function(x) { new templateSystem.Search(x); }); }); var templateSystem = {}; templateSystem.Search = Class.create({ initialize: function(search_form) { search_element = search_form.down('.term'); submit_element = search_form.down('.submit'); if(!search_element || !submit_element) return false; this.default_term = search_element.getValue(); this.default_color = search_element.getStyle('color'); this.search_element = search_element; search_element.observe('focus', this.clear.bind(this)); search_element.observe('blur', this.needReset.bind(this)); submit_element.observe('click', this.findProducts.bind(this)); search_element.observe('keypress', this.keyPress.bind(this)); }, keyPress: function(evt) { if(evt.keyCode == Event.KEY_RETURN) this.findProducts(evt); }, clear: function() { if(this.default_term == this.search_element.getValue()) { this.search_element.setValue(''); this.search_element.setStyle({color: '#000'}); } }, needReset: function() { if(this.search_element.getValue() == '') { this.search_element.setValue(this.default_term); this.search_element.setStyle({color: this.default_color}); } }, findProducts: function(evt) { Event.stop(evt); value = encodeURI(this.search_element.getValue()); if(value == '' || value == this.default_term) alert('You must enter a search term.'); else location = siteurl + '/search/terms/' + value; } }); templateSystem.Product = Class.create({ quickCart: function(product_id) { if(!product_id) throw new SyntaxError('Invalid product.'); var form = new Element('form', {'action': '/shopping-cart', method: 'post'}); var input = new Element('input', {name: 'Quant', type: 'hidden'}).setValue(1); var input2 = new Element('input', {name: 'Pid', type: 'hidden'}).setValue(product_id); form.insert(input).insert(input2); $(document.body).insert(form); form.submit(); return true; } }); var Widget = {}; Widget.YouTube = Class.create(Widget, { initialize: function(vidContainer, watchLinks) { this.container = vidContainer; this.links = watchLinks; this.options = { quality: 'hd720' }; }, loadLinks: function() { this.loadPlayer(this.links[0].readAttribute('id')); this.links.each(function(x) { x.observe('click', this.showVideo.bind(this, x.readAttribute('id'))); }.bind(this)); return this; }, loadPlayer: function(videoID) { var params = { allowScriptAccess: 'always', allowfullscreen: 'true', name: 'mode', value: 'opaque' }; var atts = { id: 'YTWidgetPlayer' }; swfobject.embedSWF('http://www.youtube.com/v/' + videoID + '?version=3&enablejsapi=1&hd=1&rel=0&egm=0&showsearch=0&showinfo=0&iv_load_policy=0&fs=1&playerapiid=ytplayer', this.container, "735", "427", "8", null, null, params, atts); return this; }, setPlayer: function() { this.player = $('YTWidgetPlayer'); }, showVideo: function(videoID, evt) { if(typeof(evt) == 'object') Event.stop(evt); this.player.loadVideoById(videoID, 0, this.options.quality); } }); function onYouTubePlayerReady(playerID) { YOUTUBECALLBACK.setPlayer(); } $load_library = (function() { alert('An external library was not properly loaded.'); });