//Kerem Ozben - 15.04.2010
var u;
if(document.location.href=="http://m.istanbulmodern.org/"){
	u = "http://m.istanbulmodern.org/anasayfa.ashx";}else{
	u = "http://iphone.istanbulmodern.org/anasayfa.ashx";}

var position = 0;
var t;
$(function(){
	veriCek(position);
	repeat();
	$('#g1 a').click(function(){ position = position - 1; veriCek(position); });	
	$('#i2 a').click(function(){ position = position + 1; veriCek(position); });
});

function repeat()
{
	var len;
		$.ajax({
			type:"GET",
			dataType:"xml",
			url:u,
			success:function(xml){
				len = $(xml).find("item[lang='TR']").length; 
				t=setTimeout("repeat()",8000);
			veriCek(position);//alert(len);
			position++;
			if(position==len)
			{position=0;}}
		});
}

function veriCek(i)
{
	$.ajax({
	    type: "GET",
 		url: u,
		dataType : "xml",
		success:function(xml){			
		
			var o = $(xml).find("item[lang='TR']");
		
           	var itemLength = o.length;
			if(i<0){ i=0; position=0; }else if(i>=itemLength){ i=itemLength-1; position=itemLength-1; }
			var itemTitle = o.eq(i).attr('title');
			var itemStartDate = o.eq(i).attr('startDate');
			var itemEndDate = o.eq(i).attr('endDate');
			var itemHref = o.eq(i).attr('href');
			var lang = o.eq(i).attr('lang');
			var itemFullDate;
				if(itemStartDate == itemEndDate)
				{
					itemFullDate = itemStartDate;
				}
				else
				{
					itemFullDate = itemStartDate + ' - ' + itemEndDate;
				}
			var itemType = o.eq(i).attr('category');
			var itemHref = o.eq(i).attr('href');
			var itemImageName = o.eq(i).attr('imageName');
			$('#anaresim').empty().append('<a href="'+ itemHref +'"><img src="'+ itemImageName +'" alt="İstanbul Modern" border="0" /></a>');
			$('p.baslik').empty().append('<a href="'+ itemHref +'">'+itemTitle+'</a>');
			$('p.ayrintilar').empty().append('<a href="'+ itemHref +'">'+itemFullDate+'</a>');
			//$('p.ayrintilar span a').empty().append(itemType);  //Etkinlik Tipini yazdirmak icin comment i kaldirin.
		}
   });		
}
