function BindAds() 
{
	// Top|GroupID|ADType
	var ads = new Array();
	ads[0] = "1|1|ad_header";
	ads[1] = "1|2|ad_skyscraper";
	ads[2] = "1|3|ad_veftv";
	ads[3] = "1|4|ad_adalfrett";
	ads[4] = "1|5|ad_popular";
	ads[5] = "1|6|ad_realestate";
	ads[6] = "1|7|ad_millifretta1";
	ads[7] = "1|8|ad_millifretta2";
	ads[8] = "1|9|ad_millifretta3";
	ads[9] = "1|10|ad_vinstri1";
	ads[10] = "2|11|ad_vinstri2";
	ads[11] = "2|12|ad_vinstri3";
	ads[12] = "1|18|ad_left";
	ads[13] = "1|19|ad_midbanner1";
	ads[14] = "1|20|ad_midbanner2";
	ads[15] = "1|21|ad_midbanner3";
	
	Dacoda.Web.FrontEnd.CAJAX.GetAds(ads, GetAds_CallBack);	
}

function BindRSS() 
{
	// Kylfingur
	Dacoda.Web.FrontEnd.CAJAX.GetRSS("http://kylfingur.vf.is/resources/rss.aspx", GetKylfingur_CallBack);
}

function GetAds_CallBack(res) 
{
	var ds = res.value; 

	if( ds != null && typeof(ds) == "object" && ds.Tables != null ) 
	{
		var strAdVinstri1 = "";
		var strAdVinstri2 = "";
		var strAdVinstri3 = "";
		
		for(var i=0; i < ds.Tables[0].Rows.length; i++) 
		{		
			var strAd = "";
			var strID = ds.Tables[0].Rows[i].ID;
			var strURL = ds.Tables[0].Rows[i].URL;
			var strTarget = ds.Tables[0].Rows[i].Target;
			var strImage = ds.Tables[0].Rows[i].Image;
			var strFlash = ds.Tables[0].Rows[i].Flash;
			var strWidth = ds.Tables[0].Rows[i].Width;
			var strHeight = ds.Tables[0].Rows[i].Height;
			var strADType	= ds.Tables[0].Rows[i].ADType;
			
			if (strFlash != "")
			{
				strAd = "<embed width=\"" + strWidth + "\" height=\"" + strHeight + "\" type=\"application/x-shockwave-flash\" quality=\"high\" wmode=\"Window\" scale=\"ShowAll\" src=\"" + strFlash + "\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" name=\"movie\"></embed>";
			}
			else if (strImage != "")
			{
				if (strURL != "")
				{
					strAd = "<a href=\"/framework/resources/forms/ads.aspx?ID=" + strID + "\"";
					if (strADType == "ad_header")
					{
						strAd += " class=\"header-banner\"";
					}
					else if (strADType == "ad_skyscraper")
					{
						strAd += " id=\"banner\"";
					}					
					strAd += " target=\"" + strTarget + "\"><img src=\"" + strImage + "\" border=\"0\"/></a>";
				}
				else
				{
					strAd = "<img src=\"" + strImage + "\"";
					if (strADType == "ad_header")
					{
						strAd += " class=\"header-banner\"";
					}
					else if (strADType == "ad_skyscraper")
					{
						strAd += " id=\"banner\"";
					}
					strAd += " border=\"0\"/>";
				}
			}


			if (strFlash != "" || strImage != "")
			{
				if(document.getElementById(strADType))
				{
					document.getElementById(strADType).innerHTML = strAd; 
				}											
			
			}
		}
	}
}

function GetMonthName(_month)
{
	if (_month == 0)
	{
		return "jan&uacute;ar";
	}
	else if (_month == 1)
	{
		return "febr&uacute;ar";
	}
	else if (_month == 2)
	{
		return "mars";
	}
	else if (_month == 3)
	{
		return "apr&iacute;l";
	}
	else if (_month == 4)
	{
		return "ma&iacute;";
	}
	else if (_month == 5)
	{
		return "j&uacute;ní";
	}
	else if (_month == 6)
	{
		return "j&uacute;l&iacute;";
	}
	else if (_month == 7)
	{
		return "&aacute;g&uacute;st";
	}
	else if (_month == 8)
	{
		return "september";
	}
	else if (_month == 9)
	{
		return "okt&oacute;ber";
	}
	else if (_month == 10)
	{
		return "n&oacute;vember";
	}
	else if (_month == 11)
	{
		return "desember";
	}
}

function GetKylfingur_CallBack(res) 
{
	var ds = res.value; 

	if( ds != null && typeof(ds) == "object" && ds.Tables != null ) 
	{
		var strContent = "<ul class=\"list\">\n"
		
		for(var i=0; i < 3; i++) 
		{
			var strTitle = ds.Tables[2].Rows[i].title;
			var strLink = ds.Tables[2].Rows[i].link;
			var strDescription = ds.Tables[2].Rows[i].description;
			var strImage = "";
			if (strDescription.indexOf("|") > 0)
			{
				var arrDescription = ds.Tables[2].Rows[i].description.split("|");
				strDescription = arrDescription[1];
				strImage = arrDescription[0];
			}
			if(strDescription.length > 100)
			{
				strDescription = strDescription.substring(0,100) + "...";
			}
			var strLink = ds.Tables[2].Rows[i].link;
		
			//correction for some erronous image source parsing
			if(strImage.indexOf('>') > -1)
			{				
				strImage = strImage.substring(0,strImage.indexOf('>'));
			}
		
			var article = "<li class=\"first\">\n";
			article += "<h4><a href=\"" + strLink + "\">" + strTitle + "</a></h4>";
			article += "<p><img src=\"http://kylfingur.vf.is/resources/imgresize.aspx?img=" + strImage + "&w=100&h=73\" style=\"width:100px;height:73px;\" alt=\"\"/>" + strDescription + "<a href=\"" + strLink + "\">Meira</a></p>\n";			
			article += "</li>\n";
					
			strContent += article;	
		}
		
		
		strContent += "</ul>";
		document.getElementById("kylfingur").innerHTML = strContent;				
	}
}
