objHighlights = {
    index: -1,
    data: [],
    publish: function (index) {
        this.index = index;
        var news = this.data[index],
            html_related_news = "",
            html_photo = "";
        if (news.related_news.length > 0) {
            var rn = $.map(news.related_news, function (o, i) {
                return dji18njs.interpolate(
                    '<li><a href="#show%(id)s">%(title)s</a></li>',
                    {
                        "id": o.id,
                        "title": o.title
                    }, true);
            });
            html_related_news = dji18njs.interpolate('<ul>%s</ul>', [rn.join("")]);
        }
        if (news.main_photo != null) {
            html_photo = dji18njs.interpolate(
                '<a href="%(link)s"><img src="%(main_photo)s" alt="%(title)s"></a>',
                {
                    "main_photo": news.main_photo,
                    "title": news.title,
                    "link":news.link
                }, true);
        }
        $("#highlights-left-news").html(dji18njs.interpolate(''
            + '<h1><a href="%(link)s">%(title)s</a></h1>'
            + '<p><a href="%(link)s">%(description)s</a></p>'
            + '%(related_news)s',
            {
                "title": news.title,
                "description": news.description,
                "related_news": html_related_news,
				"link":news.link
            }, true));
        $("#highlights-right").html(html_photo);
        this.publish_nav();
    },
    publish_nav: function () {
        var nav_nums = $.map(INDEX_HIGHLIGHTS, function (o, i) {
            return dji18njs.interpolate(
                '<li><a rel="hl%(index)s" href="#">%(index_pl)s</a></li>', {
                    "index_pl": i + 1,
                    "index": i
                }, true);
        });
        var $ul = $('<ul/>').append(nav_nums.join(''));
        $ul.find('li:first-child').addClass('first-child');
        $($ul.find('li')[this.index]).addClass('current');
        $("#hightlights-left-nav").empty().append($ul);
        var self = this;
        $('a[rel^="hl"]').click(function (e) {
            self.publish($(this).attr('rel').match(/\d+/i)[0]);
            window.location.href = '#' + $(this).attr('rel');
            return false;
        });
    },
    get_hash: function () {
        if (window.location.hash.length == 0) {
            return false;
        }
        return window.location.hash.match(/\d+/i)[0];
    },
    init: function () {
        var index = this.get_hash();
        if (!index) {
            index = 0;
        }
        this.publish(index);
    }
};

$(function () {
    //$("footer").load('include-index-footer.html', function(){
    $("#slider-and-gallery-slider-jcarousel").jcarousel();
    //});

    // Quick Filter
    // -----------------------------------------------------------------------
    $(".placeholder").placeHolder();
    $("#main-left-quick-filter-button-up").click(function (e) {
        var $self = $(this),
            scroll_top = $("#main-left-quick-filter-list").scrollTop() - 60;
        $("#main-left-quick-filter-list").animate({ scrollTop: scroll_top }, "fast");
    });
    $("#main-left-quick-filter-button-down").click(function (e) {
        var $self = $(this),
            scroll_top = $("#main-left-quick-filter-list").scrollTop() + 60;
        $("#main-left-quick-filter-list").animate({ scrollTop: scroll_top }, "fast");
    });
    // -----------------------------------------------------------------------

    // Social Links Hovering
    // -----------------------------------------------------------------------
    $(".social-links").hover(function () {
        $(this).css('background-position', "left -34px");
    }, function () {
        $(this).css('background-position', "left 0px");
    });
    // -----------------------------------------------------------------------

    objHighlights.data = INDEX_HIGHLIGHTS;
    objHighlights.init();

    // Quick Filtering...
    // -----------------------------------------------------------------------
    publish_qf(QF_DICT);
    $("#main-left-quick-filter-query").keyup(function (e) {
        var q = $(this).val().toLowerCase(),
            r = {};
        $.each(QF_DICT, function (group_name, item_data) {
            if (group_name.toLowerCase().search(q) > -1) {
                r[group_name] = item_data;
            } else {
                $.each(item_data, function (con_name, url) {
                    if (con_name.toLowerCase().search(q) > -1 && !r.hasOwnProperty(group_name)) {
                        r[group_name] = {};
                        r[group_name][con_name] = url;
                    }
                });
            }
        });
        publish_qf(r);
    });
    // -----------------------------------------------------------------------

    $("#fancy_quiz_pop").fancybox({
        'width': 538,
        'height': 538,
        'type': 'iframe'
    });

});

function publish_qf(dict) {
    var qf_html = '';
    $.each(dict, function (group_name, item_data) {
        qf_html += dji18njs.interpolate(
            '<dl><dt>%(group_name)s</dt>', {
                "group_name": group_name
            }, true);
        $.each(item_data, function (con_name, url) {
            qf_html += dji18njs.interpolate(
                '<dd><a class="fancy_f" href="%(url)s">%(con_name)s</a></dd>', {
                    "con_name": con_name,
                    "url": url
                }, true);
        });
        qf_html += '</dl>';
    });
    $("#main-left-quick-filter-list").html(qf_html);
    $(".fancy_f").fancybox({
        'width': 538,
        'height': 538,
        'type': 'iframe'
    });
}


