var curPos = 0;
var haberler = new Array();
$(function(){
	$.ajax({
		type:"GET",
		url:"xml/haberler.xml",
		dataType:"xml",
		success:function(xml){
			var l = $(xml).find('item').length;
			var n = $(xml).find('item');
			for(var i=0;i<l;i++)
			{
				haberler.push(n.eq(i));		
			}
		$('div#solok a').trigger('click');
		}
	});
	
	$('div#sagok a').click(function(){
		var l = haberler.length - 1;
		curPos++;
		if(curPos>l)
		{curPos=l}
		switch(haberler[curPos].attr('type'))
		{
			case 'Text' : 
				$('div#ayrinti').empty()
					.prepend(
						$('<a />')
							.attr('href',haberler[curPos].attr('url'))
							.attr('href','_self')
							.append(haberler[curPos].children('desc').text())
							)
					 .prepend(haberler[curPos].children('title').text());				  
				break ;
			case 'Image' : 
				$('div#ayrinti').empty()
					.prepend(
						$('<p />')
							.attr('class','haberGorsel')
							.append(
								$('<a />')
									.attr('class','haber')
									.attr('href','images/haberler/'+haberler[curPos].attr('largeSrc'))
									//.attr('target','_self')
									.attr('rel','haber')
									.append(
										$('<img />')
											.attr('src','images/haberler/'+haberler[curPos].attr('thumbSrc'))
											.attr('border','0')
											.attr('alt','haber')
											)
									)
							)
				   .prepend(haberler[curPos].children('title').text())
				break; ;
		}
		$('a.haber').fancybox();
	});
	
	$('div#solok a').click(function(){
		var l = haberler.length - 1;
		curPos--;
		if(curPos<0)
		{curPos=0}	
		switch(haberler[curPos].attr('type'))
		{
			case 'Text' : 
				$('div#ayrinti').empty()
					.prepend(
						$('<a />')
							.attr('href',haberler[curPos].attr('url'))
							.attr('target','_self')
							.append(haberler[curPos].children('desc').text())
							)
					.prepend(haberler[curPos].children('title').text());
				break ;
			case 'Image' : 
				$('div#ayrinti').empty()
					.prepend(
						$('<p />')
							.attr('class','haberGorsel')
							.append(
								$('<a />')
									.attr('class','haber')
									.attr('href','images/haberler/'+haberler[curPos].attr('largeSrc'))
									//.attr('target','_self')
									.attr('rel','haber')
									.append(
										$('<img />')
											.attr('src','images/haberler/'+haberler[curPos].attr('thumbSrc'))
											.attr('border','0')
											.attr('alt','haber')
											)
									)
							)
					.prepend(haberler[curPos].children('title').text())
					break; ;
		}
		$('a.haber').fancybox();
	});	
});
