﻿/* 
Version 1.0
Copyright SABIS® Creative 2009
http://www.sabis.net/creative
*/

(function($){
	
})(jQuery);
liteweb.AppendInit(function() {
	$("a[title^='Bookmark Us']").click(function() {
		if ($.browser.msie)
			window.external.AddFavorite(location.href, document.title);
		else {
			try {
				window.sidebar.addPanel(document.title, location.href, "");
			}
			catch (e) {
				alert("Press CTRL-D or CTRL-T(Opera) to bookmark");
			}
		}
		return false;
	});
	liteweb.StopAnim = false;
	liteweb.ShowTesti = function() {
		with (liteweb) {
			if (StopAnim)
				return;
			currentTesti++;
			currentTesti = currentTesti < testiLength ? currentTesti : 0;
			$(testiList[currentTesti]).fadeIn(1500);
			liteweb.ShowTimeout = window.setTimeout(HideTesti, 7500);
		}
	};
	liteweb.HideTesti = function(stop) {
		with (liteweb) {
			if (StopAnim)
				return;
			$(testiList[currentTesti]).fadeOut(1500);
			liteweb.HideTimeout = window.setTimeout(ShowTesti, 3500);
		}
	};
	liteweb.initTesti = function() {
		var list = liteweb.testiList = $(".testimonials");

		var a = document.createElement("a");
		a.className = "close";


		list.append(a);

		$(".testimonials a.close").bind("click", function() {
			liteweb.HideTesti()
			liteweb.StopAnim = true;
		});

		liteweb.lastTesti = 0;
		list.css("display", "none");
		liteweb.testiLength = list.length;
		liteweb.currentTesti = 0;
		liteweb.ShowTesti();
	}

	/// News Gallery ///

	liteweb.SwitchNewsImage = function() {
		with (liteweb) {
			var temp = lastNewsImage;
			lastNewsImage++;
			lastNewsImage = lastNewsImage >= NewsImgList.length ? 0 : lastNewsImage;
			$(NewsImgList[temp]).fadeOut(1000);
			$(NewsImgList[lastNewsImage]).fadeIn(1000);
		};
	};
	liteweb.initNewsGallery = function() {
		var list = liteweb.NewsImgList = $(".imgnews");
		if (list.length == 0) {
			$(".news-image-list").css("display", "none");
			return;
		}
		if (list.length == 1) {
			return;
		}
		list.each(function(i, el) {
			if (i == 0)
				return;
			$(el).css("display", "none");
		});
		liteweb.lastNewsImage = list.length - 1;
		setInterval(liteweb.SwitchNewsImage, 6000);
	};
	
	/// Gallery ///

	function HideCaption(caption) {
		$('#gallery .caption').animate({ height: '1px' }, { queue: true, duration: 300 });
		$('#gallery .gallerycontent').css({ opacity: 0.0 });
		setTimeout(function() {
			NextImage(caption);
		}, 1000);
	}

	function ShowCaption(caption) {
		$('#gallery .caption').animate({ height: '50px' }, 500);
		$('#gallery .gallerycontent').css({ opacity: 1 });
		$('#gallery .gallerycontent').html(caption);
	}
	function NextImage() {
		with (liteweb) {
			var current = ($('#gallery span.show') ? $('#gallery span.show') : $('#gallery span:first'));
			var next = ((current.next().length) ? ((current.next().hasClass('caption')) ? $('#gallery span:first') : current.next()) : $('#gallery span:first'));
			var caption = next.find('img').attr('alt');
			next.css({ opacity: 0.0 }).addClass('show').animate({ opacity: 1.0 }, 1000);
			current.animate({ opacity: 0.0 }, 1000).removeClass('show');
			setTimeout(function() {
				ShowCaption(caption);
			}, 1000);
		}
	}
	liteweb.Gallery = function() {
		HideCaption();
	};
	liteweb.initGallery = function() {
		$('#gallery span').css({ opacity: 0.0 });
		$('#gallery span:first').css({ opacity: 1.0 });
		$('#gallery .gallerycontent').html($('#gallery span:first').find('img').attr('alt')).animate(400);
		setInterval(liteweb.Gallery, 6000);
	};
});
