function closeMenu() {
	$('#findFast:visible').slideUp();
	clearTimeout(x);
}

$(function() {
	if ($.browser.msie) {
            $('#findFast').css({'margin-left':'-0px'});
         	$('#timelinePlacement').css({'margin-left':'-20px'});
     if ($.browser.version < 7)
     {
     	$('#sponsorsHeader h4').css({'margin-bottom':'6px'});
     	$('.moreInfo').css({'background-image':'url(images/popup.gif)'});
     	$('.sectionalHeader').css({'border-left':'1px solid #F0F0E8'});
     	$('.sectionalHeader').css({'border-top':'1px solid #F0F0E8'});
     	$('.sectionalHeader').css({'border-right':'1px solid #F0F0E8'});
     	$('.sportsResult').css({'padding':'0px 3% 40px 0px'});
      	$('#timelinePlacement').css({'margin-left':'-10px'});
      	$('#splashinner').css({'position':'absolute'});
    }
    $('#sponsorContent img').css({'position':'relative', 'top':'6px'});
	}
	$('#allSports li').hover(
				function() {
				var offset = $(this).offset();
				var new_top = offset.top - 35;
				var new_left = offset.left - 262;
				var x = $(this).children('.moreInfo').html();
							$('#popup').css({'display': 'block',
																'top': new_top,
															'left': new_left});
				$('#popup').html(x);
				}
				,
				function() {
					
				});
	$('#popup').mouseover(function() {
		$('#popup').show();
	});
	$('#popup').mouseout(function() {
		$('#popup').hide();
	});
	$('#allSports').mouseover(function() {
		$('#popup').show();
	});
	$('#allSports').mouseout(function() {
		$('#popup').hide();
	});
	
	$('#findbut img').click(function () {
		$('#findFast').slideDown();
		x = setTimeout("closeMenu()", 10000);
		$("body").unbind("click");
	});

	
	$('#buttonReplacement').click(function () {
		$('#findFast').slideUp();
	});
	
	$('#findFast').mouseout(function() {
		$("body").bind("click", function()
		{
			$('#findFast:visible').slideUp();
			$("body").unbind("click");
		});
	});
	$('#findFast').mouseover(function() {
		$("body").unbind("click");
	});
	
	
	$('#searchBox input').click(function() {
	if ($('#searchBox input').val() == 'Search Special Olympics')
       {
           //$('#searchBox input').val('');
       }
    });
    $('#searchBox input').blur(function() {
	if ($('#searchBox input').val() == '')
       {
           //$('#searchBox input').val('Search Special Olympics');
       }
    });
    
    $('#searchBox input').bind("keypress", function(e) {
  		if (e.keyCode == 13) {
 //really quick sorry
         javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("searchGo", "", false, "", "Search.aspx", false, true))  		  }
  		});

  	/* Links */

  		$('.specialSectional .thirdMedia:eq(2)').css({ 'margin-right': '0px' });
  		$('.specialSectional .thirdMedia:eq(5)').css({ 'margin-right': '0px' });
  		$('.specialSectional .thirdMedia:eq(8)').css({ 'margin-right': '0px' });

  	$('#newsLetter').click(function() {
	    $('#splash').show();
	    $('#splashinner').show();
//	    document.cookie='subscribeSplash=Opened;path=/;expires=Thu, 01-Jan-2030 00:00:01 GMT; host=www.specialolympics.org;';
	    $('#videoBox').hide();
  	});
  	$('#pledge_box .close').click(function() {
	    $('#splash').hide();
	    $('#splashinner').hide();
	    document.cookie='subscribeSplash=Filled;path=/;expires=Thu, 01-Jan-2030 00:00:01 GMT; host=www.specialolympics.org;';
	    $('#videoBox').show();
  	});

  	$('#mediaBack').click(function() {
  		history.back();
  	});
  	$('#help').click(function() {
  		//window.location.href = "/";
  	});
  	$('#get').click(function() {
  		//window.location.href = "/";
  	});
  	$('#FandM .FMphoto').click(function() {
  		//window.location.href = "/";
  	});
  	$('#FandM .FMvideo').click(function() {
  		//window.location.href = "/";
  	});

  	$('#World').click(function() {
  		//window.location.href = "/slideshow_neglect.aspx";
  	});
  	
  	 $('#BeAFan').click(function() {
  	 //window.open('https://ssl.charityweb.net/specialolympics/')
  	});
  	  	$('#BeAFan2').click(function() {
  	 //window.open('https://ssl.charityweb.net/specialolympics/')
  	});
  	/*var savedFontSize = readCookie('soifontsize');
  	var originalFontSize = $('html').css('font-size');
    if (savedFontSize != null)
    {
    	$('html').css({'font-size': savedFontSize + 'px;'});
    }
    $(".resetFont").click(function(){
    $('html').css('font-size', originalFontSize);
  }); */
  // Increase Font Size
  $(".increaseFont").click(function(){
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum + 2;    
    $('html').css('font-size', newFontSize);
    createCookie('soifontsize', newFontSize, 365);
  	return false;   
  });
  // Decrease Font Size
  $(".decreaseFont").click(function(){
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum - 2;
    if (newFontSize < 10)
    {
    	newFontSize = 10;
    }
    $('html').css('font-size', newFontSize);
    createCookie('soifontsize', newFontSize, 365);
    return false;
  });


    /* new nav js */

    $("#newNav ul li:last-child").addClass('lastNavLi');
    $("#newNav ul li ul li:last-child").addClass('lastLi').after("<li class='footerLi'><img src='/images/nav/navPulldownFooter_193w.png' border='0' /></li>");

    $("#newNav ul .navLi").append("<img style='position:absolute; left:-1px; z-index:502;' src='/images/nav/vertical_50h.gif' border='0' />");
    $("#newNav ul .navLi:eq(4)").append("<img style='position:absolute; right:-1px; z-index:502;' src='/images/nav/vertical_50h.gif' border='0' />");

//    $("#newNav .navLi a .selected").parent('a').addClass('selectedA');
    $("#newNav .navLi a .selected").parent('a').parent('li').removeClass('navLi').addClass('selectedLi');


    $('.navLi').hover(
        function() {
            $(this).addClass("overLi");
            $(this).children('ul').show();
            $(this).find(".navLiImg").attr("src", $(this).find(".navLiImg").attr("src").split("_off.").join("_on."));
        },
        function() {
            $(this).removeClass("overLi");
            $(this).children('ul').hide();  
            $(this).find(".navLiImg").attr("src", $(this).find(".navLiImg").attr("src").split("_on.").join("_off."));
    });
    
    
    
    $('.selectedLi').hover(
        function() {
            $(this).addClass("overLi");
            $(this).children('ul').show();
            $(this).find(".selected").attr("src", $(this).find(".selected").attr("src").split("_selected.").join("_on."));
        },
        function() {
            $(this).removeClass("overLi");
            $(this).children('ul').hide();  
            $(this).find(".selected").attr("src", $(this).find(".selected").attr("src").split("_on.").join("_selected."));
    });

    /* end new nav js */

    /* at one point will work with backend */
    $("#slides li:eq(0)").attr("onmouseover","javascript:pageTracker._trackEvent('Lead', 'clicked', 'dl01');");
    $("#slides li:eq(1)").attr("onmouseover","javascript:pageTracker._trackEvent('Lead', 'clicked', 'dl02');");
    $("#slides li:eq(2)").attr("onmouseover","javascript:pageTracker._trackEvent('Lead', 'clicked', 'dl03');");
    $("#slides li:eq(3)").attr("onmouseover","javascript:pageTracker._trackEvent('Lead', 'clicked', 'dl04');");
    $("#slides li:eq(4)").attr("onmouseover","javascript:pageTracker._trackEvent('Lead', 'clicked', 'dl05');");
    $("#slides li:eq(5)").attr("onmouseover","javascript:pageTracker._trackEvent('Lead', 'clicked', 'dl06');");

});


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


