/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright  Copyright (c) 2008 Softloop http://softloop.de/
 * @author     Vinai Kopp, Andi Jacob
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */


function setRsSelectValue(id, span, value)
{
	// set value of form field
	$(id).value = value;
	
	// de-select all options
	var options = $$('.rs-select-' + id);
	for (i = 0; i < options.length; i++) {
		options[i].removeClassName('selected');
	}

	// select clicked option
	span.addClassName('selected');
}


RsImageUpdater = Class.create();
RsImageUpdater.prototype = {
	initialize: function() { },
	setImageSet: function(attrId) {
		if (! $$('.image-set-' + attrId) || ! $$('.image-set-' + attrId).length) return;

		if ($$('.product-image-set')) {
			for (i = 0; i < $$('.product-image-set').length; i++) $$('.product-image-set')[i].addClassName('hide');
		}
		if ($$('.image-set-' + attrId)) {
			for (i = 0; i < $$('.image-set-' + attrId).length; i++) $$('.image-set-' + attrId)[i].removeClassName('hide');
			
			
			if(document.all)
			{
				$$('li.image-set-' + attrId + ' a.image-set-default')[0].fireEvent('onclick');
				
			} else {
				var clickEvent = window.document.createEvent("MouseEvent"); 
				clickEvent.initEvent("click", false, true); 
				$$('li.image-set-' + attrId + ' a.image-set-default')[0].dispatchEvent(clickEvent); 
			}
		}
	},
	setImageEvent: function(event) {
		this.setImageSet(Event.element(event).value);
	},
	bindObserver: function(element) {
		element.observe('change', this.setImageEvent.bind(this));
	}
};


