var $ = jQuery.noConflict();
$(document).ready(function(){
	
	//content pagining
	$('.article_content_page').hide();
	$('#content_page0').show();
	$('.article_content_pages :first-child').attr('id', 'current_page');
	
	
	$('.article_content_pages a').click(function(){
		var page= $(this).attr('href');
		$('.article_content_page').hide();
		$('.article_content_pages a').attr('id', '');
		$(page).show();
		$(this).attr('id', 'current_page');
	});
	
	$('#layer1').hide();
	$('#btn_newsletter').click(function(){
		
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test($('#input_newsletter').attr('value')) == false)
		{
			alert('Niepoprawny adres e-mail !');
			return;
		}
		
		var url_s= '/'+$(this).parent().attr('lang')+'/default/index/newsletterajax/';
		var data_s= 'adr='+$('#input_newsletter').attr('value');
			$.ajax({
				
				type: 'post',
				url: url_s,
				data: data_s,
				dataType: 'html',
				error: function(m)
				{
				},
				success: function(t)
				{
				   $('#newsletter-popup-content').html(t);
				   $('#layer1').show();
				   $('#layer1').center();
				}
			});
	});
	
	$('#newsletter-popup-close').click(function(){
		$('#layer1').hide();
	});
	
	
	
	//sending search form
	$('#form_search').livequery(function(){
		$(this).submit(function(){
			
			var act= '/'+$(this).attr('action')+'/default/index/searchajax/';
			var word= 'search_word='+$('#search_word_id').attr('value');
			$.ajax({				
				type: 'post',
				url: act,
				data: word,
				dataType: 'html',
				error: function(m)
				{
				},
				success: function(t)
				{
					if($('#blog_content').attr('id')) $('#blog_content').html(t);		
					else $('.content').html('<div id="search_content">'+t+'</div>');		
					
				}
			});
			return false;
		});	
	});
	
	//---------------------- search pagination list actions
	$('.Mhit_pn, .Mhit_pn_checked').livequery(function(){
		$(this).click(function(){
			$('.Mhit_page').attr('class','Mhit_page_h');
			var v = $(this).attr('name');
			var n = v.substr(0,1);
			var div = 'hp_'+n;
			$('#'+div).attr('class','Mhit_page');
			$('.Mhit_pn_checked').attr('class','Mhit_pn');
			$(this).attr('class','Mhit_pn_checked');
		});
	});
	$('#Mhit_pn_next').livequery(function(){
		$(this).click(function(){
			var n = $(this).attr('name');
			$('[name=Mhit_pn_div]').hide();
			$('#'+n+'_Mhit_hp_cont :first-child').click();
			$('#'+n+'_Mhit_hp_cont').show();
			
			var a = parseInt(n)+1;
			if($('#'+a+'_Mhit_hp_cont').attr('id'))
			{
				$(this).attr('name',a);	
			}
			else
			{
				$(this).hide();
			}
			
			var b = a - 2;
			if($('#'+b+'_Mhit_hp_cont').attr('id'))
			{
				$('#Mhit_pn_prev').attr('name',b);	
				$('#Mhit_pn_prev').show();
			}
			else
			{
				$('#Mhit_pn_prev').hide();
			}
			
			
		});
	});
	
	$('#Mhit_pn_prev').livequery(function(){
		$(this).click(function(){
			var n = $(this).attr('name');
			$('[name=Mhit_pn_div]').hide();
			$('#'+n+'_Mhit_hp_cont :first-child').click();
			$('#'+n+'_Mhit_hp_cont').show();
			
			var a = parseInt(n)-1;
			if($('#'+a+'_Mhit_hp_cont').attr('id'))
			{
				$(this).attr('name',a);	
			}
			else
			{
				$(this).hide();
			}
			
			var b = a + 2;
			if($('#'+b+'_Mhit_hp_cont').attr('id'))
			{
				$('#Mhit_pn_next').attr('name',b);	
				$('#Mhit_pn_next').show();
			}
			else
			{
				$('#Mhit_pn_next').hide();
			}
			
			
		});
	});
	
	
	$('#login').livequery(function(){
		$(this).submit(function()
		{
			var action= $(this).attr('action');
			var password= $('#password', this).attr('value');
			var login= $('#username', this).attr('value');
			var obj= this;
			
			$.ajax({
				type: 'post',
				url: action,
				data: 'username='+login+'&password='+password,
				dataType: 'html',
				error: function(m)
				{
				},
				success: function(t)
				{
				   if (parseInt(t)==1)
				   {
				   	document.location.reload(false);
				   	return true;
				   }
				   $(obj).remove();
				   $('.content').html(t);
				}
			});
			
			return false;
		});
	});
	
	
});

function printContent(url)
{
	var _url= url+'?print=1';
	window.open(_url, 'Drukuj', 'scrollbars=yes,width=650,height=500'); 
}