
$(function() {
	bg=getCookie('bg');
	if(bg!=null){
		$('body').css("background",bg+" repeat-x 0 60px");
	};
    $(".move").draggable({
        handle: 'h3',
        grid: [10,10]
    })
    .mousedown(function(){
        $(".move").not($(this)).css("z-index","1");
        $(this).css("z-index","999");
    });
    $(".manages").draggable({
        handle:'h3',
        grid:[10,10]
    });
    $("#datepicker").datepicker();
		
    $(".move .head").mousedown(function(){
        $(this).parent().addClass("opacity");
    });
    $(".move .head").mouseup(function(){
        $(this).parent().removeClass("opacity");
    });
		
		
		
    /***********************
				模块操作
		************************/
		
    //最小化(单)
    $("h3 > span:contains('-')").mousedown(function(){
        $(this).parent().nextAll().toggle("slow");
        return false;
    });

    //隐藏(单)
    $("h3 > span:contains('×')").mousedown(function(){
        $(this).parent().parent().hide("slow");
        return false;
    });
		
		


    //全部隐藏
    $("#nav_mid > li").eq(0).click(function(){
        $(".move > ul").not($(".head")).slideUp("slow");
    });
    //全部显示
    $("#nav_mid > li").eq(1).click(function(){
        $(".move > ul").not($(".head")).slideDown("slow");
    })
    //全部打开
    $("#nav_mid > li").eq(2).click(function(){
        $(".move").not($("#options_box")).slideDown("slow");
    })
    //全部关闭
    $("#nav_mid > li").eq(3).click(function(){
        $(".move").slideUp("slow");
    });
		
		



		
		
		
    //options
    $("#options .content > li").eq(0).toggle(		//设置背景色
        function(){
            var c= new Array("#fadf00","#d7006c","#009dd9","#000000","#f0f0f0","#c8c5ac","#b5b292","#9f9b74","#f2b0df","#ee86d3","#e653bc","#e032af","#b1bcb5","#97a69b","#6c8072","#5a7060","#dde56c","#d3e13c","#c8db00","#b9d300","#9faa00","#8b9000","#6e6a12","#6a5b07","#a2dbeb","#6fd2e4","#00c4dc","#00aece","#0092ba","#007a97","#00667c","#004f5d");		//可选色列表
            var str="<li style='width:200px;'>";
			
            for(i=0;i<c.length;i++){
                str+="<span onclick=(background('"+c[i]+"')) style='cursor:pointer;float:left;margin:2px;width:20px;height:20px;overflow:hidden;color:"+c[i]+";background:"+c[i]+"'>"+c[i]+"</span>";
            };
            str+="</li>";
            $("#options_box font").html("背景色");
            $("#options_box > ul").eq(0).html(str);
            left=Math.round(Math.random()*700+100);
            t=Math.round(Math.random()*350+100);
            $("#options_box").css({
                "left":left,
                "top":t
            })
            .show("slow");
        },
        function(){
            $("#options_box").hide("slow");
        }
        );
	
	
	
	
    $("#options .content > li").eq(1).toggle(		//设置背景渐变色
        function(){
			
            var str="<li style='width:200px;'>";
            var j= new Array("template/default_en/skin/images/body_bg.gif","template/default_en/skin/images/body_bg2.gif","template/default_en/skin/images/body_bg3.gif","template/default_en/skin/images/body_bg4.gif");
            for(i=0;i<j.length;i++){
                str+="<img onclick=(background('url("+j[i]+")')) src="+j[i]+" alt='' width='180px' height='35px'/>";
            };
            str+="</li>";
            $("#options_box font").html("背景渐变色");
            $("#options_box > ul").eq(0).html(str);
            left=Math.round(Math.random()*700+100);
            t=Math.round(Math.random()*400+100);
            $("#options_box").css({
                "left":left,
                "top":t
            })
            .show("slow");
        },
        function(){
            $("#options_box").hide("slow");
        }
        );
	
    $("#options .content > li").eq(2).toggle(		//设置背景图
        function(){
            var str="";
            var j= new Array("template/default_en/skin/images/bg_img_01.jpg","template/default_en/skin/images/bg_img_02.jpg","template/default_en/skin/images/bg_img_03.jpg","template/default_en/skin/images/bg_img_04.jpg");
            var m= new Array("魔术（117KB）","梦幻天空（82KB）","星空（50KB）","理想之城（126KB）");
            for(i=0;i<j.length;i++){
                str+="<li style='width:200px;margin:3px 0px;'><img onclick=(background('url("+j[i]+")')) src="+j[i]+" alt='' width='50px' height='35px' style='vertical-align:middle;margin-right:10px;cursor:pointer;'/>"+m[i]+"</li>";
            };
			
            $("#options_box font").html("背景图");
            $("#options_box > ul").eq(0).html(str);
            left=Math.round(Math.random()*700+100);
            t=Math.round(Math.random()*400+100);
            $("#options_box").css({
                "left":left,
                "top":t
            })
            .show("slow");
        },
        function(){
            $("#options_box").hide("slow");
        }
        );
		
    //管理
    $("#works > h3 > .manage").toggle(
        function(){
            l=Math.round(Math.random()*700+100);
            t=Math.round(Math.random()*350+100);
            $("#manage_show").css({
                "left":l,
                "top":t
            })
            .show("slow");
        },
        function(){
            $("#manage_show").hide("slow");
        }
   );


});
function background(c){
    $("body").css("background",c+" repeat-x 0 60px");
    SetCookie('bg',c,"7");
}

function mouse(){
    $("div").mousemove(function(e){
        var x=e.clientX;
        var y=e.clientY;
        return x;
		 
    });
}


function SetCookie(name,value,expire) {   
    var exp  = new Date();   
    exp.setTime(exp.getTime() + expire);   
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();   
}   
  
function getCookie(name) {   
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));   
    if(arr != null) return unescape(arr[2]);
    return null;
}   
  
function delCookie(name){   
    var exp = new Date();   
    exp.setTime(exp.getTime() - 1);   
    var cval=getCookie(name);   
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();   
}   

