$(document).ready( function(){


	$('img.ocen').mouseover(function(){
		
		spanC = this.parentNode.childNodes;
		for (a = 0; a < spanC.length; ++a) {
			spanC[a].src = (parseInt(spanC[a].alt) <= parseInt(this.alt))?'/img/star_10.gif':'/img/star_0.gif';
		}
	});

	$('img.ocen').mouseout(function(){
		$('img.ocen').attr('src','/img/star_0.gif');
	});

	$('img.ocen').click( function(){
		var pdata = 'ocena=' + this.alt;

		$.ajax({
			type: "POST",
			url: document.location.toString(),
			data: pdata,
			success: function(msg){

				if (msg == 'err:mark exists') {
					$("#ocen").text('Już oceniałeś ten dodatek');
				}
				else if (msg == 'err:must log in') {
					$("#ocen").text('Zaloguj się aby ocenić');
				}
				else {
					$("#ocen").text('Ocena została zapisana');
					$("#socenano").text(msg);
					ocenas = Math.round(msg * 2)/2;
					$("#socena img").each(function(){
						if (ocenas >= (parseInt(this.alt)+1)) this.src = "/img/star_10.gif";
						else if (ocenas >= (parseInt(this.alt)+0.5)) this.src = "/img/star_5.gif";
						else this.src = "/img/star_0.gif";

					});
				}
				
			}
		});
	});
	$("#kupilesY, #kupilesN").click( function(){
	
		var pdata = 'kupiony=' + this.value;
		//alert 	(pdata);
		$.ajax({
			type: "POST",
			url: document.location.toString(),
			data: pdata,
			success: function(msg){

				if (msg == 'err:must log in') {
					$("#czykupiles").text('Nie jesteś zalogowana(ny)');
				}
				else if (msg == 'ok') {
					$("#czykupiles").text('Informacja została zapisana');
				}
				else alert (msg);
				
			}
		});
	});

	$('img.actItemYoutube').each(function(){
		//alert (this);
		//alert (this.attr('width'));
		if (this.alt != '') {
			//$(this).after('<p>' + this.alt + '</p>');
			$(this).after('<object type="application/x-shockwave-flash" style="width: ' + this.width + 'px; height:' + this.height + 'px;" data="' + this.alt + '"><param name="movie" value="' + this.alt + '" /><param name="wmode" value="transparent" /></object>');
		}
		//$(this).remove();
		//this.style.display = 'none';
		
	});

	$('a.login-required').click(function() {
		this.innerHTML = $(this).attr('nicetitle');
		return false;
	});
	
	$('img.actItemYoutube').remove();


});