function slideShow(){
	var div = $('listProductsCont');
	if(!div)	return;
	div = div.getElement('div.listProducts');	
	if(!div)	return;
	var lis = div.getElements('li');
	
	lis.each(function(li){
		li.fx = new Fx.Tween(li, {
			property: 'top',
			duration: 700, 
			transition: Fx.Transitions.Quart.easeInOut,
			link:'cancel'
		}).set(-170);
	});
	
	var cur = 0;
	lis[cur].fx.set(0);
	
	var time = 5000;
	var timer = setInterval(function(){
		if( cur+1 < lis.length){
			slide(cur + 1);
		}else{
			slide(0);
		}
	},time);
	
	function slide(next){
		lis[cur].fx.start(-170);
		cur = next;
		lis[cur].fx.set(170);
		lis[cur].fx.start(0);
	}
}

/////////////////
function initFadeListImages(){
	var listImg = $('fadeImg');		
	if(!listImg) return;
	var imgs = listImg.getElements('img');
	var imgCur = 0;
	imgs[0].setStyle('opacity', 1);
	imgs[0].fx = new Fx.Tween(imgs[0], {
		duration: 3000
	});
	if(imgs.length > 1){
		for(var i = 1; i < imgs.length; i++){
			imgs[i].setStyle('opacity', 0).removeClass('hidden');
			imgs[i].fx = new Fx.Tween(imgs[i], {
				duration: 3000
			});
		}
		var lsTimer = setInterval(function(){			
			imgs[imgCur].fx.cancel().start('opacity',[1,0]);
			imgCur = (imgCur < imgs.length - 1)?(imgCur + 1):0;
			imgs[imgCur].fx.cancel().start('opacity',[0,1]);
		}, 4500);	
	}	
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  //eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if(selObj.options[selObj.selectedIndex].value == '') return;
window.open(selObj.options[selObj.selectedIndex].value, '_blank');
  
  if (restore) selObj.selectedIndex=0;
}
////////////////
var Navigator = new Class({
		
		Implements: [Options, Events, Chain],
		
		initialize: function(element, options){
			this.element = element;
			this.setOptions(options);
			this.setupNavigator();
		},
		
		setupNavigator: function(){
			var navHolder = $(this.element);
			if (!navHolder) {
				return;
			}
			var uls = navHolder.getElement('ul');
			if(!uls) return;
			var togglers = uls.getElements('a.sublev');
			var startToggle = -1;
			for(var i=0; i<togglers.length; i++){
				if(togglers[i].hasClass('open')){
					startToggle = i;
					break;
				}
			}
			
			var elements = uls.getElements('ul').setStyle('display', 'block');
			
			var accordionObj = new Accordion(togglers, elements, {
				duration: 'short',
				display: startToggle,
				show: startToggle,
				alwaysHide:true,
				onActive: function(toggler, element){
					toggler.getParent().addClass('current');				
				},
				onBackground: function(toggler, element){
					toggler.getParent().removeClass('current');
				}			
			});			
		}	
	});
//////////////////////
var Gallery = new Class({
	initialize: function(element){
		this.element = element;
		this.initScroller();
	},
	
	initScroller: function(){
		var that = this;
		var container = $(that.element);
		if (!container) {
			return;
		}
		var listContainer = container.getElement('div.listProducts3 ul');
		var contents = listContainer.getElements('li');
		var len = contents.length;		
		var scrollIndex = 0;
		var totalWidth = 0;		
		var currentLi = contents[0];
		contents.each(function(el, index){
			totalWidth += el.getCoordinates().width;			
		});
		listContainer.setStyle('width', totalWidth);
		var scrollFx = new Fx.Scroll(listContainer.getParent());
		scrollFx.set(0, 0);	
		scrollFx.toElement(contents[scrollIndex]);
		var btnPre = container.getElement('p.btnPrev a img');
		var btnNext = container.getElement('p.btnNext a img');
		if (!btnPre || !btnNext) {
			return;
		}
		if (contents.length <= 3) {
			this.setDisableButton(btnPre);
			this.setDisableButton(btnNext);
			return;
		}
		that.setDisableButton(btnPre);
		btnPre.removeEvents('click').addEvent('click', function(e){
			new Event(e).stop();	
			if(scrollIndex - 1 < 0) {
				that.setDisableButton(btnPre);
				return;
			}
			scrollIndex -= 1;
			if(scrollIndex - 1 < 0) {
				that.setDisableButton(btnPre);
			}
			that.setEnableButton(btnNext);
			scrollFx.cancel().toElement(contents[scrollIndex]);
		});
		that.setEnableButton(btnNext);
		btnNext.removeEvents('click').addEvent('click', function(e){
			new Event(e).stop();	
			if(scrollIndex + 1 > len - 3) {
				that.setDisableButton(btnNext);
				return;
			}
			scrollIndex += 1;
			if(scrollIndex + 1> len - 3) {
				that.setDisableButton(btnNext);				
			}
			that.setEnableButton(btnPre);
			scrollFx.cancel().toElement(contents[scrollIndex]);
		});
	},
	
	setDisableButton: function (btn) {
		try {			
			btn.setStyles({
				'opacity': '0.4'				
			});
		} catch(err) {}
	},

	setEnableButton: function (btn) {
		try {
			btn.setStyles({
				'opacity': '1'
			});
		} catch(err) {}
	}
});
/////////////////////
var ShowHideTab = new Class({
	
	initialize: function(container, options){
		this.container = container;
		this.setOptions(options);
		this.initTab();
	},
	
	initTab: function(){
		var that = this;
		if(!$(that.container)) return;
		var tabsContainer = $(that.container);
		var items = tabsContainer.getElements('li');
		var contents = tabsContainer.getElements('div.tabContent');	
		var activeItem = tabsContainer.getElement('li.current');	
		var activeContent = tabsContainer.getElement('div');		
			
		items.each(function(item, index){
			item.addEvent('click', function(evt){
				new Event(evt).stop();
				if(activeItem != this){
					// remove current active item
					if(activeItem){
						var content = activeItem.get('html');					
						activeItem.removeClass('current');
						activeContent.addClass('hidden');	
					};
					// set active					
					this.addClass('current');
					activeItem = this;
					activeContent = contents[index];
					activeContent.removeClass('hidden');
				}			
			});
		});	
	}	
});
ShowHideTab.implement(new Chain, new Events, new Options);

///////////////////
var gallery2 = new Class({
	
	Implements: [Options, Events],
	
	options: {
		container: 'galleryCont',		
		direction: 'LTR',
		itemWidth: 200,
		fx: null,		
		totalImages: 0,
		scrollTimeout: 2000,
		clickTimeout: 1500,
		timerScroll: null,
		timerClick: null,
		ulTags: null,
		liTags: null,
		scrollContainer: null,
		btnPrevious: null,
		btnNext: null		
	},
	
	initialize: function(options){		
		this.setOptions(options);
		this.initGallery();	
		if(this.options.totalImages >= 3){
			this.setAutoRun();
		}
	},	
	
	initGallery: function(){
		var that = this;
		that.options.container = $(that.options.container);
		if(!that.options.container) return;
		that.options.scrollContainer = that.options.container.getElement('div.listProducts3');
		that.options.btnPrevious	= that.options.container.getElement('p.btnPrev');
		that.options.btnNext	= that.options.container.getElement('p.btnNext');		
		if(!that.options.container || !that.options.scrollContainer || !that.options.btnPrevious || !that.options.btnNext){
			return;
		}
		that.options.ulTags = that.options.scrollContainer.getElement('ul');
		that.options.liTags = that.options.ulTags.getElements('li');
		that.options.totalImages = that.options.liTags.length;
		that.options.btnPrevious.enabled = true;
		that.options.btnPrevious.addEvent('click', function(e){
			if(e){
				e.stop();
			}			
			if(!that.options.btnPrevious.enabled){
				return;
			}
			window.clearInterval(that.options.timerScroll);
			window.clearTimeout(that.options.timerClick);
			that.options.direction = 'RTL';
			that.toLi(--that.options.currentIndex);
			that.options.timerClick = window.setTimeout(function(){
				that.setAutoRun();
			}, that.options.clickTimeout);
		});
		that.options.btnNext.enabled = true;
		that.options.btnNext.addEvent('click', function(e){
			if(e){
				e.stop();
			}
			if(!that.options.btnNext.enabled){
				return;
			}
			window.clearInterval(that.options.timerScroll);
			window.clearTimeout(that.options.timerClick);
			that.options.direction = 'LTR';			
			that.toLi(++that.options.currentIndex);
			that.options.timerClick = window.setTimeout(function(){
				that.setAutoRun();
			}, that.options.clickTimeout);
		});
		
		if(that.options.totalImages < 3){
			that.options.btnNext.enabled = false;
			that.options.btnPrevious.enabled = false;
			that.options.btnPrevious.setStyle('opacity', '0.5');
			that.options.btnNext.setStyle('opacity', '0.5');	
			that.options.ulTags.setStyle('width', that.options.itemWidth * 3);	
			return;
		}	
		that.options.fx = new Fx.Scroll(that.options.scrollContainer, {
			link: 'ignore',					
			onComplete: function(){				
				if(that.options.currentIndex <= 1){					
					that.options.currentIndex = that.options.totalImages + 1;
					that.options.fx.set(that.options.itemWidth * that.options.currentIndex, 0);					
				}
				if(that.options.currentIndex > that.options.totalImages + 2){				
					that.options.currentIndex = 3;	
					that.options.fx.set(that.options.itemWidth * (that.options.currentIndex), 0);					
				}
			}
		});			
		that.swapItem();
		that.options.ulTags = that.options.scrollContainer.getElement('ul');
		that.options.liTags = that.options.ulTags.getElements('li');
		that.options.liTags.each(function(li){
			//li.getElement('p').setOpacity(0.6);
		});
		
		that.options.currentIndex = 3;
		that.options.fx.set(that.options.itemWidth * that.options.currentIndex, 0);					
		that.toLi(that.options.currentIndex);				
	},
	
	swapItem: function(){
		var that = this;
		that.options.liTags[0].clone().inject(that.options.ulTags, 'bottom');
		that.options.liTags[1].clone().inject(that.options.ulTags, 'bottom');
		that.options.liTags[2].clone().inject(that.options.ulTags, 'bottom');
		that.options.liTags[3].clone().inject(that.options.ulTags, 'bottom');
		that.options.liTags[that.options.totalImages - 1].clone().inject(that.options.ulTags, 'top');		
		that.options.liTags[that.options.totalImages - 2].clone().inject(that.options.ulTags, 'top');		
		that.options.liTags[that.options.totalImages - 3].clone().inject(that.options.ulTags, 'top');		
		that.options.liTags[that.options.totalImages - 4].clone().inject(that.options.ulTags, 'top');		
	},
	
	toLi: function(index){
		var that = this;				
		that.options.fx.toElement(that.options.liTags[index]);			
	},
		
	setAutoRun: function(){
		var that = this;
		var fn = $empty;		
		if(that.options.direction == 'LTR'){
			fn = that.options.btnNext;	
		}
		else{
			fn = that.options.btnPrevious;
		}
		that.options.timerScroll = window.setInterval(function(){
			fn.fireEvent('click');
		}, that.options.scrollTimeout);
	}
});
////////////////////
function intiProductTooltip(){
	var content = $('content');
	if(!content) return;
	
	content.getElements('.listProducts2').each(function(prodlist){
		var products = prodlist.getChildren();
		if(products.length){
			var container = $('container');
			var images = container.getElementsByTagName('img');
			var tooltip = new Tips({
				onShow: function(elm){
					container.setStyle('opacity', 0.5);
					
					if(Browser.Engine.trident){
						for(var i = 0, il = images.length; i < il; i++){
							$(images[i]).setStyle('opacity', 0.3);
						}
					}
					
					elm.setStyle('visibility', 'visible');
				},
				onHide: function(elm){
					container.setStyle('opacity', 1);
					if(Browser.Engine.trident){
						for(var i = 0, il = images.length; i < il; i++){
							$(images[i]).setStyle('opacity', 1);
						}
					}
					
					elm.setStyle('visibility', 'hidden');
				}
			});
			products.each(function(prod){
				var target = prod.getElement('p a');
				var ttip = prod.getElement('.tooltip');
				
				if(target && ttip){
					target.store('tip:text', ttip.removeClass('hidden').dispose());
					tooltip.attach(target);
				}
			});
		}
	});
};

////////////////////
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  //eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if(selObj.options[selObj.selectedIndex].value == '') return;
window.open(selObj.options[selObj.selectedIndex].value, '_self');
  
  if (restore) selObj.selectedIndex=0;
}
////////////////////
window.addEvent('domready', function(){	
	intiProductTooltip();
	initFadeListImages();
	slideShow();
	new Navigator('lev1');
	//new Gallery('galleryCont');
	new gallery2();		
	new ShowHideTab('tabInfo');
	
});

