function sl_video_init() {
    SL_CURRENT_VIDEO = 1;
    SL_FIRST_VIDEO = 1;
    SL_LAST_VIDEO = 0;
    $ = jQuery;
    $('.sl_video').hide();
    $('#video-1').show();
    
    $('.sl_video').each(function(){
	    SL_LAST_VIDEO++;
	});
    if (SL_LAST_VIDEO==1) //Videoauswahl nur ab 2 Videos.
	return;
    if (SL_LAST_VIDEO>2) { //Erstes,Letztes,Vor,Zurueck nur ab 3 Videos
	$('.sl_videos').append('<a href="javascript:sl_video_prev();">&lt;&lt;</a>');
    }
    for (var i=1; i<=SL_LAST_VIDEO; i++) {
	$('.sl_videos').append('<a href="javascript:sl_video_select('+i+');">'+i+'</a> ');
    }
    if (SL_LAST_VIDEO>2) { //Erstes, Letztes, Vor, Zurueck nur ab 3 Videos
	$('.sl_videos').append('<a href="javascript:sl_video_next();">&gt;&gt;</a>');
    }
}

function sl_video_select(num) {
    $ = jQuery;
    $('#video-'+SL_CURRENT_VIDEO).hide();
    $('#video-'+num).show();
    SL_CURRENT_VIDEO = num;
}

function sl_video_next(){
    if (SL_CURRENT_VIDEO == SL_LAST_VIDEO)
	return;
    sl_video_select(SL_CURRENT_VIDEO+1);
}

function sl_video_prev(){
    if (SL_CURRENT_VIDEO == 1)
	return;
    sl_video_select(SL_CURRENT_VIDEO-1);
}

function sl_similar_add(game1,  nonce) {
    var game2 = jQuery('#similar_games_list').val();
    data = {
	'action': 'sl_add_similar',
	'game1': game1,
	'game2': game2,
	'_wpnonce': nonce
    };
    jQuery.post(ajaxurl, data, function(response){
	    if (response != 'ok') {
		alert(response);
		return;
	    }
	    var html = '<span id="similar-'+game2 +'">';
	    html += jQuery('#similar_games_list option[value='+game2+']').text();
	    html += '<a href="javascript:sl_similar_del(';
	    html += game1 + ', ';
	    html += game2 + ', ';
	    html += '\'' + nonce + '\'';
	    html += ');" title="Entfernen"> [x]</a><br/></span>';	    
	    jQuery('#similar_container').append(html);	    
	});
}

function sl_similar_del(game1, game2, nonce) {
    data = {
	'action': 'sl_del_similar',
	'game1': game1,
	'game2': game2,
	'_wpnonce': nonce,
    };
    jQuery.post(ajaxurl, data, function(response){
	    if (response != 'ok') {
		return;
	    }
	    jQuery("#similar-"+game2).remove();
	});
}