function selectActiveLink(id) {
    id++;
    $('.advantagesLinks a').removeClass('active');
    $('.advantagesLinks a[rel="clip_'+ id +'"]').addClass('active');
}

function targetLink(id) {
	var leftScroll = $('#leftScroll');
	var rightScroll = $('#rightScroll');

	if (id == 0) {
		leftScroll.attr("rel", "clip_" + 9);
	} else {
		leftScroll.attr("rel", "clip_" + id);
	}
	
	if (id == 8) {
		rightScroll.attr("rel", "clip_" + 1);
	} else {
		rightScroll.attr("rel", "clip_" + (id + 2));
	}
}

function onStopImageFlow(index) {
    $('.textHidden').hide();
    if (index == 2 || index == 4) {
        $('.chapter'+index).show();
    }
    selectActiveLink(index);
}

runOnLoad(function(){
   advantagesInit();
   $('.advantagesLinks a, .#scrollbar a').each(function() {
        $(this).unbind("click");
        $(this).click(function(){
            var clip = this.rel.split('_')[1] - 1;
            glideTo(-(clip * xstep), clip);
            selectActiveLink(clip)
        });
    });
});