$(document).ready(function () {

	function tabSwitch (evt) {
		var el	   = $(this),
			parent = evt.target.parentNode,
			tabId;

		evt.preventDefault();

	    $("ul.tabs li").removeClass("active"); //Remove any "active" class

	    if ('LI' == parent.nodeName) {
	    	$(parent).addClass("active"); //Add "active" class to selected tab
	    }

	    $(".tab_content").css({
			position: 'absolute',
			left: '-10000px'
		}); //Hide all tab content


	    // Find the href attribute value to identify the active tab + content
	    if ('LI' == parent.nodeName) {
	    	tabId = el.find('a').attr("href");
	    } else {
	    	tabId = el.attr("href");
	    }

	    $(tabId).css({
			position: 'relative',
			left: '0px'
		}); //Fade in the active content

	    return false;
	}

    //Default Action
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").css({
		position: 'relative',
		left: '0px'
	}); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(tabSwitch);
    $("ul.links li.tablink").click(tabSwitch);
    $("a.contactBtn").click(tabSwitch);

    $("ul#slideshow").innerfade({
    	containerheight: '350px',
    	timeout: 5500,
    	speed: 2000
    });

	$(".slider").easySlider({
		auto: true,
		continuous: true,
		speed: 500,
		pause: 5000
	});

	$("#slider5").easySlider({
		controlsBefore:	'<p id="controls">',
		controlsAfter:	"</p>",
		auto: true,
		continuous: true
	});
});

var accordion = function () {
	var tm = sp = 10;

	function slider (n) {
		this.nm = n;
		this.arr = [];
	}

	slider.prototype.init = function (t, c, k) {
		var a, h, s, l, i;
		a = document.getElementById(t);
		this.sl = k ? k : '';

		h = a.getElementsByTagName('dt');
		s = a.getElementsByTagName('dd');
		this.l = h.length;

		for (i = 0; i < this.l; i++) {
			var d = h[i];
			this.arr[i] = d;
			d.onclick = new Function(this.nm+'.pro(this)');
			if(c == i) {
				d.className=this.sl;
			}
		}
		l = s.length;

		for(i = 0; i < l; i++) {
			var d = s[i];
			d.mh = d.offsetHeight;
			if (c != i) {
				d.style.height = 0;
				d.style.display = 'none';
			}
		}
	};

	slider.prototype.pro = function (d) {
		for(var i = 0; i < this.l; i++) {
			var h = this.arr[i],
				s = h.nextSibling;
				s = s.nodeType != 1 ? s.nextSibling : s;

			clearInterval(s.tm);

			if (h == d && s.style.display == 'none') {
				s.style.display = '';
				su(s, 1);
				h.className = this.sl;
			} else if (s.style.display == '') {
				su(s, -1);
				h.className = '';
			}
		}
	};

	function su (c, f) {
		c.tm = setInterval(function () {
			sl(c, f);
		}, tm);
	};

	function sl (c,f){
		var h = c.offsetHeight,
			m = c.mh,
			d = f == 1 ? m - h : h;

		c.style.height = h+ (Math.ceil(d / sp) * f) + 'px';
		c.style.opacity = h / m;
		c.style.filter = 'alpha(opacity=' + h * 100 / m + ')';

		if (f == 1 && h >= m) {
			clearInterval(c.tm);
		} else if (f != 1 && h == 1) {
			c.style.display = 'none';
			clearInterval(c.tm);
		}
	}

	return {slider: slider};
}();
