/**
 * teppee web site
 *
 *  page move ajax
 *  Load center plugin
 *  Load scrollTo plugin
 *  Load imgpreload plugin
*/
$('head').append('<script type="text/javascript" src="http://n3s.sub.jp/js/ajax/center.js"></script>'+
'<script type="text/javascript" src="http://n3s.sub.jp/js/ajax/jquery.scrollTo.js"></script>'+
'<script type="text/javascript" src="http://n3s.sub.jp/js/ajax/jquery.imgpreload.min.js"></script>');
var pageMoving = {
    /**
     * get main container size
    */
    _getContainerSize : function()
    {
        return {
            width : $('#contentLeft .mainBodyPlaceholder').width(),
            height : $('#contentLeft .mainBodyPlaceholder').height()
        }
    },
    /**
     * get main container position
    */
    _getContainerPosition : function ()
    {
        return $('#contentLeft .mainBodyPlaceholder').position()
    },
    /**
     * set loading layer size and position
    */
    _setLoadingLayer : function()
    {
        var _posi = this._getContainerPosition();
        var _size = this._getContainerSize();

        $('#mainLoading').css({
            left : _posi.left,
            top : _posi.top,
            width : _size.width,
            height : _size.height
        });
        $('#mainLoading img').center();
    },
    /**
     * get HTML and rewrite By Ajax
    */
    load : function(url, callback)
    {
        if(null == this.contentTop) {
            var _ct = $('#contentBody').position();
            if(null == _ct) {
                var _ct = $('#contentBody2').position();
            }
            this.contentTop = _ct.top;
        }
        $.scrollTo(pageMoving.contentTop,260);

        this._setLoadingLayer();
        $('#mainLoading').fadeTo(0,0).show().fadeTo(120,0.85,function() {
            $.ajax({
                url : url,
                type : "get",
                cache : false,
                dataType : "html" ,
                success : function (res) {
                    $('.mainBodyContainer').html(res);
                    if(0 == $('.mainBodyContainer img').length) {
                        $('#mainLoading').fadeTo(120,0,function() {
                            $('#mainLoading').hide();
                            layoutHack.heightFit();
                            layoutHack.contentBG();
                            if($.isFunction(callback)) {
                                callback();
                            }
                        });
                        return;
                    }

                    $('.mainBodyContainer img').imgpreload({all : function() {
                        $('#mainLoading').fadeTo(120,0,function() {
                            $('#mainLoading').hide();
                            layoutHack.heightFit();
                            layoutHack.contentBG();
                            if($.isFunction(setColorBox)) {
                                setColorBox();
                            }
                            if($.isFunction(callback)) {
                                callback();
                            }
                        });
                    }});
                }
            });
        });
    },
    /**
     * content top position
    */
    contentTop : null
}

