
	//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";
		}
		
	}
	*/

$(document).ready(function(){
	//$('input[name="search_q"]').liveSearch({ajaxURL: '/test/searchResults?q='});
	//$('input[name="search_q"]').liveSearch({ajaxURL: '/index/search?query='});
	$("#textfield").typeWatch( { highlight:true, callback:performSearch } );
	
	var new_p = new Array(1);
	new_p[0] = { name: '.text_main p', actions : { backgroundColor: 'pink', fontSize: '16px'}}
	//new_p[1] = { name: '#nav a', actions : { fontSize: '18px', color: 'red'}}
	
	var old_p = new Array(1);
	old_p[0] = { name: '.text_main p', actions : { backgroundColor: 'white', fontSize: '11px'}}
	//old_p[1] = { name: '#nav a', actions : { fontSize: '16px', color: '#999999'}}
	
	$('#large_font').click(function(){ 
		event.preventDefault(event);
		customTransition(new_p, 1000);
	});
	$('#small_font').click(function(event){ 
		event.preventDefault();
		customTransition(old_p, 1000);
	});
});

//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);
			$("#ajax_container").load(hash + "");				
		}
		//alert($("a[@href='/#"+hash+"']").attr('innerHTML'));
		
	} else {
		// start page
		//$("#chapter").empty();
	}
}

$(document).ready(function(){
	// Initialize history plugin.
	// The callback is called at once by present location.hash. 
	
	//$.history.init(pageload);
	
	
	//TO MA BYC
	//$.jqwidont.init();
	if(jQuery.browser.msie && jQuery.browser.version == 6){

	}else{
		$('#claim h1').css('font-size', '20px');
		$('#claim h1').attr('class', 'cronos');
		Cufon.replace('.cronos');
	}
	
	
	// set onlick event for buttons
	rebuildLinks();
});


function rebuildLinks(shortcuts){
	if($(this).attr('class') == 'menu_link'){
			$("#menu ul.level1:visible").slideUp();
	      	$('li.main_li .main_link').css('color','#808080');
			$('.main_li').css('borderColor','#afafaf');
			$('.menu_link').css('color', '');
			$(this).css('color', '#CF2038');
		}
		
	$('#large_font').unbind('click');
	$('#small_font').unbind('click');
	
	var new_p = new Array(1);
	new_p[0] = { name: '.text_main p', actions : {  fontSize: '13px'}}
	//new_p[1] = { name: '#nav a', actions : { fontSize: '18px', color: 'red'}} backgroundColor: 'pink',
	
	var old_p = new Array(1);
	old_p[0] = { name: '.text_main p', actions : { fontSize: '11px'}}
	//old_p[1] = { name: '#nav a', actions : { fontSize: '16px', color: '#999999'}}
	
	$('#large_font').click(function(event){
		event.preventDefault(); 
		customTransition(new_p, 1000);
	});
	$('#small_font').click(function(event){
		event.preventDefault(); 
		customTransition(old_p, 1000);
	});
	

		Hyphenator.config({
			selectorfunction: function(){
				//return $("#article #text_container p, #article #text_container h2 a").get();
				return $("#article #text_container p, #article #text_container h2 a").get();
			}
		});
		
		Hyphenator.run();
				
		 $('.text_main p').each(function() {
		 	$(this).html($(this).html().replace(/ (\w{1}) /g,' $1&nbsp;'));

		  });
	 /*
	 $.jqwidont.init();
	
	 Cufon.replace('.cronos');
	 
	 if (shortcuts !== undefined ) {
	 		$("#skroty").html(shortcuts);
     }
     //if($('#loader').css('display') == 'block'){
     	$('#loader').fadeOut('fast');
     //}
   
	$("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();
		
		if($(this).attr('class') == 'menu_link'){
			data = { log: true, 'link_name': $(this).html()};
			//alert(data);
		}else{
			data = {};
		}
		$('#loader').fadeIn('fast');
		$.history.load(hash, data);
		
		
		
	
		
		if($(this).attr('class') == 'menu_link'){
			$("#menu ul.level1:visible").slideUp();
	      	$('li.main_li .main_link').css('color','#808080');
			$('.main_li').css('borderColor','#afafaf');
			$('.menu_link').css('color', '');
			$(this).css('color', '#CF2038');
		}
		
		
		
		    
		//$(this).css('color', '#CF2038');
		
		$.ga("UA-5407553-4");
		
		
		
		return false;
	});
	
	$('#large_font').unbind('click');
	$('#small_font').unbind('click');
	
	var new_p = new Array(1);
	new_p[0] = { name: '.text_main p', actions : {  fontSize: '13px'}}
	//new_p[1] = { name: '#nav a', actions : { fontSize: '18px', color: 'red'}} backgroundColor: 'pink',
	
	var old_p = new Array(1);
	old_p[0] = { name: '.text_main p', actions : { fontSize: '11px'}}
	//old_p[1] = { name: '#nav a', actions : { fontSize: '16px', color: '#999999'}}
	
	$('#large_font').click(function(event){
		event.preventDefault(); 
		customTransition(new_p, 1000);
	});
	$('#small_font').click(function(event){
		event.preventDefault(); 
		customTransition(old_p, 1000);
	});
	

		Hyphenator.config({
			selectorfunction: function(){
				//return $("#article #text_container p, #article #text_container h2 a").get();
				return $("#article #text_container p, #article #text_container h2 a").get();
			}
		});
		
		Hyphenator.run();
				
		 $('.text_main p').each(function() {
		 	$(this).html($(this).html().replace(/ (\w{1}) /g,' $1&nbsp;'));

		  });

	*/
}

function customTransition(parameter, duration) {
   for (var i in parameter){
     //$(parameter[i].name).animate(parameter[i].actions, duration);
     $(parameter[i].name).css(parameter[i].actions);
   }
}

function is_valid_email (email)
{
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}

function performSearch(){
	$('#loader').css('display', 'block'); 
	$.ajax({
		type: "GET",
		url: "/index/search?query="+$('#textfield').val(),
		cache: false,
		  success: function(html){
		  	$('#searchlist_container').show();
		    $("#searchlist_container").html(html);
		    $('#loader').css('display', 'none'); 
		  }
	});
	
}

$(document.body).click(function(event) {
	if(!$(event.target).parents('div.live-search-results').length) {
		jQuery('#searchlist .level1').slideUp(300, function(){ $('#searchlist_container').hide();});
		//jQuery('div.live-search-results').slideUp(300);
	}
});
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+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 eraseCookie(name) {
	createCookie(name,"",-1);
}

/* DATE PICKER */
function initializeDatePicker(date){
	$.dpText = {
		TEXT_PREV_YEAR		:	'Poprzedni rok',
		TEXT_PREV_MONTH		:	'Poprzedni miesiąc',
		TEXT_NEXT_YEAR		:	'Następny rok',
		TEXT_NEXT_MONTH		:	'Następny miesiąc',
		TEXT_CLOSE			:	'Zamknij',
		TEXT_CHOOSE_DATE	:	'Wybierz datę'
	}
	Date.format = 'yyyy-mm-dd';
	$('#start_date_'+date).datePicker({clickInput:true});
	$('#end_date_'+date).datePicker({clickInput:true});
	$('#start_date_'+date).bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#end_date_'+date).dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('#end_date_'+date).bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#start_date_'+date).dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
}

function checkAdvanced(is_checked){
	if(is_checked){
		$('#advanced').css('display', 'block');
		$('#month_row').css('display', 'none');
		
	}else{
		$('#advanced').css('display', 'none');
		$('#month_row').css('display', 'block');
	}
}
Hyphenator.run();