var TextSizeWidget = function() {
	var sizes = [ '100%', '120%', '140%' ];
	var cookiename = 'textsizewidget';
	var s = sizes[0];
	var tw;
	var co;

	function init() {
		co = $('#content,#intro');
		tw = $('#textwidget');
		$('.small', tw).bind('click', function(e) {
			setTextSize(0);
		});
		$('.medium', tw).bind('click', function(e) {
			setTextSize(1);
		});
		$('.large', tw).bind('click', function(e) {
			setTextSize(2);
		});

		var cv = $.cookie(cookiename);
		if (cv != null)
			setTextSize(cv);
	}
	function setTextSize(size) {
		var x = parseInt(size);
		s = sizes[0];
		if ((x >= 0) && (x < sizes.length))
			s = sizes[x];

		co.css('font-size', s);
		$.cookie(cookiename, x, {
			path : '/'
		});

		tw.trigger('update', [ s ]);
		$('a', tw).removeClass('selected');

		if (size == 0) {
			$('.small', tw).addClass('selected');
			co.removeClass('tw-large').removeClass('tw-medium');
		}
		if (size == 1) {
			$('.medium', tw).addClass('selected');
			co.removeClass('tw-large').addClass('tw-medium');
		}
		if (size == 2) {
			$('.large', tw).addClass('selected');
			co.addClass('tw-large').removeClass('tw-medium');
		}
	}
	function getSize() {
		return s;
	}
	return {
		init : init,
		getSize : getSize
	};
}();

$(function(){
	if ($.isIE6()) $('.filter').ie6TransparentBackground();
	if ($.isIE6()) $('img.pngfix').ie6TransparentImage();
	
	TextSizeWidget.init();

	$('.scroll-pane').jScrollPane();
	
	$('a.slideshow').fancybox({
		'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
		    return '<div id="tip7-title">' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
		},
		'titlePosition': 'inside'
	});
	
	
	$('img.info_button').bind('click', function(e) {
		$('div.info:visible').hide();
		$(e.currentTarget).next('div.info').stop().show();
	});
	
	$('body').bind('click', function(e) {
		if ($(e.target).hasClass('info_button')) return; // Don't cancel if it's an info button!
		$('div.info:visible').hide();
	});
});

