﻿/* 	Behzad Saeedi
	+989122035187
	behzad85@gmail.com
 */
$(document).ready(function(){
//-------------------------------------------------------------------
function parseXml(xml)
{
	if (jQuery.browser.msie)
	{
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
		xml = xmlDoc;
	}
	return xml;
}
//-------------------------------------------------------------------
jQuery.getFeed = function(options) {

    options = jQuery.extend({
    
        url: null,
        data: null,
        success: null
        
    }, options);

    if(options.url) {

        $.ajax({
            type: 'GET',
            url: options.url,
            data: options.data,
            dataType: 'xml',
            success: function(xml) {
                var feed = new JFeed(xml);
                if(jQuery.isFunction(options.success)) options.success(feed);
            }
        });
    }
};

function JFeed(xml) {
    if(xml) this.parse(xml);
};

JFeed.prototype = {

    type: '',
    version: '',
    title: '',
    link: '',
    description: '',
    parse: function(xml) {
        
        if(jQuery('channel', xml).length == 1) {
        
            this.type = 'rss';
            var feedClass = new JRss(xml);

        } else if(jQuery('feed', xml).length == 1) {
        
            this.type = 'atom';
            var feedClass = new JAtom(xml);
        }
        
        if(feedClass) jQuery.extend(this, feedClass);
    }
};

function JFeedItem() {};

JFeedItem.prototype = {

    title: '',
    link: '',
    description: '',
    updated: '',
    id: ''
};

function JAtom(xml) {
    this._parse(xml);
};

JAtom.prototype = {
    
    _parse: function(xml) {
    
        var channel = jQuery('feed', xml).eq(0);

        this.version = '1.0';
        this.title = jQuery(channel).find('title:first').text();
        this.link = jQuery(channel).find('link:first').attr('href');
        this.description = jQuery(channel).find('subtitle:first').text();
        this.language = jQuery(channel).attr('xml:lang');
        this.updated = jQuery(channel).find('updated:first').text();
        
        this.items = new Array();
        
        var feed = this;
        
        jQuery('entry', xml).each( function() {
        
            var item = new JFeedItem();
            
            item.title = jQuery(this).find('title').eq(0).text();
            item.link = jQuery(this).find('link').eq(0).attr('href');
            item.description = jQuery(this).find('content').eq(0).text();
            item.updated = jQuery(this).find('updated').eq(0).text();
            item.id = jQuery(this).find('id').eq(0).text();
            
            feed.items.push(item);
        });
    }
};

function JRss(xml) {
    this._parse(xml);
};

JRss.prototype  = {
    
    _parse: function(xml) {
    
        if(jQuery('rss', xml).length == 0) this.version = '1.0';
        else this.version = jQuery('rss', xml).eq(0).attr('version');

        var channel = jQuery('channel', xml).eq(0);
    
        this.title = jQuery(channel).find('title:first').text();
        this.link = jQuery(channel).find('link:first').text();
        this.description = jQuery(channel).find('description:first').text();
        this.language = jQuery(channel).find('language:first').text();
        this.updated = jQuery(channel).find('lastBuildDate:first').text();
    
        this.items = new Array();
        
        var feed = this;
        
        jQuery('item', xml).each( function() {
        
            var item = new JFeedItem();
            
            item.title = jQuery(this).find('title').eq(0).text();
            item.link = jQuery(this).find('link').eq(0).text();
            item.description = jQuery(this).find('description').eq(0).text();
            item.updated = jQuery(this).find('pubDate').eq(0).text();
            item.id = jQuery(this).find('guid').eq(0).text();
            
            feed.items.push(item);
        });
    }
};
var loaderHtml="<table border=0><tr><td><img src='http://adabefarsi.ir/Templates/adabefarsi_Behzad/loader.gif'></td><td style='color:#645c2a;font-size:11px;'>لطفا صبر کنید ...</td></tr></table>"
//--------------Latest News-----------------------------------------
function readLatestNews(){
$(".latestNews").html(loaderHtml);
jQuery.getFeed({
       url: rss_link_LatestNews,
       success: function(feed) {
		   $(".latestNews").html("");
            for(var i = 0; i < feed.items.length && i < 5; i++) {
				var item=feed.items[i];
				var theFeed="<table border='0'><tr><td style='font-size:11px;font-weight:500;color:#247cc0;padding:5 0 5 0;'><img src='http://adabefarsi.ir/Templates/adabefarsi_Behzad/bullet_blue.gif' style='margin:0 5 0 5;'>"+item.title+"</td></tr><tr><td style='font-size:11px;color:#616161;padding:0 10 0 10;text-align:justify;'>"+item.description+"</td></tr><tr><td style='text-align:left;padding:5px;'><div onclick=\"location.href='"+item.link+"'\" class='b_off' onmouseout='this.className=\"b_off\"' onmouseover='this.className=\"b_on\"' style='width:50px;height:18px;background-image:url(http://adabefarsi.ir/Templates/adabefarsi_Behzad/continue.gif);padding:1 0 0 8;'>ادامه...</div></td></tr></table>";
				$(".latestNews").append(theFeed);
			}
       }
   });
}
readLatestNews();
//------------------------------------------------------------------
//--------------Latest Stories-----------------------------------------
function readLatestStories(){
$(".latestStories").html(loaderHtml);
jQuery.getFeed({
       url: rss_link_latestStories,
       success: function(feed) {
		   $(".latestStories").html("");
            for(var i = 0; i < feed.items.length && i < 5; i++) {
				var item=feed.items[i];
				var theFeed="<table border='0'><tr><td style='font-size:11px;font-weight:500;color:#c02462;padding:5 0 5 0;'><img src='http://adabefarsi.ir/Templates/adabefarsi_Behzad/bullet_red.gif' style='margin:0 5 0 5;'>"+item.title+"</td></tr><tr><td style='font-size:11px;color:#616161;padding:0 10 0 10;text-align:justify;'>"+item.description+"</td></tr><tr><td style='text-align:left;padding:5px;'><div onclick=\"location.href='"+item.link+"'\" class='b_off' onmouseout='this.className=\"b_off\"' onmouseover='this.className=\"b_on\"' style='width:50px;height:18px;background-image:url(http://adabefarsi.ir/Templates/adabefarsi_Behzad/continue.gif);padding:1 0 0 8;'>ادامه...</div></td></tr></table>";
				$(".latestStories").append(theFeed);
			}
       }
   });
}
readLatestStories();
//------------------------------------------------------------------
//--------------Latest Poems-----------------------------------------
function readLatestPoems(){
$(".latestPoems").html(loaderHtml);
jQuery.getFeed({
       url: rss_link_latestPoems,
       success: function(feed) {
		   $(".latestPoems").html("");
            for(var i = 0; i < feed.items.length && i < 5; i++) {
				var item=feed.items[i];
				var theFeed="<table border='0'><tr><td style='font-size:11px;font-weight:500;color:#24c0bc;padding:5 0 5 0;'><img src='http://adabefarsi.ir/Templates/adabefarsi_Behzad/bullet_green.gif' style='margin:0 5 0 5;'>"+item.title+"</td></tr><tr><td style='font-size:11px;color:#616161;padding:0 10 0 10;text-align:justify;'>"+item.description+"</td></tr><tr><td style='text-align:left;padding:5px;'><div onclick=\"location.href='"+item.link+"'\" class='b_off' onmouseout='this.className=\"b_off\"' onmouseover='this.className=\"b_on\"' style='width:50px;height:18px;background-image:url(http://adabefarsi.ir/Templates/adabefarsi_Behzad/continue.gif);padding:1 0 0 8;'>ادامه...</div></td></tr></table>";
				$(".latestPoems").append(theFeed);
			}
       }
   });
}
readLatestPoems();
//------------------------------------------------------------------
//--------------Writers & Poets-----------------------------------------
function authorsAndPoets(){
$(".writersAndPoets").html(loaderHtml);
jQuery.getFeed({
       url: rss_link_authorsAndPoets,
       success: function(feed) {
		   $(".writersAndPoets").html("");
            for(var i = 0; i < feed.items.length && i < 5; i++) {
				var item=feed.items[i];
				var theFeed="<table border='0'><tr><td style='font-size:11px;font-weight:600;color:#a29b6c;padding:5 0 5 0;'><img src='http://adabefarsi.ir/Templates/adabefarsi_Behzad/bullet_beige.gif' style='margin:0 5 0 5;'>"+item.title+"</td></tr><tr><td style='font-size:11px;color:#616161;padding:0 10 0 10;text-align:justify;'>"+item.description+"</td></tr><tr><td style='text-align:left;padding:5px;'><div onclick=\"location.href='"+item.link+"'\" class='b_off' onmouseout='this.className=\"b_off\"' onmouseover='this.className=\"b_on\"' style='width:50px;height:18px;background-image:url(http://adabefarsi.ir/Templates/adabefarsi_Behzad/continue.gif);padding:2 0 3 6;'>بیشتر...</div></td></tr></table>";
				$(".writersAndPoets").append(theFeed);
			}
       }
   });
}
authorsAndPoets();
//------------------------------------------------------------------
//--------------Most Visited-----------------------------------------
function mostVisited(){
$(".mostVisitedz").html(loaderHtml);
jQuery.getFeed({
       url: rss_link_mostVisited,
       success: function(feed) {
		   $(".mostVisitedz").html("");
            for(var i = 0; i < feed.items.length && i < 5; i++) {
				var item=feed.items[i];
				var theFeed="<table border='0'><tr><td style='font-size:11px;font-weight:600;color:#29c1be;padding:5 0 5 0;'><img src='http://adabefarsi.ir/Templates/adabefarsi_Behzad/bullet_green.gif' style='margin:0 5 0 5;'>"+item.title+"</td></tr><tr><td style='font-size:11px;color:#616161;padding:0 10 0 10;text-align:justify;'>"+item.description+"</td></tr><tr><td style='text-align:left;padding:5px;'><div onclick=\"location.href='"+item.link+"'\" class='b_off' onmouseout='this.className=\"b_off\"' onmouseover='this.className=\"b_on\"' style='width:50px;height:18px;background-image:url(http://adabefarsi.ir/Templates/adabefarsi_Behzad/continue.gif);padding:2 0 3 6;'>بیشتر...</div></td></tr></table>";
				$(".mostVisitedz").append(theFeed);
			}
       }
   });
}
mostVisited();
//------------------------------------------------------------------

//--------------NewsFour-----------------------------------------------
function newsFour(){
	$(".newsContent").html(loaderHtml);
$.get("http://adabefarsi.ir/Templates/adabefarsi_Behzad/news.js",function(xml){
		$(".newsContent").html("");
		xml=parseXml(xml);
		var images=Array();
		var titles=Array();
		var urls=Array();
		var descriptions=Array();
		$(xml).find("item").each(function(){
			images.push($(this).find("image").text());
			titles.push($(this).find("title").text());
			urls.push($(this).find("url").text());
			descriptions.push($(this).find("description").text());
		});
//------------------------------------------------------------------
var html1='<table style="width: 100%">';
html1+='<tr><td style="width: 50%"><table style="width: 100%"><tr>';
html1+='<td valign="top" width="89"><div class="dropShadow" style="width:89px;height:86px;"><div class="dsContent" style="width:89px;height:86px;"><img style="width:89px;height:86px;" src="'+images[0]+'"></div></div></td>';
html1+='<td style="padding:10 0 0 0;" valign="top"><div class="simpleText2">'+titles[0]+'</div><div class="simpleText1">'+descriptions[0]+'</div><div><a href="'+urls[0]+'">ادامه...</a></div></td>';
html1+='</tr></table></td><td style="width: 50%"><table style="width: 100%"><tr>'
html1+='<td valign="top" width="89"><div class="dropShadow" style="width:89px;height:86px;"><div class="dsContent" style="width:89px;height:86px;"><img style="width:89px;height:86px;" src="'+images[1]+'"></div></div></td>';
html1+='<td style="padding:10 0 0 0;" valign="top"><div class="simpleText2">'+titles[1]+'</div><div class="simpleText1">'+descriptions[1]+'</div><div><a href="'+urls[1]+'">ادامه...</a></div></td></tr></table></td></tr><tr><td style="width: 50%"><table style="width: 100%"><tr>';
html1+='<td valign="top" width="89"><div class="dropShadow" style="width:89px;height:86px;"><div class="dsContent" style="width:89px;height:86px;"><img style="width:89px;height:86px;" src="'+images[2]+'"></div></div></td>';
html1+='<td style="padding:10 0 0 0;" valign="top"><div class="simpleText2">'+titles[2]+'</div><div class="simpleText1">'+descriptions[2]+'</div><div><a href="'+urls[2]+'">ادامه...</a></div></td></tr></table></td><td style="width: 50%"><table style="width: 100%"><tr>';
html1+='<td valign="top" width="89"><div class="dropShadow" style="width:89px;height:86px;"><div class="dsContent" style="width:89px;height:86px;"><img style="width:89px;height:86px;" src="'+images[3]+'"></div></div></td>';
html1+='<td style="padding:10 0 0 0;" valign="top"><div class="simpleText2">'+titles[3]+'</div><div class="simpleText1">'+descriptions[3]+'</div><div><a href="'+urls[3]+'">ادامه...</a></div></td></tr></table></td></tr></table>';
//------------------------------------------------------------------
$(".newsContent").html(html1);
//---------Featured-------------------------------------------------
var html2='<table style="width: 100%"><tr>';
html2+='<td style="width:202px;"><div class="dropShadow" style="width:202px;height:176px;"><div class="dsContent" style="width:202px;height:176px;"><img onclick=\'location.href="'+urls[4]+'"\' style="width:202px;height:176px;cursor:pointer;" src="'+images[4]+'"></div></div></td>';
html2+='<td style="padding:10 0 0 0;" valign="top"><div class="simpleText3">'+titles[4]+'</div><div class="simpleText4">'+descriptions[4]+'</div></td></tr></table>';
$(".fchrd").html(html2);
//------------------------------------------------------------------
})
}
newsFour();
//------------------------------------------------------------------
function loadAdvs(){
	var html="";
	for(i=0;i<advs.length;i++) {
		html+='<div style="width:621px;height:135px;background-image:url('+advs[i]+');"><div style="position:relative;top:110;background-color:white;height:30px;color:black;padding:5px;" class="advtext">'+txts[i]+'</div></div>';
	}
	$(".topADV").html(html);
	$(".advtext").fadeTo('slow',0.5);
}
loadAdvs();
//------------------------------------------------------------------
});