/**
*	akModal-  simplest alternative to thickbox
*	author: Amit Kumar Singh 
* 	project url : http://amiworks.co.in/talk/akmodal-simplest-alternative-to-thickbox/
 * 	inspired from early versions of thickbox
 *	
**/
/**
  * Version 2.0.0
  *  @param String  navurl             url to dispaly in the ifame
  *  @param String  title      title of the pop up box
  *  @param  Numeric  box_width	width of the box in pixels
  *  @param  Numeric  box_height	height of the box in pixels
  *   
 **/

jQuery.extend({
	showAkModal:function(navurl,title,box_width,box_height)
	{
	    leftPos = $(window).width() / 2 - box_width / 2 + $(window).scrollLeft();
	    topPos = $(window).height() / 2 - box_height / 2 + $(window).scrollTop();
	    
	    $('body').append("<div id='ak_modal_div'><iframe width='"+box_width+"' height='"+box_height+"'  frameborder=0 marginwidth='0' marginheight='0' scrolling='NO'  name='frmTest' src='"+navurl+"'></iframe></div>");
	    $('#ak_modal_div').css({left: leftPos + 'px',top: topPos +'px'});
	    
	    $.dimScreen(500, 0.7, function() {$('#ak_modal_div').fadeIn(500);});
	},
	akModalRemove:function() { $('#ak_modal_div').fadeOut(500); $('#ak_modal_div').remove(); $.dimScreenStop(); },
	akModalHideAndRedirect:function(redirect_url) {$('#ak_modal_div').fadeOut(500); $('#ak_modal_div').remove(); $.dimScreenStop(); window.location = redirect_url;}
});	

//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;
        
        return jQuery('<div></div>').attr({
        		id: '__dimScreen'
        		,fade_opacity: opacity
        		,speed: speed
            }).css({
	            background: '#000'
	            ,height: $(document).height() + 'px'
	            ,left: '0px'
	            ,opacity: 0
	            ,position: 'absolute'
	            ,top: '0px'
	            ,width: $(document).width() + 'px'
	            ,zIndex: 999
            }).appendTo(document.body).fadeTo(speed, 0.7, callback);
    },
    
    //stops current dimming of the screen
    dimScreenStop: function(callback) {
        var x = jQuery('#__dimScreen');
        var speed = x.attr('speed');
        
        x.fadeOut(speed, function() { x.remove(); if (typeof callback == 'function') callback(); });
    }
});
