/** 
 * Document    : us.js
 * Author      : Jerzy Piechowiak
 * Description : JavaScript for www.uslugistolarskie.eu
 */
var oUS = null;
(function() {
	oUS = {
		aFunctions: {},
		AddFunction: function(sName, oFunction) {
			oUS.aFunctions[sName] = oFunction;
			(typeof oFunction.Init === "function") || (oFunction.Init = function() {});
		},
		Run: function() {
			for (var nCounter in oUS.aFunctions) {
				oUS.aFunctions[nCounter].Init();
			}
		}
	};
	
	$().ready(function() {
		oUS.Run();
	});	

	(function() {
		this.Init = function() {
			var oArrayOfObjects = $("#slides");
			if(1 != oArrayOfObjects.length){
				return;
			} 
			oArrayOfObjects.slides({
				preload: true,
				container: "slides-container",
				next: "slides-next",
				prev: "slides-prev",
				preloadImage: "libs/slides/loading.gif",
				play: 5000,
				pause: 2500,
				hoverPause: true,
				animationStart: function(current){
					$('.caption').animate({
						bottom:-35
					},100);
				},
				animationComplete: function(current){
					$('.caption').animate({
						bottom:0
					},200);
				},
				slidesLoaded: function() {
					$('.caption').animate({
						bottom:0
					},200);
				}
			});
		};
		oUS.AddFunction("AddSlides", this);
	}).call({});
	
	(function() {
		this.Init = function() {
			$("#footer-top-link a").on("click", function () {
		    	$("#top").ScrollTo(1000);        
		    });
		};
		oUS.AddFunction("AddScollLinks", this);
	}).call({});
	
	(function() {
		this.Init = function() {
			$("nav ul > li:eq(" + parseInt($("nav").data("headersection")) + ")").addClass("active-tab");
		};
		oUS.AddFunction("AddClassActiveTab", this);
	}).call({});	
	
	(function() {
		this.Init = function() {
			var oFancybox = $("a.fancybox");
			if(0 == oFancybox.length){
				return;
			}
			oFancybox.fancybox({
				"speedIn"		 :	600, 
				"speedOut"		 :	200, 
				"overlayShow"	 :	true,
				"titlePosition"  : "outside",
				"overlayColor"   : "#000",
				"overlayOpacity" : 0.9,
			});			
		};
		oUS.AddFunction("ActivateFancybox", this);
	}).call({});		
	
	// Plugins
	jQuery.fn.extend({
		ScrollTo : function(oOptions){
			var oDefaults = {
				nSpeed: 1000,
				nEasing: 0
			}
			var oOptions = jQuery.extend(oDefaults, oOptions);
			return this.each(function() {
	    		var nTargetOffset = $(this).offset().top;
	    		$("html,body").animate({scrollTop: nTargetOffset}, oOptions.nSpeed, oOptions.nEasing);
	    	});			
		}}
	);
})();
