window.addEvent('domready', function(){

	var myMenu = new MenuMatic();
	
	if ($('promo')) {
		var sel = $('promo').getFirst().get('id');;
		$$('.promonavbtn').each(function(nav) {
			nav.addEvent('click',function() {
				$clear(slideshow);
				$$('.promoitem').each(function(p) {p.removeClass('show')});
				$(nav.get('rel')).addClass('show');
				sel = nav.get('rel');
			});
		});
	
	
		$$('.forward').each(function(fwd) {
			fwd.addEvent('click',function() {
				$clear(slideshow);
				$$('.promoitem').each(function(p) {p.removeClass('show')});
				var promoitem = this.getParent().getParent().getParent();
				if (promoitem.getNext()) {
					promoitem.getNext().addClass('show');
				} else {
					promoitem.getParent().getFirst().addClass('show');
				}
			});
		});	
			
			
		$$('.back').each(function(bck) {
			bck.addEvent('click',function() {
				$clear(slideshow);
				$$('.promoitem').each(function(p) {p.removeClass('show')});
				var promoitem = this.getParent().getParent().getParent();
				if (promoitem.getPrevious()) {
					promoitem.getPrevious().addClass('show');
				} else {
					promoitem.getParent().getLast().addClass('show');
				}
			});
		});
		
		
		var newslide = function() {
			$$('.promoitem').each(function(p) {
				if (p.hasClass('show')) {
					currslide = p;
					p.removeClass('show')
				}
			
			});
			if (currslide.getNext()) {
				currslide.getNext().addClass('show');
			} else {
				currslide.getParent().getFirst().addClass('show');
			}
		};
		
		var slideshow = newslide.periodical(8000);
		
	}
	
	
	var winheight = window.getSize().y;
	var footerheight = $('footer').getSize().y;
	var footer_y = $('footer').getPosition().y;
	
	if (footer_y<(winheight-footerheight)) {
		$('footer').setStyles({
			'position':'fixed',
			'bottom':'0'
		});
	}




	if ($('productmap')) {
		
		
		
		
		
		
		var tip_wrap = new Element('div',{'class':'tip','id':'tip'}).inject(document.body);
		var tip_top = new Element('div',{'class':'tiptop'}).inject(tip_wrap);
		var tip_body = new Element('div',{'id':'tip_body'}).inject(tip_wrap);
		var tip_text = new Element('div',{'id':'tip_txt'}).inject(tip_body);
		
		$$('#productmap span').each(function(span) {
			span.addEvent('mouseenter',function() {
				$('tip').inject(this);
				this.tween('color','#fff');
				if (this.hasClass('video')) {
					if ($('videoholder')) $('videoholder').destroy();
					var viddiv = new Element('div',{'id':'videoholder'}).inject($('tip_body'));
					var obj = new Swiff('/imgs/cogvideo.swf', {
						id: 'myBeautifulMovie',
						width: 320,
						height: 240,
						params: {
							wMode: 'opaque',
							bgcolor: '#000'
						},
						vars: {
							v: span.get('rel')
						}
					}).inject(viddiv);
					$('tip').setStyles({'width':'630px'});
				}
				$('tip').setStyles({
					'display':'block',
					'opacity':'0',
					'top':span.getSize().y,
					'left':(span.getSize().x/2) -  ($('tip').getStyle('width').toInt()/2)
				}).fade('in');
				$('tip_txt').set('html',span.getNext().get('html'));
			});
			span.addEvent('mouseleave',function(e) {
				if ($('videoholder')) {
					$('videoholder').destroy();
					$('tip').setStyles({'width':'300px'});
				}
				$('tip').setStyles({'display':'none'});
				span.tween('color','#9cc6cd');
			});
		});
	}
});
