var $ = jQuery.noConflict();
$(document).ready(function(){
	
	try {
	$('a[@rel*=lightbox]').lightBox();
	}
	catch(e){}
	
	$('#print_button').click(function(){
		var _url= document.location+'?print=1';
		window.open(_url, 'Drukuj', 'scrollbars=yes,width=650,height=500');
		return false;
	});
	
	//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');
	});
	
	//glosowanie
	$('#vote_form').livequery(function(){
		$(this).submit(function(){
			var value= $(':checked',this).val();
			var a_url= $(this).attr('action');
			
			$.ajax({
				type: 'post',
				url: a_url,
				data: 'poll_answers='+value,
				dataType: 'html',
				success: function(t)
				{
				   $('#sonda').html(t);
				   
				   $('.score_bar').each(function(){
					    var _width= $(this).width()+"px";
					    $(this).width("1px");
					    $(this).animate({width: _width}, 1000);
					});
				}
			});
			
			return false;
		});
	});
	
	//polec znajomemu
	$('.recommend').livequery(function(){
		$(this).submit(function(){
			var value= $('#recommend_mail',this).val();
			var a_url= $(this).attr('action');
			
			$.ajax({
				type: 'post',
				url: a_url,
				data: 'recommend_mail='+value,
				dataType: 'html',
				success: function(t)
				{
				   $('.recommend').parent().html(t);
				}
			});
			
			return false;
		});
	});
	
	
	//google maps
	$('.article_map').click(function(){
			if (!$('#map_content').attr('id'))
			{
				$(document.body).append('<div id="map_content" style="width: 100%; height: 100%; position: fixed; top: 0px;"></div><div style="width: 500px; height: 320px;" id="map_window"><div id="map" style="width: 500px; height: 320px;"></div><p class="close-map"><a href="#">zamknij</a></p></div>');
			}
			else
			{
				$('#map_content').show();
				$('#map_window').show();
			}
			
			
			var lat= $(this).attr('lat');
			var lng= $(this).attr('lng');
			$('#map').livequery(function(){
				
				map.clearOverlays();
				map.addOverlay(new GMarker(new GLatLng(lng, lat), markerOptions));
				map.setCenter(new GLatLng(lng, lat));
			});
			
			$('#map_window').center();
	});
	
	//closing window with google map
	$('#map_content').livequery(function(){
			$(this).click(function(){
				$(this).hide();
				$('#map_window').hide();

			});
			
			$('.close-map a').click(function(){
				$('#map_content').trigger('click');
			});
			
			$(document).keypress(function(e){
				if(e.keyCode==27)
				$('#map_content').trigger('click');
			});
		});
		
		$('.close-map').trigger('click');
		
		$('.content div.link').each(function(){
			var url= $(this).text();
			$(this).html('<a href="'+url+'" target="_blank">'+url+'</a>');
		});
});
