var EnjoyScripts = {};

EnjoyScripts.HeaderImages = {};

EnjoyScripts.HeaderImages = Class.create(
{
	initialize: function()
	{
		this.options = Object.extend(
		{
			image_id:								"top_banner_image",
			holding_div_id:							"div_top_banner_image_holder",
			background_div_id:						"div_top_banner_image_bg",
			testimonial_div_id:						"testimonial_extract_holder", 
			testimonial_extract_id:					"testimonial_extract", 
			testimonial_extract_class_holder_id:	"testimonial_extract_class_holder", 
			page_name:								null,
			interval:								3000,
			myId:									'hdr_EHI'
			
		}, arguments[0] || {});
				
		// Extend Controls
		this.image_ctrl = $(this.options.image_id);
		this.holding_div = $(this.options.holding_div_id);
		this.background_div = $(this.options.background_div_id);
		this.extract_holder = $(this.options.testimonial_div_id);
		this.extract_div = $(this.options.testimonial_extract_id);
		this.extract_class_holder = $(this.options.testimonial_extract_class_holder_id);
		
		// Define variables
		this.hdr_imagesUrlArray = new Array();
		this.hdr_imagesPositionArray = new Array();
		this.hdr_quotesExpected = 0;
		this.hdr_quotesUrl = null;
		this.hdr_imagesPreloadPtr = 0;
		this.hdr_imagesExpected = 0;
		this.hdr_imageArray = new Array();
		
		this.hdr_imagePtr = 0;
		this.hdr_quotesArray = new Array();
		
		// preload
		
		this.hdr_getUrls();
		
		this.hdr_preloadImages();
                this.num = 1;
                this.acc_num = 1;
                this.home_button    = new Array();
                this.home_button[1] = 'hs_top';
                this.home_button[2] = 'hs_mid';
                this.home_button[3] = 'hs_bot';
                this.home_button[4] = 'hs_landlords';

                this.accordian      = new Array();
                this.accordian[1]   = 'acc_rent';
                this.accordian[2]   = 'acc_share';
                this.accordian[3]   = 'acc_socialise';
	},
	
	copyHeaderImage: function()
	{
		try
		{
		
			// Copy image to background DIV
			this.background_div.style.backgroundImage = "url(" + this.image_ctrl.src + ")";
			
			this.hdr_imagePtr++;
			if (this.hdr_imagePtr == this.hdr_imagesExpected)
			{
				this.hdr_imagePtr = 0;
			}
			setTimeout('hdr_EHI.hideAndSetHeaderImage()', 1000);
		}
		catch (err)
		{
			alert (err.message);
		}
	},
	
	hideAndSetHeaderImage: function()
	{
		if (typeof(this.holding_div) != "undefined" && this.holding_div != null) {
			// Hide DIV holding image
			this.holding_div.style.display = 'none';
		
			// Set image to new image SRC
			this.image_ctrl.src = this.hdr_imageArray[this.hdr_imagePtr].src
		
			setTimeout('hdr_EHI.showHeaderImage()', this.options.interval);
		}
	},
	
	showHeaderImage: function()
	{
                
                // Remove all button classes
                var off_button  = $$("a[rel^='hs_']");
                for(var i = 0; i < off_button.length; i++)
                {
                    off_button[i].removeClassName('hs_sel');
                }

                // Remove all accordian classes
                var off_acc     = $$("div[rel^='acc_']");
                for(var i = 0; i < off_acc.length; i++)
                {
                    off_acc[i].removeClassName('blue');
                }

                if(this.num > 0)
                {
                    var on_button  = $$("a[rel='"+this.home_button[this.num]+"']");

					if (on_button.length > 0) {
						on_button[0].addClassName('hs_sel');
					};
                    
                }
                /*
                if(this.acc_num < 4)
                {
                    var on_acc  = $$("div[rel='"+this.accordian[this.acc_num]+"']");
                    on_acc[0].addClassName('blue');
                }
                
                this.num == 1 ? $('rent_button').removeClassName('button_lightblue') : $('rent_button').addClassName('button_lightblue');
                this.num == 2 ? $('share_button').removeClassName('button_lightblue') : $('share_button').addClassName('button_lightblue');
                this.num == 3 ? $('socials_button').removeClassName('button_lightblue') : $('socials_button').addClassName('button_lightblue');
                */
				if ($j('landlords').length) {
					this.num == 4 ? $('landlords').show() : $('landlords').hide();
				};
                

                this.num == 4 ? this.num = 0 : this.num++;
                //this.acc_num == 5 ? this.acc_num = 5 : this.acc_num++;
                
                new Effect.Appear(this.holding_div,
                {
                        duration: 1.5,
                        from: 0,
                        to: 1
                });
		
		if (this.hdr_imagePtr < this.hdr_quotesArray.length && this.hdr_quotesArray[this.hdr_imagePtr] != "")
		{
			this.extract_class_holder.className = '';
			this.extract_class_holder.addClassName(this.hdr_imagesPositionArray[this.hdr_imagePtr]);
			this.extract_div.innerHTML = this.hdr_quotesArray[this.hdr_imagePtr];
			this.extract_holder.show();
		}
		else
		{
			this.extract_holder.hide();
		}
		
		setTimeout('hdr_EHI.copyHeaderImage()', 2000);
	},
	
	hdr_getUrls: function()
	{
		
                switch (this.options.page_name)
		{
			case "home":
				this.hdr_imagesUrlArray[0] = website_homepage + "images/header-images/home0.jpg";
                this.hdr_imagesUrlArray[1] = website_homepage + "images/header-images/home1.jpg";
				this.hdr_imagesUrlArray[2] = website_homepage + "images/header-images/home2.jpg";
				this.hdr_imagesUrlArray[3] = website_homepage + "images/header-images/home3.jpg";
				this.hdr_imagesUrlArray[4] = website_homepage + "images/header-images/home4.jpg";
                                
				this.hdr_quotesExpected = 3;
				break;
			case "socials":
				this.hdr_imagesUrlArray[0] = website_homepage + "images/header-images/left-01.jpg";
				this.hdr_imagesPositionArray[0] = 'comment_holder_testimonials';
				this.hdr_imagesUrlArray[1] = website_homepage + "images/header-images/left-05.jpg";
				this.hdr_imagesPositionArray[1] = 'comment_holder_top_testimonials';
				this.hdr_imagesUrlArray[2] = website_homepage + "images/header-images/right-05.jpg";
				this.hdr_imagesPositionArray[2] = 'comment_holder_top_testimonials';
				this.hdr_quotesExpected = 3;
				break;
			case "manchester":
				this.hdr_imagesUrlArray[0] = website_homepage + "images/header-images/left-04.jpg";
				this.hdr_imagesPositionArray[0] = 'comment_holder_top';
				this.hdr_quotesExpected = 1;
				break;
			case "testimonials":
				this.hdr_imagesUrlArray[0] = website_homepage + "images/header-images/right-03.jpg";
				this.hdr_imagesPositionArray[0] = 'comment_holder_top_testimonials';
				this.hdr_imagesUrlArray[1] = website_homepage + "images/header-images/right-06.jpg";
				this.hdr_imagesPositionArray[1] = 'comment_holder_testimonials';
				this.hdr_imagesUrlArray[2] = website_homepage + "images/header-images/left-02.jpg";
				this.hdr_imagesPositionArray[2] = 'comment_holder_top_testimonials';
				this.hdr_quotesExpected = 3;
				break;
			case "sharing":
				this.hdr_imagesUrlArray[0] = website_homepage + "images/header-images/right-01.jpg";
				this.hdr_imagesPositionArray[0] = 'comment_holder_top';
				this.hdr_imagesUrlArray[1] = website_homepage + "images/header-images/right-06.jpg";
				this.hdr_imagesPositionArray[1] = 'comment_holder';
				this.hdr_imagesUrlArray[2] = website_homepage + "images/header-images/left-04.jpg";
				this.hdr_imagesPositionArray[2] = 'comment_holder_top';
				this.hdr_quotesExpected = 3;
				break;
			case "landlords":
				this.hdr_imagesUrlArray[0] = website_homepage + "images/header-images/left-02.jpg";
				this.hdr_imagesPositionArray[0] = 'comment_holder';
				this.hdr_quotesExpected = 0;
				break;
			case "shareshack":
				this.hdr_imagesUrlArray[0] = website_homepage + "images/header-images/right-06.jpg";
				this.hdr_imagesPositionArray[0] = 'comment_holder';
				this.hdr_quotesExpected = 0;
				break;
		}
		
		this.hdr_quotesUrl = website_homepage + "ajaxCalls/getTestimonialExtract.php?page_name=" + this.options.page_name +
			"&count=" + this.hdr_quotesExpected;
		this.hdr_imagesPreloadPtr = 0;
		this.hdr_imagesExpected = this.hdr_imagesUrlArray.length;
	},
	
	hdr_preloadImages: function ()
	{
		if (this.hdr_imagesPreloadPtr == this.hdr_imagesExpected)
		{
			// All loaded
			this.hdr_preloadQuotes();
		}
		else
		{
			var hdr_imgLoader = new Image();
			hdr_imgLoader.id = 'hdr_img_l_' + this.hdr_imagesPreloadPtr;
			hdr_imgLoader.src = this.hdr_imagesUrlArray[this.hdr_imagesPreloadPtr];
			hdr_imgLoader.onLoad = this.hdr_preloadImages2(hdr_imgLoader);
		}
	},
	
	hdr_preloadImages2: function(eventArgs)
	{
		this.hdr_imageArray[this.hdr_imagesPreloadPtr] = eventArgs;
		this.hdr_imagesPreloadPtr++;
		
		this.hdr_preloadImages();
	},
	
	hdr_preloadQuotes: function()
	{
		new Ajax.Request(this.hdr_quotesUrl,
			{
				method: 'get',
				onSuccess: function(transport)
				{
					eval('hdr_EHI.hdr_preloadQuotes2(transport);');
				}
			});
	},
	
	hdr_preloadQuotes2: function(eventArgs)
	{
		try
		{
			var json_object = eventArgs.responseText.evalJSON(true);
			this.hdr_quotesArray = json_object;
			this.hdr_imagePtr = 0;
			this.copyHeaderImage();
		}
		catch (err)
		{
			alert (err.message);
		}
	}
});


EnjoyScripts.RadioButton = {};

EnjoyScripts.RadioButton = Class.create(
{
    initialize: function()
    {
        this.options = Object.extend(
		{
		    cssPreFix:                      'nj_',
		    controlName:                    '',
		    uniqueIndex:                    Math.ceil(Math.random() * 1000),
		    itemHeight:                     27,
		    onChange:                       null,
		    style:                          null,
		    width:                          50,
		    paddingLeft:                    10,
			paddingRight:                   20
        }, arguments[0] || {});
        
        this.isChecked = false;
		this.original_radio_ctrl = $(this.options.controlName);
		this.groupName = this.original_radio_ctrl.name;	// Mutually-exclusive with the same group name
		
		// Get label if provided and hide original label
		this.label = this.getLabel(this.options.controlName);
        
        var label_style = "width: " + (this.options.width-this.options.paddingLeft-this.options.paddingRight) + "px;";
        if (this.options.style != null) { label_style += this.options.style; }
        label_style += 'padding-left: ' + this.options.paddingLeft + 'px;';
		label_style += 'padding-right: ' + this.options.paddingRight + 'px;';
		
        this.radioButton_html = "" + 
            "<div class=\"" + this.options.cssPreFix + "radio_container\" style=\"width: " + this.options.width + "px;\">" + 
                "<div class=\"" + this.options.cssPreFix + "radio_bg\" style=\"width: " + (this.options.width-10) + "px;\">&nbsp;</div>" + 
                "<div class=\"" + this.options.cssPreFix + "radio_bg_right\">&nbsp;</div>" + 
                "<div id=\"rdb_lbl_" + this.options.uniqueIndex + "\" class=\"" + this.options.cssPreFix + "radio_label\" style=\"" + label_style + "\">" + this.label + "</div>" + 
                "<div id=\"rdb_tick_" + this.options.uniqueIndex + "\" class=\"" + this.options.cssPreFix + "radio_tick\">&nbsp;</div>" + 
                "<div id=\"rdb_click_" + this.options.uniqueIndex + "\" class=\"" + this.options.cssPreFix + "radio_link\" style=\"width: " + this.options.width + "px;\">&nbsp;</div>" + 
            "</div>";
        
        this.original_radio_ctrl.insert({before: this.radioButton_html});
        
        this.radioButton_label_ctrl = $('rdb_lbl_' + this.options.uniqueIndex);
        this.radioButton_tick_ctrl = $('rdb_tick_' + this.options.uniqueIndex);
        this.radioButton_click_ctrl = $('rdb_click_' + this.options.uniqueIndex);
        
        // Hide label section if no label provided
        if (this.label == '') { $('rdb_lbl_' + this.options.uniqueIndex).hide(); }
        
        // Hide original radio control
        this.original_radio_ctrl.hide();
        
        // Determine if selected/ticked
        this.isChecked = this.original_radio_ctrl.checked;
        
        // Action correct tick-state
        this.renderTick();
        
        // Event to show click/tick changes
		Event.observe(this.radioButton_click_ctrl, "click", this.onClick.bindAsEventListener(this));
		Event.observe(this.radioButton_click_ctrl, "mouseover", this.onMouseOver.bindAsEventListener(this));
		Event.observe(this.radioButton_click_ctrl, "mouseout", this.onMouseOut.bindAsEventListener(this));
    },
    
    getLabel: function(radioButtonName)
	{
		var result = "";
		var labels = $$('label');
		
		for(i=0;i<labels.length;i++)
		{
			if (labels[i].htmlFor == radioButtonName)
			{
				result = labels[i].innerHTML;
				labels[i].hide();
			}
		}
		
		return result;		
	},
	
	onClick: function(eventObj)
	{
	    if (this.isChecked != this.original_radio_ctrl.checked) { this.isChecked = this.original_radio_ctrl.checked; }
	    
		if (!this.isChecked)
		{
			this.closeOthers();
			
			this.isChecked = !this.isChecked;
		    this.original_radio_ctrl.checked = this.isChecked;
    		
		    this.renderTick();
		}			
	},
	
	onMouseOver: function(eventObj)
	{
	    if (!this.isChecked)
		{
			this.radioButton_tick_ctrl.addClassName(this.options.cssPreFix + 'radioButton_ticked');
		}
	},
	
	onMouseOut: function(eventObj)
	{
	    if (!this.isChecked)
		{
			this.radioButton_tick_ctrl.removeClassName(this.options.cssPreFix + 'radioButton_ticked');
		}
	},
	
	closeOthers: function()
	{
		for (var a=0; a<Enjoy_RadioButtons.length; a++)
		{
		    var extCtrl = Enjoy_RadioButtons[a].original_radio_ctrl;
			if (this.groupName == extCtrl.name)
			{
				// Same GROUP name
				if (this.original_radio_ctrl.id != extCtrl.id && extCtrl.checked)
				{
					Enjoy_RadioButtons[a].isChecked = false;
					extCtrl.checked = false;
					Enjoy_RadioButtons[a].renderTick();
				}
			}
		}
	},
	
	renderTick: function()
	{
		if (this.isChecked)
		{
			this.radioButton_tick_ctrl.addClassName(this.options.cssPreFix + 'radioButton_ticked');
		}
		else if (this.radioButton_tick_ctrl.hasClassName(this.options.cssPreFix + 'radioButton_ticked'))
		{
			this.radioButton_tick_ctrl.removeClassName(this.options.cssPreFix + 'radioButton_ticked');
		}
		
		if (this.callBack != null)
		{
			var cb = this.options.onChange + "(" + this.options.uniqueIndex + ", '" + this.original_radio_ctrl.id + "', " + this.isChecked + ")";
			eval(cb);
		}
	}
});


EnjoyScripts.CheckBox4 = {};

EnjoyScripts.CheckBox4 = Class.create(
{
    initialize: function()
    {
        this.options = Object.extend(
		{
		    cssPreFix:                      'nj_',
		    controlName:                    '',
		    uniqueIndex:                    Math.ceil(Math.random() * 1000),
		    itemHeight:                     27,
		    onChange:                       null,
		    style:                          null,
		    width:                          50,
		    paddingLeft:                    10,
			paddingRight:                   10
        }, arguments[0] || {});
        
        this.isChecked = false;
		this.original_checkbox_ctrl = $(this.options.controlName);
		
		// Get label if provided and hide original label
		this.label = this.getLabel(this.options.controlName);

        var label_style = "width: " + (this.options.width-this.options.paddingLeft-this.options.paddingRight) + "px;";
        if (this.options.style != null) { label_style += this.options.style; }
        label_style += 'padding-left: ' + this.options.paddingLeft + 'px;';
		label_style += 'padding-right: ' + this.options.paddingRight + 'px;';
		
        this.checkbox_html = "" + 
            "<div class=\"" + this.options.cssPreFix + "checkbox_container\" style=\"width: " + this.options.width + "px;\">" + 
                "<div class=\"" + this.options.cssPreFix + "checkbox_bg\" style=\"width: " + (this.options.width-10) + "px;\">&nbsp;</div>" + 
                "<div class=\"" + this.options.cssPreFix + "checkbox_bg_right\">&nbsp;</div>" + 
                "<div id=\"chk4_lbl_" + this.options.uniqueIndex + "\" class=\"" + this.options.cssPreFix + "checkbox_label\" style=\"" + label_style + "\">" + this.label + "</div>" + 
                "<div id=\"chk4_tick_" + this.options.uniqueIndex + "\" class=\"" + this.options.cssPreFix + "checkbox_tick\">&nbsp;</div>" + 
                "<div id=\"chk4_click_" + this.options.uniqueIndex + "\" class=\"" + this.options.cssPreFix + "checkbox_link\" style=\"width: " + this.options.width + "px;\">&nbsp;</div>" + 
            "</div>";
        
        this.original_checkbox_ctrl.insert({before: this.checkbox_html});
        
        this.checkbox_label_ctrl = $('chk4_lbl_' + this.options.uniqueIndex);
        this.checkbox_tick_ctrl = $('chk4_tick_' + this.options.uniqueIndex);
        this.checkbox_click_ctrl = $('chk4_click_' + this.options.uniqueIndex);
        
        // Hide label section if no label provided
        if (this.label == '') { $('chk4_lbl_' + this.options.uniqueIndex).hide(); }
        
        // Hide original radio control
        this.original_checkbox_ctrl.hide();
        
        // Determine if selected/ticked
        this.isChecked = this.original_checkbox_ctrl.checked;
        
        // Action correct tick-state
        this.renderTick();
        
        // Event to show click/tick changes
		Event.observe(this.checkbox_click_ctrl, "click", this.onClick.bindAsEventListener(this));
		Event.observe(this.checkbox_click_ctrl, "mouseover", this.onMouseOver.bindAsEventListener(this));
		Event.observe(this.checkbox_click_ctrl, "mouseout", this.onMouseOut.bindAsEventListener(this));
    },
    
    getLabel: function(checkboxName)
	{
		var result = "";
		var labels = $$('label');
		
		for(i=0;i<labels.length;i++)
		{
			if (labels[i].htmlFor == checkboxName)
			{
				result = labels[i].innerHTML;
				labels[i].hide();
			}
		}
		
		return result;		
	},
	
	onClick: function(eventObj)
	{
	    this.isChecked = !this.isChecked;
		this.original_checkbox_ctrl.checked = this.isChecked;
		
		this.renderTick();
	},
	
	onMouseOver: function(eventObj)
	{
	    if (!this.isChecked)
		{
			this.checkbox_tick_ctrl.addClassName(this.options.cssPreFix + 'checkbox_ticked');
		}
	},
	
	onMouseOut: function(eventObj)
	{
	    if (!this.isChecked)
		{
			this.checkbox_tick_ctrl.removeClassName(this.options.cssPreFix + 'checkbox_ticked');
		}
	},
	
	renderTick: function()
	{
		if (this.isChecked)
		{
			this.checkbox_tick_ctrl.addClassName(this.options.cssPreFix + 'checkbox_ticked');
		}
		else if (this.checkbox_tick_ctrl.hasClassName(this.options.cssPreFix + 'checkbox_ticked'))
		{
			this.checkbox_tick_ctrl.removeClassName(this.options.cssPreFix + 'checkbox_ticked');
		}
		
		if (this.callBack != null)
		{
			var cb = this.options.onChange + "(" + this.options.uniqueIndex + ", '" + this.original_checkbox_ctrl.id + "', " + this.isChecked + ")";
			eval(cb);
		}
	}
});


EnjoyScripts.MECheckBox = {};

EnjoyScripts.MECheckBox = Class.create(
{
	initialize: function(radioButtonID, uniqueIndex, totalWidth, middleWidth, cssPreFix, changeEvent)
	{
		this.isChecked = false;
		this.width = totalWidth;
		this.uniqueIndex = uniqueIndex;
		this.containerWidth = parseInt(totalWidth) + 5;
		this.cssPreFix = cssPreFix;
		
		this.callBack = changeEvent;
		
		this.original_radio_ctrl = $(radioButtonID);
		this.groupName = this.original_radio_ctrl.name;	// Mutually-exclusive with the same group name
		
		this.label = this.getLabel(radioButtonID);
		
		this.radiobutton_html = "<div class=\"" + cssPreFix + "checkbox_container\" style=\"width:" + this.containerWidth + "px;\">" + 
			"<div class=\"" + cssPreFix + "checkbox_left\">&nbsp;</div>" + 
			"<div class=\"" + cssPreFix + "checkbox_middle\" style=\"width:" + middleWidth + "px;\"><label id=\"rdb_lbl_" + uniqueIndex + "\">" + 
			this.label + "</label></div>" + 
			"<div class=\"" + cssPreFix + "checkbox_right\" id=\"rdb_tick_" + uniqueIndex + "\">&nbsp;</div>" + 
			"<div style=\"float:none; clear:both;\"></div></div>";
			
		this.original_radio_ctrl.insert({before: this.radiobutton_html});
		
		this.radiobutton_label_ctrl = $('rdb_lbl_' + uniqueIndex);
		this.radiobutton_tick_ctrl = $('rdb_tick_' + uniqueIndex);
		
		this.original_radio_ctrl.hide();
		
		this.isChecked = this.original_radio_ctrl.checked;
		
		this.renderTick();
		
		// Event to show hover effects and click/tick changes
		Event.observe(this.radiobutton_tick_ctrl, "click", this.onClick.bindAsEventListener(this));
	},
	
	getLabel: function(radioButtonName)
	{
		var result = "";
		var labels = $$('label');
		
		for(i=0;i<labels.length;i++)
		{
			if (labels[i].htmlFor == radioButtonName)
			{
				result = labels[i].innerHTML;
				labels[i].hide();
			}
		}
		
		return result;		
	},
	
	renderTick: function()
	{
		if (this.isChecked)
		{
			this.radiobutton_tick_ctrl.addClassName(this.cssPreFix + 'checkbox_ticked');
		}
		else if (this.radiobutton_tick_ctrl.hasClassName(this.cssPreFix + 'checkbox_ticked'))
		{
			this.radiobutton_tick_ctrl.removeClassName(this.cssPreFix + 'checkbox_ticked');
		}
		
		if (this.callBack != null)
		{
			var cb = this.callBack + "(" + this.uniqueIndex + ", '" + this.original_radio_ctrl.id + "', " + this.isChecked + ")";
			eval(cb);
		}
	},
	
	onClick: function(eventObj)
	{
		if (this.isChecked != this.original_radio_ctrl.checked) { this.isChecked = this.original_radio_ctrl.checked; }
		
		if (!this.isChecked)
		{
			this.closeOthers();
		
			this.isChecked = !this.isChecked;
			this.original_radio_ctrl.checked = this.isChecked;
			
			this.renderTick();
		}
	},
	
	closeOthers: function()
	{
		var selBoxes = $$('input.enjoy_MECheckBox');
		
		if (selBoxes != undefined && selBoxes != null)
		{
			for (var a=0; a<selBoxes.length; a++)
			{
				if (this.groupName == selBoxes[a].name)
				{
					// Same GROUP name
					//alert ('Same Group Name: this.groupName = ' + this.groupName + "; ctrl.name = " + selBoxes[a].name);
					
					if (this.original_radio_ctrl.id != selBoxes[a].id && selBoxes[a].checked)
					{
						selBoxes[a].checked = false;
						this.renderTickExt(selBoxes[a]);
					}
				}
			}
		}
	},
	
	renderTickExt: function(ctrl)
	{
		var index = MECheckBoxes.indexOf(ctrl.id);
		
		if (index > -1)
		{
			if (ctrl.checked)
			{	
				$("rdb_tick_" + index).addClassName(this.cssPreFix + 'checkbox_ticked');
			}
			else
			{
				$("rdb_tick_" + index).removeClassName(this.cssPreFix + 'checkbox_ticked');
			}
		}
	}
});


EnjoyScripts.MECheckBox_Slim = {};

EnjoyScripts.MECheckBox_Slim = Class.create(
{
	initialize: function(radioButtonID, uniqueIndex, totalWidth, cssPreFix)
	{
		this.isChecked = false;
		this.width = totalWidth;
		this.uniqueIndex = uniqueIndex;
		this.containerWidth = parseInt(totalWidth) + 5;
		this.cssPreFix = cssPreFix;
		
		this.original_radio_ctrl = $(radioButtonID);
		this.groupName = this.original_radio_ctrl.name;	// Mutually-exclusive with the same group name
		
		this.label = this.getLabel(radioButtonID);
		
		this.radiobutton_html = "<div class=\"" + cssPreFix + "checkbox_slim_container\">" + 
			"<div class=\"" + cssPreFix + "checkbox_slim_unticked\" id=\"rdb_tick_" + uniqueIndex + "\">&nbsp;</div>" + 
			"</div>";
			
		this.original_radio_ctrl.insert({before: this.radiobutton_html});
		
		this.radiobutton_tick_ctrl = $('rdb_tick_' + uniqueIndex);
		
		this.original_radio_ctrl.hide();
		
		this.isChecked = this.original_radio_ctrl.checked;
		
		this.renderTick();
		
		// Event to show hover effects and click/tick changes
		Event.observe(this.radiobutton_tick_ctrl, "click", this.onClick.bindAsEventListener(this));
	},
	
	getLabel: function(radioButtonName)
	{
		var result = "";
		var labels = $$('label');
		
		for(i=0;i<labels.length;i++)
		{
			if (labels[i].htmlFor == radioButtonName)
			{
				result = labels[i].innerHTML;
				labels[i].hide();
			}
		}
		
		return result;		
	},
	
	renderTick: function()
	{
		if (this.isChecked)
		{
			this.radiobutton_tick_ctrl.addClassName(this.cssPreFix + 'checkbox_slim_ticked');
		}
		else if (this.radiobutton_tick_ctrl.hasClassName(this.cssPreFix + 'checkbox_slim_ticked'))
		{
			this.radiobutton_tick_ctrl.removeClassName(this.cssPreFix + 'checkbox_slim_ticked');
		}
	},
	
	onClick: function(eventObj)
	{
		if (this.isChecked != this.original_radio_ctrl.checked) { this.isChecked = this.original_radio_ctrl.checked; }
		
		if (!this.isChecked)
		{
			this.closeOthers();
		
			this.isChecked = !this.isChecked;
			this.original_radio_ctrl.checked = this.isChecked;
			
			this.renderTick();
		}
	},
	
	closeOthers: function()
	{
		var selBoxes = $$('input.enjoy_MECheckBox_Slim');
		
		if (selBoxes != undefined && selBoxes != null)
		{
			for (var a=0; a<selBoxes.length; a++)
			{
				if (this.groupName == selBoxes[a].name)
				{
					// Same GROUP name
					//alert ('Same Group Name: this.groupName = ' + this.groupName + "; ctrl.name = " + selBoxes[a].name);
					
					if (this.original_radio_ctrl.id != selBoxes[a].id && selBoxes[a].checked)
					{
						selBoxes[a].checked = false;
						this.renderTickExt(selBoxes[a]);
					}
				}
			}
		}
	},
	
	renderTickExt: function(ctrl)
	{
		var index = MECheckBoxes_Slim.indexOf(ctrl.id);
		
		if (index > -1)
		{
			if (ctrl.checked)
			{	
				$("rdb_tick_" + index).addClassName(this.cssPreFix + 'checkbox_slim_ticked');
			}
			else
			{
				$("rdb_tick_" + index).removeClassName(this.cssPreFix + 'checkbox_slim_ticked');
			}
		}
	}
});


EnjoyScripts.CheckBox = {};

EnjoyScripts.CheckBox = Class.create(
{
	initialize: function(checkBoxName, uniqueIndex, totalWidth, middleWidth, cssPreFix)
	{
		this.isChecked = false;
		this.width = totalWidth;
		this.uniqueIndex = uniqueIndex;
		this.containerWidth = parseInt(totalWidth) + 5;
		this.cssPreFix = cssPreFix;
		
		this.original_checkbox_ctrl = $(checkBoxName);
		
		this.label = this.getLabel(checkBoxName);
		
		this.checkbox_html = "<div class=\"" + cssPreFix + "checkbox_container\" style=\"width:" + this.containerWidth + "px;\">" + 
			"<div class=\"" + cssPreFix + "checkbox_left\">&nbsp;</div>" + 
			"<div class=\"" + cssPreFix + "checkbox_middle\" style=\"width:" + middleWidth + "px;\"><label id=\"chk_lbl_" + uniqueIndex + "\">" + 
			this.label + "</label></div>" + 
			"<div class=\"" + cssPreFix + "checkbox_right\" id=\"chk_tick_" + uniqueIndex + "\">&nbsp;</div>" + 
			"<div style=\"float:none; clear:both;\"></div></div>";
		
		this.original_checkbox_ctrl.insert({before: this.checkbox_html});
		
		this.checkbox_label_ctrl = $('chk_lbl_' + uniqueIndex);
		this.checkbox_tick_ctrl = $('chk_tick_' + uniqueIndex);
		
		this.original_checkbox_ctrl.hide();
		
		this.isChecked = this.original_checkbox_ctrl.checked;
		
		this.renderTick();
		
		// Event to show hover effects and click/tick changes
		Event.observe(this.checkbox_tick_ctrl, "click", this.onClick.bindAsEventListener(this));
	},
	
	getLabel: function(checkBoxName)
	{
		var result = "";
		var labels = $$('label');
		
		for(i=0;i<labels.length;i++)
		{
			if (labels[i].htmlFor == checkBoxName)
			{
				result = labels[i].innerHTML;
				labels[i].hide();
			}
		}
		
		return result;		
	},
	
	renderTick: function()
	{
		if (this.isChecked)
		{
			this.checkbox_tick_ctrl.addClassName(this.cssPreFix + 'checkbox_ticked');
		}
		else if (this.checkbox_tick_ctrl.hasClassName(this.cssPreFix + 'checkbox_ticked'))
		{
			this.checkbox_tick_ctrl.removeClassName(this.cssPreFix + 'checkbox_ticked');
		}
	},
	
	onClick: function(eventObj)
	{
		this.isChecked = !this.isChecked;
		this.original_checkbox_ctrl.checked = this.isChecked;
		
		this.renderTick();
	}
});


EnjoyScripts.Enjoy_Slider = {};

EnjoyScripts.Enjoy_Slider = Class.create(
{
	initialize: function()
	{
		this.options = Object.extend(
		{
			sourceControlName:					null, 
			cssPreFix:							"", 
			uniqueIndex:						Math.ceil(Math.random() * 1000),
			maxSize:							310, 
			axis:								'horizontal',
			valueLabel:							null,
			textLabel:							null,
			alignX:								-6,
			alignY:								-3,
			sliderWidth:						300,
			handleWidth:						17
		}, arguments[0] || {});
		
		this.original_select_ctrl = $(this.options.sourceControlName);
		
		this.slider_html = "<div class=\"" + this.options.cssPreFix + "slider_container\">" + 
			"<div class=\"" + this.options.cssPreFix + "slider_left\">&nbsp;</div>" + 
			"<div style=\"width: " + this.options.sliderWidth + "px;\" class=\"" + this.options.cssPreFix + "slider_control\" id=\"slider_control_" + this.options.uniqueIndex + "\">" + 
			"<div style=\"width: " + this.options.handleWidth + "px;\" class=\"" + this.options.cssPreFix + "slider_handle\" id=\"slider_handle_" + this.options.uniqueIndex + "\"></div></div>" + 
			"<div class=\"" + this.options.cssPreFix + "slider_right\">&nbsp;</div>" + 
			"<div class=\"slider_clear\"></div>" + 
			"</div>";
			
		this.original_select_ctrl.insert({before: this.slider_html});
		this.slider_ctrl = $('slider_control_' + this.options.uniqueIndex);
		this.slider_handle = $('slider_handle_' + this.options.uniqueIndex);
		this.original_select_ctrl.hide();
		
		this.sc_slider = null;
		
		this.renderControl();
	},
	
	renderControl: function()
	{
		var optionList = $(this.options.sourceControlName).getElementsByTagName('option');
		var nodes = $A(optionList);
	
		var minVal = 1000000;
		var maxVal = 0;
		var vals = [];
		var startVal = null;
		for(op=0; op<nodes.length;op++)
		{
			if (nodes[op].value != "")
			{
				if (parseInt(nodes[op].value) < minVal) { minVal = parseInt(nodes[op].value); }
				if (parseInt(nodes[op].value) > maxVal) { maxVal = parseInt(nodes[op].value); }
				vals.push(nodes[op].value);
				if (nodes[op].selected) { startVal = nodes[op].value; }
			}
		}
		var inc = (maxVal - minVal) / this.options.maxSize;
		
		if (vals.length > 0)
		{
			if (startVal == null) { startVal = vals[0]; }

			var js_cbo = Object.toJSON(this.options);

			this.sc_slider = new Control.Slider(this.slider_handle.id, this.slider_ctrl.id,
			{
				axis: this.options.axis,
				minimum: minVal,
				maximum: maxVal,
				range: $R(minVal,maxVal),
				increment: inc,
				sliderValue: startVal,
				values: vals,
				alignX: this.options.alignX,
				alignY: this.options.alignY,
				onChange: function(v)
					{
						var cbo = js_cbo.evalJSON(true);
						Enjoy_Sliders[cbo.uniqueIndex].showValue(v,js_cbo);
					},
				onSlide: function(v)
					{
						var cbo = js_cbo.evalJSON(true);
						Enjoy_Sliders[cbo.uniqueIndex].showValue(v,js_cbo);
					}
			});
			
			this.showValue(startVal, js_cbo);
		}
	},
	
	showValue: function(val, js_cbo)
	{
		var cbo = js_cbo.evalJSON(true);
		
		var optionList2 = $(cbo.sourceControlName).getElementsByTagName('option');
		var nodes2 = $A(optionList2);
		var selText = '';
		
		for(op=0; op<nodes2.length;op++)
		{
			if (parseInt(nodes2[op].value) == parseInt(val))
			{
				$(cbo.sourceControlName).selectedIndex = op;
				selText = nodes2[op].innerHTML;
				break;
			}
		}
		
		if (cbo.valueLabel != null)
		{
			this.setValue(cbo.valueLabel, val);
		}
		if (cbo.textLabel != null)
		{
			this.setValue(cbo.textLabel, selText);
		}
	},
	
	setValue: function(ctrlName, val)
	{
		if (ctrlName != null && $(ctrlName) != undefined)
		{
			if ($(ctrlName).tagName == "INPUT")
			{
				$(ctrlName).value = val;
			}
			else if ($(ctrlName).tagName == "TEXTAREA")
			{
				$(ctrlName).innerHTML = val;
			}
			else if ($(ctrlName).tagName == "LABEL")
			{
				$(ctrlName).innerHTML = val;
			}
		}
	}
});


EnjoyScripts.CheckBox3 = {};

EnjoyScripts.CheckBox3 = Class.create(
{
	initialize: function()
	{
	    this.options = Object.extend(
		{
		    cssPreFix:								"nj_", 
			uniqueIndex:							Math.ceil(Math.random() * 1000), 
			controlName:							"check_box",
			itemHeight:								27,
			onChange:								null,
			style:                                  null,
			width:                                  200,
			paddingLeft:                            10,
			paddingRight:                           20
		}, arguments[0] || {});
		
		this.isChecked = false;
		
		this.original_checkbox_ctrl = $(this.options.controlName);
		this.label = this.getLabel(this.options.controlName);
		this.labelControl = $(this.getLabelControlId(this.options.controlName));
		
		var label_style = 'width: ' + (this.options.width-10-this.options.paddingRight-this.options.paddingLeft) + 'px;';
		if (this.options.style != null) { label_style += this.options.style; }
		label_style += 'padding-left: ' + this.options.paddingLeft + 'px;';
		label_style += 'padding-right: ' + this.options.paddingRight + 'px;';
		
		this.checkbox_html = "" + 
		    "<div class=\"" + this.options.cssPreFix + "checkbox_container\" style=\"width: " + this.options.width + "px;\">" + 
		        "<div class=\"" + this.options.cssPreFix + "checkbox_bg\" style=\"" + label_style + "\" id=\"chk3_lbl_" + this.options.uniqueIndex + "\">" + 
		        this.label + "</div>" + 
                "<div class=\"" + this.options.cssPreFix + "checkbox_right\" id=\"chk3_tick_" + this.options.uniqueIndex + "\">&nbsp;</div>" + 
                "<div class=\"" + this.options.cssPreFix + "checkbox_link\" style=\"width: " + this.options.width + "px;\" id=\"chk3_click_" + this.options.uniqueIndex + "\">&nbsp;</div>" + 
            "</div>";
        
        this.original_checkbox_ctrl.insert({before: this.checkbox_html});
		
		this.checkbox_label_ctrl = $('chk3_lbl_' + this.options.uniqueIndex);
		this.checkbox_click_ctrl = $('chk3_click_' + this.options.uniqueIndex);
		this.checkbox_tick_ctrl = $('chk3_tick_' + this.options.uniqueIndex);
		
		this.original_checkbox_ctrl.hide();
		
		this.isChecked = this.original_checkbox_ctrl.checked;
		
		this.renderTick();
		
		// Event to show hover effects and click/tick changes
		Event.observe(this.checkbox_click_ctrl, "click", this.onClick.bindAsEventListener(this));
	},
	
	getLabelControlId: function(checkBoxName)
	{
		var result = "";
		var labels = $$('label');
		
		for(i=0;i<labels.length;i++)
		{
			if (labels[i].htmlFor == checkBoxName)
			{
				result = labels[i].id;
			}
		}
		
		return result;
	},
	
	getLabel: function(checkBoxName)
	{
		var result = "";
		var labels = $$('label');
		
		for(i=0;i<labels.length;i++)
		{
			if (labels[i].htmlFor == checkBoxName)
			{
				result = labels[i].innerHTML;
				labels[i].hide();
			}
		}
		
		return result;		
	},
	
	renderTick: function()
	{
		if (this.isChecked)
		{
			this.checkbox_tick_ctrl.addClassName(this.options.cssPreFix + 'checkbox_ticked');
		}
		else if (this.checkbox_tick_ctrl.hasClassName(this.options.cssPreFix + 'checkbox_ticked'))
		{
			this.checkbox_tick_ctrl.removeClassName(this.options.cssPreFix + 'checkbox_ticked');
		}
		
	},
	
	onClick: function(eventObj)
	{
		this.isChecked = !this.isChecked;
		this.original_checkbox_ctrl.checked = this.isChecked;
		
		this.renderTick();

		if (this.options.onChange)
		{
			var cb = this.options.onChange + "(" + this.options.uniqueIndex + ", '" + this.original_checkbox_ctrl.id + "', " + this.isChecked + ")";
			eval(cb);
		}
	}	
});


EnjoyScripts.CheckBox2 = {};

EnjoyScripts.CheckBox2 = Class.create(
{
	initialize: function()
	{
		this.options = Object.extend(
		{
			cssPreFix:								"", 
			uniqueIndex:							Math.ceil(Math.random() * 1000), 
			controlName:							"check_box",
			onChange:								null
		}, arguments[0] || {});
		
		this.isChecked = false;
		
		this.original_checkbox_ctrl = $(this.options.controlName);
		this.label = this.getLabel(this.options.controlName);
		this.labelControl = $(this.getLabelControlId(this.options.controlName));
		if (this.labelControl.title != null && this.labelControl.title != '')
		{
			this.labelControlStyle = this.labelControl.title;
		}
		
		this.checkbox_html = "<div class=\"" + this.options.cssPreFix + "checkbox_container\">" + 
			"<div class=\"" + this.options.cssPreFix + "checkbox_left\">&nbsp;</div>" + 
			"<div id=\"chk_lbl_" + this.options.uniqueIndex + "\" class=\"" + this.options.cssPreFix + "checkbox_middle\"" + 
			" style=\"" + this.labelControlStyle + "\">" + 
			this.label + "</div>" + 
			"<div class=\"" + this.options.cssPreFix + "checkbox_right\" id=\"chk_tick_" + this.options.uniqueIndex + "\">&nbsp;</div>" + 
			"<div class=\"" + this.options.cssPreFix + "clear\"></div></div>";
		
		this.original_checkbox_ctrl.insert({before: this.checkbox_html});
		
		this.checkbox_label_ctrl = $('chk_lbl_' + this.options.uniqueIndex);
		this.checkbox_tick_ctrl = $('chk_tick_' + this.options.uniqueIndex);
		
		this.original_checkbox_ctrl.hide();
		
		this.isChecked = this.original_checkbox_ctrl.checked;
		
		this.renderTick();
		
		// Event to show hover effects and click/tick changes
		Event.observe(this.checkbox_tick_ctrl, "click", this.onClick.bindAsEventListener(this));
	},
	
	getLabelControlId: function(checkBoxName)
	{
		var result = "";
		var labels = $$('label');
		
		for(i=0;i<labels.length;i++)
		{
			if (labels[i].htmlFor == checkBoxName)
			{
				result = labels[i].id;
			}
		}
		
		return result;
	},
	
	getLabel: function(checkBoxName)
	{
		var result = "";
		var labels = $$('label');
		
		for(i=0;i<labels.length;i++)
		{
			if (labels[i].htmlFor == checkBoxName)
			{
				result = labels[i].innerHTML;
				labels[i].hide();
			}
		}
		
		return result;		
	},
	
	renderTick: function()
	{
		if (this.isChecked)
		{
			this.checkbox_tick_ctrl.addClassName(this.options.cssPreFix + 'checkbox_ticked');
		}
		else if (this.checkbox_tick_ctrl.hasClassName(this.options.cssPreFix + 'checkbox_ticked'))
		{
			this.checkbox_tick_ctrl.removeClassName(this.options.cssPreFix + 'checkbox_ticked');
		}
		
	},
	
	onClick: function(eventObj)
	{
		this.isChecked = !this.isChecked;
		this.original_checkbox_ctrl.checked = this.isChecked;
		
		this.renderTick();
		
		if (this.options.onChange)
		{
			var cb = this.options.onChange + "(" + this.options.uniqueIndex + ", '" + this.original_checkbox_ctrl.id + "', " + this.isChecked + ")";
			eval(cb);
		}
	}
});


EnjoyScripts.CheckBox2_Slim = {};

EnjoyScripts.CheckBox2_Slim = Class.create(
{
	initialize: function()
	{
		this.options = Object.extend(
		{
			cssPreFix:								"", 
			uniqueIndex:							Math.ceil(Math.random() * 1000), 
			controlName:							"check_box",
			onChange:								null
		}, arguments[0] || {});
		
		this.isChecked = false;
		
		this.original_checkbox_ctrl = $(this.options.controlName);
		
		this.checkbox_html = "<div class=\"" + this.options.cssPreFix + "checkbox_container\">" + 
			"<div class=\"" + this.options.cssPreFix + "checkbox_tick\" id=\"chk2_slim_tick_" + this.options.uniqueIndex + "\">&nbsp;</div>" + 
			"</div>";
		
		this.original_checkbox_ctrl.insert({before: this.checkbox_html});
		
		this.checkbox_tick_ctrl = $('chk2_slim_tick_' + this.options.uniqueIndex);
		
		this.original_checkbox_ctrl.hide();
		
		this.isChecked = this.original_checkbox_ctrl.checked;
		
		this.renderTick();
		
		// Event to show hover effects and click/tick changes
		Event.observe(this.checkbox_tick_ctrl, "click", this.onClick.bindAsEventListener(this));
	},
	
	renderTick: function()
	{
		if (this.isChecked)
		{
			this.checkbox_tick_ctrl.addClassName(this.options.cssPreFix + 'checkbox_ticked');
		}
		else if (this.checkbox_tick_ctrl.hasClassName(this.options.cssPreFix + 'checkbox_ticked'))
		{
			this.checkbox_tick_ctrl.removeClassName(this.options.cssPreFix + 'checkbox_ticked');
		}
		
	},
	
	onClick: function(eventObj)
	{
		this.isChecked = !this.isChecked;
		this.original_checkbox_ctrl.checked = this.isChecked;
		
		this.renderTick();
		
		if (this.options.onChange)
		{
			var cb = this.options.onChange + "(" + this.options.uniqueIndex + ", '" + this.original_checkbox_ctrl.id + "', " + this.isChecked + ")";
			eval(cb);
		}
	}
});


EnjoyScripts.ListBox3 = {};

EnjoyScripts.ListBox3 = Class.create(
{
    initialize: function()
	{
		this.options = Object.extend(
		{
		    cssPreFix:								"nj_", 
			uniqueIndex:							Math.ceil(Math.random() * 1000), 
			controlName:							"select_box",
			itemHeight:								27,
			onChange:								null,
			style:                                  null,
			width:                                  200,
			paddingLeft:                            10,
			borderWidth:                            1,
			titlekey: 									""
		}, arguments[0] || {});
		
		this.disposed = false;
		
		list3_actioned = true;
		
		var label_style = 'width: ' + (this.options.width-10-this.options.paddingLeft) + 'px;';
		if (this.options.style != null) { label_style += this.options.style; }
		label_style += 'padding-left: ' + this.options.paddingLeft + 'px;';
		
		this.dropdown_top_html = "" + 
		    "<div class=\"" + this.options.cssPreFix + "dropdown_container\" style=\"width: " + this.options.width + "px;\" id=\"lb3_ddt_" + this.options.uniqueIndex + "\" title=\""+ this.options.titlekey+"\">" + 
		        "<div class=\"" + this.options.cssPreFix + "dropdown_bg\" style=\"" + label_style + "\" id=\"lb3_lbl_" + this.options.uniqueIndex + "\">&nbsp;</div>" + 
                "<div class=\"" + this.options.cssPreFix + "dropdown_right\">&nbsp;</div>" + 
                "<div class=\"" + this.options.cssPreFix + "dropdown_link\" style=\"width: " + this.options.width + "px;\" id=\"lb3_dda_" + this.options.uniqueIndex + "\">&nbsp;</div>" + 
            "</div>";
        
        this.dropdown_list_html = "<div class=\"" + this.options.cssPreFix + "dropdown_list\" style=\"display: none; width: " + (this.options.width-(this.options.borderWidth*2)) + "px;\" id=\"lb3_ddl_" + this.options.uniqueIndex + "\"></div>";
        
        this.original_select_ctrl = $(this.options.controlName);
		
		this.original_select_ctrl.insert({before: this.dropdown_top_html});
		this.original_select_ctrl.insert({before: this.dropdown_list_html});
		
		this.dropdown_container = $('lb3_ddt_' + this.options.uniqueIndex);
		this.dropdown_label_ctrl = $('lb3_lbl_' + this.options.uniqueIndex);
		this.dropdown_arrow_ctrl = $('lb3_dda_' + this.options.uniqueIndex);
		this.dropdown_list_ctrl = $('lb3_ddl_' + this.options.uniqueIndex);
		
		this.original_select_ctrl.hide();
		
		this.observeMe = new Array();
		
		this.createList();
		
		// Event to show/hide list
		Event.observe(this.dropdown_arrow_ctrl, "click", this.showList.bindAsEventListener(this));
		
		// Events to handle mouse going elsewhere
		Event.observe(this.dropdown_list_ctrl, 'mouseout', this.onMouseOut.bindAsEventListener(this));

		this.cbTimeout = null;
	},
	
	destroyList: function()
	{
		for(i=0; i<this.observeMe.length;i++)
		{
			Event.stopObserving($(this.observeMe[i]));
		}
		
		this.dropdown_list_ctrl.innerHTML = '';
	},
	
	createList: function()
	{
		// Next build the list items
		this.selectOptions = [];
		
		var optionList = null;
		var nodes = null;
		var currentlySelected = 0;
		
		var el_name = null;
		var idx = 0;
		var lastOptLabel = "";
		
		this.selectOptions.push("<ul id=\"" + this.options.controlName + "_ul\">");
		
		optionList = $(this.original_select_ctrl).getElementsByTagName('option');
		nodes = $A(optionList);
		
		for(op=0; op<nodes.length;op++)
		{
			if (nodes[op].parentNode.label != undefined)
			{
				if (nodes[op].parentNode.label != lastOptLabel)
				{
					// New optgroup
					this.selectOptions.push("<li style=\"padding-left:" + this.options.paddingLeft + "px;\">" + nodes[op].parentNode.label + "</li>");
					lastOptLabel = nodes[op].parentNode.label;
				}
			}
			
			el_name = this.options.controlName + "_" + idx;
			if (nodes[op].parentNode.label == undefined)
			{
				this.selectOptions.push("<li style=\"padding-left:" + this.options.paddingLeft + "px;\" id=\"" + el_name + "\" value=\"" + nodes[op].value + "\">" + nodes[op].innerHTML + '</li>');
			}
			else
			{
				this.selectOptions.push("<li id=\"" + el_name + "\" value=\"" + nodes[op].value + "\" class=\"indent\">" + nodes[op].innerHTML + '</li>');
			}
			this.observeMe.push(el_name);

			if (nodes[op].getAttribute("selected") || nodes[op].selected)
			{
				this.original_select_ctrl.selectedIndex = idx;
				this.dropdown_label_ctrl.innerHTML = nodes[op].innerHTML;
				currentlySelected = idx;
			}
			idx++;
		}
		
		this.selectOptions.push("</ul>");
		
		this.dropdown_list_ctrl.innerHTML = this.selectOptions.join('');
		
		for(i=0; i<this.observeMe.length;i++)
		{
			this.addObservers($(this.observeMe[i]));
		}
		
		// Add class to the currently selected LI
		Element.addClassName((this.options.controlName + "_" + currentlySelected), "selected");
	},
    	
	addObservers: function(element)
	{
	    Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
	    Event.observe(element, "click", this.onClick.bindAsEventListener(this));
	},
	
	showList: function(eventObj)
	{
		clearTimeout(this.cbTimeout);
		this.cbTimeout = null;
		if (!this.dropdown_list_ctrl.visible())
		{
			this.closeOthers();
		}
		
		Effect.toggle(this.dropdown_list_ctrl, 'appear', {duration:0.15});
		
		var scrollHeight = parseInt(this.original_select_ctrl.selectedIndex) * this.options.itemHeight;
		$(this.dropdown_list_ctrl).scrollTop = scrollHeight;		
	},
	
	showHide: function()
	{
		clearTimeout(this.cbTimeout);
		this.cbTimeout = null;
		Effect.toggle(this.dropdown_list_ctrl, 'appear', {duration:0.15});
	},
	
	onMouseOut: function(eventObj)
	{
		var command = '$(\'lb3_ddl_' + this.options.uniqueIndex + '\').hide()';
		if (this.cbTimeout == null)
		{
			this.cbTimeout = setTimeout(command, 2000);
		}
	},
	
	onHover: function(eventObj)
	{
		clearTimeout(this.cbTimeout);
		this.cbTimeout = null;
		
		var tempElement = Event.findElement(eventObj, 'LI');
		
		// Needs fixing
		var index = tempElement.id.replace(this.options.controlName + '_', '');
		var oldSelectedIndex = this.original_select_ctrl.selectedIndex;
		
		this.render(index);
		
	    Event.stop(eventObj);
	},
	
	onClick: function(eventObj)
	{
		//alert('click');
		var tempElement = Event.findElement(eventObj, 'LI');
		//alert('Element: ' + tempElement);
		var index = tempElement.id.replace(this.options.controlName + '_', '');
		//alert('index:' + index);
		var oldSelectedIndex = this.original_select_ctrl.selectedIndex;
		//alert('oldSelectedIndex: ' + oldSelectedIndex);
		if (index != oldSelectedIndex)
		{
			this.dropdown_label_ctrl.innerHTML = tempElement.innerHTML;
			this.original_select_ctrl.selectedIndex = index;
		}
		this.render(index);
		
		this.showHide();
		
	    Event.stop(eventObj);
	    
	    if (this.options.onChange)
		{
			var cb = this.options.onChange + "(" + this.options.uniqueIndex + ", '" + this.original_select_ctrl.id + "', " + 
				this.original_select_ctrl.selectedIndex + ")";
			eval(cb);
		}
	},
	
	render: function(index)
	{
		var optionList = $(this.options.controlName).getElementsByTagName('option');
		var nodes = $A(optionList);
		var entryCount = nodes.length;

		if (entryCount > 0)
		{
			for(i=0; i<nodes.length;i++)
			{
				if (i == index)
				{
					if (!Element.hasClassName((this.options.controlName + "_" + i), "selected"))
					{
						Element.addClassName((this.options.controlName + "_" + i), "selected");
					}
				}
				else
				{
					Element.removeClassName((this.options.controlName + "_" + i), "selected");
				}
			}
		}
	},
	
	closeOthers: function()
	{
		var selBoxes = $$('select.enjoyListBox3');
		
		if (selBoxes != undefined && selBoxes != null)
		{
			selBoxes.each(
				function(ctrl, index)
				{
					if (this.uniqueIndex != index && $('lb3_ddl_' + index).visible())
					{
						$('lb3_ddl_' + index).hide();
					}
				}
			);
		}
	}
});


EnjoyScripts.ListBox2 = {};

EnjoyScripts.ListBox2 = Class.create(
{
	initialize: function()
	{
		this.options = Object.extend(
		{
			cssPreFix:								"reg_", 
			uniqueIndex:							Math.ceil(Math.random() * 1000), 
			controlName:							"select_box",
			itemHeight:								26,
			onChange:								null
		}, arguments[0] || {});
		
		//alert (Object.toJSON(this.options));
		this.disposed = false;
		// Widths are all now set in the CSS
		
		this.dropdown_top_html = "<div class=\"" + this.options.cssPreFix + "dropdown_container\" id=\"lb2_ddt_" + this.options.uniqueIndex + "\">" + 
			"<div class=\"" + this.options.cssPreFix + "dropdown_left\">&nbsp;</div>" + 
			"<div class=\"" + this.options.cssPreFix + "dropdown_middle\"><div id=\"lb2_lbl_" + this.options.uniqueIndex + "\">&nbsp;</div></div>" + 
			"<div class=\"" + this.options.cssPreFix + "dropdown_right\" id=\"lb2_dda_" + this.options.uniqueIndex + "\">&nbsp;</div>" + 
			"<div class=\"clean_up\"></div></div>";
			
		this.dropdown_list_html = "<div class=\"" + this.options.cssPreFix + "dropdown_list\" id=\"lb2_ddl_" + this.options.uniqueIndex + "\" style=\"display: none;\"></div>";

		this.original_select_ctrl = $(this.options.controlName);
		
		this.original_select_ctrl.insert({before: this.dropdown_top_html});
		this.original_select_ctrl.insert({before: this.dropdown_list_html});
		
		this.dropdown_container = $('lb2_ddt_' + this.options.uniqueIndex);
		this.dropdown_label_ctrl = $('lb2_lbl_' + this.options.uniqueIndex);
		this.dropdown_arrow_ctrl = $('lb2_dda_' + this.options.uniqueIndex);
		this.dropdown_list_ctrl = $('lb2_ddl_' + this.options.uniqueIndex);
		
		this.original_select_ctrl.hide();
		
		this.observeMe = new Array();
		
		this.createList();
		
		// Event to show/hide list
		Event.observe(this.dropdown_arrow_ctrl, "click", this.showList.bindAsEventListener(this));
		
		// Events to handle mouse going elsewhere
		Event.observe(this.dropdown_list_ctrl, 'mouseout', this.onMouseOut.bindAsEventListener(this));

		this.cbTimeout = null;
	},
	
	destroyList: function()
	{
		for(i=0; i<this.observeMe.length;i++)
		{
			Event.stopObserving($(this.observeMe[i]));
		}
		
		this.dropdown_list_ctrl.innerHTML = '';
	},
	
	createList: function()
	{
		// Next build the list items
		this.selectOptions = [];
		
		var optionList = null;
		var nodes = null;
		var currentlySelected = 0;
		
		var el_name = null;
		var idx = 0;
		var lastOptLabel = "";
		
		this.selectOptions.push("<ul id=\"" + this.options.controlName + "_ul\">");
		
		optionList = $(this.original_select_ctrl).getElementsByTagName('option');
		nodes = $A(optionList);
		
		for(op=0; op<nodes.length;op++)
		{
			if (nodes[op].parentNode.label != undefined)
			{
				if (nodes[op].parentNode.label != lastOptLabel)
				{
					// New optgroup
					this.selectOptions.push("<li>" + nodes[op].parentNode.label + "</li>");
					lastOptLabel = nodes[op].parentNode.label;
				}
			}
			
			el_name = this.options.controlName + "_" + idx;
			if (nodes[op].parentNode.label == undefined)
			{
				this.selectOptions.push("<li id=\"" + el_name + "\" value=\"" + nodes[op].value + "\">" + nodes[op].innerHTML + '</li>');
			}
			else
			{
				this.selectOptions.push("<li id=\"" + el_name + "\" value=\"" + nodes[op].value + "\" class=\"indent\">" + nodes[op].innerHTML + '</li>');
			}
			this.observeMe.push(el_name);

			if (nodes[op].getAttribute("selected") || nodes[op].selected)
			{
				this.original_select_ctrl.selectedIndex = idx;
				this.dropdown_label_ctrl.innerHTML = nodes[op].innerHTML;
				currentlySelected = idx;
			}
			idx++;
		}
		
		this.selectOptions.push("</ul>");
		
		this.dropdown_list_ctrl.innerHTML = this.selectOptions.join('');
		
		for(i=0; i<this.observeMe.length;i++)
		{
			this.addObservers($(this.observeMe[i]));
		}
		
		// Add class to the currently selected LI
		Element.addClassName((this.options.controlName + "_" + currentlySelected), "selected");
	},
    	
	addObservers: function(element)
	{
	    Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
	    Event.observe(element, "click", this.onClick.bindAsEventListener(this));
	},
	
	showList: function(eventObj)
	{
		clearTimeout(this.cbTimeout);
		this.cbTimeout = null;
		if (!this.dropdown_list_ctrl.visible())
		{
			this.closeOthers();
		}
		
		Effect.toggle(this.dropdown_list_ctrl, 'appear', {duration:0.15});
		
		var scrollHeight = parseInt(this.original_select_ctrl.selectedIndex) * this.options.itemHeight;
		$(this.dropdown_list_ctrl).scrollTop = scrollHeight;		
	},
	
	showHide: function()
	{
		clearTimeout(this.cbTimeout);
		this.cbTimeout = null;
		Effect.toggle(this.dropdown_list_ctrl, 'appear', {duration:0.15});
	},
	
	onMouseOut: function(eventObj)
	{
		var command = '$(\'lb2_ddl_' + this.options.uniqueIndex + '\').hide()';
		if (this.cbTimeout == null)
		{
			this.cbTimeout = setTimeout(command, 2000);
		}
	},
	
	onHover: function(eventObj)
	{
		clearTimeout(this.cbTimeout);
		this.cbTimeout = null;
		
		var tempElement = Event.findElement(eventObj, 'LI');
		
		// Needs fixing
		var index = tempElement.id.replace(this.options.controlName + '_', '');
		var oldSelectedIndex = this.original_select_ctrl.selectedIndex;
		
		this.render(index);
		
	    Event.stop(eventObj);
	},
	
	onClick: function(eventObj)
	{
		//alert('click');
		var tempElement = Event.findElement(eventObj, 'LI');
		//alert('Element: ' + tempElement);
		var index = tempElement.id.replace(this.options.controlName + '_', '');
		//alert('index:' + index);
		var oldSelectedIndex = this.original_select_ctrl.selectedIndex;
		//alert('oldSelectedIndex: ' + oldSelectedIndex);
		if (index != oldSelectedIndex)
		{
			this.dropdown_label_ctrl.innerHTML = tempElement.innerHTML;
			this.original_select_ctrl.selectedIndex = index;
		}
		this.render(index);
		
		this.showHide();
		
	    Event.stop(eventObj);
	    
	    if (this.options.onChange)
		{
			var cb = this.options.onChange + "(" + this.options.uniqueIndex + ", '" + this.original_select_ctrl.id + "', " + 
				this.original_select_ctrl.selectedIndex + ")";
			eval(cb);
		}
	},
	
	render: function(index)
	{
		var optionList = $(this.options.controlName).getElementsByTagName('option');
		var nodes = $A(optionList);
		var entryCount = nodes.length;

		if (entryCount > 0)
		{
			for(i=0; i<nodes.length;i++)
			{
				if (i == index)
				{
					if (!Element.hasClassName((this.options.controlName + "_" + i), "selected"))
					{
						Element.addClassName((this.options.controlName + "_" + i), "selected");
					}
				}
				else
				{
					Element.removeClassName((this.options.controlName + "_" + i), "selected");
				}
			}
		}
	},
	
	closeOthers: function()
	{
		var selBoxes = $$('select.enjoy_ListBox2');
		
		if (selBoxes != undefined && selBoxes != null)
		{
			selBoxes.each(
				function(ctrl, index)
				{
					if (this.uniqueIndex != index && $('lb2_ddl_' + index).visible())
					{
						$('lb2_ddl_' + index).hide();
					}
				}
			);
		}
	}
});


EnjoyScripts.ListBox = {};

EnjoyScripts.ListBox = Class.create(
{
	initialize: function(selectBoxName, uniqueIndex, totalWidth, middleWidth, cssPreFix)
	{
		this.width = totalWidth;
		this.uniqueIndex = uniqueIndex;
		this.containerWidth = parseInt(totalWidth) + 1;
		
		this.dropdown_top_html = "<div class=\"" + cssPreFix + "dropdown_container\" style=\"width:" + this.containerWidth + "px;\">" + 
			"<div class=\"" + cssPreFix + "dropdown_left\">&nbsp;</div>" + 
			"<div class=\"" + cssPreFix + "dropdown_middle\" style=\"width:" + middleWidth + "px;\"><label id=\"lb_lbl_" + uniqueIndex + "\">&nbsp;</label></div>" + 
			"<div class=\"" + cssPreFix + "dropdown_right\" id=\"lb_dda_" + uniqueIndex + "\">&nbsp;</div>" + 
			"<div style=\"float:none; clear:both;\"></div></div>";

		this.dropdown_list_html = "<div class=\"" + cssPreFix + "dropdown_list\" id=\"lb_ddl_" + uniqueIndex + "\" style=\"width:" + totalWidth + "px; display: none;\"></div>";
		
		this.original_select_ctrl = $(selectBoxName);
		
		this.original_select_ctrl.insert({before: this.dropdown_top_html});
		this.original_select_ctrl.insert({before: this.dropdown_list_html});
		
		this.dropdown_label_ctrl = $('lb_lbl_' + uniqueIndex);
		this.dropdown_arrow_ctrl = $('lb_dda_' + uniqueIndex);
		this.dropdown_list_ctrl = $('lb_ddl_' + uniqueIndex);
		
		this.original_select_ctrl.hide();
		
		// Next build the list items
		this.selectOptions = [];
		
		var optionList = $(this.original_select_ctrl).getElementsByTagName('option');
		var nodes = $A(optionList);
		var currentlySelected = 0;
		
		for(i=0; i<nodes.length;i++)
		{
			this.selectOptions.push("<li id=\"" + selectBoxName + "_" + i + "\" value=\"" + nodes[i].value + "\">" + nodes[i].innerHTML + '</li>');
			if (nodes[i].getAttribute("selected"))
			{
				this.original_select_ctrl.selectedIndex = i;
				this.dropdown_label_ctrl.innerHTML = nodes[i].innerHTML;
				currentlySelected = i;
			}
		}
		
		if (this.original_select_ctrl.selectedIndex >= 0)
		{
			this.dropdown_label_ctrl.innerHTML = nodes[this.original_select_ctrl.selectedIndex].innerHTML;
		}
		
		this.dropdown_list_ctrl.innerHTML = "<ul>" + this.selectOptions.join('') + "</ul>";
		
		for(i=0; i<nodes.length;i++)
		{
			this.addObservers($(selectBoxName + "_" + i));
		}
		
		Element.addClassName((this.original_select_ctrl.id + "_" + currentlySelected), "selected");
		
		// Event to show/hide list
		Event.observe(this.dropdown_arrow_ctrl, "click", this.showList.bindAsEventListener(this));
		
		// Events to handle mouse going elsewhere
		Event.observe(this.dropdown_list_ctrl, 'mouseout', this.onMouseOut.bindAsEventListener(this));

		this.cbTimeout = null;
	},
	
	addObservers: function(element)
	{
	    Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
	    Event.observe(element, "click", this.onClick.bindAsEventListener(this));
	},
	
	showList: function(eventObj)
	{
		clearTimeout(this.cbTimeout);
		this.cbTimeout = null;
		if (!this.dropdown_list_ctrl.visible())
		{
			this.closeOthers();
		}
		
		Effect.toggle(this.dropdown_list_ctrl, 'appear', {duration:0.15});
	},
	
	showHide: function()
	{
		clearTimeout(this.cbTimeout);
		this.cbTimeout = null;
		Effect.toggle(this.dropdown_list_ctrl, 'appear', {duration:0.15});
	},
	
	onMouseOut: function(eventObj)
	{
		var command = '$(\'lb_ddl_' + this.uniqueIndex + '\').hide()';
		if (this.cbTimeout == null)
		{
			this.cbTimeout = setTimeout(command, 2000);
		}
	},
	
	onHover: function(eventObj)
	{
		clearTimeout(this.cbTimeout);
		this.cbTimeout = null;
		
		var tempElement = Event.findElement(eventObj, 'LI');
		
		var index = tempElement.id.replace($(this.original_select_ctrl).id + '_', '');
		var oldSelectedIndex = this.original_select_ctrl.selectedIndex;
		
		this.render(index);
		
	    Event.stop(eventObj);
	},
	
	onClick: function(eventObj)
	{
		//alert('click');
		var tempElement = Event.findElement(eventObj, 'LI');
		//alert('Element: ' + tempElement);
		var index = tempElement.id.replace($(this.original_select_ctrl).id + '_', '');
		//alert('index:' + index);
		var oldSelectedIndex = this.original_select_ctrl.selectedIndex;
		//alert('oldSelectedIndex: ' + oldSelectedIndex);
		if (index != oldSelectedIndex)
		{
			this.dropdown_label_ctrl.innerHTML = tempElement.innerHTML;
			this.original_select_ctrl.selectedIndex = index;
		}
		this.render(index);
		
		this.showHide();
		
	    Event.stop(eventObj);		
	},
	
	render: function(index)
	{
		var optionList = $(this.original_select_ctrl).getElementsByTagName('option');
		var nodes = $A(optionList);
		var entryCount = nodes.length;

		if (entryCount > 0)
		{
			for(i=0; i<nodes.length;i++)
			{
				if (i == index)
				{
					if (!Element.hasClassName((this.original_select_ctrl.id + "_" + i), "selected"))
					{
						Element.addClassName((this.original_select_ctrl.id + "_" + i), "selected");
					}
				}
				else
				{
					Element.removeClassName((this.original_select_ctrl.id + "_" + i), "selected");
				}
			}
		}
	},
	
	closeOthers: function()
	{
		var selBoxes = $$('select.enjoy_ListBox');
		
		if (selBoxes != undefined && selBoxes != null)
		{
			selBoxes.each(
				function(ctrl, index)
				{
					if (this.uniqueIndex != index && $('lb_ddl_' + index).visible())
					{
						$('lb_ddl_' + index).hide();
					}
				}
			);
		}
	}
	
});






// Initiate Controls
document.observe("dom:loaded", initiateEnjoyControls);

function initiateEnjoyControls()
{
    addEnjoy_ListBoxes3();
	addEnjoy_ListBoxes();
	addEnjoy_ListBoxes2();
	addEnjoy_CheckBoxes3();
	addEnjoy_CheckBoxes();
	addEnjoy_CheckBoxes2();
	addEnjoy_CheckBoxes2_Slim();
	addEnjoy_MECheckBoxes();
	addEnjoy_MECheckBoxes_Slim();
	addEnjoy_HeaderImages();
	addEnjoy_Sliders();
	addEnjoy_Enjoy_RadioButtons();
	addEnjoy_Enjoy_CheckBox4();
	hideSetters();
}












function addEnjoy_CheckBoxes()
{
	var selBoxes = $$('input.enjoy_CheckBox');
	
	if (selBoxes != undefined && selBoxes != null)
	{
		selBoxes.each(
			function(ctrl, index)
			{
				var sbWidth = 200;
				var midWidth = 160;
				var cssPreFix = '';
				var class_names = $w(ctrl.className);
				class_names.each(
						function(cn)
						{
							if (cn.startsWith('cwidth'))
							{
								sbWidth = cn.replace('cwidth', '');
							}
							if (cn.startsWith('mwidth'))
							{
								midWidth = cn.replace('mwidth', '');
							}
							if (cn.startsWith('cssPreFix'))
							{
								cssPreFix = cn.replace('cssPreFix', '');
							}
						}
					)
				
				new EnjoyScripts.CheckBox(ctrl.id, index, sbWidth, midWidth, cssPreFix);
				//new EnjoyListBox(ctrl.id, index);
			}
		);
	}
}


function addEnjoy_CheckBoxes2_Slim()
{
	var selBoxes = $$('input.enjoy_CheckBox2_Slim');
	
	if (selBoxes != undefined && selBoxes != null)
	{
		selBoxes.each(
			function(ctrl, index)
			{
				var cssPreFix = '';
				var onChange = null;
				var class_names = $w(ctrl.className);
				class_names.each(
						function(cn)
						{
							if (cn.startsWith('cssPreFix'))
							{
								cssPreFix = cn.replace('cssPreFix', '');
							}
							if (eval("typeof " + ctrl.name.replace('[]', '') + "_changed" + " == 'function'"))
							{
								onChange = ctrl.name.replace('[]', '') + "_changed";
							}
						}
					);
				
				new EnjoyScripts.CheckBox2_Slim(
					{
						cssPreFix: cssPreFix, 
						uniqueIndex: index, 
						controlName: ctrl, 
						onChange: onChange
					});
			});
	}
}


var MECheckBoxes = new Array();

function addEnjoy_MECheckBoxes()
{
	var selBoxes = $$('input.enjoy_MECheckBox');
	
	if (selBoxes != undefined && selBoxes != null)
	{
		selBoxes.each(
			function(ctrl, index)
			{
				var sbWidth = 200;
				var midWidth = 160;
				var cssPreFix = '';
				var onChange = null;
				var class_names = $w(ctrl.className);
				class_names.each(
						function(cn)
						{
							if (cn.startsWith('cwidth'))
							{
								sbWidth = cn.replace('cwidth', '');
							}
							if (cn.startsWith('mwidth'))
							{
								midWidth = cn.replace('mwidth', '');
							}
							if (cn.startsWith('cssPreFix'))
							{
								cssPreFix = cn.replace('cssPreFix', '');
							}
							
							if (eval("typeof " + ctrl.name + "_changed" + " == 'function'"))
							{
								onChange = ctrl.name + "_changed";
							}
						}
					)
				
				MECheckBoxes[index] = ctrl.id;
				new EnjoyScripts.MECheckBox(ctrl.id, index, sbWidth, midWidth, cssPreFix, onChange);
				//new EnjoyListBox(ctrl.id, index);
			}
		);
	}
}


var Enjoy_Sliders = new Array();

function addEnjoy_Sliders()
{
	var sliders = $$('select.enjoy_Slider');
	
	if (sliders != undefined && sliders != null)
	{
		sliders.each(
		function (ctrl, index)
		{
			var cssPreFix = '';
			var valueLabel = null;
			var textLabel = null;
			var class_names = $w(ctrl.className);
			var sliderWidth = 300;
			var handleWidth = 17;
			class_names.each(
					function(cn)
					{
						if (cn.startsWith('cssPreFix'))
						{
							cssPreFix = cn.replace('cssPreFix', '');
						}
						if (cn.startsWith('valueLabel'))
						{
							valueLabel = cn.replace('valueLabel', '');
						}
						if (cn.startsWith('textLabel'))
						{
							textLabel = cn.replace('textLabel', '');
						}
					}
				);

			var sl = new EnjoyScripts.Enjoy_Slider(
				{
					sourceControlName: ctrl.id, 
					cssPreFix: cssPreFix, 
					uniqueIndex: index,
					valueLabel: valueLabel,
					textLabel: textLabel,
					sliderWidth: sliderWidth,
					handleWidth: handleWidth					
				})
			if (sl != null) { Enjoy_Sliders.push(sl); }
		});
	}
}


var MECheckBoxes_Slim = new Array();

function addEnjoy_MECheckBoxes_Slim()
{
	var selBoxes = $$('input.enjoy_MECheckBox_Slim');
	
	if (selBoxes != undefined && selBoxes != null)
	{
		selBoxes.each(
			function(ctrl, index)
			{
				var sbWidth = 100;
				var cssPreFix = '';
				var class_names = $w(ctrl.className);
				class_names.each(
						function(cn)
						{
							if (cn.startsWith('cwidth'))
							{
								sbWidth = cn.replace('cwidth', '');
							}
							if (cn.startsWith('cssPreFix'))
							{
								cssPreFix = cn.replace('cssPreFix', '');
							}
						}
					)
				
				MECheckBoxes_Slim[index] = ctrl.id;
				new EnjoyScripts.MECheckBox_Slim(ctrl.id, index, sbWidth, cssPreFix);
				//new EnjoyListBox(ctrl.id, index);
			}
		);
	}
}


var hdr_EHI = null;
function addEnjoy_HeaderImages()
{
	if ($('top_banner_image') != undefined)
	{
		var hdr_imageControl = $('top_banner_image');
		var hdr_pageName = hdr_imageControl.title.replace('pageIs_', '');
		
		hdr_EHI = new EnjoyScripts.HeaderImages(
			{
				page_name: hdr_pageName,
				interval: 1000,
				myId: 'hdr_EHI'
			});
	}
}




function hideSetters()
{
	var set_right_divs = $$('div.set_right');
	
	if (set_right_divs != undefined && set_right_divs != null)
	{
		set_right_divs.each(
			function(ctrl, index)
			{
				$(ctrl).hide();
			});
	}
}

function flexible_move_date_changed(idx, ctrlId, ticked)
{
	if (ctrlId == 'flexible_move_date_no')
	{
		if (ticked)
		{
			$('div_flexi').hide();
		}
		else
		{
			$('div_flexi').show();
		}
	}
	else
	{
		// yes
		if (ticked)
		{
			$('div_flexi').show();
		}
		else
		{
			$('div_flexi').hide();
		}
	}
}

function pd_budget_stretch_changed(idx, ctrlId, ticked)
{
	if (ctrlId == 'pd_budget_stretch_no')
	{
		if (ticked)
		{
			$('div_stretch').hide();
		}
		else
		{
			$('div_stretch').show();
		}
	}
	else
	{
		// yes
		if (ticked)
		{
			$('div_stretch').show();
		}
		else
		{
			$('div_stretch').hide();
		}
	}
}

function copy_from_flat_changed(idx, ctrlId, ticked)
{
	if (ctrlId == 'copy_from_flat_no')
	{
		if (ticked)
		{
			$('div_flatshare').show();
		}
		else
		{
			$('div_flatshare').hide();
		}
	}
	else
	{
		// yes
		if (ticked)
		{
			$('div_flatshare').hide();
		}
		else
		{
			$('div_flatshare').show();
		}
	}
}

function share_type_changed(idx, ctrlId, selectedIdx)
{
	var val  = $(ctrlId).options[selectedIdx].value;
	if (parseInt(val) >= 3)
	{
		$('div_flat_sharers').show();
	}
	else
	{
		$('div_flat_sharers').hide();
	}	
}

function preferred_locations_flats_changed(idx, ctrlId, ticked)
{
	// preferred_locations_flats
	for(lb_ptr=0; lb_ptr<Enjoy_ListBoxes3.length; lb_ptr++)
	{
		if (Enjoy_ListBoxes3[lb_ptr].options.controlName == 'no1_location_flats')
		{
			Enjoy_ListBoxes3[lb_ptr].destroyList();
			
			if (!ticked)
			{
				var didx = getIndexOfValue($(ctrlId).value, 'no1_location_flats');
				if (didx != -1)
				{
					$('no1_location_flats').remove(didx);
				}
			}
			else
			{
				AddSelectOption($('no1_location_flats'), getCBLabel(ctrlId), $(ctrlId).value, false);
			}
			Enjoy_ListBoxes3[lb_ptr].createList();
		}
	}
}

function preferred_locations_flatshares_changed(idx, ctrlId, ticked)
{
	// preferred_locations_flats
	for(lb_ptr=0; lb_ptr<Enjoy_ListBoxes3.length; lb_ptr++)
	{
		if (Enjoy_ListBoxes3[lb_ptr].options.controlName == 'no1_location_flatshares')
		{
			Enjoy_ListBoxes3[lb_ptr].destroyList();
			
			if (!ticked)
			{
				var didx = getIndexOfValue($(ctrlId).value, 'no1_location_flatshares');
				if (didx != -1)
				{
					$('no1_location_flatshares').remove(didx);
				}
			}
			else
			{
				AddSelectOption($('no1_location_flatshares'), getCBLabel(ctrlId), $(ctrlId).value, false);
			}
			Enjoy_ListBoxes3[lb_ptr].createList();
		}
	}
}

function preferred_locations_houseshares_changed(idx, ctrlId, ticked)
{
	// preferred_locations_flats
	for(lb_ptr=0; lb_ptr<Enjoy_ListBoxes3.length; lb_ptr++)
	{
		if (Enjoy_ListBoxes3[lb_ptr].options.controlName == 'no1_location_houseshares')
		{
			Enjoy_ListBoxes3[lb_ptr].destroyList();
			
			if (!ticked)
			{
				var didx = getIndexOfValue($(ctrlId).value, 'no1_location_houseshares');
				if (didx != -1)
				{
					$('no1_location_houseshares').remove(didx);
				}
			}
			else
			{
				AddSelectOption($('no1_location_houseshares'), getCBLabel(ctrlId), $(ctrlId).value, false);
			}
			Enjoy_ListBoxes3[lb_ptr].createList();
		}
	}
}

function getIndexOfValue(val, ctrlId)
{
	var optionList = $(ctrlId).getElementsByTagName('option');
	var nodes = $A(optionList);
	var result = -1;
	
	for(op=0; op<nodes.length;op++)
	{
		if (parseInt(nodes[op].value) == parseInt(val))
		{
			result = op;
			break;
		}
	}
	return result;
}

function AddSelectOption(selectObj, text, value, isSelected) 
{
    if (selectObj != null && selectObj.options != null)
    {
        selectObj.options[selectObj.options.length] = 
            new Option(text, value, false, isSelected);
    }
}

function RemoveSelectOptions(selectObj, start) {
	 var options = selectObj.select("option"); 
	var i = 1;
	 options.each(function(item) {
		if (i > start) {
			item.remove();
			
		};
		i++
	});
}

function getCBLabel(checkBoxName)
{
	var result = "";
	var labels = $$('label');
	
	for(i=0;i<labels.length;i++)
	{
		if (labels[i].htmlFor == checkBoxName)
		{
			result = labels[i].innerHTML;
		}
	}
	
	return result;	
}


var Enjoy_CheckBox4 = new Array();
function addEnjoy_Enjoy_CheckBox4()
{
    var checkBoxes = $$('input.enjoyCheckBox4');
    if (checkBoxes != undefined && checkBoxes != null)
    {
        checkBoxes.each(
            function(ctrl, index)
            {
                var ctrlName = ctrl.id;
                var onChange = null;
                var title = ctrl.title;
                
                var obj = { controlName: ctrlName, uniqueIndex: index };
                // Other options are added by inclusion in the title tag
                
                var options = title.split('||');
                for(var i=0; i<options.length; i++)
                {
                    var o_parts = options[i].split('::');
                    if (o_parts[1] != undefined && o_parts[1] != null && o_parts[1] != '')
                    {
                        eval('obj.' + o_parts[0] + '=\'' + o_parts[1] + '\'');
                    }
                }
                
                var newCB = new EnjoyScripts.CheckBox4(obj);
                Enjoy_CheckBox4[index] = newCB;
            });        
    }
}


var Enjoy_RadioButtons = new Array();
function addEnjoy_Enjoy_RadioButtons()
{
    var radioButtons = $$('input.enjoyRadioButton');
    if (radioButtons != undefined && radioButtons != null)
    {
        radioButtons.each(
            function(ctrl, index)
            {
                var ctrlName = ctrl.id;
                var onChange = null;
                var title = ctrl.title;
                
                var obj = { controlName: ctrlName, uniqueIndex: index };
                // Other options are added by inclusion in the title tag
                
                var options = title.split('||');
                for(var i=0; i<options.length; i++)
                {
                    var o_parts = options[i].split('::');
                    
                    if (o_parts[1] != undefined && o_parts[1] != null && o_parts[1] != '')
                    {
                        eval('obj.' + o_parts[0] + '=\'' + o_parts[1] + '\'');
                    }
                }
                
                var newRB = new EnjoyScripts.RadioButton(obj);
                Enjoy_RadioButtons[index] = newRB;
            });        
    }
}

var MECheckBoxes = new Array();

function addEnjoy_MECheckBoxes()
{
	var selBoxes = $$('input.enjoy_MECheckBox');
	
	if (selBoxes != undefined && selBoxes != null)
	{
		selBoxes.each(
			function(ctrl, index)
			{
				var sbWidth = 200;
				var midWidth = 160;
				var cssPreFix = '';
				var onChange = null;
				var class_names = $w(ctrl.className);
				class_names.each(
						function(cn)
						{
							if (cn.startsWith('cwidth'))
							{
								sbWidth = cn.replace('cwidth', '');
							}
							if (cn.startsWith('mwidth'))
							{
								midWidth = cn.replace('mwidth', '');
							}
							if (cn.startsWith('cssPreFix'))
							{
								cssPreFix = cn.replace('cssPreFix', '');
							}
							
							if (eval("typeof " + ctrl.name + "_changed" + " == 'function'"))
							{
								onChange = ctrl.name + "_changed";
							}
						}
					)
				
				MECheckBoxes[index] = ctrl.id;
				new EnjoyScripts.MECheckBox(ctrl.id, index, sbWidth, midWidth, cssPreFix, onChange);
				//new EnjoyListBox(ctrl.id, index);
			}
		);
	}
}

var Enjoy_CheckBoxes3 = new Array();

function addEnjoy_CheckBoxes3()
{
	var selBoxes = $$('input.enjoyCheckBox3');
	
	if (selBoxes != undefined && selBoxes != null)
	{
		selBoxes.each(
			function(ctrl, index)
			{
				var ctrlName = ctrl.id;
				var onChange = null;
                var title = ctrl.title;
				
				if (eval("typeof " + ctrl.name.replace('[]','') + "_changed" + " == 'function'"))
				{
					onChange = ctrl.name.replace('[]','') + "_changed";
				}
				
				var obj = { controlName: ctrlName, uniqueIndex: index, cssPreFix: '', onChange: onChange, 
				    width: 200, style: null, itemHeight: 27, paddingLeft: 0, paddingRight: 0 };
				
				var options = title.split('||');
				for(var i=0; i<options.length; i++)
				{
				    var o_parts = options[i].split('::');
				    if (o_parts[1] != undefined && o_parts[1] != null && o_parts[1] != '')
				    {
				        eval('obj.' + o_parts[0] + '=' + o_parts[1]);
				    }
				}
				
				var newLB = new EnjoyScripts.CheckBox3(obj);
				Enjoy_CheckBoxes3.push(newLB);
			});
	}
}

var Enjoy_ListBoxes3 = new Array();

function addEnjoy_ListBoxes3()
{
    var selBoxes = $$('select.enjoyListBox3');
    
    if (selBoxes != undefined && selBoxes != null)
    {
        selBoxes.each(
            function(ctrl, index)
            {
                var ctrlName = ctrl.id;
                var onChange = null;
                var title = ctrl.title;
                
                if (eval("typeof " + ctrl.name + "_changed" + " == 'function'"))
				{
					onChange = ctrl.name + "_changed";
				}
				
                var obj = { controlName: ctrlName, uniqueIndex: index, cssPreFix: '', onChange: null, width: 200, style: null, itemHeight: 27, paddingLeft: 0 };
				
				var options = title.split('||');
				for(var i=0; i<options.length; i++)
				{
				    var o_parts = options[i].split('::');
				    if (o_parts[1] != undefined && o_parts[1] != null && o_parts[1] != '')
				    {
				        eval('obj.' + o_parts[0] + '=' + o_parts[1]);
				    }
				}
				
				var newLB = new EnjoyScripts.ListBox3(obj);
				Enjoy_ListBoxes3.push(newLB);
            });
    }
}

function addEnjoy_ListBoxes()
{
	var selBoxes = $$('select.enjoy_ListBox');
	
	if (selBoxes != undefined && selBoxes != null)
	{
		selBoxes.each(
			function(ctrl, index)
			{
				var sbWidth = 200;
				var midWidth = 160;
				var cssPreFix = '';
				var class_names = $w(ctrl.className);
				class_names.each(
						function(cn)
						{
							if (cn.startsWith('fwidth'))
							{
								sbWidth = cn.replace('fwidth', '');
							}
							if (cn.startsWith('mwidth'))
							{
								midWidth = cn.replace('mwidth', '');
							}
							if (cn.startsWith('cssPreFix'))
							{
								cssPreFix = cn.replace('cssPreFix', '');
							}
						}
					)
				
				new EnjoyScripts.ListBox(ctrl.id, index, sbWidth, midWidth, cssPreFix);
				//new EnjoyListBox(ctrl.id, index);
			}
		);
	}
}

var Enjoy_ListBoxes2 = new Array();

function addEnjoy_ListBoxes2()
{
	var selBoxes = $$('select.enjoy_ListBox2');
	
	if (selBoxes != undefined && selBoxes != null)
	{
		selBoxes.each(
			function(ctrl, index)
			{
				var ctrlName = ctrl.id;
				var cssPreFix = '';
				var onChange = null;
				var class_names = $w(ctrl.className);
				class_names.each(
						function(cn)
						{
							if (cn.startsWith('cssPreFix'))
							{
								cssPreFix = cn.replace('cssPreFix', '');
							}
							if (eval("typeof " + ctrl.name + "_changed" + " == 'function'"))
							{
								onChange = ctrl.name + "_changed";
							}
						}
					)
				
				var newLB = new EnjoyScripts.ListBox2({
					controlName: ctrlName,
					uniqueIndex: index,
					cssPreFix: cssPreFix,
					onChange: onChange
				});
				Enjoy_ListBoxes2.push(newLB);
			}
		);
	}
}


function addEnjoy_CheckBoxes2()
{
	var selBoxes = $$('input.enjoy_CheckBox2');
	
	if (selBoxes != undefined && selBoxes != null)
	{
		selBoxes.each(
			function(ctrl, index)
			{
				var ctrlName = ctrl.id;
				var cssPreFix = '';
				var onChange = null;
				
				var class_names = $w(ctrl.className);
				class_names.each(
						function(cn)
						{
							if (cn.startsWith('cssPreFix'))
							{
								cssPreFix = cn.replace('cssPreFix', '');
							}
						}
					)
				
				if (eval("typeof " + ctrl.name.replace('[]','') + "_changed" + " == 'function'"))
				{
					onChange = ctrl.name.replace('[]','') + "_changed";
				}
					
				new EnjoyScripts.CheckBox2({
					controlName: ctrlName,
					uniqueIndex: index,
					cssPreFix: cssPreFix,
					onChange: onChange
				});
			}
		);
	}
}

function message_alerts_by_email_changed(idx, CtrlId, ticked)
{
	var url = website_homepage + 'ajaxCalls/updateUserSetting.php';
	var params = 'type=alert_settings&setting=message_alerts_by_email&action=' + 
		(ticked ? 'add' : 'remove');
	new Ajax.Request(url, 
		{
			method: 'get', 
			parameters: params,
			onSuccess: function(transport)
			{
				var jsonString = transport.responseText;
				var jsonObject = jsonString.toJSON(true);
			},
			onFailure: function(transport)
			{
				alert('Unable to update, please try again');
			}
		});	
}

$j(document).ready(function()
{
	clickable();
	function clickable () {
		$j(".clickable").click(function (e) {

			window.location = $j(this).find('a').attr('href');
		})
	}
})
