// Basla
// ---------------------------------------------
var index = new Object;
$(function()
{
	index = Index();
	try 
	{
	} 
	catch(e) 
	{
	}
});


// Index
// ---------------------------------------------
function Index()
{
	var index = 
	{
		basla : function()
		{
			index.menu.basla();
			Xslide.init('div.krs div.resim');
			//index.tweeter.basla();
			getAjaxTwits('/AjaxTwits/AjaxTwits/AjaxTwitsRequest.php','/AjaxTwits/AjaxTwits/AjaxTwitsUpdate.php', 6)
		},
		anasayfa:
		{
			defileProgramGoster: function()
			{
				$('html,body').attr('scrollTop', 0).animate({'scrollTop': $('#defile-program').css('display','block').offset().top+'px'}, 1000, function(){});
			}
		},
		menu:
		{
			basla: function()
			{
				var root = $('div.nav').hover(function(){},function(){$(this).find('.on-aktif').trigger('mouseover');});
				root.find('ul.menu > li')
					.mouseover(function()
						{ 
							root.find('ul.menu > li.aktif').removeClass('aktif');
							var self = $(this).addClass('aktif');
							$('div.nav div.alt ul.aktif').removeClass('aktif');
							if (goster = self.attr('goster'))
							{
								$('div.nav div.alt ul.'+goster).addClass('aktif');
							}
						}
					);
			}
		},
		tweeter:
		{
			interval:null,
			basla:function()
			{
				index.tweeter.setTweets();
				index.tweeter.interval = setInterval(index.tweeter.setTweets, 55000);
			},
			setTweets: function() 
			{
				var holder = $('div.twt div.tweet');
				if (!holder.length)
				{
					clearInterval(index.tweeter.interval);
					clearTimeout(index.tweeter.interval);
					index.tweeter.interval = 0;
					return;
				}
				holder.empty().tweet({
					username: ["duplinn","24yet24"],
					join_text: "auto",
					avatar_size: 32,
					count: 10,
					auto_join_text_default: ",",
					auto_join_text_ed: "",
					auto_join_text_ing: "",
					auto_join_text_reply: "cevapladı",
					auto_join_text_url: "",
					loading_text: "Yükleniyor.."
				}); 
			}
				
		}
	}
	index.basla();
	return index;
}



function fpr(o)
{
	var h = "";
	for (var p in o)
	{
		h += p+"="+o[p]+"\n";
	}
	alert(h);
}


var Xslide = 
{
	wait: 2000,
	perScroll: 3000,
	mover:false,
	current:0,
	init: function(selector)
	{
		var self = this;
		self.root = $(selector)
		if (!self.root.length)
		{
			return;
		}
		self.holder = self.root.find('div.holder');
		self.children = self.holder.children();
		self.holder.css('width', self.children.first().width()*self.children.length);
		self.sag = $('div.krs div.sag').click(function(){ self.start(1); });
		self.sol = $('div.krs div.sol').click(function(){ self.start(-1); });
		self.metin = $('div.krs div.metin');
	},
	start: function(dir)
	{
		var self = this;
		if (self.root.find('div.holder:animated').length)
		{
			return;
		}
		self.current += dir;
		if (self.current < 0)
		{
			self.current = self.children.length - 1;
		}
		else if (self.current >= self.children.length)
		{
			self.current = 0;
		}
		self.scroll(dir);
	},
	scroll: function(dir)
	{
		var self = this;
		var holder = self.holder;
		self.sag.css('opacity', .4);
		self.sol.css('opacity', .4);
		var el = self.children.first();
		self.metin.html($(self.children[self.current]).attr('tanim'));
		holder.animate({'margin-left':el.width()*self.current*-1}, 3000, function() 
		{
			self.sag.css('opacity', 1);
			self.sol.css('opacity', 1);
		});
	}
}

