var Toaleta2012_cufon = {
	start: function(){
		var cufon_objects = [
			'h2',
			'h3.press-archive-header',
			'strong.place-sumup',
			'.banners ul li'
			].join(",");
			
			Cufon.replace(cufon_objects,{hover: true,letterSpacing: '-1px'});
			Cufon.replace('p.patrol-info a, a.lang, .news p, #container ul.tabs li a',{hover: true});
	}
}


$(document).ready(function(){
	
	$('a[rel=external]').attr('target','blank');

        /*
	$("#toilets-cities-list li a").click(function(){
		var id = $(this).parent().attr("id").slice(1);
		$("#toilets-cities-list li a.active").removeClass("active");
		$(this).addClass("active");
		Cufon.refresh();
		openPlaceInfoById(id,12,true);
		return false;
	});
        */
	
	$("#toilets-categories-list").change(function(){
		$(this).parents("form").submit();
	});
    
	$("a.watch-movie, #gallery a").fancybox({
        'zoomSpeedIn':	300, 
		'zoomSpeedOut':	300,
		'frameWidth': 540,
		'frameHeight': 296,
		'overlayShow':	true,
		'overlayOpacity': 0.9
	});
    
	$("#research-links-menu a").click(function(){
		var cls = $(this).attr("class");
		if(cls != 'active') {
			var id = $(this).attr("href");
			$(this).parents("ul").find("a.active").removeClass("active");
			$(this).addClass("active");
			$('.presentation').fadeOut('normal', function(){
				$(id).fadeIn('normal');
			});
		};
		return false;
	});
	
	var link = '/ajax';
	var loader = '<p class="loader"><img src="/static/img/ajax-loader.gif" alt="" /></p>';
	$('#main-tabs li a').click(function(){
		var me = $(this);
		url = link + me.attr('href');
		$.ajax({
			url: url,
			beforeSend: function() {
				me.closest('ul.tabs').next().html(loader)
					.end().find('a.active').removeClass('active')
					.end().end().addClass('active');
					Cufon.refresh();
			},
			success: function(data) {
				me.closest('ul.tabs').next().html(data);
			}
		});
		return false;
	});
	
	$('#main-tabs + .tabs-content p.pagination a').live('click', function(){
		var me = $(this);
		url = link + me.attr('href');
		$.ajax({
			url: url,
			beforeSend: function() {
				me.closest('.tabs-content').html(loader);
			},
			success: function(data) {
				$('.tabs-content').html(data);
			}
		});
		return false;
	});
	
	$('.mediaBigPic').jqzoom({ zoomWidth: 400,zoomHeight: 300, title: false});
	
        $('.help').hover(
            function(){
		var me = $(this);
		var posX = me.position().left;
		var posY = me.position().top;
		var help = me.find('em');
		var text = help.text();
		var clone = $('.tooltip').clone();
		clone.find('.tooltip_content').html(text).end().prependTo($('#content_audit')).css('top',posY-12).css('left',posX+30).show();
	    }
            ,function(){
		$('.tooltip:visible').remove();
	    }
        );
        
	var start_news_items = $("#hot_news li").length;
	function next_news() {
		var me = $("#hot_news"),
		    items = me.find("li"),
		    items_len = items.length,
		    height = 29,
		    top = me.css("top");
		/*if(items_len > start_news_items + 1) {
			items.slice(0,start_news_items).remove();
			me.animate({top: ''+height+''}, function(){
				setTimeout(function(){next_news()}, 5000);
			});
		}*/
		if(parseInt(top) == ((items_len - 1) * height) * -1) {
			me.append(me.html());	
		}
		me.animate({top: '-='+height+''}, function(){
			setTimeout(function(){next_news()}, 5000);
		});
		
	}
	
	setTimeout(function(){next_news()}, 5000);

});

Toaleta2012_cufon.start();
