/*
 * t is a prototype transport
 * so this can be used as the onsuccess for a Ajax.Request(...)
 */
function _showPopupWindow( t )
{
	/* Inject the content into the litebox, with additional form tags which pipe the submit through ajax */
	$( '#modal_form' ).html( t );

    _showLitebox();
	return false;
}

function _updatePopupWindow( t )
{
	/* Inject the content into the litebox, with additional form tags which pipe the submit through ajax */
	$( '#modal_form' ).html( t );

	return false;
}

function modalOpen( dialog )
{
	dialog.overlay.show();
    dialog.overlay.bind( 'click', function() { modalClose( dialog ); } );
	dialog.container.show();
	dialog.data.show();
}

function modalClose( dialog )
{
    dialog.container.hide();
	dialog.data.hide();
	dialog.overlay.hide();
	$.modal.close();
}

function _showLitebox()
{
    $( '#modal_form' ).modal( {
		onOpen: modalOpen,
		onClose: modalClose
    } );
    
	return false;
}

function open_map( page_id, map_id )
{
	var url = HTML_ROOT + '/includes/plugin_pages_map_viewer.inc.php';
	
	$.ajax( {
		type: 'GET',
		url: url,
		data: 'page_id=' + page_id + '&map_id=' + map_id,
		success: _showPopupWindow
	} );
}

function trigger_click( map_id )
{
	$( '#map_control_' + map_id ).click();
}

function open_map_layer( map_id, lat, lng, zoom )
{
	if( $( '#map_large_' + map_id ).html() == '' )
	{
		var frame = '<script type="text/javascript">FEATURE_LAT = '+lat+'; FEATURE_LNG = '+lng+'; FEATURE_ZOOM = '+zoom+';</script>' + 
					'<iframe src="' + HTML_ROOT + '/includes/maps/pages_map.php" id="map_frame" width="448" height="318" style="border: 1px SOLID #EFEFEF; background: transparent url('+HTML_ROOT+'/images/temp/ajax-loader-gray.gif) center center no-repeat;" frameborder="0" scrolling="No"></iframe>';
		
		$( '#map_large_' + map_id ).html( frame );
	}
	
	$( '#map_small_' + map_id ).hide();
	$( '#map_information_' + map_id ).css( { 'margin-left': '120px' } );
	var slideTo = { width: '450px', height: '320px' };
	$( '#map_large_' + map_id ).show().animate( slideTo, 400 );
	
	$( '#map_control_' + map_id ).attr( 'href', 'javascript:close_map_layer( ' + map_id + ', ' + lat + ', ' + lng + ', ' + zoom + ' );' ).html( 'Close Location Map' );
}

function close_map_layer( map_id, lat, lng, zoom )
{
	var slideTo = { height: '110px', width: '110px' };
	$( '#map_large_' + map_id ).hide().animate( slideTo, 400, function() { $( '#map_information_' + map_id ).css( { 'margin-left': '0px' } ); $( this ).hide(); $( '#map_small_' + map_id ).show(); } );
	
	$( '#map_control_' + map_id ).attr( 'href', 'javascript:open_map_layer( ' + map_id + ', ' + lat + ', ' + lng + ', ' + zoom + ' );' ).html( 'View Location Map' );
}

/*
 * Globally Scoped JS Evaluation
 */
(
    evalScript = function( e )
    {
        var h = evalScript.node,
        s = document.createElement( 'script' );
        s.type = 'text/javascript';
        s.text = e;
        h.appendChild( s );
        h.removeChild( s );
    }
).node = document.getElementsByTagName( 'head' )[0] || document.getElementsByTagName( '*' )[0];

function addsessiondata( value )
{
    var url = HTML_ROOT + '/includes/sessiondata.php';
    $.ajax( {
        type: 'GET',
        url: 'acid=' + value,
        cache: false
    } );
    return false;
}
