$(document).ready(function(){

	$('.searchInput').example('szukaj');

	/**
	* MENU PRODUKTOWE (DRZEWKO)
	*/
	var isTreeChanging = false;
	$('.treeMenu li span').live('click', function(){
	
		if ( isTreeChanging ){
			return false;
		}
	
		if ( $(this).parent().hasClass('active') ){
			return false;
		}
		
		isTreeChanging = true;
		
		var treeAnimationSpeed = 500;
		
		$('.treeMenu li.active ul').css({'display':'block'}).slideUp( treeAnimationSpeed );
		
		$(this).parent().find('ul').css({'display':'none'}).slideDown( treeAnimationSpeed );
		
		setTimeout(function(){
			isTreeChanging = false;
		}, treeAnimationSpeed);
		
		$('.treeMenu li.root.active').removeClass('active');
		
		$(this).parent().addClass('active');
	
	});
	
	
	/**
	* ZAKLADKI PRODUKTU
	*/
	var productTabChanging = false;
	$('#productTabs li').live('click', function(){
	
		if ( productTabChanging ){
			return false;
		}
	
		if ( $(this).hasClass('active') ){
			return false;
		}
		
		$('#productTabs li.active').removeClass('active');
		
		$(this).addClass('active');
										
		var nextTab = $('#tabContents div.tab.'+$(this).attr('id'));
		
		var tabChangingSpeed = 500;
		
		$('#tabContents div.tab.active').fadeOut( tabChangingSpeed, function(){
		
			$(this).removeClass('active');
		
			nextTab.fadeIn( tabChangingSpeed );
			nextTab.addClass('active');
		
		});
	
	});


	
	/**
	* DRZEWKO SITEMAP
	*/
	if ( $('#sitemap').size() ){
		$('#sitemap li li').removeClass('closed');
		$("#sitemap").treeview({
			animated: 300
		});
	}

	
	/**
	* WYSYLANIE FORMULARZA
	*/
	$('.orderForm').bind('submit', function(){
	
		var isValid = true;
		
		$(this).find('.bad').removeClass('bad');
	
		$(this).find('input, textarea').each(function(){
		
			if ( 'submit' != $(this).attr('type') ){
		
				if ( '' == $(this).val() ){
					isValid = false;
					$(this).addClass('bad');
				}
			
			}
		
		});
		
		if ( !isValid ){
			return false;
		}
		
		var variables = {};
		
		$(this).find('input, textarea').each(function(){
			if ( 'submit' != $(this).attr('type') ){
				variables[ $(this).attr('name') ] = $(this).val();
			}
		});
						
		$.ajax({
			url: 'ajax/mail.php',
			data: variables,
			success: function( response ){
			
				$('.formResponse').css({
					'width' : $('.formHolder').width(),
					'height' : $('.formHolder').height() 
				});
				
				if ( 'ok' == response ){
					$('.formResponseOk').fadeIn(300);
					setTimeout( function(){
						$('.orderForm input[type=text], .orderForm textarea').val('');
						$('.formResponseOk').fadeOut(300);
					}, 4000 );
				} else {
					$('.formResponseError').fadeIn(300);
					setTimeout( function(){
						$('.formResponseError').fadeOut(300);
					}, 3000 );
				}
				
			}
		});		
		
		return false;
	
	});



	/**
	* DOCIAGANIE TLA
	*/
	if ( $('body').height() < $(window).height() ){
		$('body').height( $(window).height() );
	}


	if ($.browser.msie && $.browser.version.substr(0,1)==7) {
	
		$('a[href] *').live('click', function(){
			window.location = $(this).parents('a[href]').attr('href');
		});
		
		$('a[href]').hover(function() {
			$(this).css('cursor','pointer');
		}, function() {
			$(this).css('cursor','auto');
		});
	
	}











});
