var _product = null;
var _promo = null;
var _linker = null;

function initProduct() {
		var _box = $("product");
		if (_box)
		{
			_product = $("list");
			if(_product)
			{
				_product.parentNode.className = _product.parentNode.className.replace("loader", "");
				_product.style.left = "0px";
				_product.style.visibility = "visible";
				_product._active = 0;
				_product._step = 629;
				_product._left = 0 - _product._active*_product._step;
				_product._count = _product.getElements("li.item").length;
						
				_product.fx = new Fx.Style(_product, "left", {
					duration:800,
					transition: Fx.Transitions.Expo.easeOut,
					wait:false
				});
				
				_product.fx.start(_product._left, (0 - _product._active*_product._step));
				_product._left = 0 - _product._active*_product._step;
			
				var _prev = $("prev");
				var _next = $("next");
				if (_prev && _next)
				{
					
					_next.onclick = function() {
						if (_product._active >= _product._count-1)
						{
							_product._active = 0;
						}
						else
						{
							_product._active++;
						}
						_product.fx.start(_product._left, (0 - _product._active*_product._step));
						_product._left = (0 - _product._active*_product._step);
						
						if (_linker) {
							for(k = 0; k < _linker._items.length; k++){
								_linker._items[k].parentNode.className = _linker._items[k].parentNode.className.replace("active", "");
								if (k == _product._active) {
									_linker._items[k].parentNode.className += " active";
								}
							}
						}
						
						return false;
					};
					_prev.onclick = function() {
						if (_product._active <= 0)
						{
							_product._active = _product._count-1;
						}
						else
						{
							_product._active--;
						}
						_product.fx.start(_product._left, (0 - _product._active*_product._step));
						_product._left = (0 - _product._active*_product._step);
						
						if (_linker) {
							for(k = 0; k < _linker._items.length; k++){
								_linker._items[k].parentNode.className = _linker._items[k].parentNode.className.replace("active", "");
								if (k == _product._active) {
									_linker._items[k].parentNode.className += " active";
								}
							}
						}
						return false;
					}
				}
				_linker = $("linker");
				_loc = window.location.href.split("#")[1];
				if (_linker) {
					_linker._items = _linker.getElements("a");
					_linker._items.each(function(item, i){
						item._index = i;
						if (_loc)
						{
							if (_loc == item.href.split("#")[1]) {
								_product._active = i;
								_product.fx.start(_product._left, (0 - _product._active*_product._step));
								_product._left = 0 - _product._active*_product._step;
								
							}
						}
				
					
						item.onclick = function() {
							if (this._index < _product._count) {
								_product._active = this._index;
								_product.fx.start(_product._left, (0 - _product._active*_product._step));
								_product._left = (0 - _product._active*_product._step)
							}
							for(k = 0; k < _linker._items.length; k++){
								_linker._items[k].parentNode.className = _linker._items[k].parentNode.className.replace("active", "");
							}
							this.parentNode.className += " active";
							return false;
						}
					});
					for(k = 0; k < _linker._items.length; k++){
						_linker._items[k].parentNode.className = _linker._items[k].parentNode.className.replace("active", "");
						if (_product._active == _linker._items[k]._index)
						{
							_linker._items[k].parentNode.className += " active";
						}
					}
				}
			}
		}
}

function initPromo() {
		var _box = $("promo");
		if (_box)
		{
			_promo = $("list");
			if(_promo)
			{
				_promo.style.left = "0";
				_promo.parentNode.className = _promo.parentNode.className.replace("loader", "");
				_promo._step = 202;
				_promo._left = 0;
				_promo._width = _promo.getElements("li.item").length * _promo._step;
			
				_promo.fx = new Fx.Style(_promo, "left", {
					duration:800,
					transition: Fx.Transitions.Quint.easeOut,
					wait:false
					
				});

				var _prev = $("prev");
				var _next = $("next");
				if (_prev && _next)
				{				
					_next.onclick = function() {
						var _shift = false;
						var _left = _promo._left;

						var _sep = _promo._left + _promo._width - 808;
						if (_sep >= _promo._step*2)
						{
							_shift = _left - _promo._step*2;
							_promo._left = _shift;
						}
						else {
							_shift = _left - _sep;
							_promo._left = _shift;
						}
						if (_sep == 0) {
							_shift = 0;
							_promo._left = _shift;
						}
						if (_shift || _shift == 0)
						{
							_promo.fx.start(_left, _shift);
						}
						
						return false;
					};
					_prev.onclick = function() {
						var _shift = false;
						var _sep = false;
						var _left = _promo._left;

						if (_left < (0 - _promo._step*2)) {
							_shift = _left + _promo._step*2;
							_promo._left = _shift;
						}
						else if (_left == 0) {
						_sep = _promo._left + _promo._width - 808;
							_shift = 0 -_sep;
							_promo._left = _shift;
							_promo.fx.start(_left, _shift);
						}
						else {
							_shift = 0;
							_promo._left = _shift;
						}

						if (_shift || _shift == 0)
						{
							_promo.fx.start(_left, _shift);
						}
						
						return false;
					};
				}
			}
		}
}

_links = [];


if (window.addEventListener) {
	window.addEventListener("load", initPromo, false);
	window.addEventListener("load", initProduct, false);
}
else if (window.attachEvent) {
	window.attachEvent("onload", initPromo);
	window.attachEvent("onload", initProduct);
}
