/**
*	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, registry, scroll)
	{
	    var offset={};
	    var options ={
	    margin:1,
	    border:1,
	    padding:1,
	    scroll:0
	    };
		
		if(!scroll)
		    scroll = false;
		    
	    var win_width =$(window).width();
	    var scrollToLeft=$(window).scrollLeft();
	    var win_height =$(window).height();
	    var scrollToBottom=$(window).scrollTop();
		var mod_height = box_height - 20;
		var win = 	"<div id='ak_modal_div'>";
				    
		//win += "<div class='ak_modal_inner'><div class='XBtn'><img src='/img/popClose.jpg' border='0' alt='Close' /></div>";
		win += "<div class='ak_modal_inner'><div class='XBtn'>Close</div>";
		
		if(title != '')
		    win += "<div class='ak_modal_title'>"+title+"</div>";
		    
		var background = '<div id="TB_overlay" class="TB_overlayBG backgroundPopup"/>';
		
		if(registry==true) {
			win += '<div>';
			if(scroll)
			    win += '<style type="text/css">iframe{overflow-y:scroll;}</style>';
			win += "<iframe width='"+box_width+"' height='"+box_height+"'";
		} else {
			win += '<div><img src="/img/registry/reg_cart.gif" style="float:left;" /></div><div style="clear:both"></div>';
			win += "<iframe width='"+box_width+"' height='"+box_height+"'";
		}
		
		win += "frameborder=0 marginwidth='0' marginheight='0' scrolling='AUTO'   name='frmTest' src='"+navurl+"'></iframe>";
		
		win+= "</div>";
		if(registry==true) {
			//win += "<div style='width:"+box_width+"; text-align:center'><img src='/img/dash/reg_07.gif' id='close'/></div></div>";
		} else {
			win += "</div>";
			//win += '<img src="/img/registry/reg_17.gif" id="close" style="margin-left:350px"/></div></div></div></div></div>';
		}
		
	    $('body').append(win);
		$('body').append(background);
		
		var coordX = (win_width/2-box_width/2)+scrollToLeft;
		var coordY = (win_height/2-box_height/2)+scrollToBottom;
		coordY = coordY<30?30:coordY;
		
	    $('#ak_modal_div').css({left:coordX+'px',top:coordY+'px'});		
	    $('.backgroundPopup').show();
	    
	    //round corners
	    $('.ak_modal_inner').corner();
	    $('.ak_modal_title').corner("cc:#FFFFFF");
		$('#ak_modal_div').corner();
		$('.XBtn').corner();
		
	    $('.backgroundPopup').click(function(){
	    	$('#ak_modal_div').fadeOut(500);
	    	$('#ak_modal_div').remove();
	   		$('.backgroundPopup').remove();
	    });
	    $('.XBtn').click(function(){
//	    alert('close AK modal by Xbtm');

			$('#TB_overlay',top.document).remove();
			$('#ak_modal_div',top.document).fadeOut(500);
		    $('#ak_modal_div',top.document).remove();
		});
		function closeAK() {
//	    alert('close AK modal');

			$('#ak_modal_div').fadeOut(500);
	       $('#ak_modal_div').remove();	
		}
		
		$('#ak_modal_div').fadeIn(500);
		var offset = {}
	    offset=$("#ak_modal_div").offset({ scroll: false })
	
  	    X_left=offset.left+box_width-16;
	    X_top=offset.top;

	    $('#close').css({left:X_left,top:X_top});

	},
	
	akModalRemove:function()
	{
	   $('#ak_modal_div').fadeOut(500);
	   $('.backgroundPopup').remove();
	  // $.dimScreenStop();
	},
	
	akModalHideAndRedirect:function(redirect_url)
	{

//	    alert('f1');
	    $('#ak_modal_div').fadeOut(500);
	    //$.dimScreenStop();
	    window.location=redirect_url;
	}
});	