﻿window.onerror = function() { return false; }
window.focus();
window.musicName = '';
function getDefaultWinName() {
    var name = document.location.hostname;
    name = name.replace(/\./g, "");
    return name;
}
if (typeof(window.name) == 'undefined') {    
    window.name = getDefaultWinName();
}

function hoverLight(selectorStr, lightClass) {
    if ($.browser.msie) {
        $(selectorStr).each(function() {
            $(this).hover(
            function() { $(this).addClass(lightClass); },
            function() { $(this).removeClass(lightClass); }
            );

        });
    }
}
var heightTable = new Array();
//单字级别的
//单字解析到这样,,如果是数字的话就出错
function heightLight__a(input, key) {
    var pa;
//替换成其他字符    
    for (var i = 0; i < key.length; i++) {
        pa = new RegExp("" + key.substr(i, 1) + "", "ig");
        input = input.replace(pa, '＾' + i+1);
    }
    //还原 原来的字符
    for (var i = 0; i < key.length; i++) {
        pa = new RegExp("＾" + i+1 , "ig");
        input=input.replace(pa,'<font color="red">' + key.substr(i, 1) +'</font>');
    }
    return input;
}
function heightLight(input, key) {
    var pa = new RegExp(key, 'ig');
    return input.replace(pa, '<font color="red">' + key + '</font>');
}
function heightLightLinks(selector, key) {
        if (!document.createElement) {
            return;
        }
        var mytag = "a";
        //var q = "dj";//要高亮显示的关键字
        var l = document.getElementsByTagName(mytag);
        if ("" == key) return;
        //	q=q.replace("_"/g,' ');
        words = unescape(key.replace(/\+/g, ' '));
        words = words.replace("-", " ").replace("(", " ").replace(")", " ").replace("_", " ").replace("/", " ");
        words = words.split(/\s+/);
        var temp = null;
        $(selector).each(function() {
            temp = $(this).html();
            for (w = 0; w < words.length; w++) {
                var pa = new RegExp("(" + words[w] + ")", "ig");
                temp = temp.replace(pa, "┯$1┷");
            }
            temp = temp.replace(/\┯/g, '<span style="color:red">');
            temp = temp.replace(/\┷/g, "</span>");
            $(this).html(temp);
        });
//        for (i = 0; i < l.length; i++) {
//            if (l[i].id.indexOf("d") == 0)//id=d*的才替换
//            {
//                temp = l[i].innerHTML;
//                for (w = 0; w < words.length; w++) {
//                    var pa = new RegExp("(" + words[w] + ")", "ig");
//                    temp = temp.replace(pa, "9aS$19aE");
//                }
//                temp = temp.replace(/\9aS/g, '<span style="color:red">');
//                temp = temp.replace(/\9aE/g, "</span>");
//                l[i].innerHTML = temp;
//            }
//        }
}
function musicTagsInit(selector) {

    $(selector).click(function() {
            musicTagsAjax($(this).html());
            return false;
    });
}
function musicTagsAjax(tag) {
    msuicTags_ctag=tag;
    $.getJSON("/music/ajaxtag/" + tag, function(json) {
        musicTagsShow(json);
    });
}
var msuicTags_ctag='';
//for hihi57 其他站调用,请重写本函数
function musicTagsShow(json) {
    var total = json.length;
    var txt = '<ul>';
    if (total > 1) {
        for (var i = 0; i < total; i++) {            
            txt += '<li><a href="/dj' + json[i].Id + '.dj" title="编号:'+ json[i].Id +'\r\n舞曲名:' + json[i].Name + '\r\n人气:' + json[i].Hits + '\r\n\r\nwww.hihi57.com">' + heightLight(json[i].Name,msuicTags_ctag) + '</a></li>';
        }
    } else {
    txt += '<li><font color="red">无相关舞曲</font></li>';
    }
    txt += '</ul>';
    if (document.getElementById('tags')==null) {
        $('#msgContainer').append('<div id="tags"></div>');
    }
    $('#tags').html(txt);
    msgContainer_title = msuicTags_ctag;
    msgContainerShow('tags');    
    //alert($('#tags').html());
}
var msgContainer_title = '嗨友们在听';
var msgContainer_current = 'lastplayed';
function showLastPlayed() {
    $('#key').hide();
    $('#lastplayed').show();
}
function msgContainerShow(key,setData) {
        var oshow;
        $('#' + msgContainer_current).hide();
        oshow = $('#'+key);
        oshow.show();
        $('#msgContainer label').html(msgContainer_title);
        msgContainer_current = key;
        
        if (setData != null) {
            oshow.html(setData);
        }

    }
    function showDownload(url) {        
        $('#djdownloadlink').attr('href','http://img.hihi57.com/djdownload.html?q='+url +'&name='+ window.musicName);
    }

    function text(msg) {
        document.write(msg);
    }
    $(function() {

        $("#q").one('click', function() { if ($(this).val() == $(this).attr('title')) { $(this).val(''); } });

    });
