
function insertMedia()
{
for( var k = 0, l = arguments.length; k < l; k++ )
{
document.write( arguments[k] );
}
}
function insertMedia2( node_id, string )
{
var flashNode = document.getElementById( node_id );
flashNode.innerHTML = string;
}
var QHJSINILoader = new function() {
this.initialized = false;
this.config = {};
this.init = function( loader_name, callback ) {
if( this.initialized ) {
callback( this.config[loader_name] );
} else {
$.ez( 'qhjsiniloader::configload', '', function( ezp_data ) {
if ( ezp_data.error_text ) {
console.log( 'ezjscore ajax error in qhjsiniloader::configload' );
} else {
this.initialized = true;
this.config = jQuery.parseJSON( ezp_data.content );
callback( this.config[loader_name] );
}
});
}
}
}
var QHNotificationsFunctions = {
toggleExpandButton: function() {
if( this.numberOfNotifications() > 2 ) {
$( '#notification-container-expand' ).css( 'display', 'block' );
} else {
$( '#notification-container-expand' ).css( {'display': 'none', 'margin-top': 0} );
this.setExpandAction( 'Expand' );
}
},
numberOfNotifications: function() {
return $( '.notification-item' ).length;
},
getExpandAction: function() {
return $( '#expand-action' ).html();
},
setExpandAction: function( action ) {
$( '#expand-action' ).html( action );
}
}
function QHNotifications( class_parms ) {
this.notification_array = new Array();
this.init = function( class_parms ) {
this.injectContainer();
}
this.injectContainer = function() {
if( $( '#notification-container' ).length == 0 ) {
$( 'body' ).prepend( '<div id="notification-container"></div><div id="notification-container-expand"><div id="notification-container-expand-button"><span id="expand-action">Expand</span></div></div>' );
$( '#notification-container-expand-button' ).bind( 'click', this.expandCollapse );
}
}
this.setMessage = function( parms ) {
var foundID = false;
for( var i=0; i<this.notification_array.length; i++ ) {
if( this.notification_array[i].notification_id == parms.notification_id ) {
foundID = true;
this.notification_array[i].text = parms.text;
}
}
if( !foundID )
this.notification_array.unshift( parms );
}
this.display = function() {
var page_offset = 0;
var expand_action = QHNotificationsFunctions.getExpandAction();
for( var i=0; i<this.notification_array.length; i++ ) {
var notification_item = this.notification_array[i];
if( $( '#'+ notification_item.notification_id ).length == 0 ) {
$( '#notification-container' ).prepend( '<div class="notification-item" id="'+ notification_item.notification_id +'">' +
'   <span class="notification_text">'+ notification_item.text +'</span>' +
'   <div class="notification_close_button" id="notification-close-'+ notification_item.notification_id +'"><span>[X]</span></div>' +
'</div>'
);
var item_height = parseInt( $( '#'+ notification_item.notification_id ).outerHeight() );
if( typeof notification_item.type == 'undefined' || notification_item.type != 'sticky' ) {
$( '#notification-close-'+ notification_item.notification_id ).bind( 'click', {notification_id: notification_item.notification_id}, this.removeNotification );
} else {
$( '#notification-close-'+ notification_item.notification_id +' span' ).css( 'display', 'none' );
}
$( '#'+ notification_item.notification_id ).css( {'visibility': 'visible', 'top': -item_height} );
$( '#'+ notification_item.notification_id ).animate( {'top': 0}, 500 );
page_offset = parseInt( $( '#page' ).css( 'margin-top' ) ) + item_height;
QHNotificationsFunctions.setExpandAction( 'Expand' );
} else {
$( '#'+ notification_item.notification_id +' .notification_text' ).html( notification_item.text );
page_offset = parseInt( $( '#page' ).css( 'margin-top' ) );
}
this.notification_array.splice( i, 1 );
if( QHNotificationsFunctions.numberOfNotifications() > 2 ) {
if( expand_action == 'Expand' ) {
$( '#notification-container' ).css( 'height', ( 2 * item_height ) );
}
page_offset = 2 * item_height;
}
QHNotificationsFunctions.toggleExpandButton();
}
$( '#page' ).animate( {'margin-top': page_offset}, 500 );
}
this.expandCollapse = function() {
var action = QHNotificationsFunctions.getExpandAction();
var number_of_items = QHNotificationsFunctions.numberOfNotifications();
var item_height = $( '.notification-item:last' ).outerHeight();
if( action == 'Expand' ) {
var container_height = number_of_items * item_height;
var expand_top = (number_of_items - 2 ) * item_height;
QHNotificationsFunctions.setExpandAction( 'Collapse' );
} else {
var container_height = 2 * item_height;
var expand_top = 0;
QHNotificationsFunctions.setExpandAction('Expand' );
}
$( '#notification-container' ).animate({'height': container_height}, 500);
$( '#notification-container-expand' ).animate({'margin-top': expand_top}, 500);
}
this.removeNotification = function( parm ) {
page_offset = parseInt( $( '#page' ).css( 'margin-top' ) ) - parseInt( $( '#'+ parm.data.notification_id ).outerHeight() );
$( '#'+ parm.data.notification_id ).animate( {'height': 0}, 500, 'swing', function() {
$( '#'+ parm.data.notification_id ).remove();
QHNotificationsFunctions.toggleExpandButton();
});
if( QHNotificationsFunctions.numberOfNotifications() < 3 ) {
$( '#page' ).animate( {'margin-top': page_offset}, 500 );
}
}
this.init( class_parms );
}

