jQuery.noConflict(); 

jQuery(document).ready(
    function() {

		// NOTE ! make shure to set wmode = opaque
		// otherwise swf files will be layerd on top
		// of the popup (some browsers)

		jQuery.fn.openPopupFromSwf = function(args) {			
			// clear popup content
			jQuery("#popup-content").html("");
			
			// load new content
			jQuery.get(args['url'], {}, showPopup, "html");
		}
		



		// show popup
		var showPopup = function( data, textStatus )
		{
			// if success
			if (textStatus == "success")
			{	
					
				// move container
				jQuery("#popup-container").css("top", jQuery(window).scrollTop() + "px");
				
				// cords			
				var top = ( jQuery(window).height() / 2 ) - 240;
				var left = ( jQuery(window).width() / 2 ) - 405;
			
				// center pop up
				jQuery("#popup").css("top", top + "px");
				jQuery("#popup").css("left", left + "px");
				
				// set loaded content
				jQuery("#popup-content").html(data);
				
				
				// show container
				jQuery("#popup-container").show();				
				// fade in background
				jQuery("#popup-fade").css('opacity', 0);
				jQuery("#popup-fade").show();
				jQuery("#popup-fade").fadeTo("slow",0.7);
				// fade in popup
				jQuery("#popup").fadeIn("slow", function() { jQuery("#popup-shade").show(); jQuery("#popup-shade-png").pngfix(); });				
			}
		}



		// open popup
		var openPopup = function( event )
		{
			// stop default event
			event.preventDefault();
			
			// clear popup content
			jQuery("#popup-content").html("");
			
			// load new content
			jQuery.get(jQuery(this).attr('id'), {}, showPopup, "html");
		}
		
		
		
		
		
		// close popup
		var closePopup = function( event )
		{
			// stop default event
			event.preventDefault();
			
			// fade out background and popup
			jQuery("#popup-shade").hide();
			jQuery("#popup-fade").fadeOut("normal");
			jQuery("#popup").fadeOut("normal", function() { jQuery("#popup-container").hide(); jQuery("#popup-content").html("");});
		}
		





		var closeOver = function()
		{
			jQuery("#popup-close").find('> img').attr('src', '/images/popup_close_over.gif');
		}
		
		
		var closeOut = function()
		{			
			jQuery("#popup-close").find('> img').attr('src', '/images/popup_close.gif');
		}


		
		// set links
		jQuery(".popup-link").bind("click", openPopup);
		// bind close button
		jQuery("#popup-close").bind("click", closePopup);
		jQuery("#popup-close").bind("mouseover", closeOver);
		jQuery("#popup-close").bind("mouseout", closeOut);
	}
);


function callPopupFromSwf( args )
{
	jQuery.fn.openPopupFromSwf( args );
}



