(function($) {
  var cache = [];
  $.preloadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

var os = {
	construct: function() {
		$.preloadImages("img/menu.hover.cennik.png", "img/menu.hover.uslugi.png", "img/menu.hover.galeria.png", "img/menu.hover.kursy.png", "img/menu.hover.onas.png", "img/menu.hover.publikacje.png", "img/menu.hover.kontakt.png");
		this.registerEvents();
		this.handleSheetScroll();
		this.enableLightBox();
	},
	registerEvents: function() {
		var curr = $("#menu ul").attr("class");
		
		$("#menu li a").mouseover(function() {
			var el = $(this).attr("class").split("menu")[1];
			$("#menu ul").attr("class", "menu"+el);
		}).mouseout(function() {
			$("#menu ul").attr("class", curr);
		});
		
		$("ul.thumbnails li a").mouseover(function() {
			$("ul.thumbnails li a").each(function() { $(this).removeClass("galleryActive").removeClass("galleryInactive"); });
			os.highlightGallery($(this).attr("class"));
		}).mouseout(function() { 
			os.removeGalleryHighlights();
		});
	},
	handleSheetScroll: function() {
		if ($("#sheetScroll").length > 0) {
			$("#sheetScroll").jScrollPane({
				scrollbarWidth: 7
			});
		}
	},
	enableLightBox: function() {
		if($("ul.thumbnails").length > 0) {
			$("ul.thumbnails li a").lightBox({fixedNavigation:true});
		}
	},
	highlightGallery: function(gallery) {
		$("."+gallery).addClass("galleryActive");
		$("ul.thumbnails li a").not(".galleryActive").addClass("galleryInactive");
	},
	removeGalleryHighlights: function() {
		$("ul.thumbnails li a").each(function() {
			$(this).removeClass("galleryActive").removeClass("galleryInactive");
		});
	}
}

$(document).ready(function() { os.construct(); });
