$.easing.elasout = function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	};

$(document).ready(function () {
	$('#b_titles a').each(function(){$(this).css('background','url(_img/'+$(this).attr('rel')+'0.jpg) no-repeat center center')}).mouseover(function(){$(this).css('background','url(_img/'+$(this).attr('rel')+'1.jpg) no-repeat center center')}).mouseout(function(){$(this).css('background','url(_img/'+$(this).attr('rel')+'0.jpg) no-repeat center center')});
	$('#subnav_0_link').click(function(){
		var lang=$(this).attr('data-lang');
		$('#subnav_0').css('display','block');
		if($('#b_timeline').attr('loaded') != 1){
			$('#months_navigation').css('background','#F90735 url(ajax-loader.gif) no-repeat 5px');
			$.ajax({
				type: 'GET',
				url: 'getmonths.php?l='+lang,
				cache: true,
				success: function(r) {
					$('#b_timeline').attr('loaded', 1);
					var scrollt=$('#b_timeline').attr('rel');
					$('#timeline_content').html(r);
					$('#months_holder').css('background','none');
					_fix_timeline();
					_make_draggable();
					var tm=$('.timeline_month').size();
					$('#months_navigation_holder').css('width',(tm*100)+'px');
					$('.timeline_month').each(function(){
						var title=$(this).attr('rel');
						var id=$(this).attr('id');
						var order=$(this).attr('order');
						var el=$('<li>').attr('id',id+'_trigger').click(function(){
								_get_events(id);
								$('#months_holder').scrollTo($('#'+id), 1000,{easing:'elasout'});
								$('#months_navigation_holder ul li').removeClass('selected');
								var scrollcount=(order*100)-200;
								if(scrollcount<0){
									scrollcount=0;
								}
								$('#months_navigation_inner').scrollTo(scrollcount,{easing:'elasout'});
								$(this).addClass('selected');
							}).html('<a>'+title+'</a>');
							$('#months_navigation_holder ul').append(el);
					}).mouseover(function(){
						var scrollcount=($(this).attr('order')*100)-200;
						if(scrollcount<0){
							scrollcount=0;
						}
						$('#months_navigation_inner').scrollTo(scrollcount,{easing:'elasout'});
						$('#months_navigation_holder ul li').removeClass('selected');
						$('#months_navigation_holder ul li#'+$(this).attr('id')+'_trigger').addClass('selected');
						_get_events($(this).attr('id'));
					});
					var orderx=$('#'+scrollt).attr('order');
					var scrollcount=(orderx*100)-200;
					if(scrollcount<0){
						scrollcount=0;
					}
					$('#months_holder').scrollTo($('#'+scrollt), 1000,{easing:'elasout'});
					$('#months_navigation_inner').scrollTo(scrollcount,{easing:'elasout'});
					_get_events(scrollt);
					$('#months_navigation_holder ul li#'+scrollt+'_trigger').addClass('selected');
					$('#months_navigation').css('background','#F90735');
					$('#timeline_overlay').remove();
					$('#timeline_previous').click(function(){
						var next=$('#months_navigation_holder ul li.selected').prev().attr('id');
						$('#'+next).click();
					});
					$('#timeline_next').click(function(){
						var next=$('#months_navigation_holder ul li.selected').next().attr('id');
						$('#'+next).click();
					});
				}
			});

		}
	});
	setInterval("_fade_istanpoli();",3000);
});
_fade_istanpoli=function(){
	var current=$('.current_fade');
	var id=current.attr('id');
	var next=current.attr('data-next');
	current.removeClass('current_fade');
	current.fadeOut();
	$('#'+next).addClass('current_fade').fadeIn();
}
_make_draggable=function(){
	$('#months_holder').mousedown(function (event) {
		$(this)
			.data('down', true)
			.data('x', event.clientX)
			.data('scrollLeft', this.scrollLeft);
			
		return false;
	}).mouseup(function (event) {
		$(this).data('down', false);
	}).mousemove(function (event) {
		if ($(this).data('down') == true) {
			this.scrollLeft = $(this).data('scrollLeft') + $(this).data('x') - event.clientX;
		}
		_fix_timeline();
	}).css({
            'cursor' : '-moz-grab'
    });
}
_fix_timeline=function(){
	var cwidth=0;
	$('.timeline_month').each(function(){
		cwidth=cwidth+$(this).width()+6;
	});
	$('#timeline_content').css('width',cwidth+'px');
}
_go_to_month=function(id){
	
}
_get_events=function(id){
	var lang=$('#subnav_0_link').attr('data-lang');
	var datax=$('#'+id).attr('loaded');
	if(datax<1){
		$('#months_navigation').css('background','#F90735 url(ajax-loader.gif) no-repeat 5px');
		$('#'+id).attr('loaded',1);
		$.ajax({
			type: 'GET',
			url: 'getevents.php?id='+id+'&l='+lang,
			cache: true,
			dataType: "json",
			success: function(r) {
				$('#'+id).css('background','none');
				if(r.events){
					$.each(r.events, function(k,v) {
						var el=$('<span>').addClass('b_timeline_event').html('<a href=\"etkinlik.php?id='+v.id+'\"><img src=\"_img/img.php?gosteri='+v.id+'&n=11\" /></a>').mouseover(function(){
							var tl=$(this).offset();
							$('#thisMonth_title').html(v.baslik);
							$('#thisMonth_subTitle').html(v.altbaslik);
							$('#thisMonth_date').html(v.date+'<br>'+v.time);
							$('#thisMonth_image').css('background','url(_img/img.php?gosteri='+v.id+'&n=5) no-repeat scroll 0 13px');
							$('#takvimci').css({'display':'block','top':(tl.top-243)+'px','left':(tl.left-78)+'px'});
						}).mouseout(function(){
							$('#takvimci').css('display','none');
						});
						$('#'+v.mnth+'_category_'+v.disiplin+'_'+v.day).append(el);
					});
					$('#months_navigation').css('background','#F90735');
					_fix_timeline();
				}
			}
		});
	}
}
_change_date=function(month,year){
	$('.newList').hide().parent().removeClass('newListSelFocus');
	$.ajax({
			type: 'GET',
			url: 'getevents.php?id=timeline_month_'+year+'-'+month,
			cache: true,
			dataType: "json",
			success: function(r) {
					$('#thisMonth_calendar').html('');
					if(r.wdx){
						$('#thisMonth_calendar').append(r.wdx);
					}
					if(r.mdates){
						for(i=1;i<=r.mdates;i++){
							var el=$('<span>').addClass('weekDay').attr('id','tmdate_'+i).html(i);
							$('#thisMonth_calendar').append(el);
						}
					}
					if(r.events){
						$.each(r.events, function(k,v) {
							var el=$('<a>').attr('href','etkinlik.php?id='+v.id).html(v.day).mouseover(function(){
								var tl=$(this).offset();
								$('#thisMonth_title').html(v.baslik);
								$('#thisMonth_subTitle').html(v.altbaslik);
								$('#thisMonth_date').html(v.date+'<br>'+v.time);
								$('#thisMonth_image').css('background','url(_img/img.php?gosteri='+v.id+'&n=5) no-repeat scroll 0 13px');
								$('#takvimci').css({'display':'block','top':(tl.top-243)+'px','left':(tl.left-86)+'px'});
							}).mouseout(function(){
								$('#takvimci').css('display','none');
							});
							$('#tmdate_'+v.day).html(el);
						});
					}
				}
		});
}