$(function() {
	slimboxScanPage();
	
	$('#whyFez').click(function() {
		$.ajax({url: '/process/whyFez.php', success: onWhyFezData, dataType: 'json'});
	});
});

var quotes;
var currentIndex = 0;

function onWhyFezData(data)
{
	quotes = data;
	currentIndex = parseInt( $('#whyFezQuoteIndex').html() );
	$.colorbox({html:getWhyFezHtml(), opacity:0.75, transition:'elastic', close:''});
	updateWhyFez();
}

function updateWhyFez()
{
	$('#whyFezNext').html((currentIndex + 1) + ' of ' + quotes.length + ' &hellip; Next &raquo;');
	$('#whyFezNext').click(function(event) {
		if (currentIndex < quotes.length - 1)
			currentIndex++;
		else
			currentIndex = 0;
		$.colorbox({html:getWhyFezHtml()});
		updateWhyFez();
		event.preventDefault();
	});
}

function getWhyFezHtml()
{
	return '<div class="whyFezBody"><div class="whyFezHeader"><div class="whyFezTitle">Why Fez?</div><div class="whyFezNav"><a href="#" id="whyFezNext">3 of 12 &hellip; Next &raquo;</a></div></div><div class="clear"></div><span id="whyFezText">' + quotes[currentIndex].text + '</span><p>&mdash; <span id="whyFezName">' + quotes[currentIndex].full_name + '</span><div id="whyFezFrom">' + quotes[currentIndex].from + '</div></p></div>';
}

function addToCart(id) {
	var url = '/cart/add/component/' + id;
	var types = $('#' + id + 'types').get(0);
	if (types) {
		var index = types.selectedIndex;
		url += '/' + types.options[index].value;
	}
	window.location = url;
}