$(document).ready(function(){

	// Country Home Page Market Lists
	var columnCountMarkets = $('.mhMarketList').length;
	var marketTallestCol = 0;

	for(var i = 0; i < columnCountMarkets; i++)
	{
		var marketDivUsed = $('.mhMarketList')[i];
		var marketDivHeight = jQuery(marketDivUsed).height();

		if(marketDivHeight != "NaN")
		{
			if(marketDivHeight > marketTallestCol)
			{
				marketTallestCol = marketDivHeight;
			}
		}
	}
	jQuery($('.mhMarketList')).css("height",marketTallestCol);

	// About Gojo UL
	$('#aboutGojo li:even').css("margin-right", "65px");

	var abgj = 1

	$('#aboutGojo li').each(function(){
		$('#aboutGojo li').eq(abgj).after('<div class="clear"></div>');

		abgj = abgj + 2;
	});

	// News Center
	var nc = 1;

	$('.gojonewsresources li').each(function(){
		$('.gojonewsresources li').eq(nc).after('<div class="clear"></div>');
		nc = nc + 2;
	});

	// Job Postings - Generic Table
	$('.jobPostings tr:odd, .genericTable tr:odd').css("background", "#e9f2f6");
	$('.jobPostings tr:even, .genericTable tr:even').css("background", "#fff");

	$('#featureNewsMod h2:last').css("border-bottom", "none");

	$('#gjMainHomeFeatureContainer ul li.last p:last').css("border-bottom", "none");

	$('#gjMainHomeRight p:first').css("margin-top", "30px");
	$('#gjMainHomeRight p:last').css("color", "000");

	$('.mhMarketList:first').css("margin-left", "8px");

	$('#gjHeaderNav li a:first').css("margin-left", "15px");

	var bsmCount = $('.blueSideModTop').length;

	if(bsmCount > 1)
	{
		if(bsmCount > 2 )
		{
			$('.blueSideModTop').html("<img src='/images/layout/blueSideModuleTop2.png' width='234' height='29' />");
			$('.blueSideModBottom').html("<img src='/images/layout/blueSideModuleBottom.png' width='233' height='12' />");
		}

		$('.blueSideModTop:first').css("height", "38px");
		$('.blueSideModTop:first').html("<img src='/images/layout/blueSideModuleTop1.png' width='234' height='38' />");
		$('.blueSideModBottom:first').html("<img src='/images/layout/blueSideModuleBottom.png' width='233' height='12' />");

		$('.blueSideModTop:last').html("<img src='/images/layout/blueSideModuleTop2.png' width='234' height='29' />");
		$('.blueSideModBottom:last').html("<img src='/images/layout/blueSideModuleBottom2.png' width='234' height='26' />");
		$('.blueSideModBottom:last').addClass('blueSideModBottom2');
		$('.blueSideModBottom:last').removeClass('blueSideModBottom');
	}
	else
	{
		$('.blueSideModTop').css("height", "38px");
		$('.blueSideModTop').html("<img src='/images/layout/blueSideModuleTop1.png' width='234' height='38' />");
		$('.blueSideModBottom').html("<img src='/images/layout/blueSideModuleBottom.png' width='233' height='12' />");
	}

	$('ul.productLandingPageUL li:even').css("margin-right", "104px");
	$('ul.productLandingPageUL li:even').css("padding-left", "3px");

	$('ul.marketKnowhowPageUL li:even').css("margin-right", "60px");

	/* Blue Navigation Button*/
	$('a.blueNavButton').each(function(){
		$(this).html("<div><img src='/images/layout/blueNavButtonLeft.png' width='24' height='21' /></div><div class='blueNavButtonMiddle'><span>" + $(this).html() + "</span></div><div><img src='/images/layout/blueNavButtonRight.png' width='24' height='21' /></div>");
	});

	/* Blue Small Button */
	$('a.blueSmallButton').each(function(){
		$(this).html("<div><img src='/images/layout/blueSmallButtonLeft.png' width='5' height='19' /></div><div class='blueSmallButtonMiddle'><span>" + $(this).html() + "</span></div><div><img src='/images/layout/blueSmallButtonRight.png' width='5' height='19' /></div>");
	});

	/* Blue Button */
	$('a.blueButton').each(function(){
		$(this).html("<div><img src='/images/layout/blueButtonLeft.png' width='24' height='25' /></div><div class='blueButtonMiddle'><span>" + $(this).html() + "</span></div><div><img src='/images/layout/blueButtonRight.png' width='24' height='25' /></div>");
	});
	 /*blue Large Button */
	$('a.blueLargeButton').each(function(){
		$(this).html("<div><img src='/images/layout/blueLargeButtonLeft.png' width='19' height='44' /></div><div class='blueLargeButtonMiddle'><span>" + $(this).html() + "</span></div><div><img src='/images/layout/blueLargeButtonRight.png' width='19' height='44' /></div>");
	});

	/* Market Tabs */
	$('#gjTabContainer ul li.active').each(function(){
		$(this).html("<div><img src='/images/layout/activeTab_left.gif' width='13' height='23' /></div><div class='activeTabMiddle'><span>" + $(this).html() + "</span></div><div><img src='/images/layout/activeTab_right.gif' width='13' height='23' /></div>");
	});

	$('#gjTabContainer ul li.nonActive').each(function(){
		var tabText = $(this).html();

		$(this).html("<div><img src='/images/layout/nonActiveTab_left.gif' width='13' height='23' /></div><div class='nonActiveTabMiddle'><span>" + tabText + "</span></div><div><img src='/images/layout/nonActiveTab_right.gif' width='13' height='23' /></div>");

	});

	if( $.browser.msie && $.browser.version < 7){
		$('#gjCompanyNav ul li').each(function(){
			$(this).mouseover(function(){
				$(this).css("background-color", "#004c82");
			});

			$(this).mouseout(function(){
				$(this).css("background-color", "transparent");
			});
		});

		$('#gjMainHomeNav ul li').each(function(){
			$(this).mouseover(function(){
				$(this).css("background-color", "#004c82");
			});

			$(this).mouseout(function(){
				$(this).css("background-color", "transparent");
			});
		});
	}

	$('#gjMainHomeNav ul li').eq(1).removeClass('first');
	$('#gjMainHomeNav ul li').eq(1).addClass('second');
	$('#gjCompanyNav ul li').eq(1).removeClass('first');
	$('#gjCompanyNav ul li').eq(1).addClass('second');

	$('#gjMainHomeNav ul li').click(function(){
		window.location = $(this).find("a").attr("href");return false;
	});

	$('#gjCompanyNav ul li').click(function(){
		window.location = $(this).find("a").attr("href");return false;
	});

	// News links
	$('#pageBottomLinks li').click(function(){
		window.location = $(this).find("a").attr("href");return false;
	});

	// Health Care Tabs
	$('#gjTabContainer ul li').click(function(){
		window.location = $(this).find("a").attr("href");return false;
	});

	$('#gjHeaderLanguageContainer span.change').click(function(){
		$('#gjLanguagePanel').slideToggle();
		$('#gjLanguagePanel li a span').toggle('slow');
	});

	$('#gjLanguageSelector #gjLanguagePanel li:last').css('padding-bottom', '10px');

	// Removes the dotted line from resourceItemContainer
	$('.resourceItemContainer:last').css("border-bottom", "dotted 0px #fff");

	$('.sortNews').click(function() {
		$('p#ajaxImage').css('display', 'block');
		$.ajax({
			type: "GET",
			url: "/newsProcessor.aspx",
			success: function(response) {
				$('#newsResults').html("");
				$('#newsResults').html(response);
			}
		});
	});

	$('#ContentRotator').cycle({
		fx:'scrollUp',
		delay: -1000,
		pause:true,
		height: '154',
		fit:0
	});

	$('#gojoFasciaColumnRight').cycle({
		fx:'fade',
		delay: -900,
		pause:true,
		fit:0
	});

	if($('.resourcePage2').html() != null)
	{
		if($('.resourcePage2').html().length <= 1)
		{
			$('.resourcePage2').css('display', 'none');
		}
	};

	$("sup").each(function () {
		$(this).replaceWith("<span class='supReplace'>" + $(this).text() + "</span>");
	});

	// Dispensing Options
	$(".DispensingOptions tr:even").css("background", "#e9f2f6");

	$('.CPNItem').each(function() {
			$(this).find('.Toggle').click(function(){
				$(this).parent().parent().next().find('.CPNChildItemContainer').slideToggle();
				$(this).toggleClass('Active');
				$(this).parent().next().toggleClass('Close');
				$(this).parent().parent().toggleClass('Strong');
				$(this).parent().next().find('.Exit').toggle();
				$(this).parent().next().find('.ViewProduct').toggle();

				return false;
			});
		}).next().hide();

		$('.CPNItem:even').css('background', '#e9f2f6');

	$(".DispensorRefillDescription").each(function(){
			$(this).children("li:odd").after("<div class='clear'></div>");
			$(this).children("li:even").css("margin-right", "25px");
			$(this).children("li").children(".ProductIcon:odd").css("float", "right");
	});

	$("ul.MarketList").each(function(){
			$(this).children("li:odd").after("<div class='clearfix'></div>");
			$(this).children("li:odd").css("margin-right", "0");
	});

	$(".OnlineDistributor:odd").after("<div class='clearfix'></div>");
	$(".OnlineDistributor:odd").css("float", "right");

	if($(".OnlineDistributor").length < 1)
	{
		$(".OnlineDistributorContainer").css("display", "none");
		$(".Disclaimer").css("padding-bottom", "30px");
	}

});
