if(typeof Product=='undefined') {
    var Product = {};
}

/********************* IMAGE SWITCHER ***********************/

Product.Switcher = Class.create();
Product.Switcher.prototype = {
    initialize: function(imageEl, option_list, settings, productName){
	this.imageEl = imageEl;
	this.productName = productName;
	this.option_list = option_list;
	this.settings = settings;
	this.preLoadedImage = new Image(); 
	this.preLoadedImage.onload = this.onImageLoaded.bind(this);
	this.preLoadImage = this.preLoadImage.bind(this);
	this.preLoadImageFadeOutEndFn = this.preLoadImageFadeOutEndFn.bind(this);
	this.preLoadImageFadeOutEnd=true;
    },
    onImageLoaded: function(){
	this.preLoadImageLoaded = true;
	if (this.imageFadeIn==false)
	{
		return ;
	}
	$(this.imageEl).src = this.preLoadedImage.src;
	Effect.FadeOut($(this.imageEl),{afterFinishInternal: this.preLoadImageFadeOutEndFn});
	this.preLoadImageLoaded = false;
	this.imageFadeIn = false;
    },
    preLoadImage: function(){
	this.imageFadeIn = true;
	if (this.preLoadImageLoaded==false)
	{
		return ;
	}
	$(this.imageEl).src = this.preLoadedImage.src;
	Effect.FadeOut($(this.imageEl),{afterFinishInternal: this.preLoadImageFadeOutEndFn});
	this.preLoadImageLoaded = false;
	this.imageFadeIn = false;
    },
    preLoadImageFadeOutEndFn: function(){
	if (this.nextImg)
	{
		this.preLoadedImage.src = this.nextImg;	
		this.nextImg = false;
		Effect.FadeIn($(this.imageEl),{afterFinishInternal: this.preLoadImage});
		return;
	}
	this.preLoadImageFadeOutEnd = true;
    },
    enlargeImage: function(){
	if (!(typeof this.enlargeImageContainer == 'undefined'))
	if (this.enlargeImageContainer!=null)
		return;
		container = document.createElement('div');
		hlpOverlay = document.createElement('div');
		hlpOverlay.onclick = this.closeEnalargeImage.bind(this);
		closeButton = document.createElement('a');
		hlpOverlay.id = "hlp-overlay";
		$(hlpOverlay).setStyle({'height':$(document.body).getDimensions().height + 'px'});
		n = document.createTextNode('');
		closeButton.href = "javascript:opImageSwitcher.closeEnalargeImage();";
		closeButton.appendChild(n);
		br = document.createElement('br');
		content_div = document.createElement('div');
		maintext = '<form class="doctor-form"  id="" action="" method="post" enctype="multipart/form-data">'
		+'<input type="hidden"  class="none" name="action" value="sendmail"/>'
		+'<label>Your Name:</label><input type="text" name="formname" value=""/><br />'
		+	'<label>Email address:</label><input type="text" name="email" value=""/><br />'
		+	'<label>Your question:</label><textarea name="question"></textarea><br />'
		+	'<label>Attach file:</label><input type="file" name="file-name" id="file-name"/><br />'
		+	'<input id="sendbutton" class="sendbutton" type="submit" value="Submit" name="sendbutton"/>'
		+'</form>';
		content_div.innerHTML = maintext;
		container.className = 'enlargeImageContainer';
		container.appendChild(closeButton);
		container.appendChild(br);
		container.appendChild(content_div);
		document.body.appendChild(container);
		document.body.appendChild(hlpOverlay);
		this.enlargeImageContainer = container;
		this.enlargeImageHlpOverlay = hlpOverlay;
    },
    closeEnalargeImage:function()
    {
	document.body.removeChild(this.enlargeImageContainer);
	this.enlargeImageContainer = null;
	document.body.removeChild(this.enlargeImageHlpOverlay);
	this.enlargeImageHlpOverlay = null;
    },
    onInputsLoaded:function()
    {
	if (typeof this.options =='undefined')
		this.options = $$('#' + this.option_list + ' input')
	if (this.options.length)
	this.options[0].checked = true;
    }
};