function popImage(url,windowTitle,windowName,closeOnClick,width,height,t){
	closeOnClick=true;
	if(!url)return
	function readSize(){if(t.complete)showPopup(t.width,t.height);else setTimeout(readSize,1e2)}
	function showPopup(w,h){with(window.open('',windowName||'','width='+(width||w)+',height='+(height||h)).document){open();write('<html><head><title>'+(windowTitle||'')+'</title></head><body onBlur="self.close()" style="margin:0;padding:0"><img src="'+url+'" style="display:block'+(closeOnClick?';cursor: pointer" onclick="self.close()" title="Zamknij okno"':'"')+'></body></html>');close()}}
	if(!width||!height)t=new Image(),t.src=url,readSize()
	else showPopup(width,height)
}

function popup(mylink) 
{
	if (!window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, 'Popup', 'width=636,height=400,scrollbars=yes');
	return false;
}

/*
Form2Pop Script- By Peter Bailey (http://www.peterbailey.net)
Featured on JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
*/

function createTarget(sTarget,sWhat,sOptions){
	window.open(sWhat, sTarget, sOptions);
	return false;
}

function clearInput(hInputName)
{
	if($("input[@name="+hInputName+"]").val() == 'Wypełnij pole!'){
		$("input[@name="+hInputName+"]").val('');
		$("input[@name="+hInputName+"]").css("color","#A8A8A8");
	}
}

function clearTextarea(hTextareaName)
{
	if($("textarea[@name="+hTextareaName+"]").val() == 'Wypełnij pole!'){
		$("textarea[@name="+hTextareaName+"]").val('');
		$("textarea[@name="+hTextareaName+"]").css("color","#A8A8A8");
	}
}

function initializeFancyBoxImages()
{
	jQuery("a.fancyBoxImage").fancybox({
		'zoomSpeedIn':	500,
		'zoomSpeedOut':	300,
		'overlayShow':	true,
		'hideOnContentClick': true
	});
}

function initializeInputFocusEffect(sInputName, sText)
{
	jQuery("input[name='"+sInputName+"']").attr('value', sText);
	jQuery("input[name='"+sInputName+"']").focus(function()
		{
			jQuery("input[name='"+sInputName+"']").attr('value','');
		}
	)
	jQuery("input[name='"+sInputName+"']").blur(function()
		{
			if (!jQuery("input[name='"+sInputName+"']").attr('value')) {
				jQuery("input[name='"+sInputName+"']").attr('value', sText);
			}
		}
	)
}

var iRandomRealizationInterval = null;

function setAjaxRandomUserPicture(seconds)
{
	iRandomUserPictureInterval = setInterval("changeUserGalleryPicture();", seconds * 1000);
	jQuery(".randomPictureImage").click(
		function() {
			changeUserGalleryPicture();
		}
	);
}



function changeUserGalleryPicture()
{
	var divPicture = jQuery('#ajaxUsersGallery');
	jQuery.ajax({
		method: "get",url: "ajax/getRandomUserPicture.php",data: "iRelativeNewsId=" + iRelativeNewsId + "&random=" + Math.random(),
		beforeSend: function(){
			if (iRandomUserPictureInterval) {
				clearInterval(iRandomUserPictureInterval);
			}
		}, 
		success: function(html) { //so, if data is retrieved, store it in html
			jQuery(divPicture).hide().html(html).fadeIn(1000);
			setAjaxRandomUserPicture(10);
		}
	}); 
}

function showNewRealizationImage(html)
{
	jQuery("#randomRealizationPicture").html(html.toString()); 
	jQuery("#randomRealizationPicture").fadeIn(100);
}

function setRoadHeight()
{
	
	jQuery(window).resize(
		function() {
			setFooterHeight();
		}
	)
}

function setFooterHeight()
{
	var iWraperHeight = jQuery("#wraperAll").height();
	var iBodyHeight = jQuery(window).height();
	var iFooterMargin = parseInt(jQuery("#wraperAll").css("padding-bottom"));
	var iFlashHeight = iBodyHeight - iWraperHeight - iFooterMargin;
	if (iFlashHeight < 209) {
		iFlashHeight = 209;
	}
	jQuery("#footerBackground").css("height", iFlashHeight);
}

function checkSearchQuery()
{
	jQuery("#searchForm").submit(
		function() {
			if (jQuery.trim(jQuery("#searchQuery").attr("value")).length == 0) {
				return false;
			} else {
				jQuery("#searchQuery").attr("value", jQuery.trim(jQuery("#searchQuery").attr("value")));
			}
		}
	)
}

function submitForm(sFormName, bDontHideButton){
	//showHideFixedPreloader();
	//	jQuery('#' + sFormName).submit();
	document.getElementById(sFormName).submit();
	if (!bDontHideButton) {
		jQuery('#' + sFormName + 'Submit').hide();
	}		
}

function v()
{
	void(null);
}

function showHidePreloader(bShow) {
	if (bShow) {
		jQuery("#ajaxPreloader").fadeIn();
	} else {
		jQuery("#ajaxPreloader").fadeOut();
	}
}

function setCommentsForm()
{
	jQuery("#goCoomentsForm").click(
		function() {
			jQuery(".commentForm").show(100);
			return false;
		}
	);
}

function showBigImage(sImage)
{
	//alert("aaaaa: "+sImage);
	if (sImage != 'undefined') {
		var sLink = '<a href="' + sImage + '" style="display: none;" id="hiddenLink" class="fancyBoxImage"></a>';
		//alert(sLink);
		
		oLink = jQuery("body").append(sLink);
		initializeFancyBoxImages();
		
		jQuery("#hiddenLink").trigger("click");
		jQuery("#hiddenLink").remove();
	}
	
}

function setNewsMargin()
{
	jQuery(".newsAllMargin").height(jQuery(".newsAll").height());
}


/*** JQUERY ***/
jQuery.noConflict();

jQuery(function() {
    jQuery('#dateFromInput').datepicker({
    	duration: '',
        showTime: false,
        constrainInput: true,
		time24: true,
		dateFormat: 'yy-mm-dd',
		stepMinutes: 30
     });
	 jQuery('#dateToInput').datepicker({
    	duration: '',
        showTime: false,
        constrainInput: true,
		stepMinutes: 30,
		dateFormat: 'yy-mm-dd',
		time24: false
     });
	 
	 
});


jQuery(document).ready(function() {
//	externalLinks();
	/*** FANCY BOX ***/
	initializeFancyBoxImages();
	setAjaxRandomUserPicture(1);
	setCommentsForm();
	externalLinks();	
	
	setInterval("setNewsMargin();", 100);
		
});


