if (typeof PixelCms=="undefined") var PixelCms = new Object();
PixelCms.getArticleUrl = function(id) 
{
	var cms = location.href.indexOf("http://192.168")>-1;
	if (typeof(id)=="number") 
	{
		return cms? "/XmlArticles.ashx?id="+id : "/xml/a_"+id+".xml";
	} 
	else if (typeof(id)=="string") 
	{
		return cms? "/XmlArticles.ashx?cat="+id : "/xml/index_"+id+".xml";
	}
}

PixelCms.ArticleCombo = function(_cat, divId, mode)
{
	this.cat = _cat;
	this.mode = mode;
	this.content = ge(divId);
	this.content.appendChild(this.combo = document.createElement("select"));
	this.content.appendChild(this.content = document.createElement("div"));

	this.combo.style.width = '100%';
	this.fill= function()
	{
		ky.ajax.loadXmlObject(PixelCms.getArticleUrl(this.cat), this.fill2, this);
	}

	this.fill2 = function(o) 
	{
		var id = ky.QueryString["id"];
		var si = 0;
		this.combo.options.length = 0;
		if (this.mode=="pop") this.combo.options[0] = new Option("Seçiniz...");
		for (var i=0; i<o.length; i++) 
		{
			this.combo.options[this.combo.options.length] = new Option("["+o[i].publishdate+"] "+o[i].title, o[i].id);
			if (o[i].id==id) si = i;
		}
		this.combo.selectedIndex = si;
		if (this.mode!="pop") this.getArticle();
	}

	this.getArticle = function() 
	{
		if (this.combo.selectedIndex<1)	return;
		var aid = Number(this.combo.options[this.combo.selectedIndex].value);
		if (this.mode=="pop")
		{
			this.win = window.open("","win","width=540,height=640,resizable=1");
			this.win.document.write("<html><head><style>body { font:11px Verdana; }</style></head><body><div id='content'>Yükleniyor...</div></body></html>");
			this.win.document.close();
			ky.ajax.loadXmlObject(PixelCms.getArticleUrl(aid), this.initArticle2, this);
		}
		else
		{
			this.content.innerHTML = "Yükleniyor...";
			ky.ajax.loadXmlObject(PixelCms.getArticleUrl(aid), this.initArticle, this);
		}
	}

	this.initArticle = function(o) 
	{
		this.content.innerHTML = o.body;
	}

	this.initArticle2 = function(o) 
	{
		this.win.document.getElementById('content').innerHTML = o.body;
	}

	this.fill();
	ky.utils.addHandler(this.combo, "change", this, "getArticle");
}

PixelCms.ArticleList = function(_cat, divId, url)
{
	this.cat = _cat;
	this.content = ge(divId);
	this.url = url;

	this.fill = function()
	{
		ky.ajax.loadXmlObject(PixelCms.getArticleUrl(this.cat), this.fill2, this);
	}

	this.fill2 = function(o) 
	{
		var str = "";
		for (var i=0; i<o.length; i++) {
			str+= "<h4>"+o[i].publishdate+"</h4><a href=\""+this.url+"?id="+o[i].id+"\">"+o[i].title+"</a>";
		}
		this.content.innerHTML = str;
	}

	this.fill();
}

PixelCms.ArticleDictionary = function(_cat, lettersDiv, entriesDiv, contentDiv)
{
	this.cat = _cat;

	this.letterListDiv = ge(lettersDiv);
	this.entryListDiv = ge(entriesDiv);
	this.contentDiv = contentDiv;
	ky.ajax.loadXmlObject(PixelCms.getArticleUrl(this.cat), this.fill2, this);
}

PixelCms.ArticleDictionary.prototype.fill2 = function(o) 
{
	o.sort(ky.utils.objsort);
	this.list = o;
	var lastletter;
	for (var i=0; i<this.list.length; i++) 
	{
		var a = this.trTransform(this.list[i].title.substr(0, 1));

        if (a!=lastletter)
        {
			lastletter = a;
			var span = document.createElement("a");
			span.innerHTML = a;
			span.href = 'javascript:;'
			span.className = "pixelcms-dictionary-letter";
			span.id = this.cat+"_"+a;
			ky.utils.addHandler(span, "click", this, this.setLetter, [a]);
			this.letterListDiv.appendChild(span);
        }
    }
    this.setLetter(this.list[0].title.substr(0, 1).toUpperCase());
}

PixelCms.ArticleDictionary.prototype.trTransform = function(a)
{
	a = a.toUpperCase();
	if (a=="İ") return "I";
	else if (a=="Ç") return "C";
	else if (a=="Ü") return "U";
	else if (a=="Ö") return "O";
	else if (a=="Ş") return "S";
	else return a;
}

PixelCms.ArticleDictionary.prototype.setLetter = function(a)
{
	if (this.selectedLetter!=a)
	{
		if (this.selectedLetter)
		{
			ge(this.cat+"_"+this.selectedLetter).className = 'pixelcms-dictionary-letter';
		}
		this.selectedLetter = a;
		ge(this.cat+"_"+a).className = 'pixelcms-dictionary-letter-selected';
	} 
	else return

	this.entryListDiv.innerHTML = '';
    for (var i=0; i<this.list.length; i++) 
    {
		var firstLetter = this.trTransform(this.list[i].title.substr(0, 1));
        if (a==firstLetter)
        {
			var span = document.createElement("a");
			span.href = 'javascript:;';
			span.innerHTML = this.list[i].title;
			span.className = "pixelcms-dictionary-entry";
			ky.utils.addHandler(span, "click", this, this.loadArticle, [Number(this.list[i].id)]);
			this.entryListDiv.appendChild(span);
		}
	}
}

PixelCms.ArticleDictionary.prototype.loadArticle = function(id)
{
	ge(this.contentDiv).innerHTML = 'Yükleniyor '+PixelCms.getArticleUrl(id);
	ky.ajax.loadXmlObject(PixelCms.getArticleUrl(id), this.fillDetails, this);	
}

PixelCms.ArticleDictionary.prototype.fillDetails = function(o) 
{
	ge(this.contentDiv).innerHTML = "<h2>"+o.title +"</h2>" + (o.image?"<img src='"+o.image+"' align='left' />":"") + o.body;
}
