var $ = jQuery.noConflict();
var a ;
var b ;
var c ;
function adwebnews() 
{ 
	//ADWEB NEWS - showing and hiding RSS CANALS
	
	
	$('#contact_box_submit').livequery(function(){
		$(this).click(function(){			
			var act =  $('#contact_ajax').attr('action');			
			showLoaderForm('#contact_ajax');						
			var options = {		
				url:act,	
				dataType: 'html',
				error: function(res)
				{
					$('#message').html("Nie można wysłać zmian bloga");
				},
				success:function(res)
				{
					$('#box_cont_form').html(res);					
				}
			}
			$('#contact_ajax').ajaxSubmit(options);
			return false;
		});
	});
	
	//sending search form
	$('#searchform_ajax').livequery(function()
	{
		//if($('#blog_content')) showLoader('#blog_content');				
		$(this).submit(function(){			
			showLoaderBlog('#Blog_main');
			showLoaderBlog('#blog_content');
			if($('#blog_content'))
			{
				var tar = $('#left_panel:first-child');				
			}			
			var options = {
				url: $(this).attr('action'),
				dataType: 'html',
				error: function(res)
				{
					$('#message').html("Nie można wysłać zmian bloga");
				},
				success:function(res)
				{
					$('#blog_content').html(res);
					$(tar).html(res);
					$('#Blog_main').html(res);					
					$('#default_content').html(res);
					$('#login_content').html(res);
				}
			}
			$(this).ajaxSubmit(options);
			return false;
		});
	});	
	
	$(".komentarz").livequery(function(){
		$(this).click(function(){
			var par = $(this).parent();
			var ch = par.children('[class="bialy"]');			
			if(ch.css('display') == 'none')
			{
				var arr = $(this).find('.box_arrow1');				
				if(arr.attr('class')) arr.attr('class','box_arrow2');
				ch.slideDown();	
			}
			else
			{	
				var arr = $(this).find('.box_arrow2');				
				if(arr.attr('class')) arr.attr('class','box_arrow1');
				ch.slideUp();
			}			
		});
	});
	
		//---------------------- search pagination list actions
	$('.Mhit_pn, .Mhit_pn_checked').livequery(function(){
		$(this).click(function(){			
			$('.Mhit_pn_checked').attr('class','Mhit_pn');
			$(this).attr('class','Mhit_pn_checked');	
			
			showLoaderBlog('#hp');
			
			var act= '/pl/default/index/searchpage/';
			var p = $(this).attr('name');			
			$.ajax({				
				type: 'post',
				url: act,
				data: 'search_word='+$('.Mhit_pn_cont').attr('name')+'&page='+p,
				dataType: 'html',
				error: function(m)
				{
				},
				success: function(t)
				{					
					$('#hp').html(t);		
				}
			});
			return false;
		});
	});
	$('#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();
			}			
		});
	});
	
	//sending edit profile form
	$('.editprofile').livequery(function(){
		$(this).submit(function(){			
			showLoaderBlog('#blog_content');
			var options = {
				url: $(this).attr('action'),
				dataType: 'html',
				error: function(res)
				{
					$('#message').html("Nie można wysłać zmian bloga");
				},
				success:function(res)
				{
					$('#blog_content').html(res);					
				}
			}
			$(this).ajaxSubmit(options);
			return false;
		});
	});
	
	/* --- display confirm div --- */	
	$("#confirm_userdel").livequery(function(){
		$(this).click(function(){			
			var obj = $('#confirm');
			var off = $(this).offset();
  			var left = (off.left)/2;
  			$('#confirm').fadeIn();
  			obj.css('top',off.top+'px');
  			obj.css('left',(left-90)+'px');  			
  			
			return false;
		});
	});
	
	/* --- display confirm div vith avatar --- */
	$("#confirm_avatardel").livequery(function()
	{
		$(this).click(function(){
			var obj = $('#confirm');
			var off = $(this).offset();
  			var left = (off.left)/2;
  			var act = $(this).attr('href');
  			obj.css('top',off.top+'px');
  			obj.css('left',(left-90)+'px');  			
  			
  			$.ajax({				
				type: 'get',
				url: act,				
				dataType: 'html',
				success: function(t)
				{					
					$('#confirm').html(t);
					$('#confirm').fadeIn();					
				}
			});			
  			
			return false;
		});	
	});
	
	/* ---  close confirm delete post window  --- */
  	$("#close_confirm").livequery(function(){
  		$(this).click(function(){
  			$('#confirm').fadeOut();
  		});
  	});
  	
  	/* ---  delete post with ajax  --- */
  	$("#bt_confirm_yes").livequery(function(){
  		$(this).click(function(){
  			act = $(this).parent().parent().attr('action');
  			var options = {
  				type: 'post',
  				url: act,
  				dataType: 'html',
  				error: function(m)
  				{
  					$('#message').html('Nie można usunąć');
  				},
  				success: function(t)
  				{
  					$('#confirm').fadeOut();  	  					
  					$('#blog_content').html(t);  					
  				}
  			};
  			$(this).parent().parent().ajaxSubmit(options);
  			return false;
  		});
  	});

  

  	/* --- cancel deleting post with ajax --- */
  	$("#bt_confirm_no").livequery(function(){
  		$(this).click(function(){
  			$('#confirm').fadeOut();
  		});
  	});  
  	
  	$("#confirm_userdelete").livequery(function(){
  		$(this).submit(function(){
  			var options = {
  				type: 'post',  				
  				dataType: 'html',  				
  				success: function(t)
  				{  					
  					$('#blog_content').html(t);  					
  				}
  			};
  			$(this).ajaxSubmit(options);
  			return false;
  		});
  	});
  	
  	$("#stime").livequery(function(){
  		var time = $(this).html();
  		if(time == '') time = 6;
  		stime(time);
  	});
  	 
  	$(".szukaj1, .domena").click(function(){
  		$(this).val('');
  	});
  	
  	//RSS READER AJAX
  	$('.rss_pagin a').livequery(function(){
  		$(this).click(function(){
  			
  			showLoaderForm('.rss_news_container');
  			
	  		var act = $(this).attr('href');
	  		$.ajax({				
				type: 'get',
				url: act,				
				dataType: 'html',
				success: function(t)
				{					
					$('#blog_content').html(t);				
				}
			});			
				
			return false;
  		});
  	});
}

function adwebmenu()
{
	var str = $('#menu ul').attr('id');
	var id = str.substr(2);
	$('.podmenu_'+id).fadeIn();
	
	var hover = $('#menu ul').attr('class');
	if(hover)
	{
		var style = 'active'+hover;
		$('#podmenu').attr('class',style);
		$('#podmenu ul li').attr('class','active');
		$('#podmenu ul li a').attr('class',style);
		$('.menu_'+hover+' a').attr('class',style);
	}
	
	$('#menu ul li').livequery(function(){
		$(this).mouseover(function(){
			var str = $(this).attr('class');
			var id = str.substr(5);
			$('#podmenu ul').hide()
			$('.podmenu_'+id).show();
						
			if($('#menu ul').attr('class')){			
				var style = 'active'+id;
				$('#podmenu').attr('class',style);			
				$('#podmenu ul li a').attr('class',style);	
			}
				if(window.pdmtime)
				{
					clearTimeout(window.pdmtime);
				}	
		});
		$(this).mouseout(function(){			
			if(window.pdmtime)
			{
				clearTimeout(window.pdmtime);
			}
			window.pdmtime = setTimeout("HidePodmenu()",2000);		
		});
	});
		
	$('#menus').livequery(function(){	
		$(this).mouseout(function(){
			if(window.pdmtime)
			{
				clearTimeout(window.pdmtime);
			}
			window.pdmtime = setTimeout("HidePodmenu()",2000);
		});
	});
	
	$('#podmenu').livequery(function(){
		$(this).mouseover(function(){			
			if(window.pdmtime)
			{
				clearTimeout(window.pdmtime);
			}	
		});
		$(this).mouseout(function(){
			if(window.pdmtime)
			{
				clearTimeout(window.pdmtime);
			}
			window.pdmtime = setTimeout("HidePodmenu()",2000);
		});
	});
}

$(document).ready(adwebnews);

$(document).ready(adwebmenu);

$(document).ready(setEqualBoxHeight);

//ADITIONAL ADWEBNEWS FUNCTION ---------------------------

function HidePodmenu()
{
	var id = $('#menu ul').attr('class');	
	if(!id) id = 0;
	
	var vis = $('#podmenu').attr('class');
	if(!vis) var id_vis = 0;
	else var id_vis = parseInt(vis.substr(6));
	
	if(id_vis != id)
	{
		var style = 'active'+id;		
		$('#podmenu ul').hide()
		$('.podmenu_'+id).fadeIn(1000);
		$('#podmenu').attr('class',style);			
		$('#podmenu ul li a').attr('class',style);	
	}
	else if(id == 0)
	{
		var pdm1 = $('.podmenu_1').css('display');
		if(pdm1 == 'none')
		{
			$('#podmenu ul').hide()
			$('.podmenu_1').fadeIn(1000);
		}
	}
	
}

function showLoaderForm(id)
{
	var par = $(id);
	if(par)
	{	
		par.slideUp();
		par.after('<div style="margin:auto;" class="loading">&nbsp</div>');
	}
}

function showLoaderBlog(id)
{
	var par = $(id);
	if(par)
	{	
		par.html('<div style="margin-top:5px;" class="loading">&nbsp</div>');
	}
}

function stime(time)
{
	time = parseInt(parseInt(time)-1);
	if(time>4) time = time+' sekund';
	if(time>=2 && time<=4) time = time+' sekundy';
	if(time == 1) time = '1 sekundę';
		
	$("#stime").html(time);
	if(time == 0)
	{		
		$("#stime").html(' chwilkę ');
		window.location = '/';	
	}
	else
	{
		setTimeout('stime("'+time+'")',1000);
	}
}

function setEqualBoxHeight()
{
	//setEqualBoxHeightFunction();	
	window.a = setTimeout('setEqualBoxHeightFunction();',100);
	window.b = setTimeout('setEqualBoxHeightFunction();',2000);
	window.c = setTimeout('setEqualBoxHeightFunction();',5000);
}

function setEqualBoxHeightFunction()
{	
	var tabH = new Array();	
		var str;
		var h = 0;
		var w = 0;
		
		for(i=1; i<=5; ++i)
		{			
			wall  = parseInt($("#dzial"+i+" .boksy .home_minibox_text").height());		
			w  = $("#dzial"+i+" .boksy .home_minibox_text h6").height();		
			w2 = $(".home_minibox_vshort").height();
			w3 = $(".home_minibox_vshort p").height();
			if(!w) w = 5;
			if(!w2) w2 = 5;			
			if(parseInt(w2) < parseInt(w3)){
				w2 = parseInt(w3);			
			}
			
			wr = parseInt(w)+parseInt(w2);						
			if(wall > wr) wr = wall;			
			if(parseInt(wr) > h) h = wr;						
		}			
		//alert('wall = '+wall+' w = '+w+' w2 = '+w2+' w3 = '+w3+' wr = '+wr+' h = '+h);
							
		//$(".boksy").css('height',h+'px');		
		$(".home_minibox_text").css('height',h+'px');
}
