// JavaScript Document

Shadowbox.loadSkin('classic', '/js/shadowbox/skin');
Shadowbox.loadLanguage('es', '/js/shadowbox/lang');
Shadowbox.loadPlayer(['html'], '/js/shadowbox/player');

var scroll_timer;

$(window).load(function() {
	var img = new Image();
	img.src = 'imgs/arrow_up_on.gif';
	img.src = 'imgs/arrow_down_on.gif';

	Shadowbox.init();

	$('#content_background').show('drop', {direction:'left'}, 1000, function() {
		$('#content_background').fadeTo(1000, 0.8);
		$('#news').fadeIn(1000, function() {
			if ($('#news ul').height() > $('#news').height()) $('#scroll_arrows').show();
		});
	});
});

function scroll_up(wait) {
	var scroll = parseInt($('#news ul').css('top')) || 0;
	if (scroll < 0) {
		if ($('#arrow_up').attr('src') != 'imgs/arrow_up_on.gif') $('#arrow_up').attr('src', 'imgs/arrow_up_on.gif');
		scroll_timer = setTimeout(function() {
			scroll_to(scroll + 1, 'up', wait);
		}, wait);
	} else scroll_stop('up');
}

function scroll_down(wait) {
	var scroll = parseInt($('#news ul').css('top')) || 0;
	if (scroll > $('#news').height() - $('#news ul').height()) {
		if ($('#arrow_down').attr('src') != 'imgs/arrow_down_on.gif') $('#arrow_down').attr('src', 'imgs/arrow_down_on.gif');
		scroll_timer = setTimeout(function() {
			scroll_to(scroll - 1, 'down', wait);
		}, wait);
	} else scroll_stop('down');
}

function scroll_to(scroll, direction, wait) {
	$('#news ul').css('top', scroll.toString() +'px');
	if (direction == 'up') scroll_up(wait);
	else scroll_down(wait);
}

function scroll_stop(direction) {
	if (direction == 'up') $('#arrow_up').attr('src', 'imgs/arrow_up_off.gif');
	else if (direction == 'down') $('#arrow_down').attr('src', 'imgs/arrow_down_off.gif');

	clearTimeout(scroll_timer);
}

function open_new(new_id) {
	Shadowbox.open({
		player:'html',
		title:$('#'+ new_id +' div.title a').html(),
		content:$('#'+ new_id +' div.text').html(),
		width:600,
		height:500
	});
}
