var _evt = YAHOO.util.Event, _dom = YAHOO.util.Dom;

/* Reorder banners and remove DeepZoom - Nov 2010 */
var idArray = ['product1','product2','product4'];
var _indexMap = [1,2,4];
/*var idArray = ['product2','product4','product1','product3'];
var _indexMap = [3, 1, 4, 2];*/

var _T = 0, _Index = 1;




var _duration = 3000; 
_evt.onDOMReady
(
	function() {
	
	   // alert("1");
	    collagePreloader();
	   // alert("2");
	    if (YAHOO.env.ua.ie && (YAHOO.env.ua.ie < 7)) {
	        setFixPng(_dom.getElementsByClassName('png', 'img'));
	    }
	  //  alert("3");
	    var products = _dom.getElementsByClassName('product', 'div', 'product-container');
	    for (var i = 0; i < products.length; i++) {
	        if (products[i].id != _CurrId) _dom.setStyle(products[i], 'opacity', 0)
	    }
	    _T = setTimeout(productPresentation, _duration);
	
	}
);

function collagePreloader()
{
	var body = document.getElementsByTagName('body')[0];
	for(var i = 1; i <= 4; i++)
	{
		var img = document.createElement('img');
		img.src = '/i/i'+i+'-main.jpg';
		img.style.display = 'none';
		body.appendChild(img);
	}
}


function setFixPng(arr)
{
	if(arr)
    {
        for(var i=0, l=arr.length; i < l; i++)
        {
            fixPNG(arr[i]);
        }
    }
}

function fixPNG(el)
{
    var src = el.src;
    el.src = '/i/blank.gif';
    el.runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src + '\',sizingMethod=\'scale\')';
}

function getProduct(id,e)
{
	if(isAnimate)
	{
		if(typeof(e) != 'undefined')
		{
			_evt.stopPropagation(e);
			_evt.preventDefault(e);
			if(_T) clearInterval(_T);
		}
		if(id != _CurrId)
		{
			isAnimate = !isAnimate;
			_dom.get(id).style.display = '';
			_dom.get(_CurrId+'-icon').src = _dom.get(_CurrId+'-icon').src.replace('-selected.jpg','.jpg');
			_dom.get(id+'-icon').src = _dom.get(id+'-icon').src.replace('.jpg','-selected.jpg');
			new Effect.Opacity(_CurrId,{from: 1.0, to: 0, duration: 1.0, afterFinish : function(){ _dom.get(_CurrId).style.display = 'none'; }});
			new Effect.Opacity(id,{from: 0, to: 1.0, duration: 1.0, afterFinish : function(){ _CurrId = id; isAnimate = !isAnimate; }});
		}
	}
}
var isAnimate = true;
function productPresentation()
{
	if(isAnimate)
	{
		isAnimate = !isAnimate;
		_dom.get(idArray[_Index]).style.display = '';
		_dom.get(_CurrId+'-icon').src = _dom.get(_CurrId+'-icon').src.replace('-selected.jpg','.jpg');
		new Effect.Opacity(_CurrId,{from: 1.0, to: 0, duration: 1.0, afterFinish : function(){ _dom.get(_CurrId).style.display = 'none'; }});
		new Effect.Opacity(idArray[_Index], { from: 0, to: 1.0, duration: 1.0, afterFinish:

		function() {
		    _CurrId = idArray[_Index];
		    _Index = (_Index < (idArray.length - 1)) ? _Index + 1 : 0;
		    _T = setTimeout(productPresentation, _duration);
		    _dom.get(_CurrId + '-icon').src = _dom.get(_CurrId + '-icon').src.replace('.jpg', '-selected.jpg');
		    isAnimate = !isAnimate;
		} 
		});
	}
}







