google.load("jquery", "1.4.2");
google.setOnLoadCallback(function() {
	
    /* plugin jquery for wait action*/
    $.fn.wait = function(time, type) {
        
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
        });
    };

	$('#wynik_dzialania').wait(3000).slideUp();

	$('#submit_form').click(function(){
		document.szukaj.submit();
	})

	$('#wyslij_sub').click(function(e){
		e.preventDefault();
		if ( !isValidEmail($('#sub_field').val()) ) {
			alert('Nieprawidłowy adres e-mail');
		}
		else{
			document.subskrybcja.submit();
		}
	});

	$('#duzy_obrazek').click(function(){
		$('#dark,#duzy_obraze2').remove();
		$('body').prepend('<div id="dark"></div><div id="duzy_obraze2" style="display:none"></div>');
		$('#dark').css({'left':'0px','top':'0px','opacity':'0.6','background':'#000','width':'100%','height':$(document).height()+'px','z-index':'10','position':'absolute'});
		$('#duzy_obraze2').css({'left':(($(document).width()/2)-410)+'px','top':($(document).scrollTop()+($(window).height()/2-310))+'px','width':'800px','height':'630px','border':'3px solid #a5a5a5','z-index':'11','position':'absolute','background':'#fff','padding':'10px'})	
		$('#duzy_obraze2').html('<img src="'+$(this).attr('src')+'" alt="" style="cursor:pointer;border:1px solid #5a5a5a" onclick="close_img()" /> <div style="text-align:right;padding:10px 0 0 0"><a href="javascript:close_img()"><b>Zamknij</b></a></div>');
		$('#duzy_obraze2').fadeIn(100);
	});

});

function close_img(){

	$('#duzy_obraze2').fadeOut(100,function(){
		$('#dark,#duzy_obraze2').remove();
	})
	
}

function isValidEmail(str) {  
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(str);
}

function big_img(id){
	$('#duzy_obrazek2').attr('src',id);
	if($('#duzy_obrazek2').width()!=800){
		$('#spiner').css({'display':'block'});
		$('#duzy_obrazek2').load(function(){
			$('#duzy_obrazek').attr('src',id);
			$('#spiner').css({'display':'none'});
		});		
	}
	else{
		$('#duzy_obrazek').attr('src',id);
	}				
}

