$(document).ready(function()
{
	// Let's visualize HTML code
	$('#replace_event_sponsors').replaceWith('<p class="event_sponsors">' + $('#replace_event_sponsors').text() + '</p>');

	// rounded corners //
	$(".rounded").corner("round 8px").parent().css("padding", "2px").corner("round 10px");

	// vertical slider //
	setTimeout(function(){
		var actual_height = $("#sponsor-logos" ).height();
		$('#sponsor-logos').css('height', actual_height);
	}, 500);
	var visible_height = $("#sponsor-logos" ).height();
	var total_height = $("#dyncontent-sponsors" ).height();
	var interval = 30;
	var offset = 0;
	var my_interval;
	$("#event-sponsors-buttons .nextPage").mouseover(function(){
		total_height = $("#dyncontent-sponsors" ).height();
		my_interval = setInterval(function(){
			if(total_height > visible_height)
			{
				if((0-offset) < (total_height-(interval*2)))
				{
					offset -= interval;
					$("#dyncontent-sponsors").stop().animate({"marginTop": offset+"px", 'margin-bottom': Math.abs(offset)});
				}
			}
		}, 150);
	}).mouseout(function(){
		$("#dyncontent-sponsors").stop();
		clearInterval(my_interval);
	});
	$("#event-sponsors-buttons .prevPage" ).mouseover(function(){
		my_interval = setInterval(function(){
			if(total_height > visible_height)
			{
				if(offset < 0)
				{
					offset += interval;
					$("#dyncontent-sponsors").stop().animate({"marginTop": offset+"px", 'margin-bottom': Math.abs(offset)});
				}
			}
		}, 150);
	}).mouseout(function(){
		$("#dyncontent-sponsors").stop();
		clearInterval(my_interval);
	});

	// Reset Dynamic Content Styles //
	$("#dyncontent-sponsors *").not('.sponsors_list, .text_sponsors').each(function()
	{
		this.className="";
		$(this).attr("style","");
	});
	$.each($('#dyncontent-sponsors img'), function(){
		var fakeImage = $('<img>').attr('src', $(this).attr('src'));
		var imageRatio = fakeImage.attr('width') / $(this).width();
		var newHeight = $(this).height() / imageRatio;
		$(this).css('height', newHeight);
	});
});
