$(document).ready(function() {
	
	/*--- main menu ---*/
	$("#main-menu ul").hide(); // contract the whole menu
	$("#main-menu a[href != #]").each(function() {
		// find matching url
		if (jQuery.url.attr("directory") == $(this).attr("href")) {
			$(this).parents("li").addClass("open");
			$(this).parents("ul").show();
		}
	});
	
	$("#main-menu span, #main-menu img").click(function(e) {
		var $tgt = ($(e.target).parents("li:first")); // li element
		
		$tgt.siblings().find("ul").slideUp('fast'); // hide siblings' uls
		$tgt.find("ul ul").slideUp('fast'); // hide child uls
		$tgt.children("ul").slideToggle('fast'); // toggle the current submenu

		$tgt.siblings().removeClass('open'); // remove the 'open' class from all the siblings of the clicked li
		$tgt.siblings().find('li').removeClass('open'); // remove the 'open' class from all the children of the siblings of the clicked li
		$tgt.find('li').removeClass('open'); // remove the 'open' class from all the children of the clicked li
		$tgt.toggleClass('open'); // toggle class 'open' of the clicked li
		
		// prevent jumping to the top of the page for invalid (#) links
		if ($tgt.find("a").attr("href") == '#') {
			e.preventDefault();
		}
	});
	/*--- end main menu ---*/
	
	
	/*--- bookmark & set as homepage ---*/
	$("#bookmark-button").click(function() {
		arctBookmarkIt('4PM', 'http://www.4pm.si');
	});
	$("#set-as-homepage-button").click(function() {
		arctSetAsHomepage(this, 'http://www.4pm.si');
	});
	/*--- end bookmark & set as homepage ---*/
	
	/*--- lightbox ---*/
	$('a[@rel*=lightbox]').lightBox({
		imageLoading: '/images/loading.gif',
		imageBtnClose: '/images/close.gif',
		imageBtnPrev: '/images/prev.gif',
		imageBtnNext: '/images/next.gif'
	});
	/*--- end lightbox ---*/
	
			/*--- FAQ ---*/
	
	if ($("div#faq-form-section").length) {
		$("p#faq-form-toggle").slideDown();
		$("p#faq-form-toggle").click(function() {
			$("p#faq-form-toggle").slideUp(500);
			$("div#faq-form-section").slideToggle(500);
		});
	}
	
	if ($("div#faq-list").length) {
		$("div#faq-list h2").click(function() {
			$(this).next("dl.faq-list").slideToggle(500);
			$(this).next("dl.faq-list").toggleClass('open');
			$(this).toggleClass('open');
		});
	}
	
	/*--- END FAQ ---*/
	
});