var timeout = 3000;
var nextrotate;

$(function() {
	if (!$.browser.msie && !$.browser.opera)
		$('#stocks').corner('5px');

	nextrotate = setTimeout(function(){rotatestocks()}, timeout);

	$('div.stocks_pager img').hover(function() {
		setActiveStock($(this).attr('rel'));
	}, function() {
		nextrotate = setTimeout(function(){rotatestocks()}, timeout);
	});

	$('div.stocks_view').click(function() {
		var href = $('#stock_small_' + $('img:visible', this).attr('rel')+' a').attr('href');

		document.location = href;
	})
	
	$('#video-scroller a').click(function() {
		$('#video-scroller a').removeClass('active');
		$(this).addClass('active');

		$('#video-block div.show-video').hide();
		$('#video-'+$(this).attr('rel')).show();

		return false;
	});
});

function rotatestocks() {
	obj = $(".stocks_view img:visible");

	if (!obj.next().attr('rel')) {
		setActiveStock(0);
	} else {
		setActiveStock(obj.next().attr('rel'));
	}

	nextrotate = setTimeout(function(){rotatestocks()}, timeout);
}

function setActiveStock(id) {
	clearTimeout(nextrotate);

	$(".stocks_view img:visible").fadeOut("slow");
	$('#stock_big_' + id).fadeIn("slow");

	var key = $('#stock_small_' + id).attr('rel');

	var old = $("table.stocks .active");
	var key_old = $("table.stocks .active").attr('rel');

	$("img", old).attr("src", "/public/images/index/stocks-" + key_old + ".gif");
	old.removeClass('active');
	
	$('#stock_small_' + id + ' img').attr("src", "/public/images/index/stocks-" + key + "_active.gif");
	$('#stock_small_' + id).addClass("active");
}