function loadContent(fraza, id_kategorii, producent)
{
  	if(producent == "")
  	{  		delete_cookie('producent');  	}
  	if(window.XMLHttpRequest)
    	xmlHttp_lc = new XMLHttpRequest();
  	else if(window.ActiveXObject)
    	xmlHttp_lc = new ActiveXObject("Microsoft.XMLHTTP");

  	if(xmlHttp_lc.readyState == 4 || xmlHttp_lc.readyState == 0)
  	{
    	xmlHttp_lc.open("GET", "content/ajax_act.php?ajax_act=loadContent&fraza="+fraza+"&id_kategorii="+id_kategorii+"&producent="+producent, true);
		xmlHttp_lc.onreadystatechange = function()
		{
	  		if (xmlHttp_lc.readyState == 4)
	  		{
	    		if (xmlHttp_lc.status == 200)
	    		{
	 				document.getElementById('products_container').innerHTML = xmlHttp_lc.responseText;
					$("a.group").fancybox({
						'transitionIn'	:	'elastic',
						'transitionOut'	:	'elastic',
						'speedIn'		:	600,
						'speedOut'		:	200,
						'overlayShow'	:	false
					});

					$(".powieksz_strone").fancybox({

							'width'				: 1000,
							'height'			: 800,
							'autoScale'			: 1,
							'transitionIn'		: 'elastic',
							'transitionOut'		: 'elastic',
							'type'				: 'iframe'
					});
                }
  			}
  			else
  			{
  				document.getElementById('products_container').innerHTML = "<div id='ajax_loader'><img src='content/images/ajax-loader.gif'><br/><i>Szukam produktów...</i></div>";
  			}
		}

		xmlHttp_lc.send(null);
  	}
	else
  		setTimeout('loadContent(fraza, id_kategorii, producent)', 1000);
}

function parseURL()
{
  	var str =window.location.search;
  	if(parseURL.arguments.length == 1)
    	str = parseURL.arguments[0];
  	var arr = str.substring(1).split('&');
  	var key = '';
  	var val = '';
  	if(arr.length > 0)
  	{
	  	for(var part in arr)
	  	{
	    	key = arr[part].split('=')[0];
	    	val = unescape(arr[part].substring(key.length + 1));
	    	this[key] = val;
	  	}
  	}
}

function display_connector()
{	var _GET = new parseURL();
	if(_GET['s'] == 'sprzedaz')
	{		document.getElementById('con1').style.display = 'block';	}
	if(_GET['s'] == 'produkty')
	{
		document.getElementById('con2').style.display = 'block';
	}
	if(_GET['s'] == 'galeria')
	{
		document.getElementById('con3').style.display = 'block';
	}
	if(_GET['s'] == 'kontakt')
	{
		document.getElementById('con4').style.display = 'block';
	}}

function delete_cookie(name)
{
	var date = new Date();
	date.setTime(date.getTime()-(364*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
		{
			document.cookie = name+"="+c.substring(nameEQ.length,c.length)+expires+"; path=/";		}
	}}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setZindex()
{
  	for(var i = 1; i <= 4; i++)
  	{
  		document.getElementById('b'+i).style.zIndex = 10-i;
  		document.getElementById('b'+i).style.left = -15*i+'px';
  		if(document.getElementById('con'+i).style.display == 'block')
  		{
  			document.getElementById('con'+i).style.zIndex = 10-i;
  		}
  	}}

$(document).ready(function() {
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600,
		'speedOut'		:	200,
		'overlayShow'	:	false
	});

	$(".powieksz_strone").fancybox({

			'width'				: 950,
			'height'			: 800,
			'autoScale'			: 1,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'type'				: 'iframe'
	});
});

