var basbnnr=0;
var cbanner=0;

function slideto(to)
{
	$('#slidesholder').stop();
	$('#slidesholder').animate({'top':-to});
}

function s_menuayar()
{
	if ($('#s_menu').size()!=0)
	{
		$img=$('#s_menu img:first');
		$img.position().top=$('#s_menu').position().top;
		
		$('#s_menu a').each(function()
		{
			$(this).hover(function()
			{
				$img.stop();
				$meni=$(this);
				$img.animate({'opacity':0},{duration:200, complete:function()
				{
					var left=$meni.position().left+$meni.width()/2-$img.width()/2+15;
					$img.css('left',left);
					$img.animate({'opacity':1},200);
				}});
			});
		});
		
	}
}

function portfolyos()
{
	$('.portfolyo_item').each(function()
	{
		var $span=$(this).find('span');
		$span.css('opacity',0);
		var $sh=$span.height()+14;
		$(this).hover(function()
		{
			$span.stop();
			$span.animate({'top':-$sh,'opacity':0.8});
		},
		function()
		{
			$span.stop();
			$span.animate({'top':0,'opacity':0});
		});
	});
}

function menuayar()
{
	$('#menu a').each(function()
	{
		$(this).hover(function()
		{
			var left=$(this).position().left+Math.round($(this).width()/2)-22;
			menbggit(left);
		});
	});
	
	$first=$('#menu a:first').position().left+Math.round($('#menu a:first').width()/2)-22;
	menbggit($first);
}

function bannerayar()
{
	if (cbanner==0)
	{
		cbanner=$('#bannert .banner').size();
		$("#bannert .banner:first").clone().appendTo("#bannert");
		$('#bannert .banner:first').css('opacity','1');
	}
	
	if (basbnnr==cbanner)
	{
		$('#bannert').css('top','0');
		basbnnr=0;
		bannerayar();
	}else
	{	
		$('#bannert').animate({
			top:'-=400px'
		},{complete:function()
		{	
			basbnnr++;
			setTimeout('bannerayar()',4000);
			}
		});
	}
}

function menbggit(x)
{
	$('#menbg').stop();
	$('#menbg').animate({'left':x+'px'},500);
}

function begen(id)
{
	$.ajax({type:'GET',
	url:'/funcs.php?islem=oyarttir&id='+id,
	success:function(msg)
	{
		$('#oylama').html(msg);
	}});
}

function tweetanim(id)
{
	if (id>=0)
	{
		$('#tw_'+id).fadeIn('slow');
		id--;
		setTimeout('tweetanim('+id+')',3500);
	}
}

function twittercallback( tweet ) {
    tweet[0].user.profile_image_url;
	for (var i=0; i<tweet.length; i++)
	{
		$('#tweetprof').html($('#tweetprof').html()+'<a href="http://twitter.com/actreklam" class="tweet" id="tw_'+i+'">'+tweet[i].text+'</a>');
		$('#tw_'+i).hide();
	}
	twcount=tweet.length;	
	tweetanim(tweet.length);
}

$(document).ready(function()
{
	menuayar();
	portfolyos();
	s_menuayar();
	setTimeout('bannerayar()',4000);
	$('.colorbox').colorbox();
	$('.minis').tipsy({fade: true,gravity:'s'});

	if ($('#tweetprof').size()>0)
	{
		$.ajax({
		url: "http://twitter.com/status/user_timeline/actreklam.json?count=10",
		data: { count: 1 },
		dataType: "jsonp",
		success: twittercallback
		});
	}
});