$(document).ready(function()                        
{

// aktualnosci fancybox
	
	$(".news a").fancybox();


// w3c strict	
	$('a.target').attr('target', '_blank');
	
	if($('.overflowContent').length)
	{
		$('.overflowContent').jScrollPane({
			scrollbarOnLeft: true,
			scrollbarWidth: 5
		});
	}
	
	if($('.overflowProductDescription').length)
	{
		$('.overflowProductDescription').jScrollPane({
			scrollbarOnLeft: true,
			scrollbarWidth: 5
		});
	}
	
	$('#mapka').flash({
		src: 'public/flash/mapka.swf',
		width: 686,
		height: 459
	});

/* MENU */
	/*
	$('img.showArrow').mouseover(function(){
		var id = $(this).attr('alt');	
		$('#arrow_' + id).removeClass('indexTopMenuLeftOff').addClass('indexTopMenuLeftOn');
	});
	
	$('img.showArrow').mouseout(function(){
		var id = $(this).attr('alt');
		
		$('#arrow_' + id).removeClass('indexTopMenuLeftOn').addClass('indexTopMenuLeftOff');
	});
	*/
	$('div#arrow_zegarki.indexTopMenuLeftOff').attr('class', 'indexTopMenuLeftOn');
	$('img.showArrow').mouseenter(function(){
		$('div.indexTopMenu div.indexTopMenuLeftOn').attr('class', 'indexTopMenuLeftOff');
		var id = $(this).attr('alt');	
		$('#arrow_' + id).removeClass('indexTopMenuLeftOff').addClass('indexTopMenuLeftOn');
		
		$('div.active').removeClass('active').addClass('inactive').hide();
		
		//$('div.indexLeftContent div.active').removeClass('active').addClass('inactive').hide();
		$('div#index-' + id + '-image').removeClass('inactive').addClass('active').hide().fadeIn('slow');
		
		//$('div.indexRightContent div.active').removeClass('active').addClass('inactive');		
		$('div#index-' + id).removeClass('inactive').addClass('active').hide().fadeIn('slow', function(){$('div.indexProductBox.inactive').hide();});
		
	});
	
	$('.showBottomArrow').mouseout(function(){
		var id = $(this).attr('rel');
		
		$('#bottomArrow_' + id).removeClass('bottomMenuArrowOn').addClass('bottomMenuArrowOff');
	});
	
	$('.floatingBoxClose').click(function(){
		$('.floatingBox').fadeOut();
	});
	
	$('.showFloatingBox').click(function(){
		$('.floatingBox').hide();
		var id = $(this).attr('rel');
		$('#' + id).fadeIn();
		return false;
	});
	
	$('.bottomLogosContainer').mousemove(function(e){
		var ulPadding = 15;
		var divWidth = $(this).width();
		
		$(this).css({overflow: 'hidden'});
		var lastLi = $('.bottomLogosUl').find('li:last-child');
		
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
		var left = (e.pageX - $(this).offset().left) * (ulWidth-divWidth) / divWidth;
		$(this).scrollLeft(left);
	});
	
	$('.inputFocus').focus(function(){
		var id = $(this).attr('id');
		var txt = $('#' + id + 'Hidden').val();
		
		if($(this).val() == txt) $(this).val('');
	});
	
	$('.inputFocus').blur(function(){
		var id = $(this).attr('id');
		var txt = $('#' + id + 'Hidden').val();
		
		if($(this).val() == '') $(this).val(txt);
	});
	
	$('.jsFormularz').click(function(){
		var id = $(this).attr('id');
		var data = '';
		var checkRequired = 0;
		var emailpat = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		
		var req2 = 0;
		var req3 = 0;
		
		$('#' + id + 'Maska').fadeIn(500, function(){
			
			$('#' + id + 'Form input[type="text"]').each(function(){
				
				if($(this).hasClass('email'))
				{
					if(!emailpat.test($(this).val()))
					{
						checkRequired = 1; 
						$(this).css('border-color', '#f00');
					}
						
					else $(this).css('border-color', '#333332');
				}
				
				if($(this).hasClass('required'))
				{
					if($(this).val() == '')
					{
						checkRequired = 1; 
						$(this).css('border-color', '#f00');
					}
					else	$(this).css('border-color', '#333332');
				}
				
				if($(this).hasClass('required2'))
				{
					req3 = 1;
					if($(this).val() != '') { req2 = 1; $(this).css('border-color', '#333332'); }
				}
			
				if(data) data += '&' + $(this).attr('name') + '=' + $(this).val();
				else data = $(this).attr('name') + '=' + $(this).val();
			});
			
			if(req2 == 0 && req3) {
				checkRequired = 1;
				$('#' + id + 'Info').html('Proszę podać adres email lub numer telefonu');
			}
			
			$('#' + id + 'Form textarea').each(function(){
				
				if($(this).hasClass('required'))
				{
					if($(this).val() == '')
					{
						checkRequired = 1; 
						$(this).css('border-color', '#f00');
					}
					else $(this).css('border-color', '#333332');
				}
				
				if(data) data += '&' + $(this).attr('name') + '=' + $(this).val();
				else data = $(this).attr('name') + '=' + $(this).val();
			});
			
			if(checkRequired == 1)
			{
				$('#' + id + 'Maska').fadeOut(500);
				return false;
			}
			
			data += '&tototo='+ $('input[name="tototo"]').val();
			
			$.ajax({
				type: "POST",
				url: 'index.php?c=email&m=' + id,
				data: data,
				cache: true,
				success: function(msg)
				{
					$('#' + id + 'Info').html(msg);
					$('#' + id + 'Maska').fadeOut(500);
					if(msg == 'E-mail z zapytaniem został wysłany') {
						$('.formLeft').hide();
						$('.formRight').hide();
					}
				}
			 });
		});
	});
	

	
	
	
	
	/*
	$('.subCategory, .innerCategory').mouseover(function(){
		var data = $(this).attr('id').split('_');
		var id = parseInt(data[1]);
		$.ajax({
			type: "POST",
			url: 'index.php?c=categories&m=getByIdJs&p=' + id,
			cache: false,
			success: function(msg)      
			{
				$('.debug').html(Math.random());
				var div = '';
				var items = msg.split('[8]');
				for(var i = 0; i < items.length - 1; i++)
				{
					var itemsValue = items[i].split('|');
					div += '<div class="subCategory innerCategory" id="sub_' + itemsValue[0] + '">' + itemsValue[1] + '</div>';
					$('.subCategoryOptions').html(div);
					//alert(id);
				}
				$('.subCategoryOptions').appendTo('#sub_' + id);
			}
		});

		
	});
	*/

});


