(function() {
    qianwe = {
        init:function() {
            this.search({
                inputid: '#sq',
                btn: '#hsearch',
                lid: '#st',
                tyid: '#htype',
                selected_a: '#search_option_selected a',
                list: '#search_option_list'
             });
            this.search({
                inputid: '#footsq',
                btn: '#fsearch',
                lid: '#footst',
                tyid: '#ftype',
                selected_a: '#footsearch_option_selected a',
                list: '#footsearch_option_list'
            });
        },
        myA8: function(options) {
            var settings = $.extend({
                id: '#_mya8',
                my: '#jQ_mya8' 
            },
            options || {});
            $(settings.id).click(function() {
                if (!A8.checkLogin()) {
                    A8Win.login();
                    return false;
                } else {
                     var jumpUrl = $(settings.my).attr('href');
                }
                document.location.href = jumpUrl;
            });
        },
        tab: function(options) {
            var settings = $.extend({
                id: '',
                actcss: 'tab_act',
                nolcss: 'tab_nol',
                idpre: '#tabMenu_Content' 
            },
            options || {});
            var $this = $(settings.id);
            var $$this = $this.children();
            return $$this.each(function() {
                $(this).click(function() {
                    var idx = $(this).index();
                    var len = $$this.length;
                    if ($(this).attr('class') == settings.actcss) return;
                    $$this.eq(idx).removeClass(settings.nolcss).addClass(settings.actcss).siblings().removeClass(settings.actcss).addClass(settings.nolcss);
                    for (var i = 0; i < len; i++) {
                        if (idx == i) {
                            $(settings.idpre + i).show();
                        } else {
                            $(settings.idpre + i).hide();
                        }
                    }
                });
            })
        },
        slider: function(options) {
            var settings = $.extend({
                mp_actor: '#mp_actor',
                mp_actor_li: '#mp_actor li',
                mp_numInner: '#mp_numInner',
                mp_ulPlay_mc: '#mp_ulPlay .mc',
                mp_ulPlay_num: '#mp_ulPlay .num',
                mp_numInner_span_first: '#mp_numInner span:first',
                mp_numInner_span: '#mp_numInner span',
                mp_ulPlay: '#mp_ulPlay',
                mp_ulPlay_mp_alft: '#mp_ulPlay .mp_alft',
                mp_ulPlay_mp_arit: '#mp_ulPlay .mp_arit',
                css: 'on'
            },
            options || {});

            function c(e, m) {
                e = $(e) ? $(e) : e;
                e.addClass(m).siblings().removeClass(m)
            }
            function b(e) {
                if ($(settings.mp_actor).is(":animated") == false) {
                    d += e;
                    if (d != -1 && d != h) $(settings.mp_actor).animate({
                        marginLeft: -d * fp + "px"
                    },
                    j);
                    else if (d == -1) {
                        d = h - 1;
                        $(settings.mp_actor).css({
                            marginLeft: -(fp * (d - 1)) + "px"
                        });
                        $(settings.mp_actor).animate({
                            marginLeft: -(fp * d) + "px"
                        },
                        j)
                    } else if (d == h) {
                        d = 0;
                        $(settings.mp_actor).css({
                            marginLeft: -fp + "px"
                        });
                        $(settings.mp_actor).animate({
                            marginLeft: "0px"
                        },
                        j)
                    }
                    c($(settings.mp_numInner_span).eq(d), settings.css)
                }
            }
            function g(e) {
                if ($(settings.mp_actor).css("marginLeft") != -e * fp + "px") {
                    $(settings.mp_actor).css("marginLeft", -e * fp + "px");
                    $(settings.mp_actor).fadeOut(0,
                    function() {
                        $(settings.mp_actor).fadeIn(500)
                    })
                }
            }
            function a() {
                k = setInterval(function() {
                    b(1)
                },
                5E3)
            }
            function i() {
                k && clearInterval(k)
            }
            var k = false,
            n = "",
            j = 500,
            fp = 600,
            h = $(settings.mp_actor_li).length,
            l = h * 18,
            o = (fp - (l + 26)) / 2,
            d = 0;
            $(settings.mp_actor).width(fp * h);
            $(settings.mp_actor_li).each(function() {
                n += "<span></span>"
            });
            $(settings.mp_numInner).width(l).html(n);
            $(settings.mp_ulPlay_mc).width(l);
            $(settings.mp_ulPlay_num).css("left", o);
            $(settings.mp_numInner).css("left", o + 13);
            $(settings.mp_numInner_span_first).addClass(settings.css);
            $(settings.mp_ulPlay_mp_alft).click(function() {
                b( - 1)
            });
            $(settings.mp_ulPlay_mp_arit).click(function() {
                b(1)
            });
            $(settings.mp_numInner_span).click(function() {
                d = $(this).index();
                g(d);
                c($(settings.mp_numInner_span).eq(d), settings.css)
            });
            $(settings.mp_ulPlay).hover(function() {
                i()
            },
            function() {
                a()
            });
            a()
        },
        scroll: function(options) {
            var settings = $.extend({
                rightid: '',
                leftid: '',
                wndid: '',
                contid: '',
                type: 'left',
                ftx: 'li',
                num: 3
            },
            options || {});
            var page = 1;
            $(settings.rightid).click(function() {
                var $pictureShow = $(settings.wndid);
                var downwidth = (settings.type == 'top') ? $pictureShow.height() : $pictureShow.width();
                var len = $(settings.contid).find(settings.ftx).length;
                var page_number = Math.ceil(len / settings.num);
                if (!$(settings.contid).is(":animated")) {
                    if (page == page_number) {
                        if (settings.type == 'top') {
                            $(settings.contid).animate({
                                top: '0px'
                            },
                            "slow");
                        } else {
                            $(settings.contid).animate({
                                left: '0px'
                            },
                            "slow");
                        }
                        page = 1;
                    } else {
                        if (settings.type == 'top') {
                            $(settings.contid).animate({
                                top: '-=' + downwidth
                            },
                            "slow");
                        } else {
                            $(settings.contid).animate({
                                left: '-=' + downwidth
                            },
                            "slow");
                        }
                        page++;
                    }
                }
            });
            $(settings.leftid).click(function() {
                var $pictureShow = $(settings.wndid);
                var downwidth = (settings.type == 'top') ? $pictureShow.height() : $pictureShow.width();
                var len = $(settings.contid).find(settings.ftx).length;
                var page_number = Math.ceil(len / settings.num);
                if (!$(settings.contid).is(":animated")) {
                    if (page == 1) {
                        if (settings.type == 'top') {
                            $(settings.contid).animate({
                                top: '-=' + downwidth * (page_number - 1)
                            },
                            "slow");
                        } else {
                            $(settings.contid).animate({
                                left: '-=' + downwidth * (page_number - 1)
                            },
                            "slow");
                        }
                        page = page_number;
                    } else {
                        if (settings.type == 'top') {
                            $(settings.contid).animate({
                                top: '+=' + downwidth
                            },
                            "slow");
                        } else {
                            $(settings.contid).animate({
                                left: '+=' + downwidth
                            },
                            "slow");
                        }
                        page--;
                    }
                }
            });
        },
        select: function(options) {
            var settings = $.extend({
                id: '',
                name: '',
                value_id: '' 
            },
            options || {});
            var $this = $(settings.id);	
            $('input[name="' + settings.name + '"]').each(function() {
                $(this).click(function() {

                    var k = i = 0;
                    var str = _str = '';
                    $('input[name="' + settings.name + '"]').each(function() {
                        if ($(this).attr('checked') == 'checked') {
                            k++;
                            _str += $(this).val() + ',';
                        }
                        i++;
                    });
                    str = _str.substr(0, _str.length - 1);
                    $this.attr('checked', (k == i ? true: false));
                    $(settings.value_id).val(str);
                });
            });
			
            return $this.click(function() {
				var tagName = $(this).get(0).tagName;
				if(tagName =='A'){
					var flag = $(this).hasClass('checked')? true: false;
					
				}else{
					var flag = $(this).attr('checked') == 'checked' ? true: false;				
				}
				console.log(tagName);

                var str = _str = '';
                $('input[name="' + settings.name + '"]').each(function() {
                    $(this).attr('checked', flag);
                    if (flag) _str += $(this).val() + ',';
                });
                str = _str.substr(0, _str.length - 1);
                $(settings.value_id).val(str);
            })
        },
        unselect: function(options) {
            var settings = $.extend({},
            options || {});
        },
search: function(options) {
            var settings = $.extend({
                inputid: '',
                btn: '',
                lid: '',
                tyid: '',
                selected_a: '#search_option_selected a',
                list: '#search_option_list',
                css: 'selected'
            },
            options || {});
            $(settings.selected_a).click(function() {
                $(settings.list).toggle();
                $(this).blur();
            });
            $(settings.list+' li a').click(function() {
                $(this).blur().parent('li').addClass(settings.css).siblings("li.selected").removeClass(settings.css);
                $(settings.selected_a).text($(this).text());
                $(settings.list).hide();
                $(settings.inputid).focus();
            });
            $(settings.inputid).keyup(function(event) {
                if (event.keyCode == 13) {
                    $(settings.btn).click()
                }
            }).focus(function() {
                if ($.trim($(this).val()) == '请输入歌曲或歌手！') {
                    $(this).val('');
                }
            }).blur(function() {
                if ($.trim($(this).val()) == '') {
                    $(this).val('请输入歌曲或歌手！');
                }
            });
            $(settings.btn).submit(function() {
                var k = $(settings.inputid),
                v = $(settings.lid).text(),
                b = {
                    '歌曲': '1',
                    '歌曲': '1',
                    '找人': '2',
                    '文章': '3'
                } [v] || '1',
                d = $.trim(k.val()),
                o = $(settings.tyid);

                if (d.length == 0 || d == '请输入查询关键字！') {
                    k.val('请输入查询关键字！');
                    k.focus();
                    return false;
                }
                o.val(b);
                return true;
            });
        },
        musicPlayer: function(ids, checkboxname) {
            var url = '/play.php';
            var winObj = null;
            
            if(ids.length == 0 && typeof(chkboxname) == 'undefined') return false;
            if(ids.length != 0){
                if(ids.indexOf('|') == -1) {
                    url += '?id='+ids;
                } else {
                    var tmp = ids.split('|');
                    var params = '?';
                    switch(tmp[0]){
                        case 'aid':
                        params += 'aid='+tmp[1];
                        break;
                        case 'uid':
                        params += 'uid='+tmp[1];
                        break;
                        case 'tid':
                        params += 'tid='+tmp[1];
                        break;
                    }
                    if(params.length < 4) return false;
                    url += params;
                }
            } else if(typeof(chkboxname) != 'undefined') {
                var str = '';
                $('input[name='+chkboxname+']').each(function(){
                    str += (str.length > 0 ? ',' : '')+$(this).val();
                });
                url += '?id='+str;
            }
            winObj = window.open(url,"A8MusicPlayer","toolbar=yes,menubar=yes,scrollbars=yes,location=yes,status=yes,resizable=yes");
            winObj.focus();
            return false;
        },
        hover: function(options) {
            var settings = $.extend({
                id: '.mcln_list li',
                css: 'hover'
            },
            options || {});
            $(settings.id).hover(function() {
                $(this).addClass(settings.css);
            },
            function() {
                $(this).removeClass(settings.css);
            });
        },
        menu: function(options) {
            var settings = $.extend({
                id: 'li.mainlevel',
                nid: '.nol_nav'
            },
            options || {});

            $(settings.id).mousemove(function() {
                $(this).find('ul').show(); //you can give it a speed
                $(settings.nid).hide();
            }).mouseleave(function() {
                $(this).find('ul').hide();
                $(settings.nid).show();
            });
        },
        submit: function(options) {
            var settings = $.extend({
                id: '',
                formid: ''
            },
            options || {});

            $(settings.id).click(function() {
                $(settings.formid).submit();
            });
        },
		toggle: function(options) {
			var settings = $.extend({
				id:'',
				lid:'',
				cid:'',
				height:'',
				hcss:'itemsShow',
				scss:'itemsShow'
			},
			options||{});
			$(settings.id).toggle(
				function () {
					//$(this).addClass(settings.hcss).removeClass(settings.scss);
					$(settings.lid).css('height',$(settings.cid).height());
				},
				function () {
				//	$(this).addClass(settings.scss).removeClass(settings.hcss);
					$(settings.lid).css('height',settings.height);
				}
			);
		},  flydiv: function()
        {
            
        }
	}
})();
$(function() {
    qianwe.init();
	$('a').bind('focus',
    function() {
        if (this.blur) {
            this.blur();
        };
    });
})
function correctPNG() {
    for (var i = 0; i < document.images.length; i++) {
        var img = document.images[i]
        var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
            var imgID = (img.id) ? "id='" + img.id + "' ": "";
            var imgClass = (img.className) ? "class='" + img.className + "' ": "";
            var imgTitle = (img.title) ? "title='" + img.title + "' ": "title='" + img.alt + "' ";
            var imgStyle = "display:inline-block;" + img.style.cssText;
            if (img.align == "left") imgStyle = "float:left;" + imgStyle;
            if (img.align == "right") imgStyle = "float:right;" + imgStyle;
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
            var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
			img.outerHTML = strNewHTML;
			i = i - 1;
        }
    }
}
if ($.browser.msie) {
    window.attachEvent("onload", correctPNG);
}

var web_url = webpath;
var DomainUrl = top.location.hostname;
var AuthUrl = top.location.hostname;
function Trim(){
	return this.replace(/\s+$|^\s+/g,"");
}
String.prototype.Trim=Trim;
function getObjValues(id){
	if(getObjects(id).value!=undefined)
		return getObjects(id).value.Trim();
	else
		return "";
}
function getObjects(id) { 	
	if (document.getElementById) { 
		return document.getElementById(id); 
	} else if (document.all) { 
		return document.all[id]; 
	} else if (document.layers) { 
		return document.layers[id]; 
	} 
}
function createXMLHttpRequest(){
       	if (window.XMLHttpRequest) {//www.ydh020.com
		XMLHttpReq=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {//IE 浏览器
	     try {
			    XMLHttpReq=new ActiveXObject("Msxml2.XMLHTTP");
	     } catch (e) {
		        try{
					XMLHttpReq=new ActiveXObject("Micrsost.XMLHTTP");
				} catch(e){}
	     }
        }
}
var cache = new Array();
function getHttpObject() {
    var objType = false;
    try {
        objType = new ActiveXObject('Msxml2.XMLHTTP');
    } catch(e) {
        try {
            objType = new ActiveXObject('Microsoft.XMLHTTP');
        } catch(e) {
            objType = new XMLHttpRequest();
        }
    }
    return objType;
}
function getlogin(){
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  theHttpRequest.open("GET", ""+web_url+"skin/ydh/ajax_login.php", true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
           document.getElementById("userinfo").innerHTML = unescape(theHttpRequest.responseText);
           } else {
           document.getElementById("userinfo").innerHTML = "您请求的页面出现异常错误";
                  }
           }
     }
}
function getdoHits(_id){
  var theHttpRequest = getHttpObject();
  theHttpRequest.onreadystatechange = function() {processAJAX();};
  //  alert(web_url);
  theHttpRequest.open("GET", ""+web_url+"skin/ydh/ajax.php?action=goodbad&id="+ _id, true);
  theHttpRequest.send(null);
    function processAJAX(){
       if (theHttpRequest.readyState == 4) {
         if (theHttpRequest.status == 200) {
           document.getElementById("doHits").innerHTML = unescape(theHttpRequest.responseText);
           } else {
           document.getElementById("doHits").innerHTML = "您请求的页面出现异常错误";
                  }
           }
     }
}
function up_down(_id, _do){
	 createXMLHttpRequest();
	 XMLHttpReq.open("GET", ""+web_url+"skin/ydh/ajax.php?action=doHits&id="+ _id +"&dowhat="+ _do,true);
	 XMLHttpReq.onreadystatechange= function(){
		if(XMLHttpReq.readyState == 4){
			if(XMLHttpReq.status == 200){
	           		if(XMLHttpReq.responseText == "Err_145"){
	           	        	alert('休息会吧！顶一下就可以啦！');
		        	}
                                	getdoHits(_id);
			}else alert("网络连接失败");
		}
	}
	 XMLHttpReq.send(null);
	}
function sendRequest(){
	 createXMLHttpRequest();
	 XMLHttpReq.open("GET", ""+web_url+"skin/ydh/ajax_login.php?action=login&name=" + escape(getObjValues("username")) + "&pwd=" +escape(getObjValues("password")),true);
	 XMLHttpReq.onreadystatechange= processResponse;
	 XMLHttpReq.send(null);
	 }
function goutRequest(){
	 createXMLHttpRequest();
	 XMLHttpReq.open("GET", ""+web_url+"skin/ydh/ajax_login.php?action=logout",true);
	 XMLHttpReq.onreadystatechange= processResponse;
	 XMLHttpReq.send(null);  
	 }
function processResponse() {
	 if (XMLHttpReq.readyState==4){
	 if(XMLHttpReq.status==200){
	           var msg=XMLHttpReq.responseText;
	           if(msg == "Err_100"){
	                     do_alert('用户名不允许为空！'); setTimeout('close_alert()', 3000);
	           } else if(msg == "Err_101"){
	                     do_alert('密码不允许为空！'); setTimeout('close_alert()', 3000);
	           } else if(msg == "Err_102"){
	                     do_alert('用户名或密码错误，请重试！'); setTimeout('close_alert()', 3000);
	           } else if(msg == "Err_103"){
	                     do_alert('评论内容最少6个字符！'); setTimeout('close_alert()', 2000);
	           } else if(msg == "Err_104"){
	                     do_alert('发表评论成功'); setTimeout('close_alert()', 1000);
	                     window.location.reload();
	           } else if(msg == "Err_105"){
	                     alert('发表频率太快，稍等一分钟吧！'); return false;
	           } else if(msg == "Err_106"){
	                     getlogin();
	           } else if(msg == "Err_107"){
	                     alert('对不起，此帐号已被锁定！'); return false;
	           } else if(msg == "Err_108"){
	                     alert('对不起，此帐号尚未通过审核验证！'); return false;
	           } else if(msg == "Err_109"){
	                     do_alert('登陆成功'); setTimeout('close_alert()', 1000);
						 location.href="http://www.ydh020.com/";
	                     //window.setTimeout("document.location.reload()", 500);
	           } else {
	                     document.getElementById("userinfo").innerHTML =unescape(msg);
	           }
	 } else {
                   do_alert('您请求的页面出现异常错误！'); setTimeout('close_alert()', 5000);
	        }
         }
   }
function do_alert( msg ){
    var _height = document.documentElement.clientHeight||document.body.clientHeight;
    var _top = (_height) ? (_height - 39)/2 + document.documentElement.scrollTop : 0;
    var msgObj=document.createElement('div');
    msgObj.setAttribute('id', 'msgInfo');
    msgObj.setAttribute('align', 'center');
    msgObj.style.position = 'absolute';
    msgObj.style.top = _top + 'px';
    msgObj.style.left = '0';
    msgObj.style.width = '100%';
    msgObj.style.height = '33px';
    msgObj.style.zIndex = '999';
    msgObj.innerHTML = '<span id="alert">'+ msg +'</span>';
    document.body.appendChild(msgObj);
};
function close_alert(){
    document.body.removeChild($('msgInfo'));
};
<!--
function   autoResize()   
{   try {   document.all( "right").style.height= right.document.body.scrollHeight;   }   
catch(e)   {   }   } 
-->