var cur_inter_timeline = 0;
var inter_timeline = [];
var inter_timeline_last;

function inter_timeline_swap (){
	if (inter_timeline[cur_inter_timeline].text == ''){
		$('#inter-timeline dl dt').css('background', 'none');
	} else {
		$('#inter-timeline dl dt').css('background', 'url(/bc/assets/images/trans30.png) repeat');
	}

	var move_selector = inter_timeline[cur_inter_timeline].pos;
	// if (inter_timeline[cur_inter_timeline].pos >= 0 && inter_timeline[cur_inter_timeline].pos < 720 && $('#inter-timeline dl dd .selector').css('display') == 'none') $('#inter-timeline dl dd .selector').css('display', 'block');
	$('#inter-timeline dl dd .selector').stop(false, false).animate({ left: move_selector+'px' }, 500, function(){
		// if (inter_timeline[cur_inter_timeline].pos < 0 || inter_timeline[cur_inter_timeline].pos >= 720) $('#inter-timeline dl dd .selector').css('display', 'none');
	});

	$('#inter-timeline dl dt p').stop(true, true).animate({ 'opacity': 0 }, 250, function(){
		$('#inter-timeline dl dt p').html(inter_timeline[cur_inter_timeline].text);
		$('#inter-timeline dl dt p').animate({ 'opacity': 1 }, 250);
	});
	$('#inter-timeline-img').attr('src', inter_timeline[cur_inter_timeline].img);


	if (cur_inter_timeline == 0){
		$('.inter-timeline-previous').removeClass('inter-timeline-more');
		if (cur_inter_timeline < inter_timeline_last) $('.inter-timeline-next').addClass('inter-timeline-more');
	} else if (cur_inter_timeline == inter_timeline_last){
		$('.inter-timeline-previous').addClass('inter-timeline-more');
		$('.inter-timeline-next').removeClass('inter-timeline-more');
	} else {
		$('.inter-timeline-previous').addClass('inter-timeline-more');
		$('.inter-timeline-next').addClass('inter-timeline-more');
	}
}

$(document).ready(function(){
	inter_timeline_swap();

	$('#inter-timeline dl dd li').each(function(idx) {
		if (inter_timeline_last >= idx){
			$(this).css('left', inter_timeline[idx].pos+'px');
			$('span', this).text(inter_timeline[idx].date);
		}
	});

	$('.inter-timeline-next').live('click', function(){
		if (cur_inter_timeline < inter_timeline_last){
			cur_inter_timeline++;
			inter_timeline_swap();
		}
	});

	$('.inter-timeline-previous').live('click', function(){
		if (cur_inter_timeline > 0){
			cur_inter_timeline--;
			inter_timeline_swap();
		}
	});

	$('#inter-timeline dl dd li').live('click', function(){
		var idx = parseInt($('img', this).attr('rel'));
		if (idx >= 0 && idx <= inter_timeline_last){
			cur_inter_timeline = idx;
			inter_timeline_swap();
		}
	});
});
