/*
    ==================================================================================
    dsFrontEnd Plugin JS for view: show
    ==================================================================================
*/

function ConfirmDelete( del_href, del_text ) {
    
    var dialog_width = 300;
    var dialog_v_shift = 100;
    
    var win_h = $(window).height();
    var doc_h = $(document).height();
    var doc_w = $(document).width();
    
    var dialog_left = ( doc_w / 2 ) - ( dialog_width / 2 );
    var dialog_top = $(document).scrollTop() + ( win_h / 2 ) - dialog_v_shift;
    
    // Draw the Confirmation (still hidden)
    $('body').append('<div id="dsfe-dark-alpha" style="display: none;"><div id="dsfe-confirm-delete"><p>' + del_text + '</p><a id="dsfe-cancel-delete" class="button" href="#">Abbrechen</a><a id="dsfe-confirm-delete" class="button main" href="' + del_href + '">Löschen</a></div></div>');
    
    // Set the size of the alpha-mask
    $('#dsfe-dark-alpha').css( { 
        'height': doc_h,
        'width': "100%"
    });
    
    // Set position of the dialog-box
    
    
    $('div#dsfe-confirm-delete').css( { 
        'top': dialog_top,
        'left': dialog_left,
        'width': dialog_width + "px"
    });
    
    // Enable the cancel button
    $('#dsfe-cancel-delete').click( function() {
        $('div#dsfe-confirm-delete').fadeOut("fast");
        $('#dsfe-dark-alpha').fadeOut("fast");
        $('#dsfe-dark-alpha').remove();
        return false;
    });
    
    // Display the dialog
    $('#dsfe-dark-alpha').fadeIn("fast");
    
}


function SetScroll() {
	
	var hs = window.location.hash;
	if (hs.substr(0, 1) == '#') {
		// remove # from an empty hash (for IE)
		hs = hs.substr(1);
	}
	
	if (hs != '' && $('#' + hs).length > 0) {
		var bt = $('#' + hs).offset().top;
		var bb = bt + $('#' + hs).height();
	}
	if (bt) {
		var wh = $(window).height();
		var td = Math.floor(wh/3);
		var hf = Math.floor(wh/2);
		
		// Wenn editlink innerhalb des Fenster ist wollen wir keinen Scroll
		if (bb < wh) {
			$(window).scrollTop(0);
			window.location.hash = '';
		}
	}
}

$(window).load(function(){
	SetScroll()
});
