﻿$(function() {

    $.fn.tagName = function() {
        return this.get(0).tagName;
    }

    /////right align should be for all adv label on the page
    $(".content").find(".advertisment").css( { "text-align": "right" });

    //.MODULE_MARKETINGADBLOCK
    divs = $(".Zone5 .Module .content").find("div");
    for (var i = 0; i < divs.length; i++) {
        $(divs[i]).addClass("inner_" + i).css({ "float": "left" });
        if ($(divs[i]).next() != null && $(divs[i]).next().length > 0 && $(divs[i]).next().tagName() == "BR") {
            $(divs[i]).next().next().addClass("inner_" + i).css({ "float": "left" });
            i++;
        }
    }

    for (var j = 0; j < divs.length; j++) {
        $(".inner_" + j).wrapAll('<div class="test_ads" />');
    }

    totalWidth = 0;
    imgsDiv = $(".Module.MODULE_MARKETINGADBLOCK .content").find(".test_ads").has("img");

    $(".Module.MODULE_MARKETINGADBLOCK .content").find('br').remove();


    for (var k = 0; k < imgsDiv.length; k++) {
        img = $(imgsDiv[k]).find("img");

        height = img.height();
        width = img.width();
        $(imgsDiv[k]).css({ "height": +15 + height + "px", "width": width + "px" });

        innerDivs = $(imgsDiv[k]).find("div");
        innerDivs.each(function(index, el) {
            $(el).css({ "width": width + "px", "text-align": "right", "vertical-align": "top" });
        })
        totalWidth += width;
    }

    totalAdds = imgsDiv.length;
    contentWidth = $("#Zone5").outerWidth();
    spaceSpare = contentWidth - totalWidth;

  

    imgsDiv.each(function(index, el) {
        $(el).css({ "display": "inline", "float": "left", "text-align": "center", "margin": "0px 2px" })
        if (index != totalAdds - 1) {
            $(el).css({ "margin-right": (spaceSpare / (totalAdds - 1)) - 7 + "px" });
        }
    })

    $(imgsDiv[0]).parent().find(".advertisment").each(function(index, el) {
        $(el).css({ "margin-top": "-2px" });
    })

    brs = $("#mycarousel").find("br");
    brs.remove();


    //for side adds

    sideadds = $(".MODULE_ADROTATOR .content").find("div");
    for (var i = 0; i < sideadds.length; i++) {

       // $(sideadds[i]).addClass("side_" + i).css({ "float": "left" });
        if ($(sideadds[i]).next() != null &&
                        $(sideadds[i]).next().length > 0 &&
                        $(sideadds[i]).next().hasClass("advertisment")) {
            $(sideadds[i]).next().addClass("side_" + i).css({ "float": "left" });
            i++;

        }
    }

    for (var j = 0; j < sideadds.length; j++) {
        $(".side_" + j).wrapAll('<div class="side_ads" />');
    }

    addsDiv = $(".content").find(".side_ads").has("img");

    for (var k = 0; k < addsDiv.length; k++) {

        img = $(addsDiv[k]).find("img");
        height = img.height();
        width = img.width();
        $(addsDiv[k]).css({ "height": +15 + height + "px", "width": width + "px" });

        innerDivs = $(addsDiv[k]).find("div");
        innerDivs.each(function(index, el) {
            $(el).css({ "width": width + "px", "text-align": "right", "vertical-align": "top" });
        });
    }

    addsFlash = $(".content").find(".side_ads").has("object");
    for (var f = 0; f < addsFlash.length; f++) {

        obj = $(addsFlash[f]).find("div").has("object");
        if (obj) {
            wflash = $(addsFlash[f]).find("object").attr("width");
            adv = $(addsFlash[f]).find("div").hasClass("advertisment");
            if (adv) {
                advFlash = $(addsFlash[f]).find(".advertisment");
                advFlash.css({ "width": wflash + "px", "text-align": "right" });
            }

        }
    }

    //end side adds

});


