$(document).ready(function()
{
	$('ul#main-navi a#main-navi-1, body.solaranlagen-portal ul#main-navi a#main-navi-2').hover(function()
	{
		$('ul#subnavi').css({visibility: 'visible'});
	});
	
	
	var timer;
	$('ul.sidebar-navi li a').hover(function()
	{
		var elem = $(this);
		timer = setTimeout(function()
		{
			elem.parent().parent().find('li').show();
		}, 100);
	}, function()
	{
		if(timer)
		{
			clearTimeout(timer);
			timer = null;
		}
	});
	
	
	$('ul.sidebar-navi').not('.active').find('li').not('.title').hide();
	$('ul.sidebar-navi li.active').parent().find('li').show();
});


$('div.search div.box.closeable h2').live('click', function()
{
	var parent = $(this).parent();
	if(parent.hasClass('hidden'))
	{
		parent.addClass('visible');
		parent.removeClass('hidden');
		parent.find('div.content').slideDown('fast');
	}
	else
	{
		parent.removeClass('visible');
		parent.addClass('hidden');
		parent.find('div.content').slideUp('fast');
	}
});

var voting = {
	showStars: function(stars)
	{
		var i = 0;
		$('div.search.user-profile form.vote div.stars ul li').each(function()
		{
			if(i < stars)
			{
				$(this).addClass('active');
			}
			else
			{
				$(this).removeClass('active');
			}
			i++;
		});
	}
};

$('div.search.user-profile form.vote div.stars ul li').hover(function()
{
	var stars = $(this).attr('id').replace(/star-/, '');
	voting.showStars(stars);
}, function()
{
	var stars = $('div.search.user-profile form.vote input#stars').val();
	voting.showStars(stars);
});
$('div.search.user-profile form.vote div.stars ul li').live('click', function()
{
	var stars = $(this).attr('id').replace(/star-/, '');
	$('div.search.user-profile form.vote input#stars').val(stars);
	voting.showStars(stars);
});

$('div#widget form label span.info, div#content-wrapper span.info').hover(function()
		{
			var element = $('<div></div>')
						.attr('id', 'widget-info')
						//.attr('class', 'tooltip')
						.html($(this).html());
			
			element.className += ' tooltip';

						
			if($(this).hasClass('position-below'))
			{
				element.css({
					left: $(this).position().left - 100,
					top: $(this).position().top + 25,
					maxWidth: '800px',
					minWidth: '230px'
				});
			}
			else
			{
				element.css({
					left: $(this).position().left + 20,
					top: $(this).position().top - 5,
					maxWidth: '800px'
				});
			}
			$('div#widget').append(element);
			element.show();
		}, function()
		{
			$('div#widget-info').remove();
		});
