define(['./mediaConfig'], function (config) {

    function getCookie(c_name){
        if (document.cookie.length>0){　　//先查询cookie是否为空，为空就return ""
            c_start=document.cookie.indexOf(c_name + "=");　　//通过String对象的indexOf()来检查这个cookie是否存在，不存在就为 -1　　
            if (c_start!=-1){
                c_start=c_start + c_name.length+1;　　//最后这个+1其实就是表示"="号啦，这样就获取到了cookie值的开始位置
                c_end=document.cookie.indexOf(";",c_start)　　//其实我刚看见indexOf()第二个参数的时候猛然有点晕，后来想起来表示指定的开始索引的位置...这句是为了得到值的结束位置。因为需要考虑是否是最后一项，所以通过";"号是否存在来判断
                if (c_end==-1) c_end=document.cookie.length
                return unescape(document.cookie.substring(c_start,c_end))　　//通过substring()得到了值。想了解unescape()得先知道escape()是做什么的，都是很重要的基础，想了解的可以搜索下，在文章结尾处也会进行讲解cookie编码细节
            }
        }
        return ""
    }
    var m = config.media;
    //judge param is setted
    var paramArray = ["gameId", "refer", "categoryList", "logo", "zoneLink"];
    for (var key in paramArray) {
        var value = paramArray[key];
        if (!m[value]) {
            throw new Error("mediaConfig.js: attribute \'" + value + "\' is not defined ！");
        }
    }
    //get url category param
    var category = m.category = SQ.getParam("category");

    if(category){
        document.cookie = "category="+category+";path=/";
    }else{
        category = getCookie("category")
        if(category){
            m.category = category;
        }
    }

    //set toufang page's refer
    if (category === 'toufang') {
        m.refer = SQ.getParam("refer");
    }

    //set refer_param
    if (!m.categoryList.hasOwnProperty(category)) {
        m.refer_param = "";
    }
    else {
        m.refer_param = m.categoryList[category];
    }

    //get media DOM and Logo URL
    var mediaEles = {
        logoEle: m.logoEle ? $(m.logoEle) : $("#media_logo"),
        gotoEle: m.gotoEle ? $(m.gotoEle) : $("#media_link"),
        logoDir: m.logoDir || "http://img1.37wanimg.com/market/media/logo/"
    };

    //set media's logo and media's zone_link
    if (m.logo[category] === ""||category === 'news') {
        mediaEles.logoEle.css({"display": "none"});
    } else {
        mediaEles.logoEle.attr("href", m.logo[category]).addClass("media-logo");
        $('img',mediaEles.logoEle).attr("src", mediaEles.logoDir + category + '.png');
    }
    mediaEles.gotoEle.attr("href", m.zoneLink[category]);
    var mediaParam = {
        gameId: m.gameId,
        game_server_id: m.game_server_id,
        category: m.category,
        refer: m.refer,
        refer_param: m.refer_param
    };
    return mediaParam;
});