$(document).ready(function(){
	// header functionality

if($(".lightboxVideo").size()>0){
			$(".lightboxVideo").css("visibility","visible")
		
		}
		
	var dropMenu = $('.js-dropMenuLink');

	dropMenu.mouseenter(function(){
		$(this).addClass("clicked");

		var activeMenu = $(this).children(".js-dropMenu");
		
		activeMenu.css('display','block');
		
		var ulW = activeMenu.find(".rightBlock ul").width();
		var ulH = activeMenu.find(".rightBlock ul").height();
		activeMenu.width(ulW + 50);
		activeMenu.find('.top').width(ulW + 20);
		activeMenu.find('.leftBar').height(ulH + 14);
		activeMenu.find('.rightBar').height(ulH);
		activeMenu.find('.mid').width(ulW - 54);
	});
	dropMenu.mouseleave(function(){
		$(this).removeClass("clicked");
		$(this).children(".js-dropMenu").css('display','none');	
	});

	var loginTrig = $('#js-login');
	loginTrig.click(function(e){
		e.preventDefault();
		modalTrig($(this).attr('href'));	
	});
	var modalTrig = function(targetLink){
		if(!$('#js-greyout').length){
			var realTarget = targetLink.replace('#', ' #');
			$('body').prepend(greyout).prepend(modal);
			$("#page_header").css("z-index","auto");
			$(".mi-mainMenu").css("z-index","auto");
			$('#js-greyout').fadeIn( 
						'fast',
						function(){
							if (($.browser.msie) && ($.browser.version <= 8))
								this.style.removeAttribute("filter");
							$('#js-modal').fadeIn(
										'fast',
										function(){
											$('#js-modal .mi-body').load(realTarget, function(){modalCallback();} );
										});
						}).css('height' , $(document).height() + 'px' );
			
		}
	}
	var modalCallback = function(){
		$('#js-greyout').addClass('js-modalClose');
		var closeButton = $('.js-modalClose');	
		closeButton.click(function(e){
			e.preventDefault();
			$('#js-modal').fadeOut('fast',function(){$('#js-modal').remove();$(".mi-mainMenu").css("z-index","3");});
			$('#js-greyout').fadeOut('fast', function(){
			if (($.browser.msie) && ($.browser.version <= 8))
				this.style.removeAttribute("filter");
			$('#js-greyout').remove();$("#page_header").css("z-index","3");});
		});
	}
	

	var searchField = $('#js-searchMe');
        searchField.focus(function(){// removes default text on search init.

		if ($(this).attr('value').search("Search...") > 0){
			$(this).attr('value','');
		}

	});

	searchField.focusout(function(){// adds in default search text if field is blank.
		if (!$(this).attr('value').length){
			$(this).attr('value', 'Search...');
		}
	});
	//end header section
	
 	if($('#js-imageMenu').length ){// loads image menu scripts on the homepage
 		$.getScript('/assets/mi/system/js/lazyLoad/mi_imageMenu.js', function(){
 			setTimeout(function(){imageMenuInit();}, 200);
        });        
    }
	
	$(".question_mark a, .question_list a").mouseenter(function(){ 
           var tooltip = $(this).parent().find(".hint_body"); 
            
           $(tooltip).css({ bottom: "-" + (($(tooltip).outerHeight() - $(this).height()) / 2) + "px" }).addClass("show");
      }).mouseout(function() { 
          $(this).parent().find(".hint_body").removeClass("show"); 
      });   
	  $("#zipcode .zip input#submit").click(function() {
         $("ul.driving_select").css('top','32px');

		});
		if ($("div.suggested_tire")[0] && $("div.additional_tire_michelin") [0])
		{
			$("#mainColumn .topSection").css('margin-bottom','0px');
		}
	else
		{
			$("#mainColumn .topSection").css('margin-bottom','50px');
		}
	
	//jq to target margins for #mainContent lists + borders/margins in articles 
//$('.breadCrumb li:not(:last-child)').append('&nbsp;&gt;&nbsp;');
$('.twoGrid li:nth-child(2n+2)').css('margin-right', '0');
$('.threeGrid li:nth-child(3n+3)').css('margin-right', '0');
/*$('.threeGrid li:nth-child(3n+3)').css('margin', '0');
$('#three_column_structure .threeGrid li:nth-child(2n)').css('margin-right', '20px');
$('.threeGrid li:nth-child(2n)').css('margin-right', '0');
$('#three_column_structure .threeGrid li:nth-child(3n+3)').css('margin-right', '20px');
$('.threeCol .threeGrid li:nth-child(2n+2)').css('margin-right', '0');
$('.threeCol .threeGrid li:nth-child(3n+3)').css('margin-right', '20px');*/
$('.fourGrid li:nth-child(4n+4)').css('margin', '0');
$('.fourGrid li:nth-child(4n+1)').css('clear', 'left');
$('.threeGrid li:nth-child(3n+1)').css('clear', 'left');
$('.blog h2').first().css('margin-top', '-4px');
$('.articleDetails .section').first().css({'border-top' : '1px solid #ccc', 'margin-top' : '0px'});
$('.articleDetails .singleSection').first().css({'border-top' : 'none', 'margin-top' : '0px', 'padding-top' : '0px'});
$('.articleList .section').first().css('border-top', '1px solid #ccc');
$('.articleList .section').last().css({'border-bottom' : '1px solid #ccc', 'padding-bottom' : '12px'});
$('.article p').last().css('margin-bottom', '0')
$('.articleDetails .section span.section').css('border-bottom', '1px dotted #ccc');
$('.details .section').css('border-bottom', 'none');
$('.topicContent .section').css('border-bottom', 'none');
$('.topicContent .intro p').first().css('margin-bottom', '20px')
$('.topicContent .section:eq(2) h2').css('margin-bottom', '20px')
$('.details .section').css('border-bottom', 'none');
$('.warrantyOverview .section').last().css('border-bottom', 'none');
$('.singleSection p:last-child').css('margin-bottom', '0')
$('.warrantyOverview .section').first().css({'border-top' : '1px solid #ccc', 'margin-top' : '0'});
$('.threeCol #mainColumn .section').css('border-bottom', 'none');
$('.pagination li:last-child').css('border-right', 'none');
$("#tire-advisor").addClass('js-selected');
$("#tire-selector").css({ "height" : $(".mi-tireSelector ul li:first-child .js-collapse").height() + "px", "display": "block" });
});
