﻿// 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");
            
            $(this).children('div.tl, div.tr').css({'top' : '-' + topOffset});
            $(this).children('div.tr, div.br').css({'right' : '-' + rightOffset});
            $(this).children('div.bl, div.br').css({'bottom' : '-' + bottomOffset});
            $(this).children('div.tl, div.bl').css({'left' : '-' + leftOffset});
        }
    });
    
    if (IE6) {
        $('.corners').each (function(){
            fixCorners($(this));
        });
    }
    
    /* Keep Content and Right Col the same height on the home page */
    /*if($('#home').size() > 0){
        var contentHeight = $('#leftWrap').innerHeight();
        var rightColHeight = $('#rightCol').innerHeight();
        alert (contentHeight + ", " + rightColHeight);
        if (contentHeight > rightColHeight) {
            $('#rightCol').height(contentHeight + "px");
        } else if (contentHeight < rightColHeight) {
            $('#leftWrap').height(rightColHeight + "px");
        }
    }*/
});

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");
    }
}