var ProductLanding = new Class({
	init: function()
	{
		//if (!window.ie6)
		//{
			var productLinks = $ES('div#content ul.productLinks li');
			
			$$('div#content table.productImages tr td a img').each(function(item, index)
			{
					item.addEvents({
						'mouseenter': function()
						{
							var altItems = $$('div#content table.productImages tr td a img');
							altItems.remove(item);
							
							altItems.each(function(otherItem) {
								otherItem.setOpacity(0.55);
							});
							
							productLinks[index].addClass('selected');
						},
						
						'mouseleave': function()
						{
							var altItems = $$('div#content table.productImages tr td a img');
							altItems.remove(item);
							
							altItems.each(function(otherItem) {
								otherItem.setOpacity(1);
							});
							productLinks[index].removeClass('selected');
						}
				});
			});
			
			var productImages = $$('div#content table.productImages tr td img');
		
			$ES("ul.productLinks li a", "info").each(function(item, index) {
				item.addEvents({
					'mouseenter': function(event) {
						productImages[index].fireEvent("mouseenter");
					},
					
					'mouseleave': function(event) {
						productImages[index].fireEvent("mouseleave");
					}
				});
			});
		//}
		/*else
		{
			this.createListeners();
			
			$$('div#content table.productImages tr td a').each(function (item, i)
			{
				var alphaDiv = new Element('div', {
					'class': 'alphaBox'
					}
				);
	
				var imgItem = item.getElements('img');
	
				alphaDiv.setStyle('width', imgItem.getStyle('width').toString());
				alphaDiv.setStyle('height', imgItem.getStyle('height').toString());
				alphaDiv.setStyle('top', '-' + imgItem.getStyle('height').toString());
				if (window.ie)
				{
					alphaDiv.setStyle('top', '-' + (parseInt(imgItem.getStyle('height')) + 5).toString() + 'px');
				}
	
				$$('li.stacked div ul li').each(function(item2, i)
				{
					if (item2.hasChild(item))
					{
						alphaDiv.setStyle('width', imgItem.getStyle('width').toString());
						alphaDiv.setStyle('height', imgItem.getStyle('height').toString());
						alphaDiv.setStyle('left', '-1px');
	
						if (i > 0)
						{
							var distance = parseInt(item2.getPrevious().getElement('img').getStyle('height')) + item2.getPrevious().getElement('img').getTop();
							distance -= $$('li.stacked div')[0].getTop() - (window.ie ? 9 : 6);
							alphaDiv.setStyle('top', distance + 'px');
						}
						else
						{
							alphaDiv.setStyle('top', '0px');
						}
					}
				});
	
				alphaDiv.injectAfter(item);
			});
			
			$ES("ul.productLinks li a", "info").each(function(item, index) {
				item.addEvents({
					'mouseenter': function(event) {
						$$('div#content ul.productLinks li')[index].addClass('selected');
						
						var alphaBoxes = $ES('table.productImages tr td div.alphaBox', 'content');
						alphaBoxes.remove(alphaBoxes[index]);
						
						alphaBoxes.each(function (alphaBox) {
							alphaBox.setStyle("visibility", "visible");
						});
					},
					
					'mouseleave': function(event) {
						$$('div#content ul.productLinks li')[index].removeClass('selected');
						
						var alphaBoxes = $ES('table.productImages tr td div.alphaBox', 'content');
						alphaBoxes.remove(alphaBoxes[index]);
						
						alphaBoxes.each(function (alphaBox) {
							alphaBox.setStyle("visibility", "hidden");
						});
					}
				});
			});
		}*/
	},
	
	createListeners: function()
	{
		// MouseOver
		var items = $$('div#content table.productImages tr td');
		items.remove($$('div#content table.productImages tr td.stacked')[0]);

		items.addEvent('mouseenter', function(event)
		{
			event = new Event(event);

			var targetImg = event.target.getParent().getElement('img');

			$ES('div#content ul.productLinks li')[$ES('div#content table.productImages tr td a img').indexOf(targetImg)].addClass('selected');

			$$('div#content table.productImages tr td div.alphaBox').setStyle('visibility', 'visible');
			this.getElement('div.alphaBox').setStyle('visibility', 'hidden');
		});

		// MouseOUt
		items.addEvent('mouseleave', function(event)
		{
			event = new Event(event);

			var targetImg = event.target.getParent().getElement('img');
			if (targetImg)
			{
				$ES('div#content ul.productLinks li')[$ES('div#content table.productImages tr td a img').indexOf(targetImg)].removeClass('selected');
			}

			$$('div#content table.productImages tr td div.alphaBox').setStyle('visibility', 'hidden');
		});
	}
});

var productLanding = new ProductLanding();

window.addEvent('load', function()
{
	productLanding.init();
});
