$(function(){
    //$("#search_input").focus();
	changebg();
    auto_nav();
	$("#background").bind('contextmenu',function(){return false;});
	$("#background").bind('contextmenu',function(){return false;});
    $("#search_button").bind("click",function(){
        google_search();
    });
    //words
    $.ajax({
        type:"GET",
        dataType:"xml",
        url:sitepath+"words.php",
        success:function(wordslist){
            var wnum=$("words",wordslist).length;
            i=get_random(0,wnum-1);
            c_words=$("words",wordslist).get(i);
            $("#words .words_content").html($("content",c_words).text());
            $("#words .words_from").html($("from",c_words).text()+"：");
            $("#words").show();
        }
    });
});


function vcenter(c,o){
    var p_y=Math.round((c.height()-o.height())/2)+Math.round(o.css("margin-top").replace("px",""));
    o.css("margin-top",p_y+"px");
}
function auto_nav(){
    $(".nav_menu a").mouseover(function(){
        $(".nav_menu a").removeClass("current");
        $(this).addClass("current")
    });
}
function google_search(){
    var s_url="http://www.google.cn/search?hl=zh-CN&source=hp&q=site:lingye.net ";
    var keywords=$("#search_input").val();
    if(keywords.length>1){
        window.open(s_url+keywords);
    }
}
function get_random(minnum,maxnum){
    r=Math.random();
    return Math.round((maxnum-minnum)*r)
}
function colorclock(){
    mydate=new Date();
    h=mydate.getHours();
    m=mydate.getMinutes();
    s=mydate.getSeconds();
    l=$("#colorclock").width();
    l1=(h/24)*l;
    l2=(m/60)*l;
    l3=(s/60)*l;
    $("#colorclock .clock_h").width(l1);
    $("#colorclock .clock_m").width(l2);
    $("#colorclock .clock_s").width(l3);
    h=(h>9)?h:("0"+h.toString());
    m=(m>9)?m:("0"+m.toString());
    s=(s>9)?s:("0"+s.toString());
    $("#colorclock .clock_text .h").text(h)
    $("#colorclock .clock_text .m").text(m)
    $("#colorclock .clock_text .s").text(s)
}
var clocklisten=window.setInterval(colorclock, 1000);
//if($.browser.msie && Math.round($.browser.version)<=6) window.clearInterval(clocklisten);

function changebg(){
	var screen_type=0;
	screen_w=screen.width;
	screen_h=screen.height;
	screen_type=(screen_w/screen_h)>1.4?1:0;
	
	var bgurel="http://static.1988m.com/web_bg/";
	var imgarr=[
				["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg"],
				["7.jpg","8.jpg","9.jpg","10.jpg","11.jpg"]
				];
	imgarr=imgarr[screen_type];
	var bgi=Math.round(Math.random()*(imgarr.length+1));
	if(bgi>=imgarr.length) bgi=0;
	if(bgi<imgarr.length){
		if($.browser.msie && Math.round($.browser.version)<=6){
			$("#background").remove();
			$("body").attr("style","background-attachment: fixed;background-image:url("+bgurel+imgarr[bgi]+")")
		}else{
			$("#background").fadeIn("fast",function(){
				$("#background").attr("src",bgurel+imgarr[bgi]);										
			});
		}
	}
	
}