// var _created_windows = new Array();

function boolToYesNo( value ) {

	return( value ? 'yes' : 'no' );

}
function createWindow ( oPConfig ) {

	var ret_val = null;
	
	var window_params = '';
	
	var oConfig = {
		
		'x' 		: -1,
		'y' 		: -1,
		'width' 	: 400,
		'height' 	: 400,
		'nodups'	: true,
		'scroll'	: true,
		'status'	: false,
		'location'	: false,
		'menubar'	: false,
		'toolbar'	: false,
		'hotkeys'	: false,
		'fullscreen': false,
		'resize'	: false,
		'name'		: 'dialog',
		'url'		: 'about:blank'
		
	}


	if( oPConfig && typeof( oPConfig ) == 'object' ) {
		
		for( var idx in oPConfig ) {
			if( typeof( oConfig[idx] ) != 'undefined' ) {
				oConfig[idx] = oPConfig[idx];
			}
		}
		
//		if( oConfig.nodups && _created_windows[oConfig.name] ) {
			
//			try {
			//	_created_windows[oConfig.name].close();
//			} catch ( e ) {
//				// oj, exceptionas =|
//			}
			
//			_created_windows[oConfig.name] = null;
//		
//		}
		
		if( oConfig.x < 0 ) {
			oConfig.x = Math.round( ( screen.height - oConfig.height ) / 2 );
		}
		
		if( oConfig.y < 0 ) {
			oConfig.y = Math.round( ( screen.width - oConfig.width ) / 2 );
		}
		
		window_params = 
			
			'top=' + oConfig.x + ',' +
			'left=' + oConfig.y + ',' +
			'width=' + oConfig.width + ',' +
			'height=' + oConfig.height + ',' +
			'location=' + boolToYesNo( oConfig.location ) + ',' +
			'menubar=' + boolToYesNo( oConfig.menubar ) + ',' +
			'toolbar=' + boolToYesNo( oConfig.toolbar ) + ',' +
			'hotkeys=' + boolToYesNo( oConfig.hotkeys ) + ',' +
			'fullscreen=' + boolToYesNo( oConfig.fullscreen ) + ',' +
			'resizable=' + boolToYesNo( oConfig.resize ) + ',' +
			'status=' + boolToYesNo( oConfig.status ) + ',' +
			'scrollbars=' + boolToYesNo( oConfig.scroll );
		
		ret_val = window.open( oConfig.url, oConfig.name, window_params );
		
//		_created_windows[oConfig.name] = ret_val;
		
	}
	
	return( ret_val );

}
function popup( position, nr, url ) {
	var oConfig = { 'url': url, 'width': 727, 'height': 480, 'scroll' : false , 'statusbar' : false, 'resize' : false, 'name' : position};
	var oImageWindow = createWindow( oConfig );
}

function nextImg( id, imgID, color, purl ) {
	var imgHTML = document.getElementById('img_'+id);
	var img = imgID;
	if (img==0) {
		if (images[id][img]==null) {
			img++;
		}
		if (images[id][img]==null) {
			img++;
		}
	}
	img++;
		if ( img == images[id].length ) {
		img=0;
	}
	if (images[id][img]==null) {
		img++;
		if ( img == images[id].length ) {
		img=0;
	}
		if (images[id][img]==null) {
			img++;
			if ( img == images[id].length ) {
		img=0;
	}
		}
	}
	if ( img == images[id].length ) {
		img=0;
	}
	
	var newHtml = '<a href="javascript:void(0);"  onclick="nextImg('+id+', '+img+', '+color+', \''+purl+'\');return false;">'
						+'<img src="'+images[id][img][0]+'" alt="" />'+'</a>'
					+'<a href="javascript:void(0);" onclick="popup('+id+', '+img+',\''+purl+'\');return false;">'
						+'<img class="nav" src="client/images/plus_'+color+'.png" alt="" />'
					+'</a>';
	//alert(newHtml);				
	imgHTML.innerHTML= newHtml;
}

