﻿var FocusCount = 5;
var HotspotID = 3;
var HotspotClassCount = 2;
var HotspotCount = 3;
var FeatureID = 2;
var FeatureClassCount = 3;
var FeatureCount = 5;

$(document).ready(function() {

    var $FocusNews = $('#divFocusBar');

    var mydata = { "ClassID": 0, "FocusCount": FocusCount,
        "HotspotID": HotspotID, "HotspotClassCount": HotspotClassCount, "HotspotCount": HotspotCount,
        "FeatureID": FeatureID, "FeatureClassCount": FeatureClassCount, "FeatureCount": FeatureCount
    };

    var mymethod = "../Base/AjaxService.svc/GetIndexPage";
    AjaxWithPost(mymethod, mydata,
	function(result) {
	    if (result.IsResult) {

	        //焦点图片新闻
	        var _arrImg = [];
	        var _arrTitle = [];
	        var _arrUrl = [];
	        var strLink;
	        var focus_width = 292;
	        var focus_height = 176;
	        var text_height = 22;
	        var swf_height = focus_height + text_height

	        $.each(result.Result.FocusImg, function(i) {

	            if (this.OutUrl == '') {
	                strLink = '../Main/ShowArticle.aspx?ID=' + this.ID;
	            } else {
	                strLink = this.OutUrl;
	            }
	            _arrImg.push(this.ImgSrc);
	            _arrTitle.push(this.Title);
	            _arrUrl.push(strLink);
	        });

	        var strHtml = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
					'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ' +
					'width="' + focus_width + '" height="' + swf_height + '">' +
					'<param name="allowScriptAccess" value="sameDomain">' +
					'<param name="movie" value="../Images/Flash/focus1.swf">' +
					'<param name="quality" value="high">' +
					'<param name="bgcolor" value="#F0F0F0">' +
					'<param name="menu" value="false">' +
					'<param name="wmode" value="transparent">' +
					'<param name="FlashVars" value="pics=' + _arrImg.join('|') +
					    '&links=' + _arrUrl.join('|') + '&texts=' + _arrTitle.join('|') +
						'&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '">' +
				'</object>';

	        $FocusNews.html(strHtml);


	        var $Hotspot = $('#divHotspot');
	        $.each(result.Result.Hotspot, function(i) {
	            strHtml = '', _Id = (i + 1).toString();
	            $.each(this.News, function() {
	                var _url;
	                if (this.OutUrl != '') {
	                    _url = this.OutUrl;
	                } else {
	                    _url = '../Hotspot/ShowArticle.aspx?ID=' + this.ID;
	                }
	                strHtml += '<li class="overflow">' +
	                            '<a title="' + this.Title + '" href="' + _url + '" target="_blank">' + this.Title + '</a>' +
	                           '</li>';
	            });

	            var $div = $Hotspot.find("div.d" + _Id);
	            $div.find("span").html(this.ClassName);
	            $div.find("a").attr("href", "../Hotspot/ListArticle.aspx?TC=" + this.ClassID);
	            $Hotspot.find("ul.u" + _Id).append(strHtml);
	        });

	        var $Feature = $('#divFeature');
	        $.each(result.Result.Feature, function(i) {
	            strHtml = '', _Id = (i + 1).toString();
	            $.each(this.News, function() {
	                var _url;
	                if (this.OutUrl != '') {
	                    _url = this.OutUrl;
	                } else {
	                    _url = '../Feature/ShowArticle.aspx?ID=' + this.ID;
	                }
	                strHtml += '<li><a title="' + this.Title + '" href="' + _url + '" target="_blank" class="overflow">' + this.Title + '</a>' +
	                               '<span class="date">' + this.MakeTime + '</span>' +
	                           '</li>';
	            });

	            var $div = $Feature.find("div.d" + _Id);
	            $div.find("span").html(this.ClassName);
	            $div.find("a").attr("href", "../Feature/ListArticle.aspx?TC=" + this.ClassID);
	            $Feature.find("ul.u" + _Id).append(strHtml);
	        });
	    }
	}, null, false, 10000);
});
