/****************************************************************
	Project:     Eidix Labs :: Platform
	Copyright:   2008 Eidix Labs (http://eidix.com/)
	Author:      James Linden (jl@eidix.com)
	Filename:    tmpl/ui.js
	Created:     2008-09-27 11:00 EST
****************************************************************/

var APP_AGNT = 'Eidix Labs::Platform/0.7.0';
var mouse_x = 0;
var mouse_y = 0;

function g( p_uri ) {
	HTTP.get( '/content?m=image&r=' + p_uri, g2 );
}

function g2( p_data ) {
	var o = document.getElementById( 'wrap' );
	var d = document.getElementById( 'gallery_full' );
	if( o != null && d != null ) {
		o.style.opacity = 0.2;
		d.style.display = 'block';
		d.innerHTML = p_data;
		node_center( 'gallery_full', 650, 550 );
	}
}

function go() {
	var o = document.getElementById( 'wrap' );
	var d = document.getElementById( 'gallery_full' );
	if( o != null && d != null ) {
		d.innerHTML = '';
		d.style.display = 'none';
		o.style.opacity = 1;
	}
}

function img( p_uri ) {
	HTTP.get( '/content?m=image2&q=' + p_uri, img2 );
}

function img2( p_data ) {
	var o = document.getElementById( 'wrap' );
	var d = document.getElementById( 'image_full' );
	if( o != null && d != null ) {
		o.style.opacity = 0.2;
		d.style.display = 'block';
		d.style.overflow = 'auto';
		d.innerHTML = p_data;
		node_center( 'image_full', 650, 500 );
	}
}

function go2() {
	var o = document.getElementById( 'wrap' );
	var d = document.getElementById( 'image_full' );
	if( o != null && d != null ) {
		d.innerHTML = '';
		d.style.display = 'none';
		o.style.opacity = 1;
	}
}

function mptoggle() {
	if( top.music.document ) {
		var stop = ( top.music.location.href.indexOf( '?play' ) > 0 );
		top.music.location.href = '/music' + ( ( stop ) ? '' : '?play=false' );
		var img = document.getElementById( 'musicnote' );
		if( img != null ) {
			img.src = '/tmpl/img/music' + ( ( stop ) ? '' : '2' ) + '.png';
		}
	}
}

function du( p_obj ) {
	var out = document.getElementById( 'debug' );
	if( out != null && typeof( p_obj ) == 'object' ) {
		out.value = '';
		for( var x in p_obj ) {
			if( typeof( p_obj[ x ] ) != 'object' ) {
				out.value += x + ': ' + p_obj[ x ] + '\n';
			}
		}
	}
}

function tip( p_str ) {
	var o = document.getElementById( 'tooltip' );
	if( o != null && mouse_x != null && mouse_y != null ) {
		o.innerHTML = p_str;
		with( o.style ) {
			display = 'none';
			position = 'absolute';
			top = '0px';
			left = '0px';
			if( p_str != null ) {
				display = 'block';
				top = parseInt( mouse_y + 10 ) + 'px';
				left = parseInt( mouse_x + 10 ) + 'px';
			}
		}
	}
}

function upcoords() {
	var o = document.getElementById( 'tooltip' );
	if( o != null && mouse_x != null && mouse_y != null ) {
		if( o.style.display == 'block' ) {
			o.style.top = parseInt( mouse_y + 10 ) + 'px';
			o.style.left = parseInt( mouse_x + 10 ) + 'px';
		}
	}
}

function mouseX( evt ) {
	if( evt.clientX ) {
	   return( evt.clientX + ( document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) );
	}
	else if( evt.pageX ) {
		return( evt.pageX );
	}
	else {
		return( null );
	}
}

function mouseY( evt ) {
	if( evt.pageY ) {
		return( evt.pageY );
	}
	else if( evt.clientY ) {
		return( evt.clientY + ( document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) );
	}
	else {
		return( null );
	}
}

document.onmousemove = function( p_event ) {
	p_event = ( !p_event ) ? window.event : p_event;
	mouse_x = mouseX( p_event );
	mouse_y = mouseY( p_event );
	upcoords();
}

function show_hide_music() {
	if( top.location.href.indexOf( 'content' ) >= 0 ) {
		var ox = document.getElementById( 'musicnote' );
		if( ox != null ) {
			ox.style.display = 'none';
		}
	}
	return true;
}
