/*	Modal Popup by Robert Larsson Oct 2010, Copyright (C) Lägenhetsbyte Sverige AB
	This can only be used with the written permission from Lägenhetsbyte Sverige AB

	This Modal Popup need JQuery 1.4+
*/

function PopUpModal(width,height,url) {

		var popID = 'popup1337';
		var popURL = url; //Get Popup href to define size
				
		//Pull Query & Variables from href URL
		var popWidth = width;
		var popHeight = height;

		// Test parameter
		//var url = dim[1].split('=')[1];
		// Clear div content
		$('#' + popID).html('<div class="loading" style="padding-top: ' + ((popHeight / 2)-10) + 'px;"><center><img src="images/loader-bar.gif" style="vertical-align: absmiddle;" alt="Var god vänta..." /></center></div>');

		//Fade in the Popup and add close button

		$('#' + popID).show().css({ 'width': Number( popWidth ) }).css({ 'height': Number( popHeight ) }).prepend('<a href="#" class="close"><img src="images2/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');


		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
		
		//Apply Margin to Popup
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(500); //Fade in the fade layer 

		$.ajax({
		url: url,
		success: function(data) {
			$('#' + popID).append(data);
			$('#' + popID + ' .loading').hide();
		}
		});

		return false;

}

$(document).ready(function(){

	$('body').prepend('<div id="popup1337" class="popup_block"></div>'); //Add the popup layer to bottom of the body tag.

	//When you click on a link with class of poplight and the href starts with a # 
/*	$('a.poplight[href^=#]').click(function() {
		var popID = 'popup1337';//$(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size
				
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value
		var popHeight = dim[1].split('=')[1]; //Gets the second query string value

		PopUpModal(popID,popWidth,popHeight,'/ajax/guidadtur.aspx?id=1');
	});
*/

	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
		$('#popup1337').empty(); // Empty for instance Youtube clip so it stops playing even thou its just hidden
		$('#fade , .popup_block').hide(0, function() { //fadeOut
			$('#fade, a.close').remove();
	}); //fade them both out
		
		return false;
	});

	
});
