/*
*	jQuery PopUp window
*
*	Author	- František Preissler, ja@frantisek-preissler.cz, www.frantisek-preissler.cz
*	Version	- 0.9 beta
*	Date		- 25.5.2009
*
*	Requirements:
*	jQuery JavaScript library (download the latest release at http://jquery.com).
*
*	Tested on Firefox 3.0.4 (Windows XP), Firefox 3.0.10 (Linux Ubuntu), Internet Explorer 6, Internet Explorer 7, Opera 9.6.
*
*	How to use:
*	1.	Add next lines inside <head></head> element.
*			<script src="./js/jquery-1.3.2.min.js" type="text/javascript"></script>
*			<script src="./js/scripts.js" type="text/javascript"></script>
*	2.	Add next Css style to your css file or inside <head></head> element.
*			html>body .close_popup {
*				background-image:url('../images/cross_small.png');
*			}
*	3.	For calling PopUp window use next element attribute.
*			onclick="PopUp('loaded_file.html','400','150','100','noeffect');"
*			1st parameter in PopUp function is a file what you want to load into PopUp window.
*			2nd parameter in PopUp function is a width of PopUp window.
*			3rd parameter in PopUp window is a min height of PopUp window.
*			4th parameter in PopUp window is a top margin of PopUp window.
*			5th parameter in PopUp window are effect functions of openning and closing PopUp window.
*				
*	All rights reversed.
*/

/*
*	Basic settings start
*/
var site				= "#container";				// Hlavní div stránky
var popup 			= "#popup";					// Element id of PopUp window for loading content
var popup_bg			= ".popup_bg";					// Div průhledného pozadí PopUp okna
var popup_bg_title		= "Klikněte pro zavření okna";	// Popis (title) průhledného pozadí
var close_bt			= ".close_popup";				// Div s tlačítkem pro zavření PopUp okna
var close_img			= "images/cross_small.png";		// Ikonka tlačítka pro zavření PopUp okna
var close_title		= "Zavřít toto okno";			// Popis (title) ikonky pro zavření PopUp okna
var popup_div			= '<div class="popup_bg"></div><div class="close_popup" style="display:none;"></div><div id="popup"></div>';

/*
*	End of basic settings.
*/

/*
* 	START - PopUp window
*	Do not edit another code under this line.
*/

function PopUp(url,Width,Height,Top,Effect){
	
	/* Removing all elements of PopUp window from DOM. */
	$(popup).remove();
	$(close_bt).remove();
	$(popup_bg).remove();
     $(site).before(popup_div);				// Create temporary PopUp element.
	$(popup).load(url);						// Loading page into PopUp window.

	/* If is defined width in function */
	if(Width != ''){
		var MarginLeft = '-' + eval(Width) / 2 + 'px';
		var PopUpCss = {'width' : Width+'px', 'margin-left' : MarginLeft, '-moz-border-radius'	: '5px', 'background-color' : '#FFF', 'border' : '1px solid #CCC', 	'left' : '50%', 'padding' : '5px', 'position' : 'fixed', 'z-index' : '150'}
            	$(popup).css(PopUpCss);

		var CloseMarginLeft = eval(Width / 2) - eval(1) + 'px';
		var CloseCss = {'cursor' : 'pointer', 'height' : '16px', 'left' : '50%', 'margin-left' : CloseMarginLeft, 'position' : 'fixed', 'width' : '16px', 'z-index' : '200', 'filter' : 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+close_img+',sizingMethod="scale")'}
		$(close_bt).css(CloseCss);
	}else{
          var PopUpCss = {'width' : '500px', 'margin-left' : '-250px', '-moz-border-radius' : '5px', 'background-color' : '#FFF', 'border' : '1px solid #CCC', 'left' : '50%', 'padding' : '5px', 'position' : 'fixed', 'z-index' : '150'}
            	$(popup).css(PopUpCss);

		var CloseCss = {'cursor' : 'pointer', 'height' : '16px', 'left' : '50%', 'margin-left' : '245px', 'position' : 'fixed', 'width' : '16px', 'z-index' : '200', 'filter' : 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+close_img+',sizingMethod="scale")'}
		$(close_bt).css(CloseCss);
	}

	/* If is defined height in function */
	if(Height != ''){
            	var PopUpCss = {'min-height' : Height+'px'}
            	$(popup).css(PopUpCss);
	}

	/* If is defined top margin in function */
	if(Top != ''){
		var PopUpCss = {'margin-top' : Top+'px'}
            	$(popup).css(PopUpCss);

		var CloseTopMargin = eval(eval(Top)+eval(5)) + 'px';
		var CloseCss = {'margin-top' : CloseTopMargin, 'filter' : 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+close_img+',sizingMethod="scale")'}
		$(close_bt).css(CloseCss);
	}else{
                	var PopUpCss = {'margin-top' : '100px'}
            	$(popup).css(PopUpCss);

		var CloseCss = {'margin-top' : '105px', 'filter' : 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+close_img+',sizingMethod="scale")'}
		$(close_bt).css(CloseCss);
	}
	
	var BgCss = {'background-color' : '#000', 'filter' : 'alpha(opacity=50)', '-moz-opacity' : '0.5', 'opacity' : '0.5', 'background-repeat' : 'repeat', 'height' : '100%', 'position' : 'fixed', 'width' : '100%', 'z-index' : '100'}
	$(popup_bg).css(BgCss);

	/* Efects of opening PopUp window */
	if(Effect == 'noeffect'){
		$(popup_bg).css("display","none");			// Hide a transparent background of PopUp window
                	$(popup).css("display","none");			// Hide a content inside PopUp window
                	$(popup_bg).fadeIn(0); 					// Show a transparent background
                	$(popup).toggle(0);           				// Show a content of PopUp window
	}else{
             	$(popup_bg).css("display","none");			// Hide a transparent background of PopUp window
                	$(popup).css("display","none");			// Hide a content inside PopUp window
               	$(popup_bg).fadeIn(500); 				// Show a transparent background
                	$(popup).toggle(1000);           				// Show a content of PopUp window 	
	}

	$(popup_bg).attr("title",popup_bg_title);			// Set title of transparent background

	/* PopUp close function */
          $(popup_bg).click(function(){
		if(Effect == 'noeffect'){
			$(close_bt).fadeOut(0);
			$(popup).hide(0);
			$(this).fadeOut(0);
		}else{
                           	$(close_bt).fadeOut(250);
			$(popup).hide(1500);
			$(this).fadeOut(500);
		}
	});
	$(close_bt).click(function(){
		if(Effect == 'noeffect'){
                          	$(this).fadeOut(0);
			$(popup).hide(0);
			$(popup_bg).fadeOut(0);
		}else{
			$(this).fadeOut(250);
			$(popup).hide(1500);
			$(popup_bg).fadeOut(500);
		}
	});

	setTimeout(PopUpCloseButton, 1500);			// Wait for loaded PopUp window and show close button
}

function PopUpCloseButton(){
  	$(close_bt).fadeIn(750);           					// Show close button of PopUp window
	$(close_bt).attr("title",close_title);				// Set title of close button
}

/*
* 	END - PopUp window
*/
