﻿var pagewrap;
var lastwidth;
var wasUsed = false;

document.observe("dom:loaded", function () {
    pagewrap = $('page_shadow').next();
    lastwidth = pagewrap.getWidth();
    resize();
});
window.onresize = resize;

function resize() {
    if (pagewrap.getWidth() < 952 || wasUsed) {
        $$('div.weekly-specials-wrapper').each(function (n) {
            var new_width = parseInt((n.getWidth() / 5) - 20);
            $$('div.item').each(function (i) { i.setStyle({ width: new_width + 'px' }); });
            $$('div.item img').each(function (i) { i.setStyle({ width: new_width + 'px', height: 'auto' }); });
            $$('div.item div.itemMethod').each(function (i) { i.setStyle({ width: $$('img.itemImg')[0].getWidth() + 'px' }); });
            $$('li.rrItem').each(function (i) { i.setStyle({ width: (new_width + 9) + 'px !important' }); });
            $$('div.itemImgWr').each(function (i) { i.setStyle({ height: ($$('img.itemImg')[0].getHeight() + 8) + 'px !important' }); });
            $$('div.itemCustomIcon').each(function (i) {
                i.setStyle({
                    marginLeft: ($$('img.itemImg')[0].getWidth() - 35) + 'px !important',
                    marginTop: ($$('img.itemImg')[0].getHeight() - 47) + 'px !important'
                });
            });
            $$('div.footerBox').each(function (i) {
                i.setStyle({
                    width: parseInt(($$('div.footer-nav')[0].getWidth() / 4) - 42) + 'px !important'
                });
            });

            //X is -35 Y is -47

            //1 of each:
            $$('ul.rrItemsList').each(function (i) {
                i.setStyle({ width: ($$('li.rrItem')[0].getWidth() * 10) + 'px !important' });
                i.setStyle({ height: $$('li.rrItem')[0].getHeight() + 'px !important' });
                i.setStyle({ left: '0px' });
                //i.setStyle({ left: (lastwidth + ((pagewrap.getWidth() - lastwidth) / 2)) + 'px' });
            });
            $$('div.rrClipRegion').each(function (i) {
                i.setStyle({ width: (n.getWidth() - 57) + 'px !important' });
                i.setStyle({ height: $$('li.rrItem')[0].getHeight() + 'px !important' });
            });
            $$('div.rrRelativeWrapper').each(function (i) {
                i.setStyle({ width: (n.getWidth() - 57) + 'px !important' });
                i.setStyle({ height: $$('li.rrItem')[0].getHeight() + 'px !important' });
            });
            $$('div.RadRotator').each(function (i) {
                i.setStyle({ height: $$('li.rrItem')[0].getHeight() + 'px !important' });
            });
        });
        wasUsed = true;
    }
    else
        wasUsed = false;

    var origWidth = 695;
    var origHeight = 317;
    if (pagewrap.getWidth() < 695) {
        var new_width = pagewrap.getWidth();
        var origElem = $$('div.cgslide')[0];
        var origRatio = parseFloat(origHeight) / parseFloat(origWidth);
        $$('div.leader-right').each(function (i) { i.setStyle({ width: (new_width) + 'px !important', height: parseInt(new_width * origRatio) + 'px !important' }); });
        $$('div.cgc-wrapper').each(function (i) { i.setStyle({ width: (new_width) + 'px !important', height: parseInt(new_width * origRatio) + 'px !important' }); });
        $$('div.cgc-content').each(function (i) { i.setStyle({ width: (new_width) + 'px !important', height: parseInt(new_width * origRatio) + 'px !important' }); });
        $$('div.cgslide').each(function (i) { i.setStyle({ width: (new_width) + 'px !important', height: parseInt(new_width * origRatio) + 'px !important' }); });
        $$('div.cgslide img').each(function (i) { i.setStyle({ width: (new_width) + 'px !important', height: parseInt(new_width * origRatio) + 'px !important' }); });
        $$('div.hp-main-wrapper').each(function (i) { i.setStyle({ height: parseInt(new_width * origRatio) + 'px !important' }); });
        if ($('cgc-jumpwrap'))
            $('cgc-jumpwrap').setStyle({ marginTop: (parseInt(new_width * origRatio) - 32) + 'px !important' });
    }
    else {
        var origElem = $$('div.cgslide')[0];
        $$('div.leader-right').each(function (i) { i.setStyle({ width: origWidth + 'px !important', height: origHeight + 'px !important' }); });
        $$('div.cgc-wrapper').each(function (i) { i.setStyle({ width: origWidth + 'px !important', height: origHeight + 'px !important' }); });
        $$('div.cgc-content').each(function (i) { i.setStyle({ width: origWidth + 'px !important', height: origHeight + 'px !important' }); });
        $$('div.cgslide').each(function (i) { i.setStyle({ width: origWidth + 'px !important', height: origHeight + 'px !important' }); });
        $$('div.cgslide img').each(function (i) { i.setStyle({ width: origWidth + 'px !important', height: origHeight + 'px !important' }); });
        $$('div.hp-main-wrapper').each(function (i) { i.setStyle({ height: origHeight + 'px !important' }); });
        if ($('cgc-jumpwrap'))
            $('cgc-jumpwrap').setStyle({ marginTop: (origHeight - 32) + 'px !important' });
    }
}
