$(function(){
	
	$('document').resize(function(){
		var wheight = $('html').height()+'px';
		var wwidth = $('html').width()+'px';
		$('.shadow').toggle().css({'height':wheight, 'width':wwidth});
	});
	
	$('input:submit').click(function(){
		if ( $('#agree').length > 0){
			if( $('#agree').attr('checked') != 'checked'  ){
				return false;
			}
		}
	});
	
	$('.video').click(function(){
		toggleLightbox();

		//This is jQuery's way of detecting browsers, it returns false in IE6-IE8
		if ( !$.support.leadingWhitespace ){
			var flash = '<object width="640" height="368" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" style="visibility: visible;"><param name="wmode" value="transparent"/><param name="flashvars" value="videoUrl=http://progressiveintltesting.com/video/SuperSpeedway.flv"/><param name="movie" value="http://progressiveintltesting.com/video/video.swf"/></object>';
			$('#flashContent').html(flash);
		}
	});
	$('.shadow').click(function(){
		toggleLightbox();
		if ( $.support.leadingWhitespace ){
			document.getElementById('player').pause();
		}
		$('#flashContent').empty();
	});
	
	function toggleLightbox(){
		var wheight = $('html').height()+'px';
		var wwidth = $('html').width()+'px';
		$('.videoHolder').toggle();
		$('.shadow').toggle().css({'opacity':'0.92', 'height':wheight, 'width':wwidth});
		return false;
	}

	$('.nav li ul li:first-child').find('a').css('padding-top','11px');
	
	$('#search_btn').click(function(){
		$('#simplesearch').submit();
		return false;
	});
	var dv = "Search";
	
	$('#keywords').focus(function(){
		if ($(this).val() == dv) $(this).val('');
	});
	$('#keywords').blur(function(){
		if ($(this).val() == '') $(this).val(dv);
	});
	
	
	//INI PRODUCT SLIDESHOW
	var currImg = 0;
	
	$('.main_image li').css('z-index',1);
	$('.main_image li').eq(0).css({'visibility':'visible'});
	$('.main_image li').hide().eq(0).css('z-index',2).fadeIn(1000);
	$('.main_image li').css({'visibility':'visible'});

	$('.thumbs li').click(function(){
		if( !$(this).hasClass('video') ){
			var ind = $('.thumbs li').index($(this));
			if(currImg != ind){
				$('.main_image li').css('z-index',1);
				$('.main_image li').hide().eq(ind).css('z-index',2).fadeIn();
				currImg = ind;
			}
			return false;
		}
		
	});
	

$('#submission').click(function(){
	if( $('#agree').attr('checked') == false ){
		alert('Please check that you have read and agree to the terms and conditions');
		return false;
	}else{
	
		document.getElementById('tester_form').submit();
	}
});

	
	$('.outline').live('mouseover', function(){
		$(this).parent().siblings('.desc').css('z-index',2000).stop().fadeTo(300, 1);
	});
	
	$('.highlight').live('mouseleave', function(){
		$(this).children('.desc').stop().css('z-index',500).delay(125).fadeTo(500, 0);
	});

	$('.product a').hover(function(){
		$(this).children('p').addClass('on');
	},function(){
		$(this).children('p').removeClass('on');
	});
	
	$('.related_items a').hover(function(){
		$(this).children('p').addClass('on');
	},function(){
		$(this).children('p').removeClass('on');
	});
	
	
}); /*End Doc.ready*/
