$(document).ready(function() {
	if ($.browser.msie && $.browser.version == "6.0") {
	}else{
		hideBar();
	};
	dropDown();
	stickyAdd();
	$(".accordion").tabs(".accordion div.pane", {tabs: 'h4', effect: 'slide', initialIndex: -1});
	$(".accordion2").tabs(".accordion2 div.pane_open", {tabs: 'h4', effect: 'slide', initialIndex: 0});
		
	$("#customerSupport").validate();
	
	$("a.checkCoverage2").fancybox();
	$("a.checkCoverage").fancybox();
	$("a.checkCoverage_nv").fancybox();
	$("a.popUp").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);
}


var OneEventDomainName = 'vi.choice-wireless.com';
var OneEventCookieName = 'TotallyCubular';
OneEventDocumentPath = '/';
OneEventLifetime = '1';
OneEventSecure = '';

function SetTheCookie() {
   var cookie = OneEventCookieName + "=EventOccurred";
   if(OneEventDomainName.length > 0) { 
      cookie += "; domain=" + OneEventDomainName;
      }
   if(OneEventDocumentPath.length > 0) { 
      cookie += "; path=" + OneEventDocumentPath;
      }
   if(parseInt(OneEventLifetime) > 0) {
      var expiration = new Date();
      expiration.setTime(expiration.getTime() + 
         parseInt(OneEventLifetime) * 24 * 60 * 60 * 1000);
      cookie += "; expires=" + expiration.toGMTString();
      }
   if(OneEventSecure.length > 2) { 
      cookie += "; secure";
      }
   document.cookie = cookie;
}

function CheckForCookie() {
var content = '';
if(document.cookie.length > 0) {
   var name = OneEventCookieName + "=";
   var begin = document.cookie.indexOf(name);
   var end = 0;
   if(begin > -1) {
      begin += name.length;
      end = document.cookie.indexOf(";",begin);
      if(end < begin) {
         end = document.cookie.length;
         }
      content = document.cookie.substring(begin,end);
      }
   }
if(content.length > 0) {
   // To do something when cookie is present, the 
	//     event function name goes here
	//     inserted below or comment lines replaced.

	return true;
	}
else { 
   // To do something when cookie wasn't present, the 
	//     event function name goes here
	//     inserted below or comment lines replaced.

	return false;
	}
}


function stickyAdd() {
    var offset = $("#doneAdding").offset();
    var topPadding = 15;
    $(window).scroll(function() {
        if ($(window).scrollTop() > offset.top) {
            $("#sidebar").stop().animate({
                marginTop: $(window).scrollTop() - offset.top + topPadding
            });
        } else {
            $("#sidebar").stop().animate({
                marginTop: 0
            });
        };
    });
}



