$(document).ready(function() {
    // topNav fix menu items width
    var topNavWidth = 900;
    var topNavAntal = $('#topNav li').not('.last, .search').size();           // Get number of menu items, exept search and last
    var topNavLiSearch = $('#topNav li.search').outerWidth();                 // Get width of search
    var topNavLiLast = $('#topNav li.last').outerWidth();                     // Get width of last
    var topNavLiWidth = Math.floor((topNavWidth - ((topNavLiLast + topNavLiSearch))) / topNavAntal);  // Calculate width of menu items
    var totalWidth = (topNavLiWidth * topNavAntal) + (topNavLiLast + topNavLiSearch);
    $('#topNav li').not('.last, .search').each(function() {
        $(this).width(topNavLiWidth - 1);
    });
    if (totalWidth < topNavWidth) {
        var lastWidth = ($('#topNav li.last').width() + topNavWidth - totalWidth);
        $('#topNav li.last').css('width', lastWidth);
    }

    // Safari fix
    if ($.browser.safari)
        $('#topNav li').not('.search').css('padding', '9px 0 1px');

	//fix
	var obj = $(".page-product_details .title");
	if (obj.length>0) {
		var a = obj.html().replace(/Bayer<br/gi,"<br");
		$(".title").html(a);
	}
	/*
	//fix (lang-image)	
	$(".country-5 img").each(function() { $(this).attr("src", $(this).attr("src").replace("/22-82042483", "/22-5-82042483")); }); //fi
	$(".country-5 a[href]").each(function() { this.href = this.href.replace("/22-82042483", "/22-5-82042483"); }); //fi	
	$(".country-2 img").each(function() { $(this).attr("src", $(this).attr("src").replace("/22-82042467", "/22-2-82042467")); }); //dk
	$(".country-2 a[href]").each(function() { this.href = this.href.replace("/22-82042467", "/22-2-82042467"); }); //dk
	$(".country-3 img").each(function() { $(this).attr("src", $(this).attr("src").replace("/22-82042467", "/22-3-82042467")); }); //no
	$(".country-3 a[href]").each(function() { this.href = this.href.replace("/22-82042467", "/22-3-82042467"); }); //no
	*/
	
	$(".guide a").hover(function() {
		$(this).children('img').attr('src','/partnerfiles/Bayer-Diabetes-Care/images/arrow_right_gray.gif');
	}, function() {
		$(this).children('img').attr('src','/partnerfiles/Bayer-Diabetes-Care/images/arrow_right_blue.gif');
	});
});



$(window).load(function() {
    // LeftNav height fix
    $('#leftNav, #rightContent').equalHeight();
});


$.fn.centerHeight = function() {
    var contentHeight = $('#rightContent').outerHeight();
    var tipBoxheight = $(this).outerHeight();
    var centerBlock = Math.floor(((contentHeight / 2) - (tipBoxheight / 2)));
    return this.each(function() {
        $(this).css('top', centerBlock);
    });
}

// Fix for leftNav height
$.fn.equalHeight = function() {
    var height = 0;
    var maxHeight = 0;

    // Store the tallest element's height
    this.each(function() {
        height = $(this).outerHeight();
        maxHeight = (height > maxHeight) ? height : maxHeight;
    });

    // Set element's min-height to tallest element's height
    return this.each(function() {
        var t = $(this);
        var minHeight = maxHeight - (t.outerHeight() - t.height());
        var property = $.browser.msie && $.browser.version < 7 ? 'height' : 'min-height';
        var minHeight = $.browser.msie && $.browser.version < 7 ? (minHeight - 2) : minHeight;
        t.css(property, minHeight + 'px');
    });
}
