var t9;
var _oldw =800;
var _oldh =178;

var cl = '<a href="javascript:void(0)" id="close9" title="关闭" style="float:right;padding-top:0px;padding-right:5px;"><img src="images/close.gif"/></a>';

$(document).ready(function(){
	
	var pophtml = '<div id="blk9" style="display:none;" class="blk"><div class="head"><div class="head-right"></div></div><div class="main"><div class="NoviceguideHead"><div class="NoviceguideHead_left">优拓建站向导</div></div><div id="popup-body"></div></div><div class="foot"><div class="foot-right"></div></div></div>';
	$(pophtml).appendTo('body');
	
	$("#blk9").css({display:'none',height:'395px'});
	if (INIT_OPEN == 1) {
		$("#blk9").find(".NoviceguideHead").append($(cl));
	}
	
	
	$.ajax({
		type:'get',
		async:false,
		url:'./index.php?r=Init&t='+Math.random(),
		data:{id:1},
		//dataType:'json',
		success:function(data){
			$("#popup-body").empty().append($(data)).css({height:'auto'});
		}
	});
	
    
    t9 = new PopupLayer({
        trigger: "#init_sytem_first",
        popupBlk: "#blk9",
        closeBtn: "#close9",
        useOverlay: true,
        useFx: true,
		isresize:true,
        offsets: {
            x: 20,
            y: -20
        }
    });
    t9.doEffects = function(way){
		//alert(way);
        if (way == "open") {
			t9.overlay.show();
            var w = $(document).width();
            var pw = 800;
            var h = $(document).height();
             var ph = $("#blk9").height();
			 if(ph<395){
			 	ph = 395;
			 }
            var sh = $(document).scrollTop();
            this.popupLayer.css({
				width:40,
				height:20,
                opacity: 0.3
				
            }).show(400, function(){
                this.popupLayer.animate({
                    left: (w - pw) / 2,
                    top: (h - ph) / 2,
					width:800,
					height:395,
                    opacity: 0.8
                }, 1000, function(){
                    this.popupLayer.css("opacity", 1)
                }.binding(this));
            }.binding(this));
        }
        else {
            this.popupLayer.animate({
                left: this.trigger.offset().left,
                top: this.trigger.offset().top,
                opacity: 0.1,
				width:40,
				height:20
            }, {
                duration: 500,
                complete: function(){
                    this.popupLayer.css("opacity", 1);
                    this.popupLayer.hide()
                }.binding(this)
            });
			
			$.ajax({
				type:'get',
				async:false,
				url:'./index.php?r=Init&t='+Math.random(),
				data:{id:1},
				//dataType:'json',
				success:function(data){
					$("#popup-body").empty().append($(data)).css({height:'auto'});
				}
			});
			
        }
    };
	
	if (INIT_OPEN != 1) {
		t9.autoShow(true);
	}
});


function init_next(id)
{
	var html = '';
	
	if (INIT_OPEN != 1) {
		$("#blk9").find("#close9").remove();
	}else if(id == 1 || id=="login" || id == "checklogin"){
		$("#blk9").find("#close9").remove();
		$("#blk9").find(".NoviceguideHead").append($(cl));
	}else{
		$("#blk9").find("#close9").remove();
	}
	
	_oldw = t9.popupLayer.width();
    _oldh = t9.popupLayer.height();
	
	$.ajax({
		type:'get',
		async:false,
		url:'./index.php?r=Init&t='+Math.random(),
		data:{id:id},
		//dataType:'json',
		success:function(data){
			t9.popupLayer.css({overflow: 'hidden'});
			$("#blk9").css({height:'auto'});
			$("#popup-body").empty().append($(data)).css({height:'auto'});
			
			resizepopup();
		}
	});
}

function resizepopup()
{
	var h = $(document).height();
	var w = $(document).width();
	var pw = t9.popupLayer.width();
	
	var ph = $("#popup-body").height()+34;

	t9.popupLayer.animate({
                left: (w - pw) / 2,
                top: (h - ph) / 2,
				width:pw,
				height:ph
            }, {
				duration: 500,
				complete: function(){
					t9.popupLayer.css({overflow: ''});
				}
			});
	
}