var currentSlide  = 1;
var introInterval = -1;

$(document).ready(function(){
	if($('.lightbox')) {
		$(".lightbox").lightbox();
    }
	if($('.box-main')) {
		$('.box-main.num1').show();
	
		$('#slidesmenu ul li a').click(function(e, keepPlay) {
			if(!keepPlay && introInterval != -1) clearInterval(introInterval);
		
			$('#slidesmenu ul li a.active').removeClass('active');
			$('#slidesmenu ul li a.active').href
			var pos = $(this).parent().prevAll('li').length;
			var nextSlide = (pos + 1);
			$(this).addClass('active');
			$('.box-main.num' + currentSlide).fadeOut('fast');
			$('.box-main.num' + nextSlide).fadeIn('slow');
			currentSlide = nextSlide;
			e.preventDefault();
		});
	
		function autoAnimate() {
			if(currentSlide == -1) return false;
			$('#slidesmenu ul li a').eq(currentSlide%$('#slidesmenu ul li a').length).trigger('click',[true]);
		}
		introInterval = setInterval(function(){autoAnimate()}, 5000);
	}
});

if (document.getElementsByTagName && document.getElementById) {
if (window.addEventListener) window.addEventListener('load', setImageSwaps, false);
else if (window.attachEvent) window.attachEvent('onload', setImageSwaps);
}

function setImageSwaps() {
prepareImageSwap('menu-main-left',true,true,true,true);
prepareImageSwap('top-menu',true,true,true,true);
prepareImageSwap('menu-full',true,true,true,true);
}

function prepareImageSwap(elem,mouseOver,mouseOutRestore,mouseDown,mouseUpRestore,mouseOut,mouseUp) {
//Do not delete these comments.
//Non-Obtrusive Image Swap Script by Hesido.com
//V1.1
//Attribution required on all accounts
	if (typeof(elem) == 'string') elem = document.getElementById(elem);
	if (elem == null) return;
	var regg = /(.*)(\.)([^\.]{3,4})$/
	var regg2 = /(.*)(_active\.)([^\.]{3,4})$/
	var prel = new Array(), img, imgList, imgsrc, mtchd;
	imgList = elem.getElementsByTagName('img');

	for (var i=0; img = imgList[i]; i++) {
		if (!img.rolloverSet && img.src.match(regg) && !img.src.match(regg2)) {
			mtchd = img.src.match(regg);
			img.hoverSRC = mtchd[1]+'_hover.'+ mtchd[3];
			img.outSRC = img.src;
			if (typeof(mouseOver) != 'undefined') {
				img.hoverSRC = (mouseOver) ? mtchd[1]+'_hover.'+ mtchd[3] : false;
				}
			if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;}
			if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;}
			img.rolloverSet = true;
		}
	}

	function preLoadImg(imgSrc) {
		prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc;
	}
}
function imgHoverSwap() {this.src = this.hoverSRC;}
function imgOutSwap() {this.src = this.outSRC;}
