$(function(){
	if ($('body.b2b').length)
		cycleBaker();
	else
		cycleHeaderimg();
})


function cycleHeaderimg() {
	var header, images, first, last, next, mapimg;
	
	header	= $('#header');
	images	= $('.bg img', header);
	mapimg	= $('.mask .map', header);
	
	first	= images.filter(':visible').eq(0);
	last	= images.last();
	if (!first)
		first.eq(0);
	first.show();
	images.not(first).hide();
	
	mapimg.attr('usemap', first.attr('usemap'));
	
	setInterval(
		function() {
			
			next = images.filter(':hidden').eq(0);
			if (next.length) {
				next.fadeIn(1300, function() {
					mapimg.attr('usemap', next.attr('usemap'));
				});
			}
			else {
				images.not(last).not(first).hide();
				last.fadeOut(1300, function() {
					mapimg.attr('usemap', first.attr('usemap'));
				});
			}
			
		},
		8000
	);
}

function cycleBaker() {
	var popout, images, holders;
	
	popout	= $('.popout', '#header');
	images	= $('img', popout);
	
	images
		.hide()
		.each(function() {
			var div = $(document.createElement('div'));
			
			//if ($.browser.msie)
			//	div.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+this.src+'\');');
			//else
				div.css('background-image', 'url('+this.src+')');
			
			div.appendTo(popout);
		})
		.remove()
	;
	
	holders	= $('div', popout);
	holders.eq(1).hide();
	
	setInterval(
		function() {
			
			holders.filter(':visible').fadeOut(1000);
			holders.filter(':hidden').fadeIn(1000);
			
		},
		5000
	);
}
