
function getCoords()
{
	var pic = document.getElementById('gifttag_src_image');
	picregion = YAHOO.util.Dom.getRegion(pic);

	x = region.left - picregion.left;
	y = region.top - picregion.top;
	alert(x + "|" + y);

}

function zoomin()
{
	var fld = document.forms["gifttag_formH"]["gifttag_horizVal"];
	var v = parseFloat(fld.value, 10);
	v += 5;
	fld.value = v;
	YAHOO.example.GiftTagSliders.updateHoriz()
}

function zoomout()
{
	var fld = document.forms["gifttag_formH"]["gifttag_horizVal"];
	var v = parseFloat(fld.value, 10);
	v -= 5;
	fld.value = v;
	YAHOO.example.GiftTagSliders.updateHoriz()
}

var GiftTag = function()
{
	var dd, clip, pic, pichandle, picpos, clippos, handlepos;
	var editing_text = false;
	var text1, text2;
	var text1_bottom, text2_bottom;	
	var new_font1 = "";
	var new_font2 = "";
	var new_size1 = 10;
	var new_size2 = 10;
	var apply_size1 = false;
	var apply_size2 = false;
	var apply_font1 = false;
	var apply_font2 = false;
	var is_sepia = false;
	var is_grey = false;
	var saved_settings = {};
	var print_list = {};
	var max_photos = 5;
	var num_photos = 0;
	var new_justify1 = 'center';
	var new_justify2 = 'center';
	var apply_justify1 = false;
	var apply_justify2 = false;
	var new_bold1 = 0;
	var apply_bold1 = false;
	var new_bold2 = 0;
	var apply_bold2 = false;
	
	// defaults for a new start
	saved_settings.id = 0; //
	saved_settings.photo_id = 0; //
	saved_settings.photo = ""; //
	saved_settings.scale = "100"; //
	saved_settings.text_line_1 = ""; //
	saved_settings.text_line_2 = ""; //
	saved_settings.text_line_1_y = 350;//
	saved_settings.text_line_2_y = 380;//
	saved_settings.x_offset = 0;//
	saved_settings.y_offset = 0;//
	saved_settings.bg_color = "#dddddd";//
	saved_settings.grid_color = "#ffffff";//
	saved_settings.text_color = "#000000";//
	saved_settings.font1 = "times";//
	saved_settings.font2 = "times";//
	saved_settings.text_line_1_font_size = 20;
	saved_settings.text_line_2_font_size = 20;
	saved_settings.color = 0; //0=original 1=sepia 2=grey
	saved_settings.screen_width = 450;//
	saved_settings.real_width = 900;//
	saved_settings.screen_height = 450;//
	saved_settings.real_height = 900;//
	saved_settings.text_line_1_bold = 0;
	saved_settings.text_line_2_bold = 0;
	saved_settings.justify1 = 'center';
	saved_settings.justify2 = 'center';
	
	var orig_settings = {};

	
	return{
		init: function()
		{

			text1 = new YAHOO.util.DD("gifttag_text_line_1");
			text2 = new YAHOO.util.DD("gifttag_text_line_2");

			text1.onDrag = function(e)
			{
				var clipregion = YAHOO.util.Dom.getRegion(clip);
				var pos = YAHOO.util.Dom.getXY("gifttag_rendered_text_1");
				y = pos[1] - clipregion.top;
				GiftTag.setSavedY(1, y);
			}
			text2.onDrag = function(e)
			{
				var clipregion = YAHOO.util.Dom.getRegion(clip);
				var pos = YAHOO.util.Dom.getXY("gifttag_rendered_text_2");
				y = pos[1] - clipregion.top;
				GiftTag.setSavedY(2, y);
			}
			
			dd = new YAHOO.util.DD("gifttag_picWindow");
			dd.offendingX = 0;
			dd.setOuterHandleElId("gifttag_picHandle");

			dd.onDrag = function(e)
			{
				var clipregion = YAHOO.util.Dom.getRegion(GiftTag.getClipWindow());
				var picregion = YAHOO.util.Dom.getRegion(GiftTag.getPicWindow());
				   
				//picregion.left -= 4; // to make up for the grid border in FF
				//picregion.top -= 4; // to make up for the grid border in FF
				
				x = picregion.left - clipregion.left;
				y = picregion.top - clipregion.top;
				GiftTag.setXOffset(x);
				GiftTag.setYOffset(y);
			}
			
			
			clip = YAHOO.util.Dom.get("gifttag_clipWindow");
			pic = YAHOO.util.Dom.get("gifttag_picWindow");
			pichandle = YAHOO.util.Dom.get("gifttag_picHandle");
			picpos = YAHOO.util.Dom.getXY(pic);

			this.setHandlePos();

			clipregion = YAHOO.util.Dom.getRegion(clip);
			picregion = YAHOO.util.Dom.getRegion(pic);

			picwidth = picregion.right - picregion.left;
			clipwidth = clipregion.right - clipregion.left;
			diff = picwidth - clipwidth;
			left = picregion.left - (diff/2);

			picheight = picregion.bottom - picregion.top;
			clipheight = clipregion.bottom - clipregion.top;

			diff = picheight - clipheight;
			tp = picregion.top - (diff/2);
			YAHOO.util.Dom.setXY(pic, [left, tp]);

			//this.doConstraints();
		},

		getClipWindow : function()
		{
			return clip;
		},
		
		setupOrigSettings : function(arr)
		{
			for (n in arr)
			{
				orig_settings[n] = arr[n];
			}
		},
		
		getPicWindow : function()
		{
			return pic;
		},
		
		setSavedY : function(line, pos)
		{
			eval("saved_settings.text_line_"+line+"_y = " + pos +";");
		},
		
		setXOffset : function(x)
		{
			saved_settings.x_offset = x;
		},
		
		setYOffset : function(y)
		{
			saved_settings.y_offset = y;
		},
		
		setSavedScale : function(scale)
		{
			saved_settings.scale = scale;
		},
		
		hasBeenSaved : function()
		{
			if (saved_settings.photo_id > 0)
			{
				return true;
			}
			return false;
		},
		
		setTextPos : function()
		{
			clipregion = YAHOO.util.Dom.getRegion(clip);
			var t1 = document.getElementById("gifttag_text_line_1");
			var t2 = document.getElementById("gifttag_text_line_2");
			var tp = parseInt(clipregion.top) + 16;
			var y1 = parseInt(saved_settings.text_line_1_y)-16;
			var ypos1 = tp + y1;
			var y2 = parseInt(saved_settings.text_line_2_y)-16;
			var ypos2 = tp + y2;

			YAHOO.util.Dom.setXY(t1, [clipregion.left+25, ypos1]);
			YAHOO.util.Dom.setXY(t2, [clipregion.left+25, ypos2]);
			text1.resetConstraints();
			text2.resetConstraints();
			text1.setXConstraint(0,0);
			text2.setXConstraint(0,0);
			
			var maxy = 393;
			if (is_ie)
				maxy = 386;
				
			text1.setYConstraint(y1-5,maxy-y1);
			text1_bottom = (maxy-y1) - 16;
			text2.setYConstraint(y2-5,maxy-y2);
			text2_bottom = (maxy-y2) - 16;
		},

		highlightIcon : function(obj)
		{
			//obj.style.borderColor = '#6593cf';
			return;
		},

		unHighlightIcon : function(obj)
		{
			//if ((saved_settings.color == 1 && obj.id == "sepia_icon") || (saved_settings.color == 2 && obj.id == "grey_icon"))
			//{
			//	obj.style.borderTopColor = '#6593cf';
			//	obj.style.borderLeftColor = '#6593cf';
			//	obj.style.borderRightColor = '#d1e4ff';
			//	obj.style.borderBottomColor = '#d1e4ff';
			//}
			//else
			//{
			//	obj.style.borderColor = 'transparent';
			//}
			return;
		},

		getColor : function()
		{
			return saved_settings.color;
		},
		
		restoreColorState : function(state)
		{
			if (state == 0)
			{
				document.getElementById("gifttag_color_sepia").checked = false;
				document.getElementById("gifttag_color_orig").checked = true;
				document.getElementById("gifttag_color_grey").checked = false;
			}
			if (state == 1)
			{
				document.getElementById("gifttag_color_sepia").checked = true;
				document.getElementById("gifttag_color_orig").checked = false;
				document.getElementById("gifttag_color_grey").checked = false;
			}
			if (state == 2)
			{
				document.getElementById("gifttag_color_sepia").checked = false;
				document.getElementById("gifttag_color_orig").checked = false;
				document.getElementById("gifttag_color_grey").checked = true;
			}
		},
		
		toggleSepia : function()
		{
			saved_settings.color = 1;
			document.getElementById("gifttag_color_sepia").checked = true;
			document.getElementById("gifttag_color_orig").checked = false;
			document.getElementById("gifttag_color_grey").checked = false;
			return saved_settings.color;			
			
			//this.sepiaOn();
			
			/*
			if (saved_settings.color != 1)
			{
				this.sepiaOn();
			}
			else
			{
				this.sepiaOff();
			}*/

		},

		toggleOriginal : function()
		{
			saved_settings.color = 0;
			document.getElementById("gifttag_color_sepia").checked = false;
			document.getElementById("gifttag_color_orig").checked = true;
			document.getElementById("gifttag_color_grey").checked = false;
			return saved_settings.color;			
			
			//this.sepiaOn();
			
			/*
			if (saved_settings.color != 1)
			{
				this.sepiaOn();
			}
			else
			{
				this.sepiaOff();
			}*/

		},		
		
		sepiaOn : function()
		{
			obj = document.getElementById("gifttag_sepia_icon");
			obj.style.borderTopColor = '#6593cf';
			obj.style.borderLeftColor = '#6593cf';
			obj.style.borderRightColor = '#d1e4ff';
			obj.style.borderBottomColor = '#d1e4ff';
			obj.style.borderWidth = "1px";
			document.getElementById("gifttag_grey_icon").style.borderWidth = "0px";
			saved_settings.color = 1;
		},
		
		sepiaOff : function()
		{
			//document.getElementById("sepia_icon").style.borderColor = "transparent";
			saved_settings.color = 0;
			document.getElementById("gifttag_sepia_icon").style.borderWidth = "0px";
		},
		
		toggleGrey : function()
		{
			saved_settings.color = 2;
			document.getElementById("gifttag_color_sepia").checked = false;
			document.getElementById("gifttag_color_orig").checked = false;
			document.getElementById("gifttag_color_grey").checked = true;
			return saved_settings.color;				
			
			/*
			if (saved_settings.color != 2)
			{
				this.greyOn();
			}
			else
			{
				this.greyOff();
			}
			return saved_settings.color;
			*/
		},

		greyOn : function()
		{
			obj = document.getElementById("gifttag_grey_icon");
			obj.style.borderTopColor = '#6593cf';
			obj.style.borderLeftColor = '#6593cf';
			obj.style.borderRightColor = '#d1e4ff';
			obj.style.borderBottomColor = '#d1e4ff';
			obj.style.borderWidth = "1px;"
			document.getElementById("gifttag_sepia_icon").style.borderWidth = "0px";
			saved_settings.color = 2;
		},
		
		greyOff : function()
		{
			//document.getElementById("grey_icon").style.borderColor = "transparent";
			saved_settings.color = 0;
			document.getElementById("gifttag_grey_icon").style.borderWidth = "0px";
		},

		getOrigWidth: function()
		{
			return saved_settings.screen_width;
		},

		getOrigHeight: function()
		{
			return saved_settings.screen_height;
		},

		loadImage : function(path, forcejpg)
		{
			var file = saved_settings.photo;
			if (forcejpg == true)
			{
				var arr = file.split(".");
				file = arr[0] + ".jpg";
			}
			document.getElementById("gifttag_src_image").src = path + file;
		},

		getCurrentPhoto : function()
		{
			return saved_settings.photo;
		},

		useSavedSettings : function(settings)
		{
			temp = settings[1];
			temp.id = settings.id;
			temp.photo = settings.photo;
			temp.has_jobs = settings.has_jobs;
			
			saved_settings = temp;
			YAHOO.example.GiftTagSliders.init();
			YAHOO.example.GiftTagSliders.setVert((saved_settings.scale - 100));
			this.setText(1, unescape(saved_settings.text_line_1));
			this.setText(2, unescape(saved_settings.text_line_2));
			this.setTextPos();

			if (saved_settings.bg_color.indexOf("#") == -1)
				saved_settings.bg_color = "#" + "" + saved_settings.bg_color;
			if (saved_settings.grid_color.indexOf("#") == -1)				
				saved_settings.grid_color = "#" + "" + saved_settings.grid_color;
			if (saved_settings.text_color.indexOf("#") == -1)
				saved_settings.text_color = "#" + "" + saved_settings.text_color;
			this.changeBGColor(saved_settings.bg_color);
			this.changeFontColor(saved_settings.text_color);
			new_font1 = saved_settings.font1;
			apply_line1 = true;
			new_font2 = saved_settings.font2;
			apply_line2 = true;
			
			this.applyFont();
			new_justify1 = saved_settings.justify1;
			apply_justify1 = true;
			new_justify2 = saved_settings.justify2;
			apply_justify2 = true;
			
			this.applyJustify();			
			
			this.setFontSize(saved_settings.text_line_1_font_size, 1);
			this.setFontSize(saved_settings.text_line_2_font_size, 2);
			
			
			if (saved_settings.text_line_1_bold == 1)
			{
				this.bold(1, true);
			}
			if (saved_settings.text_line_2_bold == 1)
			{
				this.bold(2, true);
			}
			
			if (saved_settings.color == 0)
			{
				this.loadImage("/photos/"+saved_settings.id+"/", false);
				this.setPhoto(saved_settings.screen_width, saved_settings.screen_height);
				this.toggleOriginal();
				//this.sepiaOff();
				//this.greyOff();
			}
			
			if (saved_settings.color == 1)
			{
				this.loadImage("/photos/"+saved_settings.id+"/sepia/", true);
				this.setPhoto(saved_settings.screen_width, saved_settings.screen_height);
				this.toggleSepia();
				//this.sepiaOn();
				//this.greyOff();
			}
			
			if (saved_settings.color == 2)
			{
				this.loadImage("/photos/"+saved_settings.id+"/grey/", true);
				this.setPhoto(saved_settings.screen_width, saved_settings.screen_height);
				this.toggleGrey();
				//this.sepiaOff();
				//this.greyOn();
			}
			this.setupOrigSettings(saved_settings);
			this.populateFontDialog();			
		},
		populateFontDialog : function()
		{
			if (saved_settings.font2 == 'times' || saved_settings.font2 == '')
			{
				document.getElementById("wizard_font2_0").checked = true;
			}
			if (saved_settings.font2 == 'arial')
			{
				document.getElementById("wizard_font2_1").checked = true;
			}
			if (saved_settings.font2 == 'Comic Sans MS')
			{
				var obj = document.getElementById("wizard_font2_4");
				document.getElementById("wizard_font2_4").checked = true;
			}
			if (saved_settings.font2 == 'Impact')
			{
				document.getElementById("wizard_font2_2").checked = true;
			}
			if (saved_settings.font2 == 'Palatino')
			{
				document.getElementById("wizard_font2_3").checked = true;
			}			
			
			if (saved_settings.font1 == 'times' || saved_settings.font1 == '')
			{
				document.getElementById("wizard_font1_0").checked = true;
			}
			if (saved_settings.font1 == 'arial')
			{
				document.getElementById("wizard_font1_1").checked = true;
			}
			if (saved_settings.font1 == 'Comic Sans MS')
			{
				document.getElementById("wizard_font1_4").checked = true;
			}
			if (saved_settings.font1 == 'Impact')
			{
				document.getElementById("wizard_font1_2").checked = true;
			}
			if (saved_settings.font1 == 'Palatino')
			{
				document.getElementById("wizard_font1_3").checked = true;
			}

			if (saved_settings.justify1 == 'left')
			{
				document.getElementById("wizard_justify1_0").checked = true;
			}
			if (saved_settings.justify1 == 'right')
			{
				document.getElementById("wizard_justify1_2").checked = true;
			}
			if (saved_settings.justify1 == 'center' || saved_settings.justify1 == '')
			{
				document.getElementById("wizard_justify1_1").checked = true;
			}
			
			if (saved_settings.justify2 == 'left')
			{
				document.getElementById("wizard_justify2_0").checked = true;
			}
			if (saved_settings.justify2 == 'right')
			{
				document.getElementById("wizard_justify2_2").checked = true;
			}
			if (saved_settings.justify2 == 'center' || saved_settings.justify2 == '')
			{
				document.getElementById("wizard_justify2_1").checked = true;
			}			
			
			
			if (saved_settings.text_line_1_bold == 1)
			{
				document.getElementById("wizard_font_style1_0").checked = true;
			}
			else
			{
				document.getElementById("wizard_font_style1_1").checked = true;
			}
			
			if (saved_settings.text_line_2_bold == 1)
			{
				document.getElementById("wizard_font_style2_0").checked = true;
			}
			else
			{
				document.getElementById("wizard_font_style2_1").checked = true;
			}

			if (saved_settings.text_line_1_font_size == 10)
			{
				document.getElementById("wizard_fontsize1_1").checked = true;
			}
			if (saved_settings.text_line_1_font_size == 15)
			{
				document.getElementById("wizard_fontsize1_2").checked = true;
			}
			if (saved_settings.text_line_1_font_size == 20)
			{
				document.getElementById("wizard_fontsize1_3").checked = true;
			}
			if (saved_settings.text_line_1_font_size == 25)
			{
				document.getElementById("wizard_fontsize1_4").checked = true;
			}
			if (saved_settings.text_line_1_font_size == 30)
			{
				document.getElementById("wizard_fontsize1_5").checked = true;
			}
			if (saved_settings.text_line_1_font_size == 35)
			{
				document.getElementById("wizard_fontsize1_6").checked = true;
			}
			if (saved_settings.text_line_1_font_size == 40)
			{
				document.getElementById("wizard_fontsize1_7").checked = true;
			}
			

			if (saved_settings.text_line_2_font_size == 10)
			{
				document.getElementById("wizard_fontsize2_1").checked = true;
			}
			if (saved_settings.text_line_2_font_size == 15)
			{
				document.getElementById("wizard_fontsize2_2").checked = true;
			}
			if (saved_settings.text_line_2_font_size == 20)
			{
				document.getElementById("wizard_fontsize2_3").checked = true;
			}
			if (saved_settings.text_line_2_font_size == 25)
			{
				document.getElementById("wizard_fontsize2_4").checked = true;
			}
			if (saved_settings.text_line_2_font_size == 30)
			{
				document.getElementById("wizard_fontsize2_5").checked = true;
			}
			if (saved_settings.text_line_2_font_size == 35)
			{
				document.getElementById("wizard_fontsize2_6").checked = true;
			}
			if (saved_settings.text_line_2_font_size == 40)
			{
				document.getElementById("wizard_fontsize2_7").checked = true;
			}
		},
		checkForChanges : function()
		{
			for (n in saved_settings)
			{
				if (orig_settings[n] != saved_settings[n])
				{
					temp1 = "";
					temp2 = "";
					if (typeof (orig_settings[n]) == "string" && typeof (saved_settings[n]) == "string")
					{
						if (orig_settings[n].indexOf("#") >= 0 || saved_settings[n].indexOf("#") >= 0)
						{
							if (orig_settings[n].indexOf("#") >= 0)
								temp1 = orig_settings[n].substr(1, orig_settings[n].length);
							else
								temp1 = orig_settings[n];
								
							if (saved_settings[n].indexOf("#") >= 0)
								temp2 = saved_settings[n].substr(1, saved_settings[n].length);
							else
								temp2 = saved_settings[n];
								
							//alert(temp1 + "|" + temp2);
							if (temp1 != temp2)
								return true;
							else
								return false;
						}						
					}
					return true;
				}
			}
			return false;
		},
		
		setPhoto : function(width, height)
		{
			document.getElementById("gifttag_src_image").setAttribute('width', width);
			document.getElementById("gifttag_src_image").setAttribute('height', height);
			
			var clipregion = YAHOO.util.Dom.getRegion(clip);
			document.getElementById("gifttag_src_image").style.top = 0 + "px";
			document.getElementById("gifttag_src_image").style.left = 0 + "px";
			
			// for firefox
			if (is_fx)
			{
				document.getElementById("gifttag_picWindow").style.top = (parseInt(saved_settings.y_offset) + 8) + "px";
				document.getElementById("gifttag_picWindow").style.left = (parseInt(saved_settings.x_offset) + 8) + "px";
			}
			else
			{
				document.getElementById("gifttag_picWindow").style.top = saved_settings.y_offset + "px";
				document.getElementById("gifttag_picWindow").style.left = saved_settings.x_offset + "px";
			}
		},

		setFont : function(line, font)
		{
			eval("new_font"+line+" = font;");
			eval("apply_line"+line+" = true;");
		},

		applyFont : function()
		{
			if (apply_line1)
			{
				saved_settings.font1 = new_font1;
				document.getElementById("gifttag_rendered_text_1").style.fontFamily = new_font1;
				apply_line1 = false;
			}
			if (apply_line2)
			{
				saved_settings.font2 = new_font2;
				document.getElementById("gifttag_rendered_text_2").style.fontFamily = new_font2;
				apply_line2 = false;
			}
			
			
			if (apply_size1)
			{
				saved_settings.text_line_1_font_size = new_size1;
				this.setFontSize(new_size1, 1);
				
				if (new_size1 < 40)
				{
					var num = new_size1 / 40;
					num = (1 - num) * 40;
					text1.setYConstraint(text1.topConstraint, text1_bottom+num);
				}
				else
				{
					text1.setYConstraint(text1.topConstraint, text1_bottom);
				}
				apply_size1 = false;
			}

			if (apply_size2)
			{
				saved_settings.text_line_2_font_size = new_size2;
				this.setFontSize(new_size2, 2);
				
				if (new_size1 < 40)
				{
					var num = new_size2 / 40;
					num = (1 - num) * 40;
					text2.setYConstraint(text2.topConstraint, text2_bottom+num);
				}
				else
				{
					text2.setYConstraint(text2.topConstraint, text2_bottom);
				}
				apply_size2 = false;
			}

			

		},

		setText : function(line, text)
		{
			text = text.split("'").join("\'");			
			eval("saved_settings.text_line_"+line+" = \"" + text + "\";");
			document.getElementById("gifttag_rendered_text_" + line).innerHTML = text;
			document.getElementById("gifttag_text_box_" + line).value = text;
		},

		bold : function(line, bForceIt)
		{
			var temp = 0;
			eval("temp = saved_settings.text_line_"+line+"_bold");

			if (bForceIt == null)
				bForceIt = false;

			if ((temp == 0) || bForceIt)
			{
				document.getElementById("gifttag_rendered_text_" + line).style.fontWeight = "bold";
				eval("saved_settings.text_line_"+line+"_bold = 1;");
			}
			else
			{
				document.getElementById("gifttag_rendered_text_" + line).style.fontWeight = "normal";
				eval("saved_settings.text_line_"+line+"_bold = 0;");
			}
		},
		doBold : function(line, bBold)
		{
			if (bBold)
			{
				document.getElementById("gifttag_rendered_text_" + line).style.fontWeight = "bold";
				eval("saved_settings.text_line_"+line+"_bold = 1;");
			}
			else
			{
				document.getElementById("gifttag_rendered_text_" + line).style.fontWeight = "normal";
				eval("saved_settings.text_line_"+line+"_bold = 0;");
			}
		},
		
		
		setBold : function(line, bBold)
		{
			eval("new_bold"+line+" = bBold;");
			eval("apply_bold"+line+" = true;");
		},
		applyBold : function()
		{
			if (apply_bold1)
			{
				this.doBold(1,new_bold1);
				apply_bold1 = false;
			}
			if (apply_bold2)
			{
				this.doBold(2,new_bold2);
				apply_bold2 = false;
			}
		},

		
		isEditingText : function()
		{
			return editing_text;
		},

		toggleText : function(bForceItOn, bForceItOff)
		{
			if ((!editing_text && !bForceItOff) || bForceItOn)
			{
				document.getElementById("gifttag_rendered_text_1").style.display = 'none';
				document.getElementById("gifttag_text_box_1").style.display = 'inline';
				document.getElementById("gifttag_rendered_text_2").style.display = 'none';
				document.getElementById("gifttag_text_box_2").style.display = 'inline';
				editing_text = true;
				return;
			}

			if (editing_text || bForceItOff)
			{
				document.getElementById("gifttag_rendered_text_1").style.display = 'inline';
				document.getElementById("gifttag_text_box_1").style.display = 'none';
				document.getElementById("gifttag_rendered_text_2").style.display = 'inline';
				document.getElementById("gifttag_text_box_2").style.display = 'none';
				editing_text = false;
				return;
			}
		},

		changeBGColor : function(val)
		{
			var clip = YAHOO.util.Dom.get("gifttag_clipWindow");
			clip.style.background = val;
			saved_settings.bg_color = val;
		},

		setThis : function(param, val)
		{
			eval("saved_settings." + param + " = '" + val + "';");
		},
		
		changeFontColor : function(val)
		{
			document.getElementById("gifttag_rendered_text_1").style.color = val;
			document.getElementById("gifttag_rendered_text_2").style.color = val;
			saved_settings.text_color = val;
		},
		setJustify : function(line, justify)
		{
			eval("new_justify"+line+" = justify;");
			eval("apply_justify"+line+" = true;");
		},
	
		applyJustify : function()
		{
			if (apply_justify1)
			{
				this.justify(1, new_justify1);
				apply_justify1 = false;
			}
			if (apply_justify2)
			{
				this.justify(2, new_justify2);
				apply_justify2 = false;
			}

		},
		
		justify : function(line, justify)
		{
			document.getElementById("gifttag_rendered_text_"+line).style.textAlign = justify;
			eval("saved_settings.justify"+line+" = justify;");
		},
		
		increaseFontSize : function(line)
		{
			if (line == null)
			{
				// do both lines
				var fs = document.getElementById("gifttag_rendered_text_1").style.fontSize;
				fs = parseInt(fs) + 5;
				if (fs > 40)
					fs = 40;
				saved_settings.text_line_1_font_size = fs;
				this.setFontSize(fs, 1);
				
				var fs = document.getElementById("gifttag_rendered_text_2").style.fontSize;
				fs = parseInt(fs) + 5;
				if (fs > 40)
					fs = 40;
				saved_settings.text_line_2_font_size = fs;
				this.setFontSize(fs, 2);
				
				if (fs < 40)
				{
					var num = fs / 40;
					num = (1 - num) * 40;
					text1.setYConstraint(text1.topConstraint, text1_bottom+num);
					text2.setYConstraint(text2.topConstraint, text2_bottom+num);
				}
				else
				{
					text1.setYConstraint(text1.topConstraint, text1_bottom);
					text2.setYConstraint(text2.topConstraint, text2_bottom);
				}
				
				
				return;
			}

			var fs = document.getElementById("gifttag_rendered_text_" + line).style.fontSize;
			fs = parseInt(fs) + 5;
			if (fs > 40)
			fs = 40;
			eval("saved_settings.text_line_"+line+"_font_size = fs;");
			
			if (fs < 40)
			{
				var num = fs / 40;
				num = (1 - num) * 40;
				if (line == 1)
					text1.setYConstraint(text1.topConstraint, text1_bottom+num);
				else
					text2.setYConstraint(text2.topConstraint, text2_bottom+num);
			}
			else
			{
				if (line == 1)
					text1.setYConstraint(text1.topConstraint, text1_bottom);
				else
					text2.setYConstraint(text2.topConstraint, text2_bottom);
			}
			
			this.setFontSize(fs, line);
		},

		doFontSize : function(line, fs)
		{
			eval("new_size"+line+" = fs;");
			eval("apply_size"+line+" = true;");
		},
		
		
		decreaseFontSize : function(line)
		{
			if (line == null)
			{
				// do both lines
				var fs = document.getElementById("gifttag_rendered_text_1").style.fontSize;
				fs = parseInt(fs) - 5;
				if (fs < 10)
					fs = 10;
				saved_settings.text_line_1_font_size = fs;
				this.setFontSize(fs, 1);
				
				var fs = document.getElementById("gifttag_rendered_text_2").style.fontSize;
				fs = parseInt(fs) - 5;
				if (fs < 10)
					fs = 10;
				saved_settings.text_line_2_font_size = fs;
				this.setFontSize(fs, 2);
				
				if (fs < 40)
				{
					var num = fs / 40;
					num = (1 - num) * 40;
					text1.setYConstraint(text1.topConstraint, text1_bottom+num);
					text2.setYConstraint(text2.topConstraint, text2_bottom+num);
				}
				else
				{
					text1.setYConstraint(text1.topConstraint, text1_bottom);
					text2.setYConstraint(text2.topConstraint, text2_bottom);
				}		
				
				return;
			}

			var fs = document.getElementById("gifttag_rendered_text_" + line).style.fontSize;
			fs = parseInt(fs) - 5;
			if (fs < 10)
			fs = 10;
			eval("saved_settings.text_line_"+line+"_font_size = fs;");
			if (fs < 40)
			{
				var num = fs / 40;
				num = (1 - num) * 40;
				if (line == 1)
					text1.setYConstraint(text1.topConstraint, text1_bottom+num);
				else
					text2.setYConstraint(text2.topConstraint, text2_bottom+num);
			}
			else
			{
				if (line == 1)
					text1.setYConstraint(text1.topConstraint, text1_bottom);
				else
					text2.setYConstraint(text2.topConstraint, text2_bottom);
			}
		
			this.setFontSize(fs, line);

		},


		showTextControls : function(line)
		{
			if (document.getElementById("gifttag_text_box_" + line).value != "")
			{
				//document.getElementById('text_line_'+line).style.borderWidth='0px';
				document.getElementById('gifttag_text_line_'+line+'_handle').style.display='inline';
				document.getElementById('gifttag_text_'+line+'_buttons').style.display='inline';
			}
		},
		
		hideTextControls : function(line)
		{
			//document.getElementById('text_line_'+line).style.borderWidth='0px';
			document.getElementById('gifttag_text_line_'+line+'_handle').style.display='none';
			document.getElementById('gifttag_text_'+line+'_buttons').style.display='none';
		},
		
		setFontSize : function(size, line)
		{
			if (line == null)
			{
				document.getElementById("gifttag_rendered_text_1").style.fontSize = size + "px";
				document.getElementById("gifttag_rendered_text_2").style.fontSize = size + "px";
			}
			else
			{
				document.getElementById("gifttag_rendered_text_"+line).style.fontSize = size + "px";
			}
		},
		
		setHandlePos : function()
		{
			clippos = YAHOO.util.Dom.getXY(clip);
			YAHOO.util.Dom.setXY(pichandle, clippos);
			clipregion = YAHOO.util.Dom.getRegion(clip);
			picregion = YAHOO.util.Dom.getRegion(pic);

			picwidth = picregion.right - picregion.left;
			clipwidth = clipregion.right - clipregion.left;
			diff = picwidth - clipwidth;
			left = picregion.left - (diff/2);

			picheight = picregion.bottom - picregion.top;
			clipheight = clipregion.bottom - clipregion.top;

			diff = picheight - clipheight;

			tp = picregion.top - (diff/2);
			YAHOO.util.Dom.setXY(pic, [left, tp]);
		},
		
		getPhotoIdsForPDF : function()
		{
			var photo_ids = "";
			for (n in print_list)
			{
				if (print_list[n] != null)
				{
					photo_ids += n + ",";
				}
			}
			return photo_ids;
		},
		
		addPhotoForPrint : function()
		{
			this.savePhoto();
			this.internal_state = INTERNAL_ADD_PHOTO;
		},

		reallyAddPhotoForPrint : function()
		{
			if (num_photos == max_photos)
			{
				alert("You can only use "+max_photos+" photos for this project");
				return;				
			}
			if (!(saved_settings.photo_id in print_list))
			{
				print_list[saved_settings.photo_id] = saved_settings.photo;
				this.updatePrintList();
			}
		},

		removePhotoForPrint : function(photo_id)
		{
			if (photo_id in print_list)
			{
				delete print_list[photo_id];
				this.updatePrintList();
			}
		},		
		
		updatePrintList : function()
		{
			pl = document.getElementById('gifttag_photos_to_print');
			pl.innerHTML = "Click to Remove<br/>";
			num_photos = 0;
			for (n in print_list)
			{
				if (print_list[n] != null)
				{
					num_photos++;
					pl.innerHTML += '<a href="javascript:GiftTag.removePhotoForPrint('+n+');">&nbsp;'+print_list[n]+'</a><br/>';
					//<img src="images/remove.gif" style="border: 0px; cursor: pointer;" onclick="">
				}
			}
		},

		hasPrintList : function()
		{
			var c = 0;
			for (n in print_list)
			{
				if (print_list[n] != null)
				{
					c++;
				}
			}
			return c;
		},
		
		getPrintList : function()
		{
			return print_list;
		},
		
		erasePrintList : function()
		{
			print_list = {};
		},		
		
		savePhoto : function()
		{
			BlockWizard.savePhoto(saved_settings);
		},
		
		getSize : function(size)
		{
			return 0;
		},			
		
		setMaxPhotos : function(size)
		{
		},			
		
		setPhotoId: function(id)
		{
			saved_settings.photo_id = id;
			this.setupOrigSettings(saved_settings);
			if (internal_state = INTERNAL_ADD_PHOTO)
			{
				this.reallyAddPhotoForPrint();
			}
		},
		
		
		doConstraints: function()
		{
			region = YAHOO.util.Dom.getRegion('gifttag_clipWindow');
			picregion = YAHOO.util.Dom.getRegion(dd.getEl());


			dd.resetConstraints();

			region = YAHOO.util.Dom.getRegion('gifttag_clipWindow');
			picregion = YAHOO.util.Dom.getRegion('gifttag_src_image');

			var xmax = region.left - picregion.left;
			var xmin = picregion.right - region.right;

			var ymax = region.top - picregion.top;
			var ymin = picregion.bottom - region.bottom;


			dd.setXConstraint(xmin, xmax);
			dd.setYConstraint(ymin, ymax);

			// =============

			region = YAHOO.util.Dom.getRegion('gifttag_clipWindow');
			picregion = YAHOO.util.Dom.getRegion('gifttag_src_image');

			x = picregion.left;
			y = picregion.top;
			if (picregion.right < region.right)
			{
				xdiff = region.right - picregion.right;
				x += xdiff;
				YAHOO.util.Dom.setXY('gifttag_src_image', [x, y]);
			}
			if (picregion.bottom < region.bottom)
			{
				ydiff = region.bottom - picregion.bottom;
				y += ydiff;
				YAHOO.util.Dom.setXY('gifttag_src_image', [x,y]);
			}

			if (picregion.left > region.left)
			{
				xdiff = picregion.left - region.left;
				x -= xdiff;
				YAHOO.util.Dom.setXY('gifttag_src_image', [x,y]);
			}

			if (picregion.top > region.top)
			{
				ydiff = picregion.top - region.top;
				y -= xdiff;
				YAHOO.util.Dom.setXY('gifttag_src_image', [x,y]);
			}

		}
	}
} ();

YAHOO.util.Event.addListener(window, "load", GiftTag.init, GiftTag, true);

YAHOO.example.GiftTagSliders = function() {

	var Dom = YAHOO.util.Dom;
	var Event = YAHOO.util.Event;
	var first_run = 0;
	var thumb_pos = [];
	var init_vert_val = 0;
	var yslider;

	var initVert = function() {

		var bg="gifttag_vertBGDiv",thumb="gifttag_vertHandleDiv",valFld="gifttag_vertVal";
		var holdSize = false;
		var bottomPerc = null;
		       // thumbObj = document.getElementById(thumb);
		      // readOutObj = document.getElementById("readOut");
		     // pos = YAHOO.util.Dom.getXY(thumbObj);
		   // YAHOO.util.Dom.setXY(readOutObj, [pos[0],pos[1]]);

		    if (first_run < 2)
		    {
		    	first_run++;
		    	thumb_pos =  YAHOO.util.Dom.getXY(thumb);
		    	init_vert_val = Dom.get(valFld).value
		    }
		    else
		    {
		    	thumbObj = document.getElementById(thumb);
		    	YAHOO.util.Dom.setXY(thumbObj, thumb_pos);
		    	Dom.get(valFld).value = init_vert_val;
		    }			

		    yslider = null;
		    
		yslider = YAHOO.widget.Slider.getVertSlider(bg,thumb, 100, 200, 1);
		yslider.subscribe("change", function(offsetFromStart) {
			readOutObj = document.getElementById("gifttag_readOut");
			pos = YAHOO.util.Dom.getXY(thumb);
			

		
			YAHOO.util.Dom.setXY(readOutObj, [pos[0]+25,pos[1]]);


			Dom.get(valFld).value = offsetFromStart;
			offsetFromStart += 100;
			zoomcount = offsetFromStart;
			width = GiftTag.getOrigWidth() * (offsetFromStart * .01);
			height = GiftTag.getOrigHeight() * (offsetFromStart * .01);
			Dom.get(bg).title = offsetFromStart + "%";
			GiftTag.setSavedScale(offsetFromStart);
			readOutObj.innerHTML = offsetFromStart + "%";
			/*
			if (!holdSize)

			else
			readOutObj.innerHTML = bottomPerc;

			region = YAHOO.util.Dom.getRegion('clipWindow');
			testWidth = region.right - region.left;
			testHeight = region.bottom - region.top;
			if (width <= testWidth)
			{
			width = testWidth;
			if (!holdSize)
			{
			if (!bottomPerc)
			bottomPerc = offsetFromStart + "%";

			holdSize = true;
			}
			}
			else
			{
			holdSize = false;
			}

			if (height <= testHeight)
			{
			height = testHeight;
			if (!holdSize)
			{
			if (!bottomPerc)
			bottomPerc = offsetFromStart + "%";

			holdSize = true;
			}
			}
			else
			{
			holdSize = false;
			}
			*/


			document.getElementById("gifttag_src_image").setAttribute('width', width);
			document.getElementById("gifttag_src_image").setAttribute('height', height);
			YAHOO.util.Dom.setStyle('gifttag_picWindow', 'width', width);
			YAHOO.util.Dom.setStyle('gifttag_picWindow', 'height', height);


			//GiftTag.doConstraints();
		});

		yslider.subscribe("slideEnd", function() {
			offsetFromStart = this.getValue();
			Dom.get(valFld).value = offsetFromStart;

			offsetFromStart += 100;
			zoomcount = offsetFromStart;
			width = GiftTag.getOrigWidth() * (offsetFromStart * .01);
			height = GiftTag.getOrigHeight() * (offsetFromStart * .01);


			//if (!holdSize)
			readOutObj.innerHTML = offsetFromStart + "%";
			GiftTag.setSavedScale(offsetFromStart);
			Dom.get(bg).title = offsetFromStart + "%";
			/*
			region = YAHOO.util.Dom.getRegion('clipWindow');
			testWidth = region.right - region.left;
			testHeight = region.bottom - region.top;
			if (width <= testWidth)
			{
			width = testWidth;
			if (!holdSize)
			{
			readOutObj.innerHTML = offsetFromStart + "%";
			holdSize = true;
			}
			}
			else
			{
			holdSize = false;
			}
			if (height <= testHeight)
			{
			height = testHeight;
			if (!holdSize)
			{
			readOutObj.innerHTML = offsetFromStart + "%";
			holdSize = true;
			}
			}
			else
			{
			holdSize = false;
			}
			*/

			document.getElementById("gifttag_src_image").setAttribute('width', width);
			document.getElementById("gifttag_src_image").setAttribute('height', height);
			YAHOO.util.Dom.setStyle('gifttag_picWindow', 'width', width);
			YAHOO.util.Dom.setStyle('gifttag_picWindow', 'height', height);
			picregion = YAHOO.util.Dom.getRegion('gifttag_picWindow');


			//GiftTag.doConstraints();
		});

	};

	return {

		init: function() {
			initVert();
		},

		updateVert:function() {
			var fld = document.forms["gifttag_formH"]["gifttag_horizVal"];
			var v = parseFloat(fld.value, 10);
			if ( isNaN(v) ) v = 0;
			yslider.setValue(Math.round(v));
			var newVal = yslider.getValue();
			if (v != newVal) {
				fld.value = newVal;
			}
			return false;
		},

		setVert: function(val)
		{
			yslider.setValue(val);
		}

	}
	this.setupOrigSettings(saved_settings);
}();

YAHOO.util.Event.on(window, "load", YAHOO.example.GiftTagSliders.init);

