var curForm = '';

var myRules = {
    'a.language' : function (element) {
        element.onmouseover = function () {
            $$('a.language').each(function(link) {
                flag = link.childNodes[0];
                flag.src = flag.src.replace(/flag_(de|uk|fr).gif/, "flag_$1_bw.gif");
            });
            
            flag = element.childNodes[0];
            flag.src = flag.src.replace(/_bw.gif/, '.gif');
        },
        element.onmouseout = function () {
            $$('a.language').each(function(link) {
                flag = link.childNodes[0];
                flag.src = flag.src.replace(/flag_(de|uk|fr).gif/, "flag_$1_bw.gif");
            });

            flag = $('flag_' + curLanguage);
            flag.src = flag.src.replace(/_bw.gif/, '.gif');
        }
    },
    // Input fields at the main page
    'input.box-no' : function (element) {
        element.onfocus = function () {
            // Change font color through css class
            Element.addClassName(this, 'box-act');
            // Activate field
            Field.activate(this);
        },
        element.onblur = function () {
            if (this.value == this.defaultValue) {
                Element.removeClassName(this, 'box-act');
            }
        }
    },
    // Search form
    '#formSearch' : function (element) {
        element.onsubmit = function () {
            box = $('formSearch-fieldSearch');
            if (box.value == box.defaultValue) {
                box.value = '';
            }
        }
    },
    // Update postage costs at checkout
    '#country_id' : function (element) {
        element.onchange = function () {
			updatePostage();
        }
    },
    //
    '#paymentChooser' : function (element) {
        element.onchange = function () {
            paymentId = element.options[element.selectedIndex].value;
            for (i = 1; i <= 4; i++) {
                Element.hide('payment_' + i);
            }
            if (paymentId) {
                Element.show('payment_' + paymentId);
            }

			updatePostage();
        }
    }
};

Behaviour.register(myRules);

Behaviour.addLoadEvent(
    function () { 
        // Select first form element in forms
        if ($('formHighlight')) {
            Form.focusFirstElement('formHighlight');
            new Effect.Highlight(Form.findFirstElement('formHighlight'), {duration:1.5});
        }
		if ($('flash')) {
			new Effect.Highlight('flash', { duration: 1.0 });
		}
    }
);