function Weblink_UserInterface_ModuleFlash(current,serviceValidator)
{
	var that = this;
	this.$ = $(this);
	
	this.init = function(){
		if($('#weblink_updater > div.body div.module-flash').size()!=0) $('#weblink_updater > div.body div.module-flash').remove();
		$('#weblink_updater > div.body').append('<div class="module-flash screen"></div>');
		$('#weblink_updater > div.body div.module-flash').append('<div class="left-column"></div>').append('<div class="right-column"></div>').append('<div class="footer"></div>');
		$('#weblink_updater > div.body div.module-flash div.left-column').append('<div class="loading"></div>');
		$('#weblink_updater > div.body div.module-flash div.right-column').append('<div class="loading"></div>');
		
		
		var SI = new Weblink_ServerInterface();
		SI.$.one('dataLoaded',that.displayFirmware);
		SI.$.one('dataLoaded',function(){that.setUpFlash(current.device);});
		SI.getFirmwareDetail(current.device,current.vehicle,current.firmware);
		
		$('#weblink_updater > div.body div.module-flash').slideDown('slow');
	};
	
	this.show = function(){
		that.setUpFlash(current.device);
		$('#weblink_updater > div.body div.module-flash').show();
	};
	
	this.hide = function(){
		$('#weblink_updater > div.body div.module-flash').hide();
	};
	
	this.displayFeatures = function(){
		$('div.feature-selection').hide();
		if(serviceValidator('readConfiguration',{'device':current.device})){
			
			that.updateFeatures();
			$('div.feature-selection img.edit,div.feature-selection img.save').die('click');
			$('div.feature-selection img.edit').live('click',
				function(){
					if(typeof(tracking) != "undefined"){
						tracking.addInfo("Clicked feature edit button");
					}
					$(this).removeClass('edit');
					$(this).addClass('save');
					var src = $(this).attr('src');
					$(this).attr('src',src.replace('edit','save'));
					$('table.feature-selection input[featureid]').show();
				}
			);
			$('div.feature-selection img.save').live('click',
				function(){
					$(this).addClass('edit');
					$(this).removeClass('save');
					var src = $(this).attr('src');
					$(this).attr('src',src.replace('save','edit'));
					$('table.feature-selection input[featureid]').hide();
					that.$.triggerHandler('featuresEdited');
				}
			);
			$('div.feature-selection').slideDown();
			$('table.feature-selection input[featureid]').hide();
			$('table.feature-selection input[featureid]').click(
				function(){
					var val = $(this).attr('checked');
					//val = (val==true?'1':'0');
					var featureid =  $(this).attr('featureid');
					current.device.eeprom.setState(featureid,val);
					checkFeature(featureid,val)
				}
			);
			
			
		} else {
			$('div.feature-selection img.edit,div.feature-selection img.save').remove();
			$('div.feature-selection').slideDown();
		}
		
	};
	function checkFeature(ft,state){
		jq = $('table.feature-selection input[featureid='+ft+']');
		if(jq.size()==0) return;
		if(typeof(state)!="undefined"){
			if(state==1 || state==true){
				jq.attr('checked','checked');
				$('table.feature-selection td[featureid='+ft+']').removeClass('dim');
			} else {
				jq.removeAttr('checked');
				$('table.feature-selection td[featureid='+ft+']').addClass('dim');
			}
		}
		
	}
	this.updateFeatures = function(){
		if(current.device.eeprom && current.device.eeprom.map){
			var map = current.device.eeprom.map;
			for(x in map){
				if(typeof(map[x])=="undefined") continue;
				checkFeature(x,map[x]);
			}
		}
	};
	this.displayFirmware = function(evt,data){
		$('#weblink_updater > div.body div.module-flash div.left-column').empty().html(data);
		$('#weblink_updater > div.body div.module-flash div.left-column div.selected-firmware').hide().slideDown();
		$('#weblink_updater > div.body div.module-flash div.left-column div.selected-firmware img.buttons.edit').click(
					function(){
						if(typeof(tracking) != "undefined"){
							tracking.addInfo("Clicked firmware edit button");
						}
						delete current.device.eeprom;
						that.$.triggerHandler('editFirmwareSelection');
					});
		$('#weblink_updater > div.body div.module-flash div.left-column div.install-guide img.buttons.download').click(
					function(){
						var id = $(this).attr('installguideid');
						if(typeof(id)!="undefined"){
						location.href='/common/file/get-install-guide/id/'+id;
						}
						});
		$('#weblink_updater > div.body div.module-flash div.left-column div.install-guide').hide().slideDown('normal',function(){
			$('body').scrollTo($(this),1000,{axis:'y',offset:200});
		});
		that.displayFeatures();
		if(current.starter){
			that.displayStarterInfo(current.starter);
		};
	};
	this.displayStarterInfo = function(starter){
		if($('#weblink_updater > div.body div.module-flash div.left-column div.remote-starter-infos').size()==0)
		$('#weblink_updater > div.body div.module-flash div.left-column div.install-guide').after('<div class="remote-starter-infos"></div>');
		$('#weblink_updater > div.body div.module-flash div.left-column div.remote-starter-infos').hide().empty().append('<div class="header"></div><div class="body"></div>');
		
		var jq = $('#weblink_updater > div.body div.module-flash div.left-column div.remote-starter-infos div.body')
			.append('<span class="name">'+starter.get('Manufacturer').RsuManufacturerName+'</span>');
		if(starter.get('Product') && starter.get('Product').RsuProductName) jq.append('<span class="description">'+starter.get('Product').RsuProductName+'</span>');
		if(starter.get('Firmware') && starter.get('Firmware').RsuFirmwareName){
			jq.append('<span class="description">'+starter.get('Firmware').RsuFirmwareName+'</span>');
			if(starter.get('Latest') && starter.get('Latest').RsuFirmwareName) jq.append('<span class="latest">There is a more recent firmware for your remote starter. Please press the button below to update.</span>');
		}
		else if(starter.get('Latest') && starter.get('Latest').RsuFirmwareName) jq.append('<span class="description">Firmware is not recognized. Please press the button below to update to the latest version.</span>');
		//TODO Implement remote starter update
		$('#weblink_updater > div.body div.module-flash div.left-column div.remote-starter-infos div.body').append('<div class="buttons"></div>');
		if(starter.get('Firmware')){
			$('#weblink_updater > div.body div.module-flash div.left-column div.remote-starter-infos div.body div.buttons').append('<img class="buttons edit-config" src="/weblink/images/buttons/edit-config.en.gif"/>');
		}
		if(starter.get('Latest')){
			$('#weblink_updater > div.body div.module-flash div.left-column div.remote-starter-infos div.body div.buttons').append('<img src="/weblink/images/buttons/update-firmware.en.gif" class="buttons update-firmware"/>');
		}
		$('img.edit-config').one('click',function(){
			if(typeof(tracking) != "undefined")
				tracking.addInfo("Click starter EDIT CONFIGURATION button");
			that.$.triggerHandler('editStarterConfiguration');
		});
		if(!serviceValidator('flash',{'device':starter})){
			$('img.update-firmware').click(function(){ErrorMessage('Weblink Updater 4.1 or higher required for Remote Starter Firmware Update.');});
		} else {
			$('img.update-firmware').click(function(){that.setUpFlash(starter);});
		}
		$('#weblink_updater > div.body div.module-flash div.left-column div.remote-starter-infos').slideDown();
	};
	
	this.setUpFlash = function(device){
		function callFlash(){
			if(typeof(tracking) != "undefined"){
				tracking.addInfo("Start flash device");
			}
			$('div.buttons img.flash').remove();
			if(device.isModule()){
				that.$.triggerHandler('flashCalled');
			} else if (device.isStarter()){
				that.$.triggerHandler('starterFlashCalled');
			}
		}
		
		$('#weblink_updater > div.body > div.module-flash div.right-column').empty().hide()
			.append('<div class="image-status"></div>')
			.append('<div class="progress"></div>')
			.append('<div class="buttons"></div>')
			.append('<div class="text-status"></div>');
		$('div.module-flash div.progress').append('<div class="bar"><div class="fill"></div></div>');
		$('#weblink_updater > div.body div.right-column div.buttons')
			.append('<img class="flash buttons" src="/weblink/images/buttons/flash.en.gif">');
		var path = '/weblink/images/status/flash/module/ready.jpg';
		if(device.isBlade()){
			path = '/weblink/images/status/flash/blade/ready.jpg';
		} else if(device.isModule()){
			path = '/weblink/images/status/flash/module/ready.jpg';
		} else if(device.isStarter()){
			path = '/weblink/images/status/flash/starter/ready.jpg';
		}
		$('div.module-flash div.image-status').empty().append('<img src="'+path+'"/>');
		$('div.module-flash div.progress div.bar').hide();
		$('div.buttons img.flash,div.buttons img.flash-again,div.buttons img.flash-another').die('click');
		$('div.buttons img.flash,div.buttons img.flash-again').live('click',callFlash);
		$('div.buttons img.flash-another').live('click',function(){location.reload()})
		$('#weblink_updater > div.body > div.module-flash div.right-column').slideDown();
	};
	this.progressStarts = function(){
		
		$('div.module-flash div.progress div.bar').show();
		$('div.module-flash div.progress div.bar div.fill').removeClass('success').removeClass('error').addClass('in-progress');
		var src = $('div.module-flash div.image-status img').attr('src');
		$('div.module-flash div.image-status img').attr('src',src.replace(/ready|success|failed/,'flashing'));

		$('div.text-status').html("Flashing");
	};
	
	this.progress = function(perc){
		if(perc <= 100 && perc >= 0){
			$('div.module-flash div.progress div.bar div.fill').width(perc+'%');
		}
	};
	this.progressComplete = function(){
		var src = $('div.module-flash div.image-status img').attr('src');
		$('div.module-flash div.progress div.bar div.fill').width('100%');
		$('div.module-flash div.progress div.bar div.fill').removeClass('in-progress').addClass('success');
		$('div.module-flash div.image-status img').attr('src',src.replace(/ready|flashing/,'success'));
		
		if(/starter/.test($('div.module-flash div.image-status img').attr('src'))){
			$('#weblink_updater > div.body div.right-column div.buttons').empty();
			current.starter.setInfos('Firmware',current.starter.get('Latest'));
			current.starter.setInfos('Latest',null);
			that.displayStarterInfo(current.starter);
			setTimeout(function(){that.setUpFlash(current.device);},3000);
		} else {
			$('#weblink_updater > div.body div.right-column div.buttons').empty()
			.append('<img class="flash-another buttons" src="/weblink/images/buttons/flash-another.en.gif">')
			.append('<img class="flash-again buttons" src="/weblink/images/buttons/flash-again.en.gif">');
		}
		$('div.text-status').empty();
	};
	this.progressError = function(error){
		var src = $('div.module-flash div.image-status img').attr('src');
		$('div.module-flash div.progress div.bar div.fill').removeClass('in-progress').addClass('error');
		$('div.module-flash div.image-status img').attr('src',src.replace(/ready|flashing/,'failed'));
		$('#weblink_updater > div.body div.right-column div.buttons').empty()
		.append('<img class="flash-another buttons" src="/weblink/images/buttons/flash-another.en.gif">')
		.append('<img class="flash-again buttons" src="/weblink/images/buttons/flash-again.en.gif">');
		$('div.text-status').html(error);
	};
	this.displayManual = function(){
		
	};
}