﻿$(document).ready(function() {
	jQuery.fn.exists = function() { return jQuery(this).length>0; }



	// last hit visible
	//$('li.hit:last').addClass('onlyhit');


//poziome rozwijane menu

$('#vert .lvl2').not('.hit > ul').hide();
$('#vert .lvl3').not('.hit > ul').hide();
$('#vert .lvl4').not('.hit > ul').hide();

$('#vert ul > li').click(function() {
	var selfClick = $(this).find('ul:first').is(':visible');
	if (selfClick) {
		return;
	}

	$(this)
		.parent()
		.find('> li ul:visible')
		.slideToggle(300);
	$(this)
		.find('ul:first')
		.stop(true, true)
		.slideToggle(300);
});



	// Focus border remove



			$("a").focus(function() {

				$(this).blur();

			});







	// Slider



		$('#slider > li ul').click(function(e){

			e.stopPropagation();

		}).filter(':not(:first)').hide();



		$('#slider > li').click(function() {

			var selfClick = $(this).find('ul:first').is(':visible');

			if (selfClick) {

				return;

			}

			$(this)

				.parent()

				.find('> li ul:visible')

				.slideToggle();

			$(this)

				.find('ul:first')

				.stop(true, true)

				.slideToggle();

		});



		$('#slider li ul li:last-child').addClass('last');







	// Fancybox



			if($(".fancy").exists()) {

				$(".fancy").fancybox({

					'titlePosition'	:	'over',

					'padding'			: 0,

					'transitionIn'		: 'none',

					'transitionOut'		: 'none',

					'type'              : 'image',

					'changeFade'        : 0,

					'onComplete'	:	function() {

						$("#fancybox-wrap").hover(function() {

							$("#fancybox-title").show();

						}, function() {

							$("#fancybox-title").hide();

						});

					}

				});

			}



























	// Clear input



			clearInput = function (arg) {

				var $nam = $(arg).val();



				$(arg).focus(function() {

					if(	$(this).val() == $nam) {

						$(this).val('');

					}

				})



				$(arg).blur(function() {

					if(	$(this).val() == '') {

						$(this).val($nam);

					}

				});

			}



			clearInput("#name");

			clearInput("#email");













	// Opacity



			$.fn.opacity = function() {

				$(this).hover(

				  function () {

					$(this).css({ opacity: ".9" });

				  },

				  function () {

					$(this).css({ opacity: "1" });

				  }

				);

			}



			if($(".more").exists()) { $(".more").opacity(); }

			if($("#gallery").exists()) {

				$("#gallery a").opacity();





			}













	// Remove margin in last element





	var art = $("article").height();

	var asi = $("aside").height();



	if ( $("body").hasClass("start") ) {

		if ( art > asi ) {

			$("article").css({ borderRight: "1px solid #d5d5dc" });

		} else {

			$("aside").css({ borderLeft: "1px solid #d5d5dc" });

		}

	}







	// Drop down menu



		ddsmoothmenu.init({

			mainmenuid: "horiz",

			orientation: 'h',

			classname: 'ddsmoothmenu',

			//customtheme: ["#1c5a80", "#18374a"],

			contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]

		})



});

