Element.addMethods({ locateAncestor: function(element,tag) { return element.ancestors().detect(function(e) { if (tag == e.tagName) { return $(element); } return false; }); }, exists: function(element) { if ($(element) != undefined || $(element) != null) { return $(element); } else { return false; } }, extract: function(element) { /* Removes Parent Node and replaces Child */ var extractedElement = element.firstDescendant(); var inner = element.innerHTML; element.replace(inner); return extractedElement; }, transport: function(element, destination) { /* Moves Element into new Parent */ var toTransport = element.clone(); $(destination).insert({ bottom: toTransport }); $(element).remove(); return toTransport; }, makeFirstChild: function(element) { /* Moves element to be first Child */ var toTransport = element.clone(); $(element).parentNode.insert({ top: toTransport }); $(element).remove(); return toTransport; }, clone: function(element) { /* Make Clone of Element */ var clone = new Element(element.tagName); $A(element.attributes).each(function(attribute) { if ( attribute.name != 'style' ) { clone[attribute.name] = attribute.value; } }); clone.setStyle(element.getStyles()); clone.update(element.innerHTML); return clone; }, copy: function(element,destination) { var toTransport = element.clone(); $(destination).insert({ bottom: toTransport }); return toTransport; }, contents: function(element) { /* Return Contents of Element */ return $(element).innerHTML; }, setHeight: function(element, setHeight) { element = $(element); element.setStyle({ height: setHeight}) }, centerize: function(element, limitX, limitY) { /* Place element in center of viewport */ element = $(element); var elementDims = element.getDimensions(); var viewPort = document.viewport.getDimensions(); var offsets = document.viewport.getScrollOffsets(); var centerX = (viewPort.width / 2 - elementDims.width / 2); // + offsets[0]; var centerY = (viewPort.height / 2 - elementDims.height / 2); // + offsets[1]; if ( limitX && centerX < limitX ) { centerX = parseInt(limitX); } if ( limitY && centerY < limitY ) { centerY = parseInt(limitY); } element.setStyle( { position: 'fixed', top: Math.floor(centerY) + 'px', left: Math.floor(centerX) + 'px' } ); return element; }, centerizeWithin: function(element, container) { /* Place element in center of another element */ element = $(element); container = $(container); var elementDims = element.getDimensions(); var containerDims = container.getDimensions(); var centerX = containerDims.width / 2 - elementDims.width / 2; var centerY = containerDims.height / 2 - elementDims.height / 2; container.setStyle({ position: 'relative' }); element.setStyle( { position: 'absolute', top: Math.floor(centerY) + 'px', left: Math.floor(centerX) + 'px' } ); return element; }, fadeOut: function(element) { Effect.Fade(element, { duration: 0.2 }); } }); /* @Globals - Storage for Globally used Vars */ var Globals = { browserVersion: '', browserName: '' }; /* Load Events on DOM load */ document.observe("dom:loaded", function() { Cart.initiate(); Search.initiate(); Event.observe(document, 'click', function(event) { var target; if (!event) { event = window.event; } if (event.target) { target = event.target; } else if (event.srcElement) { target = event.srcElement; } if (target.nodeType == 3) { target = target.parentNode; } Globals.currentFocusNode = target; if (Globals.currentFocusNode.id != 'swarn') { $('swarn').hide(); if (!Globals.currentFocusNode.descendantOf('RP_CART')) { Interface.destroyCartContextMenu(); } $$("#GJUMP").each(function() { if (!Globals.currentFocusNode.descendantOf('GJUMP') && !Globals.currentFocusNode.hasClassName('aa')) { $$('#GJUMP').each(function(e){ e.remove(); }); } }); } }); /* Search Box */ $$('#a_login').detect(function(e) { e.observe('click', Interface.revealLoginForm); }); Event.observe('search_form', 'submit', function(e) { if (!Search.checkSearchQuery()) { e.stop(); } }); Event.observe('sbq', 'focus', function(){ $('swarn').hide(); }); Event.observe('sbq', 'keyup', function(e) { Search.quickSearch(e); }); Event.observe(document, 'mouseover', function(event) { var elt = $(Event.element(event)); if (elt == $('TM_VIDEO_CATALOG') || elt.descendantOf($('TM_VIDEO_CATALOG')) || elt.descendantOf($('cat_menu'))) { Interface.revealMenu(); } else { Interface.concealMenu(); } }); /* Fix IE's Z-index Issues */ if (Globals.browserName == 'MSIE') { var zIndexNumber = 1000; $$("div").each(function(e) { e.setStyle({ zIndex: zIndexNumber }); zIndexNumber -= 1; }); } $('overlay').setStyle({ zIndex: 5000 }).observe('click', function() { $('overlay').fadeOut(); $('overlay_message').update(); } ); $('overlay_message').setStyle({ zIndex: 8000 }); $$("ul#menubar li").each(function(e) { Event.observe(e, 'mouseover', function() { e.addClassName('hilite'); }); Event.observe(e, 'mouseout', function() { e.removeClassName('hilite'); }); }); /* Top Buttons Hovering */ $$('td.topbuttons').each(function(e) { Event.observe(e, 'mouseover', function(event) { e.setStyle({ backgroundColor: '#F9D6BD' }); }); Event.observe(e, 'mouseout', function(event) { e.setStyle({ backgroundColor: '' }); }); }); /* Shopping Cart Add/Remove */ $$('td.buybuttons img').each(function(e){ Event.observe(e, 'click', function() { var h = e.id.split("_"); Cart.add(h[1], h[2]); e.blur(); }); }); $$('a.cart_remove').each(function(e){ Event.observe(e, 'click', function() { var h = e.id.split("_"); Cart.remove(h[1], h[2]); }); }); $$('.mycart td.row').each(function(e){ Event.observe(e, 'click', function(evt) { Interface.displayCartContextMenu(e.id, evt.pointerX(), evt.pointerY()); }); }); $$('a#add_engine').each(function(e){ Event.observe(e, 'click', Search.addSearchEngine); }); }); var Cached = { activeAddressRow: "", activeSomething: 0 }; /* @Interface - Menus, etc */ var Interface = { isOpenMenu: 0, revealMenu: function() { if (this.isOpenMenu == 0) { $('cat_menu').setStyle({ zIndex: 8000 }).show(); this.isOpenMenu = 1; } }, concealMenu: function() { if (this.isOpenMenu == 1) { $('cat_menu').hide(); this.isOpenMenu = 0; } }, hideUpgradeBar: function() { $('upgrade_bar').hide(); new Ajax.Request('/idx/option_cookie/upgradebar/', { method: 'get' }); }, revealLoginForm: function() { $('a_login').blur(); if (!$('hform').visible()) { Effect.BlindDown('hform', { duration: 0.4, afterFinish: function() { $('f_login').focusFirstElement(); } }); } else { $('f_login').focusFirstElement(); } }, smoothFade: function(id, showOnComplete) { Effect.Fade(id, { duration: 0.5, afterFinish: function() { $(id).update(); if (showOnComplete == true) $(id).show(); } }); return $(id); }, smoothBlindUp: function(id, showOnComplete) { Effect.BlindUp(id, { duration: 0.5, afterFinish: function() { $(id).update(); if (showOnComplete == true) $(id).show(); } }); return $(id); }, destroyUpgradeMessage: function() { this.smoothBlindUp('upgrade_bar'); new Ajax.Request('/idx/option_cookie/upgrade_bar/'); }, launchWindow: function(url, dims, position, isScroll, isResize, isCentered) { var dims = dimensions.split('x'); var width = dims[0]; var height = dims[1]; if (isCentered == 1) { left = (screen.width - width) / 2; top = (screen.height - height) / 2; } else { var pos = position.split(','); left = pos[0]; top = pos[1]; } window.open(url,'','width='+ width +', height='+ height +', left='+ left +', top='+ top +', screenX='+ left +', screenY='+ top +', scrollbars='+ is_scroll +', resizable= '+ is_resize +', menubar=no, toolbar=no'); }, isOpenCartContextMenu: 0, displayCartContextMenu: function (id, xPos, yPos) { yPos -= 10; xPos -= 10; if (this.isOpenCartContextMenu == 1) { this.destroyCartContextMenu(); } var deleteDiv = new Element('div', { id: 'R'+ id }).addClassName('remove').update('Remove "'+ $(id).title +'"'); var viewDiv = new Element('div', { id: 'V'+ id }).addClassName('view').update('Go to Product Info Page'); var cancelDiv = new Element('div', { id: 'C'+ id }).addClassName('cancel').update('Cancel'); var containDiv = new Element('div', { id: 'cr_context' }).insert({ top: viewDiv }).insert({ bottom: deleteDiv }).insert({ bottom: cancelDiv }).setStyle({ position: 'absolute', top: yPos+'px', left: xPos+'px', zIndex: 2000 }).show(); $('container').insert({ top: containDiv }); this.isOpenCartContextMenu = 1; Event.observe('C'+id, 'click', this.destroyCartContextMenu); Event.observe('R'+id, 'click', function() { $(id).update($('preloadimg_load_bar_orange').contents()); var h = id.split("_"); Cart.quickRemove(h[1], h[2]); }); Event.observe('V'+id, 'click', function() { var h = id.split("_"); Interface.go('/go/'+h[2]); }); }, destroyCartContextMenu: function() { if ($('cr_context') != null) { $('cr_context').remove(); } }, go: function(uri) { window.location = uri; } }; /* @Search - stuff for Search Box */ var Search = { rawData: "", initiate: function() { this.rawData = new Array(); this.initiateQuickSearch(); }, checkSearchQuery: function() { var query = $('sbq').value; if (query.length < 3) { if (!$('swarn').visible()) { $('swarn_msg').update('Query must be at least 3 characters in length.'); Effect.BlindDown('swarn', {duration: 0.3}); return false; } } else { $('swarn').update().hide(); $('search_form').submit(); } }, initiateQuickSearch: function() { if (Search.rawData.size() == 0) { new Ajax.Request('/get_titles/', { onSuccess: function(t){ Search.rawData = t.responseText.evalJSON(); } }); } }, quickSearch: function(e) { //if (!(e.keyCode >= 65 && e.keyCode <= 90) && !(e.keyCode >= 97 && e.keyCode <= 122) && !(e.keyCode == 8)) return false; var q = $('sbq').value; $('quick_search_result').update("

Quick Title Results

"); if (q.length > 1) { this.rawData.detect(function(e){ var re = new RegExp( "" + q, "i"); if (e.title.match(re)) { var div = new Element('div').addClassName('result').update(""+ e.title +""); $('quick_search_result').insert(div); Event.observe(div, 'mouseover', function() { div.setStyle({ backgroundColor: '#FFEDD6' }); }); Event.observe(div, 'mouseout', function() { div.setStyle({ backgroundColor: '' }); }); } }); var resultCount = $('quick_search_result').childElements().size() - 1; if (resultCount > 0) { if (!$('quick_search_result').visible()) { Effect.Appear('quick_search_result', { duration: 0.3 }); document.observe('click', function(evt) { var target = evt.target; if (!target.descendantOf('quick_search_result') && target.id != 'sbq') { Effect.Fade('quick_search_result', { duration: 0.2 }); } }); } } else { $('quick_search_result').hide(); } } else { $('quick_search_result').hide(); } }, addSearchEngine: function() { $('add_engine').blur(); if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) { window.sidebar.addSearchEngine( "http://www.russianbare.com/lib/searchbar/enaturenet.src", "http://www.russianbare.com/lib/searchbar/enaturenet.png", 'Enature.net', 'DVD & Video'); } else { alert("Netscape 6 or Mozilla is needed to install a sherlock plugin"); } } }; /* @Cart - Shopping Cart */ var Cart = { loadingBars: "", inlineHTMLCache: "", initiate: function() { this.loadingBars = $('preloadimg_load_bar_orange').contents(); }, add: function(id, format, addMultiple) { var notifyDiv = $('IC_'+ id); this.inlineHTMLCache = notifyDiv.contents(); notifyDiv.update(this.loadingBars); new Ajax.Request('/cart/add', { parameters: { pid: id, format: format, add_multiple: addMultiple }, onComplete: function(t) { data = t.responseText.evalJSON(); if (data.message == 'DUPLICATE') { $('overlay').show(); $('overlay_message').update(data.html).centerize().show(); } else { notifyDiv.update(data.cart_row); Event.observe('RM_'+ data.cart_id +'_'+ data.pid, 'click', function(e) { Cart.remove(data.cart_id, data.pid, 1); }); $('RP_CART').update(data.main_cart); $('BASE_CART').update($('BASE_ACCOUNT').contents()); if (data.cart_total == 1) { Effect.BlindDown('RP_CART', { duration: 0.4 }); } } if (addMultiple) { $('overlay_message').update(); Effect.Fade('overlay', { duration: 0.2 }); } $$('.mycart td.row').each(function(e){ Event.observe(e, 'click', function(evt) { Interface.displayCartContextMenu(e.id, evt.pointerX(), evt.pointerY()); }); }); } }); }, cancelAdd: function(id) { $('IC_'+ id).update(this.inlineHTMLCache).show(); $('overlay_message').update(); Effect.Fade('overlay', { duration: 0.2 }); }, remove: function(cid, pid, bypass) { var notifyDiv = $('IC_'+ pid); this.inlineHTMLCache = notifyDiv.contents(); notifyDiv.update(this.loadingBars); new Ajax.Request('/cart/remove', { parameters: { pid: pid, cart_id: cid, bypass: bypass }, onComplete: function(t) { var data = t.responseText.evalJSON(); if (data.message == 'MULTIPLE' && bypass != 1) { $('overlay').show(); $('overlay_message').update(data.html).centerize().show(); } else { if (bypass == 1) Cart.cancelRemove(pid); if (data.item_total == 0) { notifyDiv.update(data.html); Interface.smoothFade.delay(3, notifyDiv, true); } else { notifyDiv.update(data.cart_remain); Event.observe('RM_'+ cid +'_'+ pid, 'click', function(e) { Cart.quickRemove(cid, pid); }); } if (data.cart_total > 0) { $('RP_CART').update(data.main_cart); } else { Effect.BlindUp('RP_CART', { duration: 0.5, afterFinish: function() { $('RP_CART').update(); $('BASE_CART').update(); } }); } } $$('.mycart td.row').each(function(e){ Event.observe(e, 'click', function(evt) { Interface.displayCartContextMenu(e.id, evt.pointerX(), evt.pointerY()); }); }); } }); }, quickRemove: function (cid, pid) { Interface.destroyCartContextMenu(); new Ajax.Request('/cart/remove', { parameters: { pid: pid, cart_id: cid, bypass: 1 }, onComplete: function(t) { var data = t.responseText.evalJSON(); if (data.cart_total > 0) { $('RP_CART').update(data.main_cart); } else { Effect.BlindUp('RP_CART', { duration: 0.5, afterFinish: function() { $('RP_CART').update(); $('BASE_CART').update(); } }); } $$('#IC_'+pid).find(function(e) { e.remove(); }); $$('.mycart td.row').each(function(e){ Event.observe(e, 'click', function(evt) { Interface.displayCartContextMenu(e.id, evt.pointerX(), evt.pointerY()); }); }); } }); }, cancelRemove: function(pid) { $('overlay_message').update().hide(); $('overlay').hide(); $('IC_'+ pid).update(this.inlineHTMLCache); }, displayShippingRates: function() { var nuDiv = new Element('div', { id: 'shiprates_shell' }).setStyle({ width: '450px', backgroundColor: '#000', padding: '10px' }).update($('shipping_prices').contents()); $('overlay').show(); $('overlay_message').insert({ top: nuDiv }).centerize().show(); Event.observe('shiprates_shell', 'click', function() { $('shiprates_shell').remove(); $('overlay_message').hide(); $('overlay').hide(); }); } }; /* @Plaza - Potpurri Functions */ var Plaza = { randomString: function(len) { var chars = "0123456789Zabcdef"; var randomstring = ''; for (var i=0; i < len; i++) { var rnum = Math.floor(Math.random() * chars.length); randomstring += chars.substring(rnum,rnum+1); } return randomstring; }, generateNuCaptcha: function() { Event.stopObserving('simg'); var image = $('simg'); var div = image.parentNode; var divContents = div.contents(); div.update($('preloadimg_load_bar_orange').contents()); //.setStyle({ position: 'relative', width: '100px' }); div.firstDescendant().centerizeWithin(div); new Ajax.Request('/ti/regenerate', { parameters: { generate_new: 'true' }, onSuccess: function() { var nuImage = new Element('img', { alt: 'Loading...', id: 'simg', title: 'Click to generate a fresh image', src: '/ti/generate/'+ Plaza.randomString(12) +'.png', width: 240, height: 55 }).setStyle({border: '1px solid #000', cursor: 'pointer' }); div.update().insert({ top: nuImage }); Event.observe('simg', 'click', Plaza.generateNuCaptcha); } }); }, installCountryCookie: function() { new Ajax.Request('/idx/set_country/', { method: 'GET' }); } }; /* @Gallery - Gallery Funtions */ var Gallery = { pageJump: function(element, event, urlBit, totalImages, perPage) { var totalPages = 1; var curSt = parseInt(""); var curPage = 1; $$('#GJUMP').each(function(e){ e.remove(); }); if ( totalImages % perPage == 0 ) { totalPages = totalImages / perPage; } else { totalPages = Math.ceil( totalImages / perPage ); } var innerDiv = new Element('div', { id: 'GJUMP' }).addClassName('goto').setStyle({ position: 'absolute', top: event.pointerY() +'px', left: event.pointerX() +'px', zIndex: 3000 }); for (i = 1; i <= totalPages; i++ ) { var nuPg = new Element('div').update('Page '+ i +''); innerDiv.insert({ bottom: nuPg }); } $('container').insert({ bottom: innerDiv }); innerDiv.show(); } }; /* Deprecated [procedural] code to replace with OO */ //----------------------------------------------- // Going Somewhere? //----------------------------------------------- function boink(url) { Interface.go(url); }