  $(function() {
	$('#nav img').load(function() {
		$('#nav li').each(function() {
			$(this).width($(this).width()).css({backgroundPosition: ($(this).width()+1)+'px top', paddingRight: '29px', marginRight: '0px'})
				.hover(navHover, navOut).children('a').focus(navHover).blur(navOut);
		});
	});
	
	$('#index-list a').each(function() {
		$(this).hover(listHover, listOut).focus(listHover).blur(listOut);
	});
	
	$('input.cap-text').focus(function(){
		if (this.value == this.getAttribute('value')) 
			$(this).val('').css('text-align', 'left');
	}).blur(function(){
		if (this.value == '') 
			$(this).val(this.getAttribute('value')).css('text-align', '');
	});
	
	$('form:has(input.cap-text)').submit(function() {
		$(this).find('input.cap-text').each(function(){
			if (this.value == this.getAttribute('value')) 
				$(this).val('').css('text-align', 'left');
		});
		return true;
	});
	
	
	$('#tabs > div').hide();
	
	to_show = (window.location.hash != '' && $('#tabs > div'+window.location.hash).length != 0)?window.location.hash:$('#tabs-nav li:first-child a').attr('href');
	$(to_show).show();
	$('a[href="'+to_show+'"]').addClass('active');
	
	$('#tabs-nav a').click(function() {
		$('#tabs-nav a').removeClass('active');
		$(this).addClass('active');
		$('#tabs > div').hide();
		$($(this).attr('href')).show();
		return false;
	});
	
	$('#stars-container label').hide();
	$('[name=ocena]').rating();
	$('[name=ocena2]').rating();
	
	$('a.lb').click(function() {
		$('#main-img').attr('src', $(this).attr('href'));
		return false;
	});

	if ($('#opinions li').length>0) {
		$('#comment-form').hide();
		$('#cfs').click(function() {
			$(this).closest('div').hide();
			$('#comment-form').show('slow');
			return false;	
		});
	} else {
		$('#cfs').closest('div').hide();
	}
	
	$('.fav').show().click(function() {
		var url = $(this).attr('href') == '#' ? location.href : $(this).attr('href');
		var title = $(this).attr('title') == '' ? $('title').text() : $(this).attr('title');
		
		if (window.sidebar && window.sidebar.addPanel)
    	{
			window.sidebar.addPanel(title,url,null); return false
		}
        
		if (window.external && window.external.addFavorite)
        {
			window.external.addFavorite(url,title); return false
		}
	});
	
	$('#cproducer').change(function() {
		if ($(this).val() != -1)
			window.location = $(this).val();
	});
	
	$('#searchbar').click(function() {
		if (window.external.AddSearchProvider != undefined)
		{
			addp('http://www.mouseking.pl/op_mouseking.xml');
		} else {
			alert("Twoja przeglądarka nie obsługuje wyszukiwarek");
		}
		return false;
	});

  });
  
	var navHover = function() {
		($(this).is('a')?$(this).parent():$(this)).stop().animate({backgroundPosition: ($(this).width()+10)+'px top'}, 800);
	}
	
	var navOut = function() {
		($(this).is('a')?$(this).parent():$(this)).stop().animate({backgroundPosition: ($(this).width()+1)+'px top'}, 800);
	}
	
	var listHover = function() {
		$(this).data('stopped', false);
		$(this).stop().css({'color': '#454545'}).animate({'color': '#841f20'}, 600);
	}
	
	var listOut = function() {
		$(this).data('stopped', true);
		if ($(this).data('timedOut'))
		{
			clearTimeout($(this).data('timeout'));
		} else {
			$(this).data('timedOut', true);
		} 
		$(this).data('timeout', setTimeout("listFade("+$('#index-list a').index(this)+")", 500));
	}
	
	var listFade = function(what) {
		t = $($('#index-list a').get(what));
		if (t.data('stopped'))
		{
			t.stop().data('timedOut', false).animate({'color': '#454545'}, 600);
		}
	}
	
	function addp(csurl) {
		try {
			window.external.AddSearchProvider(csurl);
		} catch (e) {
			alert("You need to use Internet Explorer (7.0 or later) or Firefox (2.0 or later) to install the OpenSearch plug-in.");
		}
	}


/*	$(function(){
		$('#content > div').addClass('cfirst');
		
		DD_roundies.addRule('#content div.cfirst', '14px');
		DD_roundies.addRule('#products li', '14px');
		DD_roundies.addRule('#nav-bar', '6px');
		
		$('input.cap-text').focus(function(){
			if (this.value == this.getAttribute('value')) 
				$(this).val('').css('text-align', 'left');
		}).blur(function(){
			if (this.value == '') 
				$(this).val(this.getAttribute('value')).css('text-align', '');
		});
		if ($.browser.opera) {
			$('head').append('<link rel="stylesheet" href="opera.css" type="text/css">');
		}
		
		$('.product-gallery a').css({left: '15px', opacity: '0.6'}).hover(function() {
			$(this).stop().animate({left: '0px', opacity: '1'}, 800);
		}, function() {
			$(this).stop().animate({left: '15px', opacity: '0.6'}, 800);
		});
		//$('#sform').submit(function(){return confirm('Czy na pewno?');});
	});*/