//dimScreen()
//by Brandon Goldman
jQuery.extend({
    //dims the screen
    dimScreen: function(speed, opacity, callback) {
        if(jQuery('#__dimScreen').size() > 0) return;
        
        if(typeof speed == 'function') {
            callback = speed;
            speed = null;
        }

        if(typeof opacity == 'function') {
            callback = opacity;
            opacity = null;
        }

        if(speed < 1) {
            var placeholder = opacity;
            opacity = speed;
            speed = placeholder;
        }
        
        if(opacity >= 1) {
            var placeholder = speed;
            speed = opacity;
            opacity = placeholder;
        }

        speed = (speed > 0) ? speed : 500;
        opacity = (opacity > 0) ? opacity : 0.5;
		body_h = $('body').height();
		
        return jQuery('<div></div>').attr({
                id: '__dimScreen'
                ,fade_opacity: opacity
                ,speed: speed
            }).css({
            background: '#000'
            ,height: body_h+'px'
            ,left: '0px'
            ,opacity: 0
            ,position: 'absolute'
            ,top: '0px'
            ,width: '100%'
            ,zIndex: 999
        }).appendTo(document.body).fadeTo(speed, opacity, callback);
    },
    
    //stops current dimming of the screen
    dimScreenStop: function(callback) {
        var x = jQuery('#__dimScreen');
        var opacity = x.attr('fade_opacity');
        var speed = x.attr('speed');
        x.fadeOut(speed, function() {
            x.remove();
            if(typeof callback == 'function') callback();
        });
    }
});
				
function startPageFlip(isbn) {
	$.dimScreen(200, 0.8, function() {
		$('.fblike').hide();
		$('body').append('<div id="pageflip-container" style="width:100%; height:100%; z-index:1000; position:absolute; top:38px; left:0;"><div id="pageflip-content" style="width:940px; height:660px; margin:auto;"><div id="pageflip-bar" style="background-color:#ffffff;position:relative;float:right; top:0px;height:22px;right:0px;width:22px;cursor:pointer;font-size:18px;font-weight:bold;font-family:Verdana;text-align:center;">X</div><div id="flashcontent" style="width:100%; height:100%;"><h1><a href="http://www.dorner-verlag.at" title="Verlag E. Dorner">Verlag E. Dorner</a></h1> <p>Um das Buch anzusehen, ben&ouml;tigen Sie den neuesten <a href="http://adobe.com/go/getflashplayer">Flash player</a>.</p> </div> <script type="text/javascript"> var so = new SWFObject("/pageflip/book.swf", "book", "100%", "100%", "8", "#e6e2d7"); so.addVariable("xmlFile","'+isbn+'/data/pages.xml"); so.addVariable("baseDir","'+isbn+'/data/pages/"); so.addVariable("fullscreen","true"); so.addParam("menu","false"); so.write("flashcontent"); </script></div></div>');
		$('#flashcontent').click(function(event) {
			event.stopPropagation();
		});
		$('#pageflip-container').click(function() {
			$('#__dimScreen').remove();
			$('#pageflip-container').remove();
			$('.fblike').show();
		});
		$('#__dimScreen').click(function() {
			$('#pageflip-container').remove();
			$('#__dimScreen').remove();
			$('.fblike').show();
		});
	});
}
