/*
* Sliding Element Replacer (unobtrusive)
* Link Confirmation (unobtrusive)
* Author: Rich Joslin (http://richjoslin.com)
* First Release: 2008.05.11
* Requires: MooTools 1.11 or greater
*/

function initShoeImgSwapLinks() {
	if ($('shoe-nav')) {
		$ES('a', 'shoe-nav').each(function(el) {

			// preload enlargement images
			// hide the link, preload the enlargement image, then re-display the link
			var tempDiv = new Element('div');
			tempDiv.setAttribute('class', 'thumbpreloader');
			tempDiv.injectInside(el.getParent());
			var spinner = new Element('img');
			spinner.setAttribute('src', '/themes/ryz/images/ajax-loader.gif');
			spinner.injectInside(tempDiv);
			new Asset.image(el.getProperty('href'), {onload: function(){
				tempDiv.setStyle('display', 'none');
			}});

			// set up the click events
			el.addEvent('click', function(e) {
				new Event(e).stop();
				$('shoe-nav').getElements('li').each(function(el) {
					el.removeProperty('class');
				});
				el.getParent().setProperty('class', 'on');
				var slideSwap = $('shoe-image-detail');
				var newSrc = el.getProperty('href');
				var oldImg = slideSwap.getFirst();
				var oldImgClone = slideSwap.getFirst().clone();
				var newImg = slideSwap.getFirst().clone();
				newImg.addEvent('load', function() {
					var tempDiv = new Element('div');
					tempDiv.injectInside(slideSwap);
					oldImgClone.injectInside(tempDiv);
					newImg.injectInside(tempDiv);
					var slideFx = new Fx.Style(tempDiv, 'left', { duration: 300, transition: Fx.Transitions.Bounce.easeOut });
					slideFx.addEvent('onComplete', function() {
						oldImg.setProperty('src', newSrc);
						tempDiv.remove();
					});
					slideFx.start(0, -430);
				});
				newImg.setProperty('src', newSrc);
			});
		});
	}
}

function initDeleteLink() {
	$$('a[class=deleteshoe]').each(function(alink) {
		alink.removeEvents('click');
		alink.addEvent('click', function(e) {
			if(!confirm('Are you sure you want to delete this design? This cannot be undone!')) {
				new Event(e).stop();
			}
		});
	});
}

window.addEvent('domready', function() { initShoeImgSwapLinks(); initDeleteLink(); });
