$(document).ready(function() {
	if ($.browser.msie && $.browser.version == "6.0") {
	}else{
		hideBar();
	};
	dropDown();
	
	$(".accordion").tabs(".accordion div.pane", {tabs: 'h4', effect: 'slide', initialIndex: -1});
	
	$("#customerSupport").validate();
	
	$("a.checkCoverage2").fancybox();
	$("a.checkCoverage").fancybox();
	$("a.checkCoverage_nv").fancybox();
	
	function check(button) {
		if (button.checked)
		button.checked=false
	}

});

//CREATES NEW WINDOW FOR EXTERNAL LINKS
$(function(){
    $('a.new-window').click(function(){
    window.open(this.href);
    return false;
    });
});

$(function() {
	$(".hearing-aid tr:odd").addClass("odd");
});


//HIDES STICKY EVENT/SOCIAL BAR
function hideBar() {
	$("div.minimize").click(function () {
      	$("div.top_bottom_border, div#choiceBar_wrapper").animate({ 
        	width: "0",
			height: "31",
			opacity: 0,
        	marginLeft: "0"
      		}, 200 );
    	}).click(function callback() {
  			$('div.maximize').removeClass('closed').addClass('open');
			$('div.minimize').removeClass('open').addClass('closed');
		});
		$("div.maximize").click(function () {
      	$("div.top_bottom_border").animate({ 
        	width: "995",
			height: "31",
        	opacity: 1,
        	marginLeft: "0"
      		}, 200 );
    	}).click(function callback() {
  			$('div.minimize').removeClass('closed').addClass('open');
			$('div.maximize').removeClass('open').addClass('closed');
		});
		$("div.maximize").click(function () {
      	$("div#choiceBar_wrapper").animate({ 
        	width: "100%",
			height: "31",
        	opacity: 1,
        	marginLeft: "0"
      		}, 200 );
    	}).click(function callback() {
  			$('div.minimize').removeClass('closed').addClass('open');
			$('div.maximize').removeClass('open').addClass('closed');
	});
}
//DROPDOWN MAIN NAV
function dropDown(){
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}

	var config = {    
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 0, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 10, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#mainNav li div.sub, ul#mainNav_nv li div.sub").css({'opacity':'0'});
	$("ul#mainNav li, ul#mainNav_nv li").hoverIntent(config);
}

