(function(){
    Eturas = function() {};
    Eturas.resizeURL = document.referrer;
    Eturas.parentWindow = (window.parent && window.parent.length);
    Eturas.updateIframeHeight_repeat = false;
    Eturas.updateIframeHeight_off = false;

    Eturas.updateIframeHeight = function(repeat){
        if(!Eturas.parentWindow) return;
        if(Eturas.updateIframeHeight_off) return;
        if(jQuery('div#main').length && Eturas.parentWindow) {
            newHeight = jQuery('div#main').height()+8;
            $.postmessage({
                target: window.parent,
                type: 'new_resize',
                data: {height:""+newHeight+"", windowName:window.name, windowLocation:window.location.href.replace(window.location.hash,''), hash: window.location.hash.substring(1)},
                url: Eturas.resizeURL,
                success: function(data) {
//                    if(!Eturas.updateIframeHeight_repeat){
                        jQuery('body').attr('setHeight',newHeight);
                        newHeight_2 = jQuery('div#main').height();
                        Eturas.updateIframeHeight_repeat = true;
//                        setTimeout("Eturas.updateIframeHeight(1);",100);
//                    }else{
//                        jQuery('body').attr('setHeight_2',newHeight);
//                        Eturas.updateIframeHeight_repeat = false;
//                    }
                }
            });
            if(!repeat)setTimeout("Eturas.updateIframeHeight(1);",200);
        }
    };
    Eturas.pageToTop = function(){
        if(Eturas.parentWindow){
            $.postmessage({
                target: window.parent,
                type: 'top',
                data: {hash: window.location.hash.substring(1), windowName:window.name},
                success: function(data){},
                url: Eturas.resizeURL
            });
        }else{
            window.scroll(0,0);
        }
    };

    Eturas.pageToiFrameTop = function(tP, wName){
        if(Eturas.parentWindow){
            if(typeof wName == 'undefined') wName = window.name;
            $.postmessage({
                target: window.parent,
                type: 'iframeTop',
                data: {hash: window.location.hash.substring(1), windowName:wName, topPlius: tP},
                success: function(data){},
                url: Eturas.resizeURL
            });
        }else{
            window.scroll(0,tP);
        }
    };

    Eturas.callCustomScript = function(script_url){
        if(Eturas.parentWindow){
            if(typeof wName == 'undefined') wName = window.name;
            $.postmessage({
                target: window.parent,
                type: 'callCustomScript',
                data: {hash: window.location.hash.substring(1), windowName:wName, script_url: script_url},
                success: function(data){},
                url: Eturas.resizeURL
            });
        }
    };
    $(document).ready(function(){
        Eturas.updateIframeHeight();
    });
})(window);

