﻿
$(document).ready(function () {

    $.ajaxSetup({
        // Disable caching of AJAX responses */ 
        cache: false
    });

    //    $.getJSON('/Home/GetList', function (data) {
    //        alert('here');
    //        $("#news").fillSelect(data);
    //    });
    $.getJSON('/Home/SimpleNewsFeed/', function (response) {
        //alert(data['0'].toString());
        $.each(response, function (i, item) {
            //alert(item.Headline);
            $("#news").append("<li class='title'><a href='/Home/News'>" + formatDate(item.ArticleDate) + " - " + item.Title + "</a></li><br/>");

        });

    });

    $.getJSON('/Home/RandomSponsorImage', function (data) {
        //alert(data.Data.Id + ':' + data.Data.Name + ':' + data.Data.Path + ':' + data.Data.Direction + ':' + data.Data.Size);
        if (data.Path != null && data.Path.length > 0) {
            $("#imgSponsor").attr("src", data.Path);

            if (data.Direction.indexOf("width") >= 0) {
                $("#imgSponsor").attr("width", 300);
            }
            else {
                $("#imgSponsor").attr("height", 150);
            }
            $("#imgSponsor").attr("alt", data.Name + " Image");
            //$("#imgSponsor").show();
            $("#imgName").hide();
            $("#imgSponsor").removeAttr("style");
        }
        else {
            $("#imgName").html(data.Name);
            $("#imgSponsor").hide();
            $("#imgName").show('slow');
        }

        //alert($(".inner").html());
    });
});

function formatDate(jsonDate) {
    var newDate = new Date(parseInt(jsonDate.substr(6)));
    return newDate.getMonth() + '/' + newDate.getDate() + '/' + newDate.getFullYear();
}


////$.fn.clearSelect = function () {
////    return this.each(function () {
////        if (this.tagName == 'SELECT')
////            this.options.length = 0;
////    });
////} 


////$.fn.fillSelect = function (data) {
////    return this.clearSelect().each(function () {
////        if (this.tagName == 'SELECT') {
////            var dropdownList = this;
////            $.each(data, function (index, optionData) {
////                var option = new Option(optionData.Text, optionData.Value);

////                if ($.browser.msie) {
////                    dropdownList.add(option);
////                }
////                else {
////                    dropdownList.add(option, null);
////                }
////            });
////        }
////    });
////}

