				


				function WidgetEditor(rowID, wCode, wWPCode)
                {
    				this.rowID = rowID;
    				this.replacementLabel 			= '__REPLACEMENT__'; 
    				this.widthReplacementLabel 		= '__REPLACEMENT_VALUE__WIDTH__'; 
    				this.heightReplacementLabel 	= '__REPLACEMENT_VALUE__HEIGHT__'; 
					this.code 						= wCode; 
					this.WPcode 					= wWPCode;
					this.widgetType					= 'poll';
                    this.itemID						= 0;
                    this.width 						= 0;
                    this.height 					= 0;
                    this.mainColor 					= '';
                    this.backgroundColor 			= '';
                    this.bordersColor 				= '';
                    this.headerFooterTextColor 		= '';
                    this.headerFooterBackgroundColor= '';
                    this.font 						= '';
					this.showVotes 					= 1;
					this.roundedCorners 			= 1;
    				this.rootUrl 					= '';
					this.skin 						= '';
					this.voteButtonCaption			= '';
					this.readmoreLinkCaption		= '';
                }
                
                WidgetEditor.prototype.init = function()
				{
					
					$('#iWidgetCodeContainer' + this.rowID).html(this.getCode());
					$('#iWidgetWPCodeContainer' + this.rowID).html(this.getWPCode());

					$('#iWidgetCodeContainer' + this.rowID).css('backgroundColor', '#' + this.headerFooterBackgroundColor);
					$('#iWidgetCodeContainer' + this.rowID).css('color', '#' + this.headerFooterTextColor);
					$('#iWidgetCodeContainer' + this.rowID).css('fontFamily',this.font);
					$('#iWidgetWidthselector' + this.rowID).val(this.width);
					$('#iWidgetHeightselector' + this.rowID).val(this.height);
					
					var checkedValue = true;
					if (this.showVotes == 0)
					{
						checkedValue = false;
					}else
					{
						checkedValue = true;
					}
					$('#iWidgetShowVotes'+this.rowID).attr('checked',checkedValue);

				
				}
				
                
                WidgetEditor.prototype.getCode = function()
				{
    				
    				var wCode = this.code;
			        
    				var encodedObject = new Object();
    				encodedObject.itemID					= this.itemID;
			        encodedObject.width 					= this.width;
			        encodedObject.height 					= this.height;
			        encodedObject.mainColor 				= this.mainColor;
			        encodedObject.backgroundColor 			= this.backgroundColor;
			        encodedObject.bordersColor 				= this.bordersColor;
			        encodedObject.headerFooterTextColor 	= this.headerFooterTextColor;
			        encodedObject.headerFooterBackgroundColor= this.headerFooterBackgroundColor;
                    encodedObject.font 						= this.font;
                    encodedObject.showVotes 				= this.showVotes;
                    encodedObject.roundedCorners 			= this.roundedCorners;
                    encodedObject.rootUrl 					= this.rootUrl;
                    encodedObject.skin 						= this.skin;
                    encodedObject.voteButtonCaption			= this.voteButtonCaption;
                    encodedObject.readmoreLinkCaption		= this.readmoreLinkCaption;
                    
					return wCode.replace(this.replacementLabel,JSON.stringify(encodedObject));
				}
                
				WidgetEditor.prototype.getWPCode = function()
				{
					var wCode = this.WPcode;
					var url = '';
					wCode = wCode.replace(this.widthReplacementLabel, this.width.toString());
					wCode = wCode.replace(this.heightReplacementLabel, this.height.toString());

					if(this.widgetType == 'poll')
					{
						url = this.rootUrl+'/wigets/poll/'+this.itemID+'/color1/'+this.mainColor+'/color2/'+this.backgroundColor+'/vts/'+this.showVotes+'/font/'+this.font+'/color3/'+this.bordersColor+'/color4/'+this.headerFooterTextColor+'/color5/'+this.headerFooterBackgroundColor+'/corners/'+this.roundedCorners+'/';
						url += 'width/'+this.width+'/height/'+this.height+'/';
						if(this.skin != '') url += 'skin/'+escape(this.skin)+'/';
						if(this.voteButtonCaption != '') url += 'voteBtnCpt/'+escape(this.voteButtonCaption)+'/';
						if(this.readmoreLinkCaption != '') url += 'readLnCpt/'+escape(this.readmoreLinkCaption)+'/';
					}else
					{
						if(this.widgetType == 'survey')
						{
							url = this.rootUrl+'/wigets/lpw/'+this.itemID+'/color1/'+this.mainColor+'/color2/'+this.backgroundColor+'/vts/'+this.showVotes+'/font/'+this.font+'/color3/'+this.bordersColor+'/color4/'+this.headerFooterTextColor+'/color5/'+this.headerFooterBackgroundColor+'/corners/'+this.roundedCorners+'/';
							url += 'width/'+this.width+'/height/'+this.height+'/';
							if(this.skin != '') url += 'skin/'+escape(this.skin)+'/';
							if(this.voteButtonCaption != '') url += 'voteBtnCpt/'+escape(this.voteButtonCaption)+'/';
							if(this.readmoreLinkCaption != '') url += 'readLnCpt/'+escape(this.readmoreLinkCaption)+'/';
						}
					}
					wCode = wCode.replace(this.replacementLabel, url);
					return wCode;
				}

				
				WidgetEditor.prototype.onCustomizedSizeChanged = function(width, height)
				{
					width = parseInt(width);
					height = parseInt(height);
	                if(width > 0) { this.width = width;}
	                if(height>0)  { this.height = height;}
	                this.init();
				}
				
				
				WidgetEditor.prototype.onFontChanged = function(font)
				{
	                this.font = font;
	                this.init();
				}

				WidgetEditor.prototype.onCornersChanged = function(mode)
				{

					if(mode == 5)
					{
						this.skin = 'tbd';
						this.voteButtonCaption			= '';
						this.readmoreLinkCaption		= '';
						$('#iWidgetEditorDailyBeastContainer_' + this.rowID).hide();
						$('#iWidgetEditorDefalutColorsContainer_' + this.rowID).show();
						$('#iWidgetEditorDefalutFontsContainer_' + this.rowID).show();

					}else if(mode == 4)
					{
						this.skin = 'animal_beat';
						this.voteButtonCaption			= '';
						this.readmoreLinkCaption		= '';
						$('#iWidgetEditorDailyBeastContainer_' + this.rowID).hide();
						$('#iWidgetEditorDefalutColorsContainer_' + this.rowID).show();
						$('#iWidgetEditorDefalutFontsContainer_' + this.rowID).show();

					}else if(mode == 3)
					{
						this.skin = 'examiner';
						this.voteButtonCaption			= '';
						this.readmoreLinkCaption		= '';
						$('#iWidgetEditorDailyBeastContainer_' + this.rowID).hide();
						$('#iWidgetEditorDefalutColorsContainer_' + this.rowID).show();
						$('#iWidgetEditorDefalutFontsContainer_' + this.rowID).show();
					}else if(mode == 2)
					{
						this.skin = 'daily_beast';
						$('#iWidgetEditorDefalutColorsContainer_' + this.rowID).hide();
						$('#iWidgetEditorCustomColorsContainer_' + this.rowID).hide();
						$('#iWidgetEditorDefalutFontsContainer_' + this.rowID).hide();
						$('#iWidgetEditorDailyBeastContainer_' + this.rowID).show();
					}else
					{
						this.skin = '';
						this.voteButtonCaption			= '';
						this.readmoreLinkCaption		= '';
						$('#iWidgetEditorDailyBeastContainer_' + this.rowID).hide();
						$('#iWidgetEditorDefalutColorsContainer_' + this.rowID).show();
						$('#iWidgetEditorDefalutFontsContainer_' + this.rowID).show();
					}
	                this.roundedCorners = mode;
	                this.init();
				}
				
				WidgetEditor.prototype.switchColorScheme = function(controlID,mainColor,backgroundColor,bordersColor,headerFooterTextColor,headerFooterBackgroundColor)
				{
                    this.mainColor = mainColor;
                    this.backgroundColor = backgroundColor;
                    this.bordersColor = bordersColor;
                    this.headerFooterTextColor = headerFooterTextColor;
                    this.headerFooterBackgroundColor = headerFooterBackgroundColor;
		            this.init();
					$('div[name=nColorSchemeItem]').width(25);
					$('div[name=nColorSchemeItem]').height(12);
					var controlSelector = '#'+controlID;
					$(controlSelector).height(17);
					$(controlSelector).width(25);


				}
		
		
				WidgetEditor.prototype.changeShowVotes = function(val)
				{	
					var switcher = '#iWidgetShowVotes'+this.rowID;
					$(switcher).attr('checked',val);
					if(val == true) this.showVotes = 1; else this.showVotes = 0;
	                this.init();
				}				

				WidgetEditor.prototype.changeVoteButtonCaption = function(button,caption)
				{	
					this.voteButtonCaption = caption;
	                this.init();

					$('.cVoteBtnCustomization').removeClass('press_poll_btn');
					$('#'+button.id).addClass('press_poll_btn');

					$('.cVoteBtnCustomization').css('color','#000000');
					$('#'+button.id).css('color','green');

				}				


				WidgetEditor.prototype.changeReadmoreLinkCaption = function(button,caption)
				{	
					this.readmoreLinkCaption = caption;
	                this.init();

					$('.cReadMoreLinkCustomization').removeClass('press_poll_btn');
					$('#'+button.id).addClass('press_poll_btn');

					$('.cReadMoreLinkCustomization').css('color','#000000');
					$('#'+button.id).css('color','green');

				}				


				
				WidgetEditor.prototype.switchSizeMode = function(mode)
				{	
					var filter = 'input[name=widget_size_NW'+this.rowID+']';
					$(filter).attr('checked',false);					
					var defaultPanel = '#iWidgetEditorDefalutSizesContainer_'+this.rowID;
					var customPanel = '#iWidgetEditorCustomSizesContainer_'+this.rowID;
					if(mode == 0)
					{
						//standard settings
						$(customPanel).hide(); 
						$(defaultPanel).show(); 
					}else
					{
						//custom settings
						$(defaultPanel).hide(); 
						$(customPanel).show(); 
					}
				}			
				
				WidgetEditor.prototype.switchColorMode = function(mode)
				{	
					var defaultPanel = '#iWidgetEditorDefalutColorsContainer_'+this.rowID;
					var customPanel = '#iWidgetEditorCustomColorsContainer_'+this.rowID;
					if(mode == 0)
					{
						//standard settings
						$(customPanel).hide(); 
						$(defaultPanel).show(); 
					}else
					{
						//custom settings
						$(defaultPanel).hide(); 
						$(customPanel).show(); 
					}
				}			


		        WidgetEditor.prototype.previewPoll = function() 
				{
					var url = this.rootUrl+'/wigets/poll/'+this.itemID+'/height/'+this.height+'/width/'+this.width+'/color1/'+this.mainColor+'/color2/'+this.backgroundColor+'/vts/'+this.showVotes+'/font/'+this.font+'/color3/'+this.bordersColor+'/color4/'+this.headerFooterTextColor+'/color5/'+this.headerFooterBackgroundColor+'/corners/'+this.roundedCorners+'/';
					if(this.skin != '') url += 'skin/'+escape(this.skin)+'/';
					if(this.voteButtonCaption != '') url += 'voteBtnCpt/'+escape(this.voteButtonCaption)+'/';
					if(this.readmoreLinkCaption != '') url += 'readLnCpt/'+escape(this.readmoreLinkCaption)+'/';
					var frog = window.open(url,'WidgetPreview','width='+this.width+',height='+this.height+',status=0,toolbar=0,menubar=0,location=0,resizable=1,scrollbars=1');
					frog.focus();
				}

		        WidgetEditor.prototype.previewLPW = function() 
				{
					var url = this.rootUrl+'/wigets/lpw/'+this.itemID+'/height/'+this.height+'/width/'+this.width+'/color1/'+this.mainColor+'/color2/'+this.backgroundColor+'/vts/'+this.showVotes+'/font/'+this.font+'/color3/'+this.bordersColor+'/color4/'+this.headerFooterTextColor+'/color5/'+this.headerFooterBackgroundColor+'/corners/'+this.roundedCorners+'/';
					if(this.skin != '') url += 'skin/'+escape(this.skin)+'/';
					if(this.voteButtonCaption != '') url += 'voteBtnCpt/'+escape(this.voteButtonCaption)+'/';
					if(this.readmoreLinkCaption != '') url += 'readLnCpt/'+escape(this.readmoreLinkCaption)+'/';
					var frog = window.open(url,'WidgetPreview','width='+this.width+',height='+this.height+',status=0,toolbar=0,menubar=0,location=0,resizable=1,scrollbars=1');
					frog.focus();
				}

				
				WidgetEditor.prototype.selectCode = function (objId) 
				{
					if (document.selection) document.selection.empty(); 
					else if (window.getSelection) window.getSelection().removeAllRanges();
					
					if (document.selection) {
						var range = document.body.createTextRange();
						range.moveToElementText(document.getElementById(objId));
						range.select();
					}
					else if (window.getSelection) {
						var range = document.createRange();
						range.selectNode(document.getElementById(objId));
						window.getSelection().addRange(range);
					}
				}
				
