// JavaScript Document

$(document).ready(function(){
						   
	/*grayscale($('img'));*/
	
	if ( $.browser.opera ) {
		/*Cufon.replace('h1, h2, h3, .d1,.topLinkBox a, .butLinkBox a, .wiecej a, .topH, .prod .nazwa, .logoS, .miniInfo, .cenaD, .LboxImg .info', {
			//textShadow: '0px 1px 2px #FFF',
		hover: {
			//textShadow: '0px 1px 4px #6F0000'
			}
		});*/
		
		$(".hints .miniProd .opisM").css({height: 58+"px"});
		$(".infoB").css({height: 136+"px"});
	}
	
	
	$(".navigation #menu li").hover(
		function(){
		//$(this).animate({ 'padding-left': "35" }, 200);
		},
		function(){
		//$(this).animate({ 'padding-left': "20" }, 50);
	});
	
	$(".navigation h1").hover(
		function(){
			$(this).fadeTo(10, 0.4, function() {
			$(this).fadeTo(300, 1);
			});
		},
		function(){
		$(this).fadeTo(10, 0.4, function() {
			$(this).fadeTo(300, 1);
			});
	});
	
	
	$(".topLinkBox a[rel='login']").colorbox({href:"http://www.zielinscy.pl/login.php", iframe:true, innerWidth:505, innerHeight:364, onComplete:function(){
		if ( $.browser.opera ) {
			
		}
		
		}, onClosed:function(){ location.reload(true); }	
	});
	
	$(".butNavi a[rel='loginB']").colorbox({href:"http://www.zielinscy.pl/login.php", iframe:true, innerWidth:505, innerHeight:364, onComplete:function(){
		if ( $.browser.opera ) {
			
		}}, onClosed:function(){ location.reload(true); }	
	});
	
	$("a[rel='lightbox']").colorbox();
	
	$(function(){
	positionFooter(); 
		function positionFooter(){
			if($(document.body).height() < $(window).height()){
				$(".footer").css({height: 110+"px"});
			} else {
				$(".footer").css({height: ($(window).height()-$(".main").height()-1)+"px"});
			}
		}
	
	$(window)
		.scroll(positionFooter)
		.resize(positionFooter)
		.load(positionFooter)
	});
	
	$('.koszBoxFull .koszItemBox').last().css('background-image', 'none');
	$('.selectList li').last().css('border-bottom-color', 'transparent');
	//jQuery(".koszBoxFull .koszItemBox").addClass("lastItem");
	
	
	$('a.BackToTop').click(function(){
     $('html, body').animate({scrollTop: '0px'}, 'slow');
     return false;
	});
	

	
	$('#transport #dostSelect li a').click(function() {
		var name = $(this).text();
		var price = $(this).attr('rel');
		$('#dostSelect .selected').text(name);
    	$('#dostSelect .selectList').hide();
		
		$('#transport .cena').text(price + ' zl');
		
		var formSesja = $("#sesjaKosz").val();
		$.post("http://www.zielinscy.pl/ajaxItemUpdate.php", {zamowienie: formSesja, TransCena: price, transport: 1, TransText: name}, function(data){
			//$('.log').text(data);
			location.reload();
		});
		
		
		return false;
	});
	
	$("#dostSelect .selectList").hover(
		function(){
		//$('.selectList').slideDown();
		},
		function(){
		$(this).hide();
	});
	
	$('#dostSelect .selected').click(function() {
        //var value = $(this).attr('value');
		//var title = $('#tab' + id).attr('title');
		//$('.tabHider').hide();
		//$('#infoTab').text(' - ' + title);
     	$('#dostSelect .selectList').show();
        // alert(id);
     	return false;
   });
	
//	$('#koszClear').click(function() {
//		$('.koszBoxFull input:checkbox:checked').parents('.koszItemBox').hide('.koszItemBox');
//        $('.koszBoxFull input:checkbox:checked').parents('.koszItemBox').remove('.koszItemBox');
//		$('.koszBoxFull .koszItemBox').last().css('background-image', 'none');
//     	return false;
//   });

	$("#koszCountBut").hide();
	
	
	
	$('a#koszCount').click(function() {
		location.reload();
		return false;
	})
	
	$('a#koszClear').click(function() {
		$("#action").val('1');
		$("#koszyk").submit();
		return false;
	});
	
	
	
	$(".ImptIlosc").change(function() {
		$("#koszCountBut").show();
		
		var formIlosc = $(this).val();
		var formTowar = $(this).attr('title');
		var formSesja = $("#sesjaKosz").val();
		
		//$('.log').text(formIlosc + "|" + formSesja + "|" + formTowar);
		
		$.post("http://www.zielinscy.pl/ajaxItemUpdate.php", {ilosc: formIlosc, zamowienie: formSesja, towar: formTowar, update: 1}, function(data){
			//$('.log').text(data);
		});
		
	});
	
	$('.ImptIlosc').keyup(function(e) {
		if(e.which==13) return false;
		c = $(this).val().replace( /[A-Za-z\s]/g ,'1');
		$(this).val(c);
		//$(this).val(1);
		
		$("#koszCountBut").show();
	});
	
	$('.produkty .prodBox').click(function() {
		var itemID = $(this).attr('itemref');								   
		//window.location = "index.php?pid=produkt&id="+itemID;								   
	});
	
	//SKLEP
	
	$('.wybierz label input').click(function() {
	//$('.wybierz label input').attr('checked')(
	//	function() {
			$('.log').append("<strong>Hello</strong>");
			
	//	}
	//);
	});
	
	$("input[name='dostWybor']").click(function() {
			var opcja = $(this).val();
			
			if (opcja == 1){
				$("input[type='text']").attr("readonly", true);
				$("input[name='imie']").val($("input[name='tmp_imie']").val());
				$("input[name='nazwisko']").val($("input[name='tmp_nazwisko']").val());
				$("input[name='ulica']").val($("input[name='tmp_ulica']").val());
				$("input[name='kod']").val($("input[name='tmp_kod']").val());
				$("input[name='miasto']").val($("input[name='tmp_miasto']").val());
				$("input[name='telefon']").val($("input[name='tmp_telefon']").val());
				$("input[name='firma']").val($("input[name='tmp_firma']").val());
				$("input[name='tel1']").val($("input[name='tmp_tel1']").val());
				$("input[name='tel2']").val($("input[name='tmp_tel2']").val());
				$("input[name='fax']").val($("input[name='tmp_fax']").val());
				$("input[name='nip']").val($("input[name='tmp_nip']").val());
				$("input[name='regon']").val($("input[name='tmp_regon']").val());
				
				$.post("http://www.zielinscy.pl/ajaxItemUpdate.php", $("#dostawaForm").serialize(), function(data){});
				$('#zestButBox').show();
				
			} else {
				$(".formDivBox label input[type='text']").removeAttr("readonly");
				$(".formDivBox label input[type='text']").val('');
				$('#zestButBox').hide();
			}
			
			
			
			
	});
	
	$("#dostawaForm input[type='text']").change(function() {
		var inputs = $('input.required'), empty = false;
		// can also use :input but it will grab textarea/select elements and you need to check for those..
		
		inputs.each(function() {
			if ( $(this).val() == '' ) {
				empty = true;
				return;
			}
		});
		
		if ( empty ) {
			$('#zestButBox').hide(); // or true I believe.
		} else {
			$('#zestButBox').show();
		}
	});
	
	
	
	//SKLEP KONIEC
	
	$('a#contactFormSend').click(function() {
		$("#kontaktForm").hide();
		$('.content .loader').show();
		$('.kontaktFormlog').text('');
		$('.kontaktFormlog').hide();
		$(".footer").css({height: ($(window).height()-$(".main").height()-1)+"px"});

		$.post("http://www.zielinscy.pl/ajaxContactForm.php", $("#kontaktForm").serialize(), function(data){
			$('.content .loader').hide();
			if (data == 'ok'){
				$('.emailSendBox').show();
				$('.kontaktFormlog').text('');
				$('.kontaktFormlog').hide();
				$("#kontaktForm").hide();
				$(".footer").css({height: ($(window).height()-$(".main").height()-1)+"px"});
			} else {
				$('.kontaktFormlog').text(data);
				$('.kontaktFormlog').show();
				$("#kontaktForm").show();
				$(".footer").css({height: 110+"px"});
			}
			
			
			
			//location.reload();
		});
		
		return false;
	});
	
	$('a#regFormSend').click(function() {
		$("#registerForm").hide();
		$('.content .loader').show();
		$('.kontaktFormlog').text('');
		$('.kontaktFormlog').hide();
		$(".footer").css({height: ($(window).height()-$(".main").height()-1)+"px"});

		$.post("http://www.zielinscy.pl/ajaxRegForm.php", $("#registerForm").serialize(), function(data){
			$('.content .loader').hide();
			if (data == 'ok'){
				$('.emailSendBox').show();
				$('.kontaktFormlog').text('');
				$('.kontaktFormlog').hide();
				$("#registerForm").hide();
				$('.RegSendBox').show();
				$(".footer").css({height: ($(window).height()-$(".main").height()-1)+"px"});
			} else {
				$('.kontaktFormlog').text(data);
				$('.kontaktFormlog').show();
				$("#registerForm").show();
				$(".footer").css({height: 110+"px"});
			}
			
			
			//location.reload();
		});
		
		return false;
	});
	
	$('a#applicationFormSend').click(function() {
		$("#applicationForm").hide();
		$('.content .loader').show();
		$('.appFormlog').text('');
		$('.appFormlog').hide();
		//$(".footer").css({height: ($(window).height()-$(".main").height()-1)+"px"});

		$.post("http://www.zielinscy.pl/ajaxApplicationForm.php", $("#applicationForm").serialize(), function(data){
			$('.content .loader').hide();
			if (data == 'ok'){
				$('.appFormBox p strong').text('Aplikacja została wysłana. Dziękujemy.');
				$('.appFormlog').text('');
				$('.appFormlog').hide();
				$("#applicationForm").hide();
				$('.appFormlog').html(data);
			} else {
				$('.appFormlog').html(data);
				$('.appFormlog').show();
				$("#applicationForm").show();
				//$(".footer").css({height: 110+"px"});
			}
			
			
			
			
			//location.reload();
		});
		
		return false;
	});
	
if ($('#sendCV').length != 0){	
var cvButton = $('#sendCV'), interval;
new AjaxUpload(cvButton,{
		action: 'http://www.zielinscy.pl/cms/updNew.php?picType=cv&picNr=1',
		onSubmit : function(file, ext){
			$('#sendProgress1').text('Dodawanie CV...');
			$('#sendProgress1').show();
			this.disable();
		},
		onComplete: function(file, response){
			$('#sendProgress1').text(response);
			var htmlStr = response;
			$('#pliczek_1').val(response);
			this.enable();						
		}
});
}
	
	
	$('a#zestBut').click(function() {
		$(".koszBoxFull").hide();
		$('.RegSendBox').hide();
		$('.content .loader').show();
		$('.kontaktFormlog').text('');
		$('.kontaktFormlog').hide();
		//$('.content .RegSendBox').show();
		$(".footer").css({height: ($(window).height()-$(".main").height()-1)+"px"});

		$.post("http://www.zielinscy.pl/ajaxItemUpdate.php", $("#dostawaForm").serialize(), function(data){
			$('.content .loader').hide();
			//$('.Formlog').text(data);
			if (data == 'ok'){
				$('#RegSendBoxOK').show();
				//$('.RegSendBox h2').text('DANE ZOSTALY UAKTUALNIONE. PRZEKIEROWANIE...');
				setTimeout(function() {
					//$('.RegSendBox').hide();
					//$(".koszBoxFull").show();
					//$(".footer").css({height: ($(window).height()-$(".main").height()-1)+"px"});
					
					window.location.replace($("input[name='lnk']").val());
					
				}, 2000);
				
				//
				//$('.kontaktFormlog').hide();
				//$("#registerForm").hide();
				
				
			} else {
				$('#RegSendBoxERR').show();
				setTimeout(function() {
					$('#RegSendBoxERR').hide();
					$('.Formlog').text(data);
					$('.kontaktFormlog').text(data);
					$('.kontaktFormlog').show();
					$(".koszBoxFull").show();
					$(".footer").css({height: 110+"px"});
				}, 2000);
				
			}
			
			
			
			//location.reload();
		});
		
		return false;
	});
	
	$('.activateBox .countdown').countDown({
		startNumber: 20,
		callBack: function(me) {
			$(me).text('0').css('color','red');
			window.location.replace("http://www.zielinscy.pl/");
		}
	});
	
	$('#zamowBut').click(function() {
		$(".koszBoxFull").hide();
		$('.content .loader').show();
		$('.kontaktFormlog').text('');
		$('.kontaktFormlog').hide();
		//$('.content .RegSendBox').show();
		$(".footer").css({height: ($(window).height()-$(".main").height()-1)+"px"});

		$.post("http://www.zielinscy.pl/ajaxZamowienie.php", { MM_insert: "zamowienieForm" }, function(data){
			$('.content .loader').hide();
			$('.Formlog').text(data);
			if (data == 'ok'){
				$('.RegSendBox').show();
				//$('.kontaktFormlog').text('');
				//$('.kontaktFormlog').hide();
				//$("#registerForm").hide();
				$(".footer").css({height: ($(window).height()-$(".main").height()-1)+"px"});
			} else {
				//$('.kontaktFormlog').text(data);
				//$('.kontaktFormlog').show();
				//$("#registerForm").show();
				$(".footer").css({height: 110+"px"});
			}
			
			
			
			//location.reload();
		});
		
		return false;
	});
	
//	$('.produkty .prodBox').hide();
//	$('.produkty .prodBox').hide().each(function(index){
//		var $li = $(this);
//
//			setTimeout(function() {
//				$li.fadeTo("slow", 0.8);
//			}, index * 200);
//	});
//	
//	$(".produkty .prodBox").hover(
//	  function () {
//		$(this).fadeTo("fast", 1);
//	  },
//	  function () {
//		$(this).fadeTo("fast", 0.8);
//	  }
//	);

	$('.pointerek').click(function() {
		var myLink = $(this).attr('itemref');
		window.location.href='http://www.zielinscy.pl/oferta/produkt/'+myLink+'.html';
		
		return false;
	});
	
	$(".prodOpisBoxFixed div").removeClass('d1');
	$(".prodOpisBoxFixed div").removeClass('d2');
	$(".prodOpisBoxFixed div:even").addClass('d1');
	$(".prodOpisBoxFixed div:odd").addClass('d2');
	
	/*	if ($('.growlUI').length != 0){
		$.blockUI({ 
            message: $('div.growlUI'), 
            fadeIn: 700, 
            fadeOut: 700, 
            timeout: 20000, 
            showOverlay: true, 
            centerY: true, 
			centerX: true,
            css: { 
                width: '550px',  
				top:  ($(window).height() - 750) /2 + 'px', 
                left: ($(window).width() - 550) /2 + 'px',
                right: '10px', 
                border: 'none', 
                padding: '4px',  
                '-webkit-border-radius': '5px', 
                '-moz-border-radius': '5px'
            } 
        });
		
		$('.blockOverlay').attr('title','Kliknij by zamknąć').click($.unblockUI);
		}*/
	
});	
