//Slide.js
var imgs, elA, elB, sFx, distance, place = 1;
var VV_loadedCount = 0, gogogo = false, started = false;
var slideOpts = {
	transition : 2700,
	pause : 2200
}
window.addEvent('domready', function() {
	$$('#slide img').each(function(e) {
		e.setStyle('display','none');
		e.setStyle('opacity',0);
		});
			
	$$('ul.mainmenu a').each(function(el) {
		if(document.location.href.indexOf(el.href) != -1) {
			el.addClass("active");
			el.title = "(You are currently viewing this section)";
		}
	})
	new Tips($$('ul.mainmenu a'), {
		offsets : {'x' : -10}
	});

	new SmoothScroll({
		offset : {
			x : 0 , y: -40
		}
	});
	
	$$('.expandimg').each(function(el) {
		new Image().src = el.src.replace("-small","")
		el.addEvent('mouseenter',function() {
			var p = this.getPosition();
			var im = this.clone().setStyles({
				position:'absolute',
				'z-index' : 99
			}).addEvent('mouseleave',function() {
				this.remove();
			}).injectBefore(this).src = this.src.replace("-small","");
		});
	});
	
	$$('.replaceimg').each(function(el) {
		new Image().src = el.src.replace(".j","-hover.j");
		
		$(el).addEvent("mouseenter", function() {
			this.src = this.src.replace(".j","-hover.j");
		})
		
		$(el).addEvent("mouseleave", function() {
			this.src = this.src.replace("-hover.",".");
		})
		
	})
	
	
	$$('.submenu').getParent().addEvent('mouseenter', function(el) {$E('ul.submenu', this).setStyle('display','block')}).addEvent('mouseleave',function(el) {
			new Function("$E('ul.submenu',this).setStyle('display','none')").bind(this).delay(200)
		})

	if($('slide')) {
		window.addEvent('load', function() {
				imgs =$$('#slide img');
	     	elB =imgs[0],
				elB.setStyle('display','block');
				new Fx.Style(elB,'opacity',{duration : slideOpts.transition}).start(0,1).chain(function() {
					slider.delay(slideOpts.pause);
					});
		});
	}
});
slider = function() {
	started = true;
	elA = imgs[place++];
	if(place == imgs.length) 
		place = 0;
	sFx = new Fx.Elements(new Array(elA, elB), {duration : slideOpts.transition, transition: Fx.Transitions.linear});
	elA.setStyle('display','block')
		sFx.start({
		'0' : {
			opacity : [0,1]
		},
		'1' : {
			opacity : [1,0]
		}
	}).chain(function() {
		elB.setStyle('display','none');
		elB = elA;
		slider.delay(slideOpts.pause);
	});
}
sortImgs = function(a,b) {
	return (a.src.split('/').getLast().split('.')[0]+1 > b.src.split('/').getLast().split('.')[0]);
}