$(document).ready(function() {
	var path = $('#appName').html();
	
	$("a.image").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'scrolling'     :   'no',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'autoDimensions':   true,
		'autoScale'		:	true,
		'titlePosition' :	'over',
		'titleFromAlt'	:	true,
		'overlayShow'	:	false
	});
	
	$("a.grouped_images").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'type'			:   'inline',
		'scrolling'     :   'no',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'autoDimensions':   true,
		'autoScale'		:	true,
		'titlePosition' :	'over',
		'titleFromAlt'	:	true,
		'overlayShow'	:	false,
		'onComplete'    :   function() {
			$.get(path + '/imageSearch/countImagePreview', {id: $("div[id^='data_']:visible").attr('id')});
		}
	});
	
	
	$("a.lnkAddToLightbox").click(function(event) {
		event.preventDefault();				
		var id = $(this).attr('href');
		if (id != '') {
			$.get(path + '/lightBox/add', {id: id}, function(data) {
			  $('#lightbox_count').html(data);
			});
			$.jGrowl($('#msg_' + id).text());
		}
	});
	
	$("a.lnkRemoveFromLightbox").click(function(event) {
		event.preventDefault();
		
		var id = $(this).attr('href');
		if (id != '') {
			$.get(path + '/lightBox/ajaxRemove', {id: id}, function(data) {
			  $('#lightbox_count').html(data);
			});
			$.jGrowl($('#msg_' + id).text());
		}
	});
	
	$(".flipToMetadata").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
		
	});
	
	$(".lnkChangeUser").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
	$('.lnkAdminAction').click(function() {
		$('.tett').click();
	});
	
	
	$('.tett').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
		
	$(".lnkDownloadOverview").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		'onComplete'    :   function() {
			var id = $("div[id^='user_']:visible").attr('id').substring(5);
		    $('#table-' + id).dataTable({
		    	"oLanguage": {
		    		"oPaginate": {
		    			"sFirst": "Erste",
		    			"sLast": "Letzte",
		    			"sNext": "Nächste",
		    			"sPrevious": "Vorige"
		    		},
		    		"sInfo": "_START_ - _END_ von _TOTAL_",
		    		"sInfoEmpty": "Keine Daten verfügbar",
		    		"sProcessing": "Daten werden beschafft...",
		    		"sZeroRecords": "Keine Daten zum Anzeigen"
		    	},
		    	"bDestroy"   : true,
		    	"bInfo": true,
		    	"bFilter": false,
		    	"bLengthChange": false,
		    	//"sPaginationType": "full_numbers",
		    	"iDisplayLength": 18,
	    		"bProcessing": true,
	    		"bServerSide": true,
	    		"sAjaxSource": path + "/admin/getuserdownloads",
	    		"fnServerData": function ( sSource, aoData, fnCallback ) {
					aoData.push( { "name": "id", "value": id } );
					$.getJSON( sSource, aoData, function (json) {
						fnCallback(json)
					} );
				}

	    	});
		}
	});
	
	$("span.tooltip").tooltip({
		track: true, 
	    delay: 500, 
	    showURL: false, 
	    opacity: 1, 
	    showBody: " - ",
	    fade:250, 
	    bodyHandler: function() {
			return $($(this).attr('rel')).html();
		}
	});
	
	
	$(".menuLink").click(function() {
		$.jGrowl($("#menuLinkNotAvailable").text());
	});
	
	if ($('#instantAppMessage').text() != "") {
		$.jGrowl($('#instantAppMessage').text());
    }
	
	$('.deleteUser > a').click(function () {
		$(this).fastConfirm({
			questionText: "Soll dieser User wirklich gel&ouml;scht werden?",
			proceedText: 'Ok',
			cancelText: 'Doch nicht',
			onProceed: function(trigger) {
				
				location.href=$(trigger).attr('href');
				$(trigger).fastConfirm('close');
				
			},
			onCancel: function(trigger) {
				$(trigger).fastConfirm('close');
		}});
		return false;
	});
	
	
	
	$('.deleteImage > a').click(function () {
		$(this).fastConfirm({
			questionText: "Soll dieses Bild wirklich unwiderruflich gel&ouml;scht werden?",
			proceedText: 'Ok',
			cancelText: 'Doch nicht',
			onProceed: function(trigger) {
				
				location.href=$(trigger).attr('href');
				$(trigger).fastConfirm('close');
				
			},
			onCancel: function(trigger) {
				$(trigger).fastConfirm('close');
		}});
		return false;
	});
	
	
	$('#adminActionDeleteThumbs > a').click(function () {
		$(this).fastConfirm({
			questionText: "Es werden alle Preview und Thumbnail-Bilder, sowie deren Indexeintr&auml;ge gel&ouml;scht",
			proceedText: 'Ok',
			cancelText: 'Doch nicht',
			onProceed: function(trigger) {
				
				location.href=$(trigger).attr('href');
				$(trigger).fastConfirm('close');
				
			},
			onCancel: function(trigger) {
				$(trigger).fastConfirm('close');
		}});
		return false;
	});

});

function openPopup(url) {
	window.open(url,'Druckansicht', 'width=800,height=800,scrollbars=yes');
	
}



