
function userpannel() {}
userpannel.prototype = {
	producerselector : function( command ) {
		command = command.toLowerCase();
		switch ( command ) {
			case 'show' :
			$( 'producerselector' ).style.display = 'block';
			var cacheactions = { '#producerbutton@onmouseout' : function() { document.body.onclick = function() { userpannel.producerselector( 'hide' ); } } }
			elementEventBinder._eventBind( cacheactions );
			$( 'producerselector' ).style.left = $( 'producerbutton' ).offsetLeft + 58 + 'px';
			break;

			case 'hide' :
			$( 'producerselector' ).style.display = 'none';
			document.body.onclick = null;
			break;
		}
	},

	brandselectclean : function() {
		var nodes = $( 'brandlist' ).getElementsByTagName( 'a' );
		for ( var x in nodes ) {
			nodes[x].className = '';
		}
	},

	brandselect : function( brandid ) {
		if ( selection == true ) return false;

		var req = httpRequest, reqx = new req.contentLoader;
		reqx.initialize();
		userpannel.brandselectclean();

		reqx.HttpRequest.onreadystatechange = function() {
			if ( reqx.HttpRequest.readyState == '4' ) {
				var modelobject = eval( reqx.HttpRequest.responseText );
				if ( modelobject.length > 0 && modelobject[0].err != undefined ) {
					alert( 'An Error' );
				} else {
					with ( $( 'modellist' ) ) {
						innerHTML = ''; style.background = '#f8f8f8'; style.border = '1px solid #dddddd';
					}

					for ( var x in modelobject ) {
						var modelElement = document.createElement( 'a' );
						with ( modelElement ) {
							id = 'model_' + modelobject[x].category_id;
							if ( modelid && modelid == modelobject[x].category_id ) {
								className = 'selected';
							}
							innerHTML = modelobject[x].category;
							var command = key ? key : 'articles';
							href = userpannelPageURL + '&action=index&key=' + command + '&producer=' + producerid + '&brand=' + brandid + '&models=' + modelobject[x].category_id;
						}
						$( 'modellist' ).appendChild( modelElement );
					}
					// mozilla firefox exception
					var mozbr = document.createElement( 'br' );
					mozbr.clear = 'all';
					$( 'modellist' ).appendChild( mozbr );
				}
				selection = false;
			} else {
				selection = true;
				$( 'brand_' + brandid ).className = 'selected';
				with ( $( 'modellist' ) ) {
					innerHTML = '数据正在加载中,请稍候 ... ...';
					style.background = '#CF294C';
					style.border = '0px';
					style.color = '#ffffff';
				}
			}
		}
		$( 'brand_' + brandid ).blur();

		reqx.sendHttpRequest( 'GET', userpannelRequestURL + '&action=getcategory&key=modellist&brand=' + brandid );
	},

	loadimage : function() {
		var req = httpRequest, reqx = new req.contentLoader;
		reqx.initialize();

		reqx.HttpRequest.onreadystatechange = function() {
			if ( reqx.HttpRequest.readyState == '4' ) {
				var json = eval( reqx.HttpRequest.responseText );
				if ( json.length > 0 && json[0].error != undefined ) {
					alert( 'an error' );
				} else {
					var imasker = document.createElement( 'div' );
					with ( imasker ) {
						id = 'imagemasker';
						className = 'imagemasker';
						style.left = '0px';
						style.top = '0px';
					}
					$( 'imageviewer' ).appendChild( imasker );
					$( 'imageinfo' ).parentNode.removeChild( $( 'imageinfo' ) );
					$( 'imageviewer' ).style.background = 'url("' + systemurl + json[0].file + '") no-repeat 0px 0px';
					//alert( $('imageviewer').style.backgroundPositionX );
				}
			}
		}
		reqx.sendHttpRequest( 'GET', userpannelRequestURL + '&action=index&key=loadimage&source=' + source );
	}
}
var userpannel = new userpannel;


var articleactions = {
	'#producerbutton@onclick' : function() {
		userpannel.producerselector( 'show' );
		if ( $( 'producerbutton' ) )
			$( 'producerbutton' ).blur();
	}
}


var usercenterindexaction = {
	'#producerbutton@onclick' : function() {
		userpannel.producerselector( 'show' );
		if ( $( 'producerbutton' ) )
			$( 'producerbutton' ).blur();
	}
}