/* ToC:
	- Turn off no-js
	- Flop-out
*/

$(document).ready(function() {
	// =Turn off no-js
	$('body.no-js').addClass('js').removeClass('no-js');

	// =Flop-out
	var flopOut = '#flopOut > li';

	$(flopOut).each(function(){
		var flopee = $(this);
		// ie only - hide images in lists
		if ($.browser.msie && $.browser.version.substr(0,1)<8) {
			var nuisanceItem = flopee.find('.gifts li');
			$(nuisanceItem).css({"visibility": "hidden"});
			var ieHidden = true;
		}
		// wrap a div round that is to be animated instead of the whole li
		$(flopee).wrapInner('<div>').find('h3').prependTo(flopee).append('<span class="indicator"></span>');
		// Find height of each and then set it - to avoid jump at end of animation
		var divHeight = $(flopee).find('div').height();
		$(flopee).find('div').height(divHeight).hide();
		$(flopee).find('h3').click(function(){
			// ie only
			if ($.browser.msie && $.browser.version.substr(0,1)<8) {
				if ( ieHidden == false ) {
					$(nuisanceItem).css({"visibility": "hidden"});
					ieHidden = true;
				};
			};
			$(this).parent('li').find('div').slideToggle('slow', function() {
				// Animation complete - this alters the indicator arrow
				$(flopee).toggleClass('flopped');
				// ie only
				if ($.browser.msie && $.browser.version.substr(0,1)<8) {
					if ( ieHidden == true ) {
						$(nuisanceItem).css({"visibility": "visible"});
						ieHidden = false;
					};
				};
			});

		});
	});
});
