var PullDownMenu = function () {
	var $ = jQuery;
	return {
		init: function() {
			var instance = this;

			instance.handleSearchForm();
			instance.dropDownMenu();
			instance.handleLastChild();
		},

		dropDownMenu: function() {
			$(".parent-nav-item").hoverIntent(
				{
					interval: 50,
					timeout: 100,
					over: function () {
						var instance = $(this);
						var child = $('.child-menu', this);

						instance.addClass("pull_down_menu");
						child.slideDown(100);
					},

					out: function () {
						var instance = $(this);
						var child = $('.child-menu', this);

						child.slideUp(150);
						instance.removeClass("pull_down_menu");
					}
				}
			);
		},

		handleSearchForm: function() {
			var searchForm = $('#banner .search');

			if (searchForm.length) {
				var searchInput = searchForm.find('input[@type=image]');
				var searchLink = $('<a class="search-input-link" href="javascript:;"></a>');

				searchLink.click(
					function() {
						$(this).parents('form')[0].submit();
					}
				);

				searchInput.hide();
				searchInput.before(searchLink);
			}
		},

		handleLastChild: function () {
			var instance = this;

			$('#footer ul li:last').addClass('last-child');
		}
	};
}();


jQuery(document).ready(

	/*
	This function gets loaded when all the HTML, not including the portlets, is
	loaded.
	*/
	
	function() {
		PullDownMenu.init();
	
	    jQuery("a.email").each(function(t){ 
			var t = jQuery(this);
	        //alert(jQuery(this));
	        var p = t.text().split(" ");
	        var junior =  p[0] + "@" + p[2];
	        //alert(junior);
	        this.href = "mailto:" + junior + "?subject=" +p.slice(4).join(" ");
	    }); 
			 
		jQuery(".ahrefMenu a").bind("click", function(t) { return false; });
		
		//Dla 'Formularza kontaktowego'
		jQuery(".ctrl-holder input:radio").addClass("inputRadioType");
		jQuery(".ctrl-holder input:checkbox").addClass("inputRadioType");
		
		//Dla 'Menu'
		jQuery(".nav-menu-style-1 ul li.open ul li:last").css("border-width","0px");
	}
);

Liferay.Portlet.ready(

	/*
	This function gets loaded after each and every portlet on the page.

	portletId: the current portlet's id
	jQueryObj: the jQuery wrapped object of the current portlet
	*/

	function(portletId, jQueryObj) {
	}
);

jQuery(document).last(

	/*
	This function gets loaded when everything, including the portlets, is on
	the page.
	*/

	function() {
		var x = window.innerHeight - 274;
		jQuery("#contentbg").css("min-height", "" + x + "px");
		
	}
);
