function storeEngineReady(engine){
	
	var voteList = $('<ol />');
	$('#ocen option').each(function(i){
		voteList.append('<li><a id="ocen'+(i+1)+'" href="#" title="'+$(this).text()+'">'+$(this).text()+'</a></li>');
		voteList.find('a:last').data('href','/glosuj/glos?v='+(i+1)+'&id='+$('#cartoon_id').val());
	});
	var cartoon_id = $('#cartoon_id');
	$('#ocen form').replaceWith(voteList);
	voteList.append(cartoon_id);
	try{
	$('#ocen').pngFix();
	}catch(e){
	
	}
	
	var voted = false;
	votes = $.jStore.CurrentEngine.get('votes');
	if(votes){
		votes = JSON.parse(votes);
	}else{
		votes={};
	}

	if(! votes[$('#cartoon_id').val()]){
		$('#ocen a').bt({
		  contentSelector: "$(this).attr('title')",
		  cssStyles: {color: '#000', fontWeight: 'bold'},
		  shrinkToFit: true,
		  padding: 10,
		  cornerRadius: 10,
		  spikeLength: 15,
		  spikeGirth: 5,
		  positions: ['top']
		});
	}else{
		$('#ocen a').addClass('notSet');
		$('#ocen li:eq('+(votes[$('#cartoon_id').val()] - 1)+') a').removeClass('notSet').addClass('set');
		voted=true;
	}
	
	$('#ocen a').click(function(e){
		e.preventDefault();
		if(!voted){
			$.get($(this).data('href'), function(data){
				$('#av').html(data);
			});
			$('#ocen a').addClass('notSet');
			$(this).removeClass('notSet').addClass('set');
			$('#ocen a').btOff();
			$('#ocen a').unbind('click').bind('click', function(e){
				e.preventDefault();
			});
			
			votes = $.jStore.CurrentEngine.get('votes');
			if(votes){
				votes = JSON.parse(votes);
			}else{
				votes={};
			}
			votes[$('#cartoon_id').val()*1] = $(this).parent().prevAll().size() + 1;
console.log(JSON.stringify(votes));
			$.jStore.CurrentEngine.set('votes', JSON.stringify(votes));
		}
	});
}

if($.jStore){
	$.extend($.jStore.defaults, {  
		project: 'animowane',   
		flash: 'js/jStore.Flash.html'  
	});

	$.jStore.ready(function(engine){
		 if(engine.type == "Flash"){
			 jQuery.jStore.flashReady(function(){
				   engine.ready(function(){ 
						 storeEngineReady(this);
					});
			 });
		 }else{
			 engine.ready(function(){ 
				 storeEngineReady(this);
			 });
		 }
	}); 
}


$(document).ready(function(){
	if($.jStore){
		$.jStore.load();
	}	
	if($('nav').size()){
		$('.tv').each(function(i){
			var href = $(this).next().attr('href');
			var title = $(this).next().attr('title');
			$(this).find('img').wrapAll('<a href="'+href+'" title="'+title+'"></a>');
		});
	}
}); 