Event.observe(window, 'load', function() {
    var images = $$('a.imageswitch');

    images.each(function(i) {

	i.observe( 'click', function( event ) {
		Event.stop(event);

	    var view = $('imageswitch_view');
	    var href = this.readAttribute('href');

	    var bg = this.getStyle('backgroundImage');
	    bg = bg.replace(/^url\(/g, "").replace(/\)$/g, "").replace(/\"/g, "");

	    var vbg = view.getStyle('backgroundImage');
	    vbg = vbg.replace(/^url\(/g, "").replace(/\)$/g, "").replace(/\"/g, "");
	    vbg = vbg.split('#');
	   
	    //leading " and last " must be cuttet off 
	    vbg_small = vbg[1];
	    vbg_big = vbg[0];

		//alert('small:' + vbg_small + '; big:' + vbg_big);

	    this.setStyle({ backgroundImage: 'url(' + vbg_small + ')' });
	    this.writeAttribute('href', vbg_big);

		//alert('views bg will be:' + 'url(' + href + '#' + bg + ')');

	    view.setStyle({ backgroundImage: 'url(' + href + '#' + bg + ')' });
	    view.writeAttribute('href', href);
	});
    });
});
