	//preload
	
	var url = document.URL;

	if(document.location.hash){
		url =url.substring(0, url.lastIndexOf("#"));
	}

	if(url.substring(0,7) == 'http://'){
		url = url.substring(8+document.domain.length);
	}else{
		url = url.substring(1+document.domain.length);
	}
	
	if(url.length > 0){
		
		if(document.location.hash){
			location.href = "/"+document.location.hash;
		}else{
			location.href = "/#"+url;
		}
	}else{

		if(document.location.hash){
			location.href = "/"+document.location.hash;
		}else{
			location.href = "/#index";
		}
		
	}




/*

//var $j = jQuery.noConflict();
//var $ = {};
// PageLoad function
// This function is called when:
// 1. after calling $.historyInit();
// 2. after calling $.historyLoad();
// 3. after pushing "Go Back" button of a browser
function pageload(hash) {
	// hash doesn't contain the first # character.
	if(hash) {
		// restore ajax loaded state only if it isnt true anchor!!
		if(!$("a[@href='/#"+hash+"']").attr('innerHTML')){
			//alert(hash);
			$("#ajaxloader").load(hash + "");				
		}
		//alert($("a[@href='/#"+hash+"']").attr('innerHTML'));
		
	} else {
		// start page
		//$("#chapter").empty();
	}
}
*/

$(document).ready(function(){
});


	function preloadImages() {
		for(var i = 0; i<arguments.length; i++)
		{
			jQuery("<img>").attr("src", arguments[i]);
		}
	}

// PageLoad function
	// This function is called when:
	// 1. after calling $.historyInit();
	// 2. after calling $.historyLoad();
	// 3. after pushing "Go Back" button of a browser
	function pageload(hash) {
		// hash doesn't contain the first # character.
		if(hash) {
			// restore ajax loaded state
			$("#ajaxloader").load(hash);
		} else {
			// start page
			$("#ajaxloader").empty();
		}
	}
	
	$(document).ready(function(){
		// Initialize history plugin.
		// The callback is called at once by present location.hash. 
		$.historyInit(pageload);
		
		// set onlick event for buttons
		$("a[rel='history']").click(function(){
			// 
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			// moves to a new page. 
			// pageload is called at once. 
			$.historyLoad(hash);
			return false;
		});
	});

function rebuildLinks(){
	/*
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

	try {
		var pageTracker = _gat._getTracker("UA-5407553-5");
		pageTracker._trackPageview();
	} catch(err) {}
	*/
	$("a[rel='history']").unbind('click');
	
	$("a[rel='history']").click(function(event){
	  var hash = this.href;
	  if(hash.substring(0,7) == 'http://'){
			hash = hash.substring(8+document.domain.length);
		}else{
			hash = hash.substring(1+document.domain.length);
		}
		hash = hash.replace(/^.*#/, '');

		//var link_title = $(this).html();

		$.historyLoad(hash);
		
		$(document).pngFix(); 
		return false;
	});

	
}


function is_valid_email (email)
{
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}

function performSearch(){
	
	$.ajax({
		type: "GET",
		url: "/index/search?query="+$('#textfield').val(),
		cache: false,
		  success: function(html){
		  	$('#searchlist_container').show();
		    $("#searchlist_container").html(html);
		    
		  }
	});
	
}

function toTop() {
	$('html, body').animate({
		scrollTop: $("#header").offset().top
		}, 800);
}
		
function toContent(link){
	$('html, body').animate({
		scrollTop: 262
		}, 1000, 'easeOutBounce');
		var hash = link;
			//hash = hash.replace(/^.*#/, '');
			// moves to a new page. 
			// pageload is called at once. 
			$.historyLoad(hash);
}

function rebuildShoppingBag(){
	if($('#basket').css('height') != '0px'){
		$("#basket").animate({ height : $('#basketInner').height() }, 100, 'easeOutBounce');
	}
}
//globalny onload
$(document).ready(function() {
	//PNG FIX
	 $(document).pngFix(); 
	//tutaj funkcja która obsluguje koszyk
	$('a#slick-toggle').click(function(event) {
		event.preventDefault();
		if ($('#basket').css('height') == '0px') {
			//jQuery.easing.def = 'easeInQuad';
			$('#basket').animate({ height : $('#basketInner').height() }, 400, 'easeInQuad'); 
		} else {
			//jQuery.easing.def = 'easeOutBounce';
				$("#basket").animate({ height : "0px" }, 400, 'easeOutBounce');
		}
	});

	$('a#slick-hide').click(function(event) {
		event.preventDefault();
		alert('111');
		//jQuery.easing.def = 'easeOutBounce';
		$("#basket").animate({ height : "0px" }, 400, 'easeOutBounce');
	});
});

function initializeScroller(){
				$('#scroller2').fadeIn(5000);
				$('#scroller').fadeIn(5000);
				var initWidth = $('#scroller').innerWidth();
				$('#scroller2').css("marginLeft", $('#scroller2').innerWidth()+"px");
				//alert(initWidth);
				function animateIt(start, side){
						start = start-30;
						
						$(side).animate({ "marginLeft": (start)+'px' }, '1500', 'linear', function(){
							if(Math.abs(start) >= initWidth){
	
								$(side).css("marginLeft", initWidth+"px");
								start = initWidth;
							}
							animateIt(start, side);
						});
	
					
					}
				 	animateIt(0, "#scroller");
				 	animateIt(initWidth, "#scroller2");
			}