/**
 * KrispyKreme.com: Video Player Popup Layer Behavior
 *
 * Copyright (c) 2007 Matthew Knight (http://www.reconstrukt.com)
 *
 * @requires jQuery v1.2
 *
 */
 
$(document).ready(function(){
	
	// banner behaviors
	$('#video-popup-container').jqm({
		trigger:'#video-popup-trigger',
		modal: true,
		overlay: 70,
		onShow: function(h) {
			var a = $("#video-popup-tabs li a[_active='true']");
			if (a.length > 0) {
				a.trigger('mouseover').click();	
			} else {
				$('#video-popup-tabs li a:first').trigger('mouseover').click();	
			}
			if ( ((navigator.userAgent.indexOf('Win') != -1) && $.browser.msie && ($.browser.version >= 7) ) ) {
				// ie7 transparency issues
				$('body table:first').addClass('ie7transparent');
				h.o.hide();
			}
			h.w.show();
		},
		onHide: function(h) {
			/* callback executed on window hide. Hide notice, overlay. */
			if ( ((navigator.userAgent.indexOf('Win') != -1) && $.browser.msie && ($.browser.version >= 7) ) ) {
				// ie7 transparency issues
				$('body table:first').removeClass('ie7transparent');
			}
			$('#video-popup-player').empty();
			h.w.hide();
			if (h.o) h.o.remove();
		}
	});
	
	// tab behaviors
	$('#video-popup-tabs li a').hover(
		function() { $(this).addClass( $(this).attr('_over') ); },
		function() { if ( $(this).attr('_active') != 'true' ) $(this).removeClass( $(this).attr('_over') ); }
	).click(function(){
		$(this).attr('_active', 'true').parent().siblings().each(function(){
			$(this).find('a').attr('_active', 'false').trigger('mouseout');
		});
		// load video
		var so  = new SWFObject("homepage_video/player/video-standalone.swf", "kkvideo", "370", "304", "8", "#FFFFFF");
		// wmode on mac/FF causes problems
		if ( !((navigator.userAgent.indexOf('Mac') != -1) && $.browser.mozilla) ) {
			so.addParam('wmode', 'transparent');
		}
		so.addVariable('videoPath', $(this).attr('_vid'));
		so.write("video-popup-player");
	});	

	// image map behavior for branded version
	$('#branded-video-map area').each(function(){
		var n = $(this).attr('rel');
		$(this).click(function(){
			var sel = 'a#video-popup-tab' + n;
			$(sel).attr('_active', 'true').parent().siblings().each(function(){
				$(this).find('a').attr('_active', 'false').trigger('mouseout');
			});
			$('#video-popup-container').jqm().jqmShow();
		});
	});
	
});

