﻿$(function () {
    wa.contentBlocks.init();
});
/*--- CONTENT BLOCK INIT ---*/
(function (wa, $) {
    wa.contentBlocks = {};
    wa.contentBlocks.init = function () {
        var c = wa.cookieJar.get('isLiveEdit');
        if (c === 'false') {
            $('body').removeClass('editOn');
        }
        else {
            $('body').addClass('editOn')
        }

        $('a#toggleEdit').click(function () {
            var c = wa.cookieJar.get('isLiveEdit');

            if ($('body').attr('class') == 'editOn') {
                wa.cookieJar.set('isLiveEdit', '', -1);
                wa.cookieJar.set('isLiveEdit', 'false', 100);
            }
            else {
                wa.cookieJar.set('isLiveEdit', '', -1);
                wa.cookieJar.set('isLiveEdit', 'true', 100);
            }
            $('body').toggleClass('editOn');
            return false;
        });

        if (wa.common.elementExists('.contentBlock')) {
            $('.contentBlock').each(function () {
                $pan = $(this);
                pos = $pan.offset();

                curtop = pos.top.toString();
                curleft = pos.left.toString();
                curheight = $pan.height();
                curwidth = $pan.width();
                currel = $pan.attr('rel');

                if (curwidth == '0' && curheight == '') {
                    curwidth = $pan.parent().width() + 'px';
                    curheight = '10';
                }
                else {
                    curwidth = curwidth + 'px';
                }
                editBlock = '<div rel="' + currel + '" class="editableContent" style="height:' + curheight + 'px; width:' + curwidth + '; top:' + curtop + 'px; left:' + curleft + 'px">&nbsp;</div>';
                $('body').append(editBlock);

                if ($pan.parent().is(':hidden')) {
                    $('.editableContent').eq($pan.index('.contentBlock')).css('top', '-9999px');
                    $pan.mouseover(function () {
                        t = $(this);
                        newPos = t.offset();
                        newHeight = t.height();
                        var div = $('.editableContent').eq(t.index('.contentBlock'));
                        div.attr('style', 'height:' + newHeight + 'px; width:' + curwidth + '; top:' + newPos.top + 'px; left:' + newPos.left + 'px');
                    });
                    var actionDiv = $('.editableContent').eq($pan.index('.contentBlock'));
                    actionDiv.mouseout(function () {
                        $(this).css('top', '-9999px');
                    });
                }

            });
        }
    };
} (window.wa = window.wa || {}, jQuery));
