$( function() {

/*
	$( '#navigationContent li:has(ul)' ).each( function( i ) {

		//Insert navigation item to left of obj.
		//if has children ul

		var sub_ul = $( this ).children( 'ul' ).remove();

		$( this ).prepend(

			$( '<button />' ).button( { icons: { primary: 'ui-icon-triangle-1-s' } } ).click( function() {

				sub_ul.toggle();

				if( sub_ul.is( ':visible' ) ) {

					$( this ).button( { icons: { primary: 'ui-icon-triangle-1-n' } } );
				} else {

					$( this ).button( { icons: { primary: 'ui-icon-triangle-1-s' } } );
				};
			} )
		);

		$( this ).append( sub_ul );
	});*/

	/** Image Gallery Dialog **/
	$( '.preview' ).click( function() {

		var img = $( this ).attr( 'href' );
		var title = $( this ).attr( 'title' );

		$( '<div/>', {
				id: 'preview-dialog',
				title: title
			})
			.appendTo( 'body' )
			.dialog( {
				modal: true,
				autoOpen: false,
				height: 'auto',
				width: 'auto',
				resizable: false,
				buttons: {
					Ok: function() {
						$( this ).dialog( 'close' );
					}
				},
				close: function( event, ui ) {

					$( '#preview-dialog' ).remove();
				}
			});

		$( '<img/>', {
				src: img,
				alt: title
			})
			.appendTo( '#preview-dialog' );
/*
		$( '<div/>', {
				style: 'position: absolute; top: 50px; left: 0px; height: 100px; width: 160px;'
			})
			.appendTo( '#preview-dialog' );

		$( '<div/>', {
				style: 'position: absolute; top: 50px; right: 0px; height: 100px; width: 160px;'
			})
			.appendTo( '#preview-dialog' );
*/
		$( '#preview-dialog' ).dialog( 'open' );
		return false;
	});
});

/** Open Link in new window **/
function popUp( url, name, winargs ) {

	if( typeof( url ) !== 'undefined' && url != "" ) {

		if( typeof( name ) !== 'undefined' || name == "" ) {

			name = "_blank";
		}

		if( typeof( winargs ) === 'undefined' || winargs === "" ) {

			newwindow = window.open( url, name );
		} else {

			newwindow = window.open( url, name, winargs );
		}

		if( window.focus ) {

			newwindow.focus();
		}
	}

	return false;
}
