﻿$(document).ready(function() {


// Form validate
	$("#error, #ok").hide();
	if($('#contact-form').length > 0) {
		$('#contact-form').bind('submit', function(){
			var valid = true;
			$('.required').click(function(){
				$(this).removeClass('error-input');
			});
			$('.required').each(function(){
				if($(this).val()==''){
					$(this).addClass('error-input');
					 valid = false;
				}else{
					$(this).removeClass('error-input');
				}
			});
			if(!valid){
				$('#error').fadeIn();
				return false;
			}
		});
	}

	// ajax form

		if($('#contact-form').length > 0) {
			$.getScript('js/jquery.form.js', function(){
				$('#contact-form').ajaxForm(function(){
					if($('#error').is(':visible') == true) {
						$('#error').fadeOut(300);
						$('#ok').delay(300).fadeIn(300);
					} else {
						$('#ok').fadeIn(300);
					}

					$('#contact-form input, #contact-form textarea, #contact-form select, #contact-form button').attr('disabled', 'disabled');
				});
			});
		}





	if( $("html").hasClass('ie7') || $("html").hasClass('ie8') ) {

		$('h1').addClass('iefont');
		/*$('#vert ul li a').addClass('iefont');
		$('h2').addClass('iefont');
		$('h4').addClass('iefont');
		$('h5').addClass('iefont');
		$('h6').addClass('iefont');*/
	}

	var ua = $.browser;
	if(ua.mozilla) { $('h1').addClass('ff'); };

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


	// Focus border remove

			$("a").focus(function() {
				$(this).blur();
			});

	// 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();
						});
					}
				});
			}

			if($(".ask").exists()) {
				$(".ask").fancybox({
					'titlePosition'		: 'inside',
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'padding'			: '0',
					'onStart'			: function() {
						$('#contact-form #thanks').hide();
						$('#contact-form #form').show();
						$('#contact-form button').show();
						$('#contact-form input').val('');
						$('#contact-form textarea').val('');
					 }
				});
			}

			$('a.fancyclose').click(function(){
			   $.fancybox.close();
			});

	// Opacity

			$.fn.opacity = function() {
				$(this).hover(
				  function () {
					$(this).stop().fadeTo('fast',.8);
				  },
				  function () {
					$(this).stop().fadeTo('fast',1)
				  }
				);
			}


	// Menu Drop-Down II:

			// li.hit jest zawsze rozwiniete, reszta ukryta
			$('.lvl2').not('.hit .lvl2').hide();

			//rozwijanie odpowiedniego poziomu i zwijanie pozostaĹych
			$('#vert li').click(function(){
				$('li .lvl2').not(this).slideUp();
				$(this).find('.lvl2').slideToggle();
			});


	// _blank

			$(function() {
				$('a.blank').click( function() {
					window.open(this.href);
					return false;
				});
			});

	// Remove margin

			if($("#gallery").exists()) {
				var i = 3;
			    $('#gallery a').each(function() {
					var item = $('#gallery a:eq('+i+')');
	    				i=i+4;
				    	item.css({ marginRight: '0' });
			    });
		    }

	// Long site

			if($("aside").exists()) { } else {
				$("article").css({ width: "100%" });
			}




});

