/*global $, isIE6cw, Element */



jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"], {
    random: function(a, i, m, r) {
        if (i == 0) {
            jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
        };
        return i == jQuery.jQueryRandom;
    }
});


function CWCOMMON() {
		
	function disableSubmit(theform) {
		$(theform).children(":submit").attr("disabled", "disabled");
	}
		
	function enableSubmit(theform) {
		$(theform).children(":submit").removeAttr("disabled");
	}

	function attachEvents() {
		$('#cwTopSearch').unbind('submit').submit(function () {				
			disableSubmit(this);
			if ($(this).children("input:text").attr("value").length < 3) {
				alert('Please enter at least 3 characters in the Search For field.');
				$(this).children("input:text").focus();
				enableSubmit(this);
				return false;
			}
		});
		
		$('#txthdrSearchBox').unbind('focus').focus(function () {
			if (this.value === this.defaultValue) {
				this.value = '';
				$(this).css("color", "#000");
			}
		});

		$('.cwNavLiveChat').unbind('click').click(function () {
			this.newWindow = window.open('http://livechat.boldchat.com/aid/142769424466612198/bc.chat?wdid=2326716049170654513&amp;rdid=1127668387570267469&amp;url=' + escape(document.location.href), 'Chat', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480');
			this.newWindow.focus();
			this.newWindow.opener = window;
			return false;				
		});
		
               
			   
			   
		$('#holidayNoticeControl').unbind('click').click(function () {
			var holidayNoticeWrapper = $("#holidayNotice");
			if(holidayNoticeWrapper.hasClass("cwExpanded")) {
				holidayNoticeWrapper.slideUp(500);
				holidayNoticeWrapper.removeClass("cwExpanded");
			} else {
				holidayNoticeWrapper.slideDown(500);
				holidayNoticeWrapper.addClass("cwExpanded");
				//_trackEvent("holidayBanner", "expand", "year", "2010");
			}
			
									
		});
			   
	}
	attachEvents();
	
}


CWCOMMON.prototype.setupProductVideo = function (){
	var videoLinkImage;
		
	videoLinkImage = $(".launchVideoLink img").attr("src");
	videoLinkImage = videoLinkImage.replace(".jpg", "-hover.jpg");
	videoLinkImage = videoLinkImage.replace(".gif", "-hover.gif");
	videoLinkImage = videoLinkImage.replace(".png", "-hover.png");
	videoLinkImage = "url(.." + videoLinkImage + ")"; 
	$(".launchVideoLink").css("background-image", videoLinkImage);
	
	
	player = $f("videoPlayer", "flowplayer/flowplayer.commercial-3.1.3.swf",{ 
		key: '#$1f53ad968bbc3cebe47',
		plugins: {
			controls: {
				buttonOverColor: '#0087C7',
				sliderGradient: 'none',
				volumeSliderColor: '#0087C7',
				volumeSliderGradient: 'none',
				timeBgColor: '#262626',
				buttonColor: '#000000',
				backgroundGradient: 'none',
				bufferGradient: 'none',
				borderRadius: '0px',
				tooltipColor: '#97D5FF',
				tooltipTextColor: '#0087C7',
				sliderColor: '#97D5FF',
				backgroundColor: '#929292',
				progressColor: '#0087C7',
				bufferColor: '#C2E2FF',
				durationColor: '#ffffff',
				progressGradient: 'none',
				timeColor: '#C2E2FF',
				height: 20,
				opacity: 1.0
			}
		},
		clip: { 
			autoPlay: true,
			onBegin: function () { // make play button (re)appear 
				this.getPlugin("play").css({opacity: 1}); 
			}, 
			onFinish: function () { // hide play again button 
				this.getPlugin("play").css({opacity: 0}); 
			}
		}
	});
	
	$("a[rel]").overlay({
		expose: { color: '#000000', opacity: 0.8, closeSpeed: 1000 },
		onBeforeLoad: function() {// when overlay is opened, load our player
			if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) 	{
				document.location.href = player.getClip(0).url.replace(".mov", ".m4v");
			}
			player.load();
		},
		onClose: function() {// when overlay is closed, unload our player
			player.unload();
		}
	});
}

$(document).ready(function () {
	CWCOMMON();
});


