﻿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 ?
				27 :
				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 -1 :
					this._a.outerWidth() + 2,
				width: this.div.width() < this._a.width()? this._a.width() - 0: 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 hccs = {
	preparenews: function(){
		var list = liteweb.newsList = $(".home-news>.news-text>p");
		liteweb.lastNews = 0;
		list.each(function(i, el){
			if(i > 0)
			{
				$(el).css({
					display: "none"
				});
			}
			if(i == 4)
				return;
			var a = document.createElement("a");
			a.href = "javascript:";
			if(i == 0)
				a.className = "ac";
			$(a).bind("click", function(){
				displaynews(i);
			});
			a.innerHTML = i+1;
			$(".n-pages").append(a);
			
		});
	},
	currentAlbum: 0,
	albumsLength: 0,
	albumsList: null,
	albumLinks: null,
	preparegallery: function(){
		var _ = hccs;
		var list = _.albumsList = $(".home-gallery>.gallery a>img");
		_.albumLinks = $(".home-gallery>.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 _ = hccs;
		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(){
			}
		});
		$(".home-gallery .album-title").attr("href", 
			$(_.albumLinks[_.currentAlbum]).attr("href")
		);
		$(".home-gallery .album-title").attr("title", 
			$(_.albumLinks[_.currentAlbum]).attr("title")
		);
		$(".home-gallery .footer-title").text(
			$(_.albumLinks[_.currentAlbum]).attr("title")
		); 
	}
};


