				function setActiveSize(control)
				{
					$('a.wPSizeselector').removeClass('active');
					$(control).addClass('active');	
				}

				function setActiveColor(control)
				{
					$('a.wPColorselector').removeClass('active');
					$(control).addClass('active');	
				
				}
				
				function fnSelect(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);
					}
				}
				
				function LPW(wCode,wDefaultWidth,wDefaultHeight,wDefaultMainColor,wDefaultBackgroundColor,wReplacementLabelWidth,wReplacementLabelHeight,wreplacementLabelMainColor,wreplacementLabelBackgroundColor,wReplacementLabelShowVotes)
                {
    				this.code = wCode;
                    this.width = wDefaultWidth;
                    this.height = wDefaultHeight;
                    this.mainColor = wDefaultMainColor;
                    this.backgroundColor = wDefaultBackgroundColor;
					this.showVotes = 1;
    				this.replacementLabelWidth = wReplacementLabelWidth; 
    				this.replacementLabelHeight = wReplacementLabelHeight; 
    				this.replacementLabelMainColor = wreplacementLabelMainColor; 
    				this.replacementLabelBackgroundColor = wreplacementLabelBackgroundColor; 
    				this.replacementLabelShowVotes = wReplacementLabelShowVotes; 
    				this.rootUrl = '';

                }
                
                LPW.prototype.init = function(width,height,maincolor,backgroundColor)
                {
                    if((width > 0) && (height > 0))
                    {
                        this.width = width;
                        this.height = height;
                    }

                    if((maincolor != '') && (backgroundColor != ''))
                    {
                        this.mainColor = maincolor;
                        this.backgroundColor = backgroundColor;

                    }
                    var code = lpw.code.replace(this.replacementLabelWidth, this.width);
    				code = code.replace(this.replacementLabelHeight, this.height);
    				code = code.replace(this.replacementLabelMainColor, this.mainColor);
    				code = code.replace(this.replacementLabelBackgroundColor, this.backgroundColor);
    				code = code.replace(this.replacementLabelShowVotes, this.showVotes);


                    $('#iWidgetCodeContainer').html(code);

                    $('#iWidgetCodeContainer').css('backgroundColor', '#' + this.backgroundColor);
                    $('#iWidgetCodeContainer').css('color', '#' + this.mainColor);

                    $('#iWidgetWidthselector').val(lpw.width);
                    $('#iWidgetHeightselector').val(lpw.height);
                    $('#iCustomizedMainLPWColor').css('backgroundColor', '#' + this.mainColor);
                    $('#iCustomizedBackgroundLPWColor').css('backgroundColor', '#' + this.backgroundColor);
                    $('#iWidgetMainColorSelector').val(lpw.mainColor);
                    $('#iWidgetBackgroundColorSelector').val(lpw.backgroundColor);

                }

		        LPW.prototype.preview = function(id) 
				{
					var frog = window.open(this.rootUrl+'wigets/poll/'+id+'/color1/'+this.mainColor+'/color2/'+this.backgroundColor+'/vts/'+this.showVotes+'/','WidgetPreview','width='+this.width+',height='+this.height+',status=0,toolbar=0,menubar=0,location=0,resizable=1,scrollbars=1');
				}
				
				LPW.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);
					}
				}
				
				$(document).ready(function()
				{
					
					
					
					$('#iWidgetShowVotes1').click(function()
					{
						changeShowVotes($('#iWidgetShowVotes1').attr('checked'));
					});
					
					$('#iWidgetShowVotes2').click(function()
					{
						changeShowVotes($('#iWidgetShowVotes2').attr('checked'));
					});
					
					changeShowVotes = function(val)
					{
						$('#iWidgetShowVotes1').attr('checked',val);
						$('#iWidgetShowVotes2').attr('checked',val);
						if(val == true) lpw.showVotes = 1; else lpw.showVotes = 0;
                        lpw.init(0,0,'','');
					}				
					
					
					$('#taWidgetCodeSwitcherID').click(function()
					{
						$('#taWidgetCodeID').toggle();
					});
                    
					$('#iSettingsModeSwitcher1').click(function()
					{
						$('#iDefalutLPWSettingContainer').hide();
						$('#iCustomLPWSettingContainer').show();
					});
                    
					$('#iSettingsModeSwitcher2').click(function()
					{
						$('#iDefalutLPWSettingContainer').show();
						$('#iCustomLPWSettingContainer').hide();
					});
					$('#iWidgetCodeSelector').click(function()
					{
						fnSelect('iWidgetCodeContainer');
					});

					$('#iCustomizedMainLPWColor').click(function(){ 
						$('#iWidgetMainColorSelector').click();
					});
					
					$('#iCustomizedBackgroundLPWColor').click(function(){ 
						$('#iWidgetBackgroundColorSelector').click();
					});

					$('#iWidgetWidthselector').keyup(function()
					{
                        lpw.width = $('#iWidgetWidthselector').val();
                        lpw.init(0,0,'','');
					});
					$('#iWidgetHeightselector').keyup(function()
					{
                        lpw.height = $('#iWidgetHeightselector').val();
                        lpw.init(0,0,'','');
					});

                    $('#iWidgetMainColorSelector').ColorPicker({
                    	onSubmit: function(hsb, hex, rgb) {
                            lpw.mainColor = hex;
                            lpw.init(0,0,'','');
                    		$('#iWidgetMainColorSelector').ColorPickerHide();
                    	},
                        onChange: function (hsb, hex, rgb) {
                            lpw.mainColor = hex;
                            lpw.init(0,0,'','');
                    	},
                    	onBeforeShow: function () {
                    		$(this).ColorPickerSetColor(this.value);

                    	}
                    })
                    .bind('keyup', function(){
                    	$(this).ColorPickerSetColor(this.value);
                        lpw.mainColor = this.value;
                        lpw.init(0,0,'','');

                    });

                    $('#iWidgetBackgroundColorSelector').ColorPicker({
                    	onSubmit: function(hsb, hex, rgb) {
                    		$('#iWidgetBackgroundColorSelector').val(hex);
                    		$('#iWidgetBackgroundColorSelector').ColorPickerHide();
                    	},
                        onChange: function (hsb, hex, rgb) {
                            lpw.backgroundColor = hex;
                            lpw.init(0,0,'','');
                    	},
                    	onBeforeShow: function () {
                    		$(this).ColorPickerSetColor(this.value);
                    	}
                    })
                    .bind('keyup', function(){
                    	$(this).ColorPickerSetColor(this.value);
                    });
					
			});

