if (typeof Einstein === 'undefined' || !Einstein) {
	var Einstein = {};
}
if (!Einstein.home) {
	Einstein.images = [];
	Einstein.images[0] = '/images/home/main_theatre2.jpg';
	Einstein.images[1] = '/images/home/main_theatre3.jpg';
	Einstein.images[2] = '/images/home/main_theatre4.jpg';
	Einstein.images[3] = '/images/home/main_theatre5.jpg';
	Einstein.images[4] = '/images/home/main_theatre6.jpg';

	Einstein.home = (function() {
		var views = [], prevIndex = 0, curIndex = 0, opacity = 0, pause = false,
		add = (function() {
			if (window.addEventListener) { return function(o, t, f) { o.addEventListener(t, f, false); }; }
			else if (window.attachEvent) { return function(o, t, f) { o.attachEvent('on' + t, f); }; }
			else { return function() { }; }
		} ()),
		remove = (function() {
			if (window.removeEventListener) { return function(o, t, f) { o.removeEventListener(t, f, false); }; }
			else if (window.detachEvent) { return function(o, t, f) { o.detachEvent('on' + t, f); }; }
			else { return function() { }; }
		} ());
		function addView(div, loaded, src) {
			views[views.length] = {
				'div': div,
				'loaded': loaded,
				'src': src
			};
		}
		function updateAlpha() {
			if (opacity < 100) {
				opacity += 10;
				views[curIndex].div.style.filter = 'alpha(opacity=' + opacity + ')';
				setTimeout(updateAlpha, 100);
			}
			else {
				views[curIndex].div.style.filter = 'alpha(opacity=100)';
				finishTransition();
			}
		}
		function updateOpacity() {
			if (opacity < 1) {
				opacity += 0.1;
				views[curIndex].div.style.opacity = opacity;
				setTimeout(updateOpacity, 100);
			}
			else {
				views[curIndex].div.style.opacity = 1;
				finishTransition();
			}
		}
		function transitionImage() {
			opacity = 0;
			views[prevIndex].div.style.zIndex = '1';
			if (views[curIndex].div.filters) {
				updateAlpha();
			}
			else {
				updateOpacity();
			}
			views[curIndex].div.style.display = 'block';
			views[curIndex].div.style.zIndex = '2';
		}
		function displayImage() {
			var img = document.createElement('img');
			views[curIndex].loaded = true;
			img.onload = function() {
				img.onload = null;
				var a = document.createElement('a');
				a.href = '/services.html';
				views[curIndex].div.appendChild(a);
				a.appendChild(img);
				transitionImage();
			};
			img.width = 654;
			img.height = 348;
			img.border = 0;
			img.src = views[curIndex].src;
		}
		function startTransition() {
			if (pause) {
				setTimeout(startTransition, 100);
			}
			else {
				prevIndex = curIndex;
				curIndex = (curIndex + 1) % views.length;
				if (views[curIndex].loaded) {
					transitionImage();
				}
				else {
					displayImage();
				}
			}
		}
		function finishTransition() {
			views[prevIndex].div.style.display = 'none';
			views[prevIndex].div.style.zIndex = '0';
			setTimeout(startTransition, 3000);
		}
		function shuffle(a) {
			var i, n = a.length, t;
			while (n > 1) {
				i = Math.floor(Math.random() * n--);
				t = a[i];
				a[i] = a[n];
				a[n] = t;
			}
		}
		function load() {
			var vp, div, i, l;
			remove(window, 'load', load);
			vp = document.getElementById('homeSlideShow');
			if (vp) {
				div = vp.getElementsByTagName('div');
				if (div && div.length === 1) {
					addView(div[0], true, '');
					shuffle(Einstein.images);
					for (i = 0, l = Einstein.images.length; i < l; i++) {
						div = document.createElement('div');
						div.style.display = 'none';
						div.style.position = 'absolute';
						div.style.left = '0';
						div.style.top = '0';
						addView(div, false, Einstein.images[i]);
						vp.appendChild(div);
					}
					vp.onmouseout = function() { pause = false; };
					vp.onmouseover = function() { pause = true; };
					setTimeout(startTransition, 3000);
				}
			}
		}
		add(window, 'load', load);
		return true;
	} ());
}