
	/* --------------------------------------------------
	 * maguro DataAssist javascript functions with jQuery
	 * --------------------------------------------------
	 */

/**
 * DOM ready
 *
 * javascript to be executed on load
 *
 */
$(document).ready(function ()
{
	attachEvents();
	clientSlideShow();
});

function attachEvents()
{
	$('#pagination .prev').click(function () {
		turnNews(this);
		return false;
	});
	$('#pagination .next').click(function () {
		turnNews(this);
		return false;
	});
	$('.popup').click(function () {
		openPopup(this, 'popup', 'width=700, height=700');
		return false;
	});
	$('.external').attr('target', '_blank');
	// special case shop
	$('a[href$="/shop"]').attr('target', '_blank');
}

function openPopup(link, name, attributes)
{
	if (name = '') {
		name = getTime();
	}
	if (attributes != '') {
		attributes += ', ';
	}
	attributes += 'resizable=yes, scrollbars=yes';
	var popup = window.open(link.href, name, attributes);
	popup.focus();
}

function turnNews(link)
{
	var speed = 500;
	var news  = $('#news').not('#pagination');
	// hide news
	news.slideUp(speed);
	// ajax request for next news
	$.getJSON(link.href, { type: 'json' }, function (json) {
		$('body').css('background-image', 'url(' + json.background + ')');
		$('#news').html(json.entry);
		// safari rendering bug workaround
		if ($.browser.safari) {
			$('#pagination').css('display', 'none');
		}
		attachEvents();
	});
	// show news
	news.slideDown(speed, function () {
		// safari rendering bug workaround
		if ($.browser.safari) {
			$('#pagination').css('display', 'block');
		}
	});
}

/**
 * clientSlideShow
 *
 * slideshow for the client logos
 *
 */
function clientSlider(ul)
{
	ul.css('margin-left', 0);
	ul.animate({
		marginLeft: '-' + ul.width() + 'px'
	}, 40000, 'linear', function () {
		clientSlider(ul);
	});
}

function clientSlideShow()
{
	var ul = '#foot ul';
	var margin = 30;
	if ($.browser.msie && $.browser.version == '6.0') {
		margin = 38;
	}
	var width = 0;
	$(ul + ' li').each(function (i) {
		width += ($(this).width() + margin);
	});
	$(ul).width(width);
	$(ul).wrap('<div></div>');
	$(ul).clone().appendTo($(ul).parent());
	$(ul + ':last').css('margin-right', '-' + width + 'px');
	clientSlider($(ul + ':first'));
}
