﻿$(window).load(function () {
	// ------------------- initVar
	var menuSpeed = 700;
	// ------------------- menu fx
	var menu_img_loaded = {
		img_menu_1: false,
		img_menu_2: false,
		img_menu_3: false,
		img_menu_4: false
	}
	menu_fx();
	function menu_fx()
	{
		menu_fx_started = true;
		
		menu1 = {
			posX : parseInt($('.img_menu_1').position().left) + 3,
			posW : $('.img_menu_1').width() - 5
		};
		menu2 = {
			posX : parseInt($('.img_menu_2').position().left) + 3,
			posW : $('.img_menu_2').width() - 5
		};
		menu3 = {
			posX : parseInt($('.img_menu_3').position().left) + 3,
			posW : $('.img_menu_3').width() - 5
		};
		menu4 = {
			posX : parseInt($('.img_menu_4').position().left) + 3,
			posW : $('.img_menu_4').width() - 5
		};
		
		var $activeMenu = $('.menuActive .img_menu');
		if ($activeMenu.position())
		{
			var originMargin = parseInt($activeMenu.position().left) + 3;
			var originWidth = $activeMenu.width() - 5;
		}
		else
		{
			var originMargin = -20;
			var originWidth = 1;
		}
		
		$(".redPx").stop().animate({
			'margin-left' : originMargin,
			'width' : originWidth
		}, {
			queue : false,
			duration : menuSpeed
		});
		
		$(".b1").hover(function () {
			$(".redPx").stop().animate({
				'margin-left' : menu1.posX,
				'width' : menu1.posW
			}, {
				queue : false,
				duration : menuSpeed
			});
		}, function () {
			$(".redPx").stop().delay(1800).animate({
				'margin-left' : originMargin,
				'width' : originWidth
			}, {
				queue : false,
				duration : menuSpeed
			});
		});
		$(".b2").hover(function () {
			$(".redPx").stop().animate({
				'margin-left' : menu2.posX,
				'width' : menu2.posW
			}, {
				queue : false,
				duration : menuSpeed
			});
		}, function () {
			$(".redPx").stop().delay(1800).animate({
				'margin-left' : originMargin,
				'width' : originWidth
			}, {
				queue : false,
				duration : menuSpeed
			});
		});
		$(".b3").hover(function () {
			$(".redPx").stop().animate({
				'margin-left' : menu3.posX,
				'width' : menu3.posW
			}, {
				queue : false,
				duration : menuSpeed
			});
		}, function () {
			$(".redPx").stop().delay(1800).animate({
				'margin-left' : originMargin,
				'width' : originWidth
			}, {
				queue : false,
				duration : menuSpeed
			});
		});
		$(".b4").hover(function () {
			$(".redPx").stop().animate({
				'margin-left' : menu4.posX,
				'width' : menu4.posW
			}, {
				queue : false,
				duration : menuSpeed
			});
		}, function () {
			$(".redPx").stop().delay(1800).animate({
				'margin-left' : originMargin,
				'width' : originWidth
			}, {
				queue : false,
				duration : menuSpeed
			});
		});
	}
	
});

$(document).ready(function () {
	var lngSpeed = 300;
	
	// ------------------- lang select
	$(".langBtn").hover(function(){
		$(".langActive .langArrow").stop().animate({
			'top' : "-34px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(this).find(".langArrow").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".langActive .langOn").stop().fadeTo("slow", 0);
		$(this).find(".langOn").stop().fadeTo("slow", 1);
	}, function(){
		if (!$(this).hasClass('langActive'))
		{
			$(".langActive .langArrow").stop().animate({
				'top' : "0px"
			}, {
				queue : false,
				duration : lngSpeed
			});
			$(this).find(".langArrow").stop().animate({
				'top' : "-34px"
			}, {
				queue : false,
				duration : lngSpeed
			});
			$(".langActive .langOn").stop().fadeTo("slow", 1);
			$(this).find(".langOn").stop().fadeTo("slow", 0);
		}
	});
	
	// ------------------- lang select
	/*$(".langActive .langOn").fadeTo("slow", 1);
	
	$(".langActive .langArrow").animate({
		'top' : "35px"
	}, {
		queue : false,
		duration : lngSpeed
	});
	
	$(".lngBtn1").hover(function () {
		$(".redArrowLang1").stop().animate({
			'top' : "35px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang2").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang3").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
	}, function () {
		$(".redArrowLang1").stop().animate({
			'top' : "35px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang2").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang3").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
	});
	
	$(".lngBtn2").hover(function () {
		$(".redArrowLang1").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang2").stop().animate({
			'top' : "35px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang3").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".lng02On").stop().fadeTo("slow", 1);
		$(".lng01On").stop().fadeTo("slow", 0);
	}, function () {
		$(".redArrowLang1").stop().delay(1800).animate({
			'top' : "35px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang2").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang3").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".lng02On").stop().fadeTo("slow", 0);
		$(".lng01On").stop().fadeTo("slow", 1);
	});
	
	$(".lngBtn3").hover(function () {
		$(".redArrowLang1").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang2").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang3").stop().animate({
			'top' : "35px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".lng03On").stop().fadeTo("slow", 1);
		$(".lng01On").stop().fadeTo("slow", 0);
	}, function () {
		$(".redArrowLang1").stop().delay(1800).animate({
			'top' : "35px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang2").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".redArrowLang3").stop().animate({
			'top' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
		$(".lng03On").stop().fadeTo("slow", 0);
		$(".lng01On").stop().fadeTo("slow", 1);
	});*/
	
	// ------------------- wyszukiwarka
	$('.wyszukaj_input').focus(function () {
		$(".wyszukaj_txt").stop().fadeTo("fast", 0);
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue) {
			this.value = '';
		}
		if (this.value != this.defaultValue) {
			this.select();
		}
	});
	$('input[type="text"]').blur(function () {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == '') {
			this.value = (this.defaultValue ? this.defaultValue : '');
			$(".wyszukaj_txt").stop().fadeTo("slow", 1);
		}
	});
	
	$(".txtArrowSzukaj").css('left', 456);
	$(".wyszukiwarka").hover(function () {
		$(".txtArrowSzukaj").stop().animate({
			'left' : "446px"
		}, {
			queue : false,
			duration : lngSpeed
		});
	}, function () {
		$(".txtArrowSzukaj").stop().animate({
			'left' : "456px"
		}, {
			queue : false,
			duration : lngSpeed
		});
	});
	
	$('.txtArrowSzukaj, .txtSzukaj').click(function(e){
		var $valueField = $(this).parent('form').find('.wyszukaj_input');
		if ($.trim($valueField.val()) != '')
		{
			$(this).parent('form').submit();
		}
	});
	
	// ------------------- certyfikat fx
	$(".btn_certyfikat_arrow").css('left', 76);
	$(".btn_certyfikat").hover(function () {
		$(".btn_certyfikat_arrow").stop().animate({
			'left' : "88px"
		}, {
			queue : false,
			duration : lngSpeed
		});
	}, function () {
		$(".btn_certyfikat_arrow").stop().animate({
			'left' : "78px"
		}, {
			queue : false,
			duration : lngSpeed
		});
	});
	
	// ------------------- produkt fx
	$(".btn_zobacz_arrow").css('left', 76);
	$(".btn_zobacz").hover(function () {
		$(".btn_zobacz_arrow").stop().animate({
			'left' : "86px"
		}, {
			queue : false,
			duration : lngSpeed
		});
	}, function () {
		$(".btn_zobacz_arrow").stop().animate({
			'left' : "76px"
		}, {
			queue : false,
			duration : lngSpeed
		});
	});
	
	// ------------------- newsletter
	$('.news_input').focus(function () {
		$(".adres_mail").stop().fadeTo("fast", 0);
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue) {
			this.value = '';
		}
		if (this.value != this.defaultValue) {
			this.select();
		}
	});
	$('input[type="text"]').blur(function () {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == '') {
			this.value = (this.defaultValue ? this.defaultValue : '');
			$(".adres_mail").stop().fadeTo("slow", 1);
		}
	});
	
	$(".newsArrow").css('left', 0);
	$(".newsy").hover(function () {
		$(".newsArrow").stop().animate({
			'left' : "-10px"
		}, {
			queue : false,
			duration : lngSpeed
		});
	}, function () {
		$(".newsArrow").stop().animate({
			'left' : "0px"
		}, {
			queue : false,
			duration : lngSpeed
		});
	});
	
	$('.newsArrow, .txtSave').click(function(){
		$(this).parent('form').submit();
	});
	
	// ------------------- slideshow fx
	$('.slideshow').cycle({
		fx : 'fade'
	});	
	
	// ------------------- certyfikaty
	$("a[rel=galeriaAll]").fancybox({
		'transitionIn' : 'none',
		'transitionOut' : 'none',
		'titlePosition' : 'over',
		'overlayOpacity' : '.85',
		'overlayColor' : '#000',
		'titleFormat' : 'title'
	});
	// ------------------- wybrane produkty
	$(".scrollMod").jCarouselLite({
		visible:6,
	 	auto: 4000,
   		speed: 1000,
        btnNext: ".next",
        btnPrev: ".prev"
    });
	// ------------------- logotypy fx
	$('.logo_mod').cycle({
		fx : 'fade'
	});
	
	// menu
	$('.menu > ul > li > a').click(function(e){
		e.preventDefault();
		var $parentLI = $(this).parents('li');
		if ($parentLI.find('ul:visible').length)
		{
			$parentLI.find('ul:visible').slideUp();
		}
		else
		{
			$parentLI.find('ul').slideDown();
		}
	});
	
	$('.product_line a').click(function(e){
		e.preventDefault();
		$product_line = $(this).parents('.product_line');
		if ($(this).hasClass('product_active'))
		{
			$product_line.find('.product_data').slideUp();
			$(this).removeClass('product_active');
		}
		else
		{
			$(this).addClass('product_active');
			$product_line.find('.product_data').slideDown();
			$product_line.find('.product_error').hide();
			if (!$product_line.find('.product_container').is(':visible'))
			{
				var url = $(this).attr('href');
				url = url.replace('produkty\/produkt', 'produkty\/produkt_js');
				$product_line.find('.product_preloader').show();
				$.ajax({
					type: 'GET',
					url: url,
					dataType: 'html',
					success: function(response) {
						$product_line.find('.product_container').html(response).slideDown(function(){
							$product_line.find('.product_preloader').hide();
						});
						$("a[rel=galeriaAll]").fancybox({
							'transitionIn' : 'none',
							'transitionOut' : 'none',
							'titlePosition' : 'over',
							'overlayOpacity' : '.85',
							'overlayColor' : '#000',
							'titleFormat' : 'title'
						});
					},
					error: function() {
						var response = 'Pobieranie danych nie powiodło się, prosimy spróbować ponownie.';
						$product_line.find('.product_error').html(response).slideDown(function(){
							$product_line.find('.product_preloader').hide();
						});
					}
				});
			}
		}
	});
});

