

function selectAll(element, names)
{
	var reg=new RegExp(names);
	
	for(var i=0;i<element.form.elements.length;i++)
	{
		if(element.form.elements[i].name.match(reg))
		{
			element.form.elements[i].checked=element.checked;
		}
	}
	
}

function confirmUrl(url, text)
{

	if(window.confirm(text))
	{
		document.location.href=url;
	}
}

function initBlogImages(type)
{
	if(type==undefined) type='.blog_photo';
	
	$(type).click(
		function()
		{
			if(!$('#bigger_photo').length)
			{
				var el=document.createElement('div');
				el.id='bigger_photo';
				
				document.body.appendChild(el);
				
				$(el).css('top',(document.documentElement.clientHeight-$(el).height())/2).css('left',(document.documentElement.offsetWidth-$(el).width())/2);
				
				$('#bigger_photo').click(
				function()
				{
					$(this).removeShadow();
					$(this).remove();
				});
			}
			
			var img=new Image();
			
			img.showTitle=$('span', this).html();
			
		
			img.src=$('img',this).attr('rel');
			//debugLay(img);
			
			img.onload=function()
			{
				if($('#bigger_photo').length)
				{	
					if(!$('#bigger_photo img').length)
					{
						document.getElementById('bigger_photo').appendChild(document.createElement('img'));
					}
					
					if(this.showTitle)
					{
						if(!$('#bigger_photo_title').length)
						{
							var el=document.createElement('div');
							el.id='bigger_photo_title';
							
							document.getElementById('bigger_photo').appendChild(el);
						}
						
						$('#bigger_photo_title').html(this.showTitle);
						
					}
					
					$('#bigger_photo img').attr('src',this.src);
					$('#bigger_photo').removeShadow().css('width',this.width).css('height','auto').css('top',((document.documentElement.clientHeight-$('#bigger_photo').height())/2)+$(window).scrollTop()).css('left',(document.documentElement.offsetWidth-$('#bigger_photo').width())/2).dropShadow();
					
				}
				else return false;
			}
		
			if(img.readyState=='complete')
			{
				img.onload();
			}
			
		}
	)
}

function initCalendarEvents()
{
$('.c_event').mouseover(
	function(){
		var offsets=$('div',this).offset();
		$(this).css('width',$(this).width()).css('height',$(this).height()).removeClass('c_event').addClass('c_event_active');
		$('.show',this).css('top',offsets.top-14).css('left',offsets.left-6).dropShadow({blur:2,left:1,top:2,opacity:0.5});
		
		if(navigator.appVersion.indexOf('MSIE 6.0'))
		{
			$('.show div',this).css('width',$(this).width());
		}
	})

$('.c_event').mouseout(
	function(){
		$('.show',this).removeShadow();
		$(this).removeClass('c_event_active').addClass('c_event');
		if(navigator.appVersion.indexOf('MSIE 6.0'))
		{
			$(this).css('width','auto');
		}
	})
}

var menuTimeout=false;
var activeSubmenu=false;


function initSubMenu()
{
	$('.hm_border a[rel^=sublinks_]').mouseover(
	function()
	{
		clearTimeout(menuTimeout);
		if(activeSubmenu)
		{
			activeSubmenu.css('display','none');
		}
		
		var offsets=$(this).offset();
		
		activeSubmenu=$('#'+$(this).attr('rel'));
		
		var aLeft=offsets.left-4;
		if($(this).attr('rel')=='sublinks_2')
		{
			aLeft=aLeft-$('#'+$(this).attr('rel')).width()+$(this).width()+4;
		}
		clearTimeout(menuTimeout);
		
		$('#'+$(this).attr('rel')).css({display:'block', left:aLeft, top: (offsets.top+$(this).height()-1), width:$('#'+$(this).attr('rel')).width()}).mouseout(
		function()
		{
			clearTimeout(menuTimeout);
			menuTimeout=setTimeout(
			function()
			{
				if(activeSubmenu)
				{
					activeSubmenu.css('display','none');
					activeSubmenu=false;
				}
				
			}, 1000);
		}
		).mouseover(function(){clearTimeout(menuTimeout);});
	});
}

function showMessagesMenu()
{
	var offsets=$('#wiadomosci').offset();
	
	//alert(offsets);
	$('#messages_links').css({display:'block', 'left':(offsets.left-4), 'top': ($('#wiadomosci').height()+offsets.top-1)});
	
	document.getElementById('messages_links').onmouseout=document.getElementById('wiadomosci').onmouseout=function()
	{
		clearTimeout(wiadomosciTimeout);
		
		wiadomosciTimeout=setTimeout(function()
		{
			$('#messages_links').css('display','none');
		}, 1000);
		
	}
}

function showParams(obj)
{
	var str='';
	for(var i in obj)
	{
		str+=i+':'+obj[i]+"\n";
	}
	return str;
}

function vote(voteList, eId, voteNumber)
{
	$.ajax({
		url:'/ajax/voting_list/vote', 
		data:
		{
			'vote':voteNumber, 
			'list':voteList,
			'element':eId
		}, 
		success: function(obj)
		{
			
			$('#vote_element_'+eId+' .vote_buttons .voting_line_loader').remove();
			if(obj && obj.average)
			{
				if(voteList=='galeria_kibicow')
				{
					$('#vote_element_'+eId+' .gv_score').html('Ocena: <span>'+obj.average+'</span>');
					$('#vote_element_'+eId+' .gv_place').text(obj.place);
				}
				else
				{
					$('#vote_element_'+eId+' .vote_average').text('Ocena: '+obj.average);
					$('#vote_element_'+eId+' .vote_users').text('Głosujących: '+obj.voting_users);
					$('#vote_element_'+eId+' .vote_points').text('Punktów: '+obj.points);
					$('#vote_element_'+eId+' .lk_place').text(obj.place);
				}
				
				$('#vote_element_'+eId+' .vote_buttons a').each(
					function()
					{
						if($(this).text()!=voteNumber)
						{
							$(this).removeAttr('href').removeClass().replaceWith('<div class="gv_nv">'+$(this).text()+'</div>');
						}
						else
						{
							$(this).removeAttr('href').removeClass().replaceWith('<div class="gv_sv">'+$(this).text()+'</div>');
						}
						
					})
				//var obj=$('#vote_element_'+eId+' '+to);
				//obj.css('height',obj.height()).html().prepen;
				
				//$('#vote_element_'+eId+' '+to+' .voting_line_loader').css({'opacity':0.5,'width':obj.width()-12});
			}
			else
			{
				if(obj && obj.error)
				{
					var error=obj.error;
				}
				else
				{
					var error='Wystąpił nieznany błąd';
				}
				
				var obj=$('#vote_element_'+eId+' '+to);
				obj.css('height',obj.height()).text('').prepend('<div class="voting_line_loader vll_error">'+error+'</div>');
				$('#vote_element_'+eId+' .vote_buttons .voting_line_loader').css({'opacity':0.5,'width':obj.width()-12});
			}
			
		},
		beforeSend:function()
		{
			
			var obj=$('#vote_element_'+eId+' .vote_buttons');
			
			obj.html('<div class="voting_line_loader">Proszę czekać</div>'+obj.html());
			var left=$(obj).offset();
			
			$('.voting_line_loader', obj).css({'left':left.left, 'position':'absolute','opacity':0.9,'width':obj.width()});
			
		},
		dataType:'json',
		type:'post'
		});
}


function debugLay(obj)
{
	if(!document.getElementById('debug_layer'))
	{
		var div=document.createElement('div');
		div.id='debug_layer';
		div.style.position='absolute';
		div.style.overflow='auto';
		div.style.width='400px';
		div.style.height='500px';
		div.style.padding='10px';
		div.style.backgroundColor='#ffffff';
		div.style.zIndex='2000';
		div.style.textAlign='left';
		div.style.left='10px';
		div.style.top='50px';
		
		document.body.appendChild(div);
	}
	else
	{
		var div=document.getElementById('debug_layer');
	}
	
	var str='';
	for(var i in obj)
	{
		str+='<strong>'+i+'</strong>:'+obj[i]+"<br/>";
	}
	
	div.innerHTML=str;
	div.innerHTML+='<a href="javascript:closeDebugLay()" style="display: block;">Zamknij</a>';
}

function closeDebugLay()
{
	if(document.getElementById('debug_layer'))
	{
		document.getElementById('debug_layer').parentNode.removeChild(document.getElementById('debug_layer'));
	}
	
}

