﻿// IE6 only - adjust the position of bottom and right corners if the
// height / width of the div so it is an odd number
// This solves the problem with incorrectly positioned corners at the
// bottom of divs with height:auto

$(document).ready(function() {
    $('div.corners').each(function() {
        if ($(this).children('div.corner').size() == 0) {
            $(this).wrapInner($('<div class="boxContent"></div>'));
            $(this).prepend($('<div class="tl corner"></div><div class="tr corner"></div><div class="bl corner"></div><div class="br corner"></div>'));

            var topOffset = $(this).css("border-top-width");
            var rightOffset = $(this).css("border-right-width");
            var bottomOffset = $(this).css("border-bottom-width");
            var leftOffset = $(this).css("border-left-width");

            if (parseInt(topOffset) > 0) { $(this).children('div.tl, div.tr').css({ 'top': '-' + topOffset }); }
            if (parseInt(rightOffset) > 0) { $(this).children('div.tr, div.br').css({ 'right': '-' + rightOffset }); }
            if (parseInt(bottomOffset) > 0) { $(this).children('div.bl, div.br').css({ 'bottom': '-' + bottomOffset }); }
            if (parseInt(leftOffset) > 0) { $(this).children('div.tl, div.bl').css({ 'left': '-' + leftOffset }); }
        }
    });

    $('h2.corners, h1.corners').each(function() {
        if ($(this).children('div.corner').size() == 0) {
            $(this).wrapInner($('<div class="boxContent"></div>'));
            $(this).css("padding", "0");
            $(this).prepend($('<div class="tl corner"></div><div class="tr corner"></div><div class="bl corner"></div><div class="br corner"></div>'));

            var topOffset = $(this).css("border-top-width");
            var rightOffset = $(this).css("border-right-width");
            var bottomOffset = $(this).css("border-bottom-width");
            var leftOffset = $(this).css("border-left-width");

            if (parseInt(topOffset) > 0) { $(this).children('div.tl, div.tr').css({ 'top': '-' + topOffset }); }
            if (parseInt(rightOffset) > 0) { $(this).children('div.tr, div.br').css({ 'right': '-' + rightOffset }); }
            if (parseInt(bottomOffset) > 0) { $(this).children('div.bl, div.br').css({ 'bottom': '-' + bottomOffset }); }
            if (parseInt(leftOffset) > 0) { $(this).children('div.tl, div.bl').css({ 'left': '-' + leftOffset }); }
        }
    });

    if (IE6 == false) {
        /*$('ul#nav-prod > li').each(function() {
            $(this).append($('<span class="tl corner"></span><span class="tr corner"></span><span class="bl corner"></span><span class="br corner"></span>'));

            var topOffset = $(this).css("border-top-width");
            var rightOffset = $(this).css("border-right-width");
            var bottomOffset = $(this).css("border-bottom-width");
            var leftOffset = $(this).css("border-left-width");

            if (parseInt(topOffset) > 0) { $(this).children('span.tl, span.tr').css({ 'top': '-' + topOffset }); }
            if (parseInt(rightOffset) > 0) { $(this).children('span.tr, span.br').css({ 'right': '-' + rightOffset }); }
            if (parseInt(bottomOffset) > 0) { $(this).children('span.bl, span.br').css({ 'bottom': '-' + bottomOffset }); }
            if (parseInt(leftOffset) > 0) { $(this).children('span.tl, span.bl').css({ 'left': '-' + leftOffset }); }
        }).addClass('corners');*/
    }
    if (IE6) {
        $('.corners').each(function() {
            fixCorners($(this));
        });
    }
});

function fixCorners(box){
    if ($(box).innerHeight() % 2 != 0 ) {
        // Get the bottom coordinate of the bottom corners and subtract 1px
        var currentBtm = $(box).find('div.bl').css('bottom');
        $(box).children('div.bl').css('bottom', parseInt(currentBtm)-1+"px"); 
        $(box).children('div.br').css('bottom', parseInt(currentBtm)-1+"px");
    }
    if ($(box).innerWidth() % 2 != 0 ) {
        // Get the bottom coordinate of the bottom corners and subtract 1px
        var currentRight = $(box).find('div.tr').css('right');
        $(box).children('div.tr').css('right', parseInt(currentRight)-1+"px");
        $(box).children('div.br').css('right', parseInt(currentRight)-1+"px");
    }
}