var movies = new Array();

function addMovie(id){
	if( IsInMoviesArray(id) ){
		var i; var j;
		for (i = 0; i < movies.length; i++) {
			if (movies[i]['id'] == id) {
				j = i;
			}
		}
		addMovie_AlwaysExists_MSG(movies[j]['name']);
	}else{
		$.ajax({
			type: "POST",
			url: "ajax_showcase.php",
			data: 'action=addMovie&ID='+id,
			dataType: 'json',
			success: function(data, status){
				if(typeof(data.error) != 'undefined'){
					if(data.error=='Always exists'){
						addMovie_AlwaysExists_MSG(data.name);
					}else if(data.error != ''){
						alert(data.error+'\n\n'+data.name+'\n'+data.image+'\n');
					}else{
						movies.push({
								'id' : data.id,
								'name' : data.name,
								'image' : data.image
						});
						$('#topnav').append('<a href="?s=showcase"><img id="showcase-m_'+data.id+'" width="77" height="50" style="float:left;border-left:#FFF solid 4px;margin-top:2px;display:none;" src="'+data.image+'" alt="showcase: '+data.name+'" title="showcase: '+data.name+'"/></a>');
						$('#topnav img:last').show('slow');
					}
				}
			},
			error: function (data, status, e){
				alert(e);
			}
		});
	}
	return false;
}
function addMovie_AlwaysExists_MSG(filmname){
	if(typeof(filmname)=='undefined'){
		alert('Dieser Film ist bereits in Ihrem pers&ouml;nlichen Showcase..');
	}else{
		//alert('Der Film "'+filmname+'" ist bereits in Ihrem pers&ouml;nlichen Showcase..');
		$.blockUI('<span style="float:right;margin-right:2px;">[<a href="#" onclick="$.unblockUI;">x</a>]</span><p>Der Film "'+filmname+'" ist bereits in Ihrem pers&ouml;nlichen Showcase..</p>', { width: '500px' });
		$('.blockUI').click($.unblockUI); 
	}
}

function delMovie(id){
	$.ajax({
		type: "POST",
		url: "ajax_showcase.php",
		data: 'action=delMovie&ID='+id,
		dataType: 'json',
		success: function(data, status){
			if(typeof(data.error) != 'undefined'){
				if(data.error=='Not exists'){
					delMovie_NotExists_MSG(data.name);
				}else if(data.error != ''){
					alert(data.error+'\n\n'+data.name+'\n'+data.image+'\n');
				}else{
					$('#showcase-m_'+data.id+'').hide('slow', function(){ $(this).parent().remove(); } );
					$('#showcase_detail-m_'+data.id+'').hide('slow',
						function(){
							$(this).remove();
							if( data.inf==0 ){
								$('#showcase_detail-empty').show('slow');
							}
						}
					);
				}
			}
		},
		error: function (data, status, e){
			alert(e);
		}
	});
}
function delMovie_NotExists_MSG(filmname){
	if(typeof(filmname)=='undefined'){
		alert('Dieser Film ist ist nicht in Ihrem pers&ouml;nlichen Showcase..');
	}else{
		alert('Der Film "'+filmname+'" ist nicht in Ihrem pers&ouml;nlichen Showcase..');
	}
}

function IsInMoviesArray(elem) {
	var i;
	for (i = 0; i < movies.length; i++) {
		if (movies[i]['id'] == elem) {
			return true;
		}
	}
	return false;
}

function playMovie(id,src){
	setTimeout('_playMovie(' + id + ', "' + src + '")', 50);	
}
function _playMovie(id,src){
	//alert('id: ' + id + ', src: ' + src);
	
	var movieWidth = 512;
	var movieHeight = 288 + 15;
	var movieSource = src;
	
	$('<a href="' + movieSource + '" class="{width:' + movieWidth + ', height:' + movieHeight + ', caption:0}">' + id + '</a>').mediaboxNow();
	
	/*
	if( $.browser.msie ){
		setTimeout("$('#WaitForMovieLoad').hide();", 3500);
	}else{
		setTimeout("$('#WaitForMovieLoad').animate({opacity:0},3000);", 3500);
	}
	*/
	if( $('#nav_sub li a.active').length > 0 ){
		var CurImgData = $('#nav_sub li a.active').metadata();
	}else{
		var CurImgData = $('#Movie_' + id + '_Helper').metadata();
	}
	
	$('#MovieInformation').html( (CurImgData.IsNew?'<img src="/images/new.png" style="margin-left:-50px;" />':'')+'<img src="' + CurImgData.TitleIMG + '" width="248" />' );
	$('.blockMsg img[@src$=.png]').ifixpng();
	
}

function makeMePlay(obj,ID){
	$(obj).click(function() { 
		$('<div style="color:#000;">MovieID: '+ID+'<br /><img width="500" height="333" /></div>').displayBox(); 
		return false; 
	}); 
}