var g_ie6 = 0;
var g_clog = new Array();
g_clog[0] = '/prepair/images/provenPix_clog_0static_img.jpg';
g_clog[1] = '/prepair/images/provenPix_clog_1enhance_img.jpg';
g_clog[2] = '/prepair/images/provenPix_clog_2fatigue_img.jpg';
g_clog[3] = '/prepair/images/provenPix_clog_3pressure_img.jpg';
g_clog[4] = '/prepair/images/provenPix_clog_4footbed_img.jpg';
g_clog[5] = '/prepair/images/provenPix_clog_5arch_img.jpg';
g_clog[6] = '/prepair/images/provenPix_clog_6strap_img.jpg';

var g_flip = new Array();
g_flip[0] = '/prepair/images/provenPix_flip_0static_img.jpg';
g_flip[1] = '/prepair/images/provenPix_flip_1enhance_img.jpg';
g_flip[2] = '/prepair/images/provenPix_flip_2fatigue_img.jpg';
g_flip[3] = '/prepair/images/provenPix_flip_3pressure_img.jpg';
g_flip[4] = '/prepair/images/provenPix_flip_4footbed_img.jpg';
g_flip[5] = '/prepair/images/provenPix_flip_5arch_img.jpg';

var g_slide = new Array();
g_slide[0] = '/prepair/images/provenPix_slide_0static_img.jpg';
g_slide[1] = '/prepair/images/provenPix_slide_1enhance_img.jpg';
g_slide[2] = '/prepair/images/provenPix_slide_2fatigue_img.jpg';
g_slide[3] = '/prepair/images/provenPix_slide_3pressure_img.jpg';
g_slide[4] = '/prepair/images/provenPix_slide_4footbed_img.jpg';
g_slide[5] = '/prepair/images/provenPix_slide_5arch_img.jpg';

var g_prod = '';

$(function() {
	if(typeof document.body.style.maxHeight === "undefined") {
		g_ie6 = 1;
	}
	// email updates
	$('#emailUpsForm').validate({
		errorLabelContainer: '#emailUpsVal',
		submitHandler: function(form) {
			$('#contestReturn').fadeIn('fast');
			$(form).ajaxSubmit({
				target: '#emailUpsReturn'
			});
		}
	});
	// background video
	$('#video').flash({
		src: '/prepair/video_adam.swf',
		width: 448,
		height: 284,
		wmode: 'opaque'
	},
	{version: 8}
	);
	$('img.v2, img.v3').fadeTo('fast', 0.5);
	$('#bgVid img').each(function(i) {
		$(this).click(function() {
			if ($(this).hasClass('v1') == true && $(this).hasClass('active') != true) {
				$('img.v2').removeClass('active').fadeTo('fast', 0.5);
				$('img.v3').removeClass('active').fadeTo('fast', 0.5);
				$('img.v1').addClass('active').fadeTo('fast', 0.99);
				$('#video').empty().flash({
					src: '/prepair/video_adam.swf',
					width: 448,
					height: 284,
					wmode: 'opaque'
				},
				{version: 8}
				);
			} else if ($(this).hasClass('v2') == true && $(this).hasClass('active') != true) {
				$('img.v1').removeClass('active').fadeTo('fast', 0.5);
				$('img.v3').removeClass('active').fadeTo('fast', 0.5);
				$('img.v2').addClass('active').fadeTo('fast', 0.99);
				$('#video').empty().flash({
					src: '/prepair/video_matty.swf',
					width: 448,
					height: 284,
					wmode: 'opaque'
				},
				{version: 8}
				);
			} else if ($(this).hasClass('v3') == true && $(this).hasClass('active') != true) {
				$('img.v1').removeClass('active').fadeTo('fast', 0.5);
				$('img.v2').removeClass('active').fadeTo('fast', 0.5);
				$('img.v3').addClass('active').fadeTo('fast', 0.99);
				$('#video').empty().flash({
					src: '/prepair/video_testim.swf',
					width: 448,
					height: 284,
					wmode: 'opaque'
				},
				{version: 8}
				);
			} else {
			}
		});
	});
	// proven pix
	$('#mapClog area').each(function(i) {
		$(this).hover(function() {
			num = $(this).attr('class');
			prepImage(g_clog, 'clog', num);
			
		}, function() {
			hideImage();
		});
	});
	$('#mapFlip area').each(function(i) {
		$(this).hover(function() {
			num = $(this).attr('class');
			prepImage(g_flip, 'flip', num);
		}, function() {
			hideImage();
		});
	});
	$('#mapSlide area').each(function(i) {
		$(this).hover(function() {
			num = $(this).attr('class');
			prepImage(g_slide, 'slide', num);
		}, function() {
			hideImage();
		});
	});
	
	$('#controls li.c1 a').click(function() {
		if ($(this).hasClass('active')) {
			
		} else {
			$('#provenPix div.active').fadeOut('fast', function() {
				$(this).removeClass('active');
				$('#controls li a.active').removeClass('active');
			});
			$('#clog').fadeIn('fast', function() {
				$(this).addClass('active');
				$('#controls li.c1 a').addClass('active');
			});
		}
	});
	
	$('#controls li.c2 a').click(function() {
		if ($(this).hasClass('active')) {
			
		} else {
			$('#provenPix div.active').fadeOut('fast', function() {
				$(this).removeClass('active');
				$('#controls li a.active').removeClass('active');
			});
			$('#flip').fadeIn('fast', function() {
				$(this).addClass('active');
				$('#controls li.c2 a').addClass('active');
			});
		}
	});
	
	$('#controls li.c3 a').click(function() {
		if ($(this).hasClass('active')) {
			
		} else {
			$('#provenPix div.active').fadeOut('fast', function() {
				$(this).removeClass('active');
				$('#controls li a.active').removeClass('active');
			});
			$('#slide').fadeIn('fast', function() {
				$(this).addClass('active');
				$('#controls li.c3 a').addClass('active');
			});
		}
	});
	
	$('map *').tooltip({
		delay: 0,
		track: true,
		showURL: false,
		fixPNG: true,
		top: 0,
		left: 20
		/*bodyHandler: function() {
			c = 'Size ';
			c = c + $(this).siblings('span').text();
			c = c + ' is currently out of stock. You can get an email notice when it becomes available - just select this size and fill in your email address.';
			return c; 
    }*/
	});

});

function prepImage(array,prod,num) {
	g_prod = prod;
	target = '#' + prod;
	$('<img>').appendTo(target).attr('src', array[num]).addClass('layer');
	$(target + ' img.layer').onImagesLoad({
		itemCallback: showImage
	});
}

function showImage() {
	$('#' + g_prod + ' img.layer').fadeIn('fast');
}

function hideImage() {
	$('#' + g_prod + ' img.layer').fadeOut('fast', function() { $(this).remove(); });
}