ie9 = (navigator.userAgent.indexOf( 'MSIE 9' ) !== -1);
jQuery(document).ready(function(){
	if (ie9)
		checkImages();		
});

/* If images are disabled*/
function checkImages(){
	if (!IsImageOk(document.getElementById("imagetest"))){
		var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
		
		/* Top Navigation */
		if (jQuery('#home_page').length){
			jQuery('#home_page').append('<div id="Header">'+
				'<h2>ONE A DAY: More of what matters to you</h2>'+
				'<a href="index.html" class="logo"><b>ONE-A-DAY</b></a>'+
				'<a class="buyonline" href="buyonline.html"><span>BUY ONLINE</span></a>'+
				'<ul class="subnav">'+
					'<li><a class="contact_us" href="contactus.html"><span>CONTACT US</span></a></li>'+
					'<li><a class="sitemap" href="sitemap.html"><span>SITEMAP</span></a></li>'+
				'</ul>'+
				'<div id="navigation">'+
					'<a href="index.html" class="link1">home</a>'+
					'<img src="img/line.gif" />'+
					'<a href="products.html" class="link2">Products</a>'+
					'<img src="img/line.gif" />'+
					'<a href="whats_your_oad.html" id="whatsyour"><span>what\'s your one a day?</span></a>'+
					'<img src="img/line.gif" />'+
					'<a href="faqs.html" class="link3">faqs</a>'+
					'<img src="img/line.gif" />'+
					'<a href="healthwellness.html" class="link4">health &amp; wellness</a>'+
					'<img src="img/line.gif" />'+
					'<a href="kids/index.html" target="_blank" class="link5">kids multivitamins</a>'+
				'</div>'+
			  '</div>');
			jQuery('#navigation').css('z-index','0');
			jQuery('#flashcontent').css({'position':'absolute','z-index':'10000001'});
		}
		if (isIE6){
				jQuery('#navigation').css('top','50px');
		}
		
		//add general css rules
		jQuery('#navigation a, #navigation a span, #Header a, #Header .buyonline span, #Header .subnav a span, #Header .subnav, #Header .subnav a.contact_us, #Header a b, #BayerLinks li.popuplinks a span,#Footer .Copyright span, .footer .copy span, #navigation #whatsyour, #BayerLinks').addClass('images_disabled');
		
		/*finish top nav*/
		jQuery('#navigation img').remove();
		jQuery('#Header').append('<p class="tagline_images_disabled">More of What Matters to You</p>');
		jQuery('#Header').append('<p class="bayer_cross_images_disabled">Bayer Healthcare</p>');
		
		//remove footer image
		jQuery('#Footer .Copyright, .footer .copy').css("background-image","none");
		//remove footer image separators
		jQuery('#Footer img, #home_page .footer img').remove();
		
		//replace product imgs with spans
		jQuery('.WomenExpanded img').each(function(){
			var altText = jQuery(this).attr("alt");
			jQuery(this).replaceWith("<span>"+altText+"</span>");
		});
		//fix spacing
		jQuery('.WomenExpanded a').after('<br /><br />');
		jQuery('.LifeStyle .space2').removeClass('space2');
		//webkit product buttons
		if (window.devicePixelRatio){
			jQuery('.#ProductsButtons img').each(function(){
				var altText = jQuery(this).attr("alt");
				jQuery(this).replaceWith("<span>"+altText+"</span>");
			});
		}
		
		//vitacraves buttons alt text
		jQuery("#vitacraves_landing .hide_text, #vitacraves_immunity .hide_text, .vitacraves_buttons").addClass("font_size_boost");
		jQuery(".hide_text").removeClass("hide_text");
		jQuery('.vitacraves_buttons img').each(function(){
				var altText = jQuery(this).attr("alt");
				jQuery(this).replaceWith("<span>"+altText+"</span>");
			});
		jQuery(".vitacraves_buttons li").addClass("give_width");
		
		//vitacraves fixes
		jQuery(".content .textpart.bg_vitacraves_1dollar, .content .textpart.bg_vitacraves_landing, #vitacraves_immunity .content .textpart.bg_vitacraves_1dollar").css("background-image","none");
		if (window.devicePixelRatio){
			jQuery(".subcontent.subcont_vitacraves .girl_btn img").each(function(){
				var altText = jQuery(this).attr("alt");
				jQuery(this).replaceWith("<span>"+altText+"</span>");
			});
		}
		jQuery(".content .textpart .facebook_link img").each(function(){
			var altText = jQuery(this).attr("alt");
			jQuery(this).replaceWith("<span>"+altText+"</span>");
		});
		
		//show headlines
		jQuery(".content .products_main h2 span").addClass("show_text");
		
		//add products content
		if (jQuery("#vitacraves_gummies").length){
			var buy_product = '<p>Buy This Product Now!</p>';
			if (jQuery("#vitacraves_gummies").length)
				buy_product = '<p>Buy These Products Now!</p>';
			if (jQuery("#retailers_dropdown").length){
				jQuery(".products_main").prepend('<div style="position: absolute; top:100px; left:20px; width: 160px;">'+
										buy_product+							
										jQuery("#retailers_dropdown").html()+
										'</div>');
			}
		}
		
		//spacing fix
		jQuery("#vitacraves_landing .content.cont_vitacraves .textpart h2").addClass('space_bottom');
		
		//hide bg images
		jQuery('.content .products_main h2').css("background-image","none");
		if (window.devicePixelRatio){
			//webkit
			jQuery('.contentarea .content h1 img').each(function(){
				var altText = jQuery(this).attr("alt");
				jQuery(this).replaceWith("<span>"+altText+"</span>");
			});
		}
		
	}
}

function IsImageOk(img) {
	if (!img.complete) {
        return false;
    }

    //These give the true size of the image. If it failed
    // to load, either of these should be zero.
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }

    // No other way of checking: assume it's ok.
    return true;
}

jQuery(window).load(function(){
	if (!ie9){//new src doesn't work w/ webkit
		if (!window.devicePixelRatio)
			jQuery("#imagetest").attr("src","img/1x1.gif?"+Math.random());
		checkImages();
	}
});
