$(document).ready(function() {
	bindPrizersBlockList();
});

function bindPrizersBlockList() {
	$('#prizers_block_list a').live('click', function() {
		obj = $(this);
		inside = obj.next();
		
		if(!inside.html()) {
			blockId = $(this).attr('bid');
			
			if(blockId) {
				$.get("/prizers/list?bid=" + blockId, null, function(data) {
					inside.html(data).slideDown('slow');
					obj.find('img').attr('src', obj.find('img').attr('src').replace(/arrow_down/, "arrow_up") );
				});
			}
		} else if(inside.css('display') == 'block')	{
			inside.slideUp('slow');
			setTimeout("obj.find('img').attr('src', obj.find('img').attr('src').replace(/arrow_up/, 'arrow_down') )", 500);
		} else {
			inside.slideDown('slow');
			setTimeout("obj.find('img').attr('src', obj.find('img').attr('src').replace(/arrow_down/, 'arrow_up') )", 500);
		}
		
		return false;
	});
	
	$('.prizer img').live('mousemove', function(e) {
		txt = $(this).attr('comment');
		ptitle = $(this).attr('ptitle');
		prize = $(this).parents('.prizers_gift_block:eq(0)').find('h2').text();
		name = $(this).parents('.prizer:eq(0)').find('p:first').text();

		if($(this).attr('bpic')) {
			$('#prizer_big_pic .marka_preview_body').find('p:first').html( ptitle + " <label>" + prize + "</label>").parent().find("img:first").attr('src', "/uploads" + $(this).attr('bpic') ).parent().find("h3").text(name).parent().find("p:last").html(txt);
			$('#prizer_big_pic').addClass('position' + $(this).attr('index')).css('top', (e.pageY+10)-$('#prizers_block_list').offset().top + 'px').show();
			$('#prizer_big_pic').show();
		}
	});
	
	$('.prizer img').live('mouseout', function(e) {
		$('#prizer_big_pic').hide().removeClass();
	});
}

