﻿liteweb.AppendInit(function() {
	var dur = 300;
	var easing = "easeOutQuad";

	$(".topmenu>li").each(function(i, el) {
		el.menu = createMenu(el, null, i);
	});

	function createMenu(el, parent) {
		var m = {};
		m.el = $(el);
		m._a = $(el).children("a");

		m.div = $(el).children("div.topmenu-sub");
		m._ol = m.div.children("ol");
		if (m._a.length == 0 || m._ol.length == 0)
			return;

		var span = m._a.children("span");
		/*if (span.length > 0)
		this._a = span;
		*/
		m.a = m._a[0];
		m.ol = m._ol[0];

		m.li = m._ol.children("li");
		//alert();
		m.maxHeight = m._ol.outerHeight() + 0; //m.li.length * 23 + 22 + ($.browser.safari && $.browser.version < 526 ? (-2) : 0);

		m.visible = false;
		m.hideMe = false;
		m.parent = parent;
		m.a.menu = m;
		m.div[0].menu = m;

		m.show = function() {
			this.hideMe = false;
			if (this.visible)
				return;
			this.visible = true;

			this.div.css({
				overflow: "visible",
				visibility: "visible",
				height: 0,
				top: this.parent === null ?
				16 :
				this._a.offset().top - $(this.a.parentNode.parentNode).offset().top - 7,
				left: this.parent === null ?
					this._a.offset().left - $(this.a.parentNode.parentNode).offset().left + 21 :
					this._a.outerWidth() + 2,
				width: this.div.width() < this._a.width()? this._a.width() - 4: this.div.width()
			});
			this.div.stop();
			var animateTo = { height: this.maxHeight };
			if (!$.browser.msie)
				$.extend(animateTo, { opacity: 1 });
			this.div.animate(animateTo, { duration: dur, easing: easing });
			this._a.addClass("_hover");
		};
		m.hide = function() {
			this.hideMe = true;
			window.setTimeout(function() {
				m._hide();
			}, 50);
		}
		m._hide = function() {
			if (!this.hideMe)
				return;
			this.visible = false;
			for (var i = 0; i < this.children.length; i++) {
				if (this.children[i].visible)
					return;
			}
			this.div.stop();
			var animateTo = { height: 0 };
			if (!$.browser.msie)
				$.extend(animateTo, { opacity: 0 });

			this.div.animate(animateTo, { duration: dur / 2, easing: easing,
				complete: function() {
					if (!this.menu.hideMe)
						return;
					this.menu.div.css("visibility", "hidden");
					this.menu._a.removeClass("_hover");
				}
			});
		}
		m.children = [];
		m.li.each(function(i, el) {
			m.children.push(el);
			el.menu = createMenu(el, this);
			var $a = $($(this).children("a"));
			if($(el).children("div.topmenu-sub").length == 0)
				$a.addClass("arrow1");
		});
		if (m.children.length > 0 && m.parent != null) {
			m._a.addClass("arrow");
		}
		m._a.bind("mouseover", function() {
			if (this.menu) {
				this.menu.show();
			}
		});
		m._a.bind("mouseout", function() {
			if (this.menu)
				this.menu.hide();
		});
		m.div.bind("mouseover", function() {
			if (this.menu)
				this.menu.show();
		});
		m.div.bind("mouseout", function() {
			if (this.menu)
				this.menu.hide();
		});
		return m;
	}
	function hideMenu(el) {
		window.setTimeout(function() {
			_hideMenu(el);
		}, 200);
	}
	function _hideMenu(el) {
		if (el.childVisible)
			return;
		alert(el);
		el._sub.css("display", "none");
		el._ol.css("height", 0)
		el._a.removeClass("_hover");
	}
});

var isc = {
	currentAlbum: 0,
	albumsLength: 0,
	albumsList: null,
	albumLinks: null,
	preparegallery: function() {
		var _ = isc;
		var list = _.albumsList = $(".gallery a>img");
		_.albumLinks = $(".gallery a");
		_.albumsLength = list.length;
		list.each(function(i, el) {
			if (i > 0) {
				$(el).css("opacity", 0);
			}
		});
		$("a[title='Previous Album']").click(function() {
			_.changePhoto(-1);
		});
		$("a[title='Next Album']").click(function() {
			_.changePhoto(1);
		});
	},
	changePhoto: function(step) {
		var _ = isc;
		var temp = _.currentAlbum;
		_.currentAlbum += step;
		_.currentAlbum = _.currentAlbum == _.albumsLength ? 0 : _.currentAlbum < 0 ? _.albumsLength - 1 : _.currentAlbum;
		$(_.albumsList[temp]).animate(
			{ left: step * 300, opacity: 0 },
			{ duration: 300, complete: function() {
			}
			});
		$(_.albumsList[_.currentAlbum]).css("left", 0);
		$(_.albumsList[_.currentAlbum]).animate(
			{ opacity: 1 },
			{ duration: 300, complete: function() {
			}
			});
		$(".galleryholder .album-title").attr("href",
			$(_.albumLinks[_.currentAlbum]).attr("href")
		);
		$(".galleryholder .album-title").attr("title",
			$(_.albumLinks[_.currentAlbum]).attr("title")
		);
		$(".galleryholder .footer-title").text(
			$(_.albumLinks[_.currentAlbum]).attr("title")
		);
	},
	prepareevents: function() {
		var _ = isc;
		liteweb.animDuration = 600;
		liteweb.events = $("div.eventslist div.events");
		liteweb.events.css({ position: "absolute", display: "none" });
		var ul = document.createElement("ul");
		var ar = [];
		liteweb.events.each(function(i, el) {
			ar.push("<li><a href=\"javascript:\" onclick=\"isc.EventsItem({0}, this)\"{2}>{1}</a></li>".Format(i, i + 1, i == 0 ? " class=\"selected\"" : ""));
		});
		ul.innerHTML = ar.join("");
		$(".events-links").append(ul);
		if (liteweb.events.length == 0)
			return;
		liteweb.lastEventsItem = $(liteweb.events[0]);
		liteweb.lastEventsItem.css({ display: "block" });
		var $ul = $(ul);
		var offset = $ul.offset();
		$ul.css({
			position: "absolute",
			top: offset.top,
			left: offset.left,
			zIndex: 100
		});
		var eventsslider = liteweb.eventsslider = $(document.createElement("div"));
		var $a = $($ul.children("li").children("a")[0]);
		eventsslider.addClass("eventsslider");
		eventsslider.css({
			position: "absolute",
			top: $a.offset().top + 1,
			left: $a.offset().left + 1,
			zIndex: 99
		});
		$(".events-links").append(eventsslider);
		liteweb.oldEventsNav = $a;
	},
	EventsItem: function(i, el) {
		if (el.className.indexOf("selected") >= 0)
			return;
		liteweb.oldEventsNav.removeClass("selected");
		var $el = $(el);

		var animateTo = {
			left: $el.offset().left + 1
		};

		liteweb.eventsslider.animate(animateTo, { duration: liteweb.animDuration });

		liteweb.oldEventsNav = $el;
		liteweb.oldEventsNav.addClass("selected");

		if (liteweb.lastEventsItem != undefined) {
			liteweb.lastEventsItem.fadeOut(liteweb.animDuration);
		}
		liteweb.lastEventsItem = $(liteweb.events[i]);
		liteweb.lastEventsItem.fadeIn(liteweb.animDuration);
	},
	preparenews: function() {
		var _ = isc;
		liteweb.animDuration = 600;
		liteweb.news = $("div.newslist div.news");
		liteweb.news.css({ position: "absolute", display: "none" });
		var ul = document.createElement("ul");
		var ar = [];
		liteweb.news.each(function(i, el) {
			ar.push("<li><a href=\"javascript:\" onclick=\"isc.NewsItem({0}, this)\"{2}>{1}</a></li>".Format(i, i + 1, i == 0 ? " class=\"selected\"" : ""));
		});
		ul.innerHTML = ar.join("");
		$(".news-links").append(ul);
		if (liteweb.news.length == 0)
			return;
		liteweb.lastNewsItem = $(liteweb.news[0]);
		liteweb.lastNewsItem.css({ display: "block" });
		var $ul = $(ul);
		var offset = $ul.offset();
		$ul.css({
			position: "absolute",
			top: offset.top,
			left: offset.left,
			zIndex: 100
		});
		var newsslider = liteweb.newsslider = $(document.createElement("div"));
		var $a = $($ul.children("li").children("a")[0]);
		newsslider.addClass("newsslider");
		newsslider.css({
			position: "absolute",
			top: $a.offset().top + 1,
			left: $a.offset().left + 1,
			zIndex: 99
		});
		$(".news-links").append(newsslider);
		liteweb.oldNewsNav = $a;
	},
	NewsItem: function(i, el) {
		if (el.className.indexOf("selected") >= 0)
			return;
		liteweb.oldNewsNav.removeClass("selected");
		var $el = $(el);

		var animateTo = {
			left: $el.offset().left + 1
		};

		liteweb.newsslider.animate(animateTo, { duration: liteweb.animDuration });

		liteweb.oldNewsNav = $el;
		liteweb.oldNewsNav.addClass("selected");

		if (liteweb.lastNewsItem != undefined) {
			liteweb.lastNewsItem.fadeOut(liteweb.animDuration);
		}
		liteweb.lastNewsItem = $(liteweb.news[i]);
		liteweb.lastNewsItem.fadeIn(liteweb.animDuration);
	},
	preparetestimonials: function() {
		var _ = isc;
		liteweb.animDuration = 600;
		liteweb.testimonials = $("div.testimonialslist div.testimonial");
		liteweb.testimonials.css({ position: "absolute", display: "none" });
		var ul = document.createElement("ul");
		var ar = [];
		liteweb.testimonials.each(function(i, el) {
			ar.push("<li><a href=\"javascript:\" onclick=\"isc.TestimonialsItem({0}, this)\"{2}>{1}</a></li>".Format(i, i + 1, i == 0 ? " class=\"selected\"" : ""));
		});
		ul.innerHTML = ar.join("");
		$(".testimonial-links").append(ul);
		if (liteweb.testimonials.length == 0)
			return;
		liteweb.lastTestimonialsItem = $(liteweb.testimonials[0]);
		liteweb.lastTestimonialsItem.css({ display: "block" });
		var $ul = $(ul);
		var offset = $ul.offset();
		$ul.css({
			position: "absolute",
			top: offset.top,
			left: offset.left,
			zIndex: 100
		});
		var slider = liteweb.slider = $(document.createElement("div"));
		var $a = $($ul.children("li").children("a")[0]);
		slider.addClass("slider");
		slider.css({
			position: "absolute",
			top: $a.offset().top + 1,
			left: $a.offset().left + 1,
			zIndex: 99
		});
		$(".testimonial-links").append(slider);
		liteweb.oldTestimonialsNav = $a;
	},
	TestimonialsItem: function(i, el) {
		if (el.className.indexOf("selected") >= 0)
			return;
		liteweb.oldTestimonialsNav.removeClass("selected");
		var $el = $(el);

		var animateTo = {
			left: $el.offset().left + 1
		};

		liteweb.slider.animate(animateTo, { duration: liteweb.animDuration });

		liteweb.oldTestimonialsNav = $el;
		liteweb.oldTestimonialsNav.addClass("selected");

		if (liteweb.lastTestimonialsItem != undefined) {
			liteweb.lastTestimonialsItem.fadeOut(liteweb.animDuration);
		}
		liteweb.lastTestimonialsItem = $(liteweb.testimonials[i]);
		liteweb.lastTestimonialsItem.fadeIn(liteweb.animDuration);
	}
}


$(document).ready(function() {


	lw.center = $("#section-two .container h3");
	if(lw.center[0] == null)
		return;
	lw.centerTimeout = 0;
	lw.lastCenterEl = $(lw.center[0]);
	lw.lastCenterEl.addClass("_active");
	var _parent = lw.lastCenterEl[0].parentNode;
	var parent = $(_parent);
	var p = parent.children("div.b");
	if (!p[0]._height)
		p[0]._height = p.height();

	lw.center.bind("mouseover", function() {
		clearTimeout(lw.centerTimeout);
		lw.lastHoverCenter = $(this);
		lw.centerTimeout = setTimeout(_OpenTab, 500);
	});
	lw.center.click(function() {
		clearTimeout(lw.centerTimeout);
		lw.lastHoverCenter = $(this);
		lw.centerTimeout = setTimeout(_OpenTab, 1);
	});
	lw.center.bind("mouseout", function() {
		clearTimeout(lw.centerTimeout);
	});
	
	function _OpenTab() {
		var el = lw.lastHoverCenter;
		if (el.hasClass("_active"))
			return;
		el.addClass("_active");
		_HideTab(lw.lastCenterEl);
		lw.lastCenterEl = el;
		if (!el.hasClass("no-effect")) {
			el.animate(1000);
		} 

		var _parent = el[0].parentNode;
		var parent = $(_parent);
		var p = parent.children("div.b");
		if (!p[0]._height)
			p[0]._height = p.height();
		p.css({ height: 0, display: "block", "visibility": "visible", "overflow": "hidden", "position": "relative" });
		p.animate({ height: p[0]._height }, { duration: 500 });
	}
	function _HideTab(el) {
		el.removeClass("_active");
		if (!el.hasClass("no-effect")) {
			el.animate(1000);
		}
		var _parent = el[0].parentNode;
		var parent = $(_parent);
		var p = parent.children("div.b");
		p.animate({ height: 0 }, { duration: 500 });

	}
	
	
	lw.centertwo = $("#section-one .container h3");
	if(lw.centertwo[0] == null)
		return;
	lw.centertwoTimeout = 0;
	lw.lastCentertwoEl = $(lw.centertwo[0]);
	lw.lastCentertwoEl.addClass("_active");
	var _parent = lw.lastCentertwoEl[0].parentNode;
	var parent = $(_parent);
	var p = parent.children("div.b");
	if (!p[0]._height)
		p[0]._height = p.height();

	lw.centertwo.bind("mouseover", function() {
		clearTimeout(lw.centertwoTimeout);
		lw.lastHoverCentertwo = $(this);
		lw.centertwoTimeout = setTimeout(_OpenTabTwo, 500);
	});
	lw.centertwo.click(function() {
		clearTimeout(lw.centertwoTimeout);
		lw.lastHoverCentertwo = $(this);
		lw.centertwoTimeout = setTimeout(_OpenTabTwo, 1);
	});
	lw.centertwo.bind("mouseout", function() {
		clearTimeout(lw.centertwoTimeout);
	});
	
	function _OpenTabTwo() {
		var el = lw.lastHoverCentertwo;
		if (el.hasClass("_active"))
			return;
		el.addClass("_active");
		_HideTab(lw.lastCentertwoEl);
		lw.lastCentertwoEl = el;
		if (!el.hasClass("no-effect")) {
			el.animate(1000);
		} 

		var _parent = el[0].parentNode;
		var parent = $(_parent);
		var p = parent.children("div.b");
		if (!p[0]._height)
			p[0]._height = p.height();
		p.css({ height: 0, display: "block", "visibility": "visible", "overflow": "hidden", "position": "relative" });
		p.animate({ height: p[0]._height }, { duration: 500 });
	}
	function _HideTabTwo(el) {
		el.removeClass("_active");
		if (!el.hasClass("no-effect")) {
			el.animate(1000);
		}
		var _parent = el[0].parentNode;
		var parent = $(_parent);
		var p = parent.children("div.b");
		p.animate({ height: 0 }, { duration: 500 });

	}
	
})
