/**
 * Pictue enlargement check box.
 */

//if (!co.uk.baughfarm.PictureResize) co.uk.baughfarm.PictureResize = {};

/**
 * @author Mark Franklyn Baker
 * @version 0.1 Feb 21 2009
 * @param stringProperty - string - a string holding the location of the property
 * 									that is going to hold this object. 
 * @param inputParentID - string -  the value of the element id attribute,
 * 									which is going to contain the inputField. 
 * @param imageName - string - the value of the img elements name attribute.
 * @param smallWidth, smallHeight - string - the default size.
 * @param largeWidth, largeHeight - string - the alternative size, set when checked is true
 * @param toolTip - string -
 * @type constructor
 */
co.uk.baughfarm.PictureResize = function (stringProperty, inputParentID, imageName,
 								smallWidth, smallHeight, largeWidth, largeHeight,
 								toolTip) {

	// check for required classes
	if (!uk.co.mfbaker.Cookie) {
alert('co.uk.baughfarm.PictureResize'
+'\nuk.co.mfbaker.Cookie class is required '
+'');
	}
	else {
	
		this.imageName = imageName;
		this.smallWidth = smallWidth;
		this.smallHeight = smallHeight;
		this.largeWidth = largeWidth;
		this.largeHeight = largeHeight;
	
    	// input checkbox
    	this.inputField = document.createElement('input');
    	this.inputField.setAttribute('type', 'checkbox');
		this.inputField.setAttribute('alt', toolTip);
		this.inputField.setAttribute('title', toolTip);
		this.inputField.onclick = new Function(stringProperty+'.onClick(this);');
	
		this.inputParent = document.getElementById(inputParentID);
	
		this.inputParent.appendChild(this.inputField);
	
		this.cookie = new uk.co.mfbaker.Cookie('ukCoBaughfarmPictureResize');

//alert('co.uk.baughfarm.PictureResize'
//+'\ncookie.checked: '+co.uk.baughfarm.Utility.dbsv(this.cookie.checked)
//+'');
		if (!this.cookie.checked) this.cookie.checked = false;
		this.inputField.checked = this.cookie.checked;

//alert('co.uk.baughfarm.PictureResize'
//+'\ncookie.checked: '+co.uk.baughfarm.Utility.dbsv(this.cookie.checked)
//+'\nthis.inputField.checked: '+co.uk.baughfarm.Utility.dbsv(this.inputField.checked)
//+'');

		this.setSize();
	
	}
	
}

/**
 * on click handler.
 * @author Mark Franklyn Baker
 * @version 0.1 Feb 21 2009
 * @param inputField the same object as this.inputField.
 * @type instance-method
 */
co.uk.baughfarm.PictureResize.prototype.onClick = function (inputField) {
	this.setSize();
	this.store();
}

/**
 * store state.
 * @author Mark Franklyn Baker
 * @version 1.1 Apr 07 2009
 * @type instance-method
 */
co.uk.baughfarm.PictureResize.prototype.store = function () {

//alert('co.uk.baughfarm.PictureResize.store'
//+'\ncookie.checked: '+co.uk.baughfarm.Utility.dbsv(this.cookie.checked)
//+'\nthis.inputField.checked: '+co.uk.baughfarm.Utility.dbsv(this.inputField.checked)
//+'');

	if (this.cookie.checked !== this.inputField.checked) {
		this.cookie.checked = this.inputField.checked;
		this.cookie._cookieWrite();
	}

}



/**
 * set the size of the image, according to the users selection.
 * @author Mark Franklyn Baker
 * @version 0.1 Feb 21 2009
 * @param 
 * @type instance-method
 */  
co.uk.baughfarm.PictureResize.prototype.setSize = function () {

	if (this.inputField.checked) {
		document.images[this.imageName].style.width = this.largeWidth;
		document.images[this.imageName].style.height = this.largeHeight;
	}
	else {
		document.images[this.imageName].style.width = this.smallWidth;
		document.images[this.imageName].style.height = this.smallHeight;
	}
	
}
         
/**
 * called by the initialisation code, when this instance already existed.
 * i.e. when the user went "back" to this page.
 * @author Mark Franklyn Baker
 * @version 0.1 Feb 21 2009
 * @type instance-method
 */             
co.uk.baughfarm.PictureResize.prototype.onReload = function () {


	// read in the cookie values
	this.cookie._cookieRead();
//alert('co.uk.baughfarm.PictureResize.onReload'
//+'\ncookie.checked: '+co.uk.baughfarm.Utility.dbsv(this.cookie.checked)
//+'');
	
	if (typeof this.cookie.checked==='boolean') {
		// set the checked value to the stored cookie checked value.
		this.inputField.checked = this.cookie.checked;
	}
	else {
		// the cookie value was NOT set/found for some reason.
	 	this.cookie.checked = this.inputField.checked;
	}
	
	this.setSize();
	
}

