
Tapestry.FieldEventManager = Class.create({

    initialize : function(field)
    {
        this.field = $(field);
        var id = this.field.id;
        this.label = $(id + '-label');
        this.icon = $(id + '-icon');

        this.translator = Prototype.K;

        document.observe(Tapestry.FOCUS_CHANGE_EVENT, function(event)  {

        }.bindAsEventListener(this));
    },

    /** Removes validation decorations if present. Hides the ErrorPopup,
     *  if it exists.
     */
    removeDecorations : function()
    {
        this.field.removeClassName("t-error");

        if (this.label)
            this.label.removeClassName("t-error");

        if (this.icon)
            this.icon.hide();

        if (this.errorPopup)
            this.errorPopup.hide();
    },

    /**
     * Show a validation error message, which will add decorations to the
     * field and it label, make the icon visible, and raise the
     * field's Tapestry.ErrorPopup to show the message.
     * @param message validation message to display
     */
    showValidationMessage : function(message)
    {
        $T(this.field).validationError = true;
        $T(this.field.form).validationError = true;

        this.field.addClassName("t-error");

        if (this.label)
            this.label.addClassName("t-error");

        if (this.icon)
        {
            if (! this.icon.visible())
                new Effect.Appear(this.icon);
        }

        if (this.errorPopup == undefined)
            this.errorPopup = new Tapestry.ErrorPopup(this.field);

        this.errorPopup.showMessage(message);
    },


    validateInput : function()
    {
        if (this.field.disabled) return false;

        if (! this.field.isDeepVisible()) return false;

        var t = $T(this.field);

        var value = $F(this.field);

        t.validationError = false;

        if (this.requiredCheck)
            this.requiredCheck.call(this, value);

        // Don't try to validate blank values; if the field is required, that error is already
        // noted and presented to the user.

        if (!t.validationError && ! value.blank())
        {
            var translated = this.translator(value);

            // If Format went ok, perhaps do the other validations.

            if (! t.validationError)
            {
                this.field.fire(Tapestry.FIELD_VALIDATE_EVENT, {
                    value: value,
                    translated: translated
                });
            }
        }

        // Lastly, if no validation errors were found, remove the decorations.

        if (! t.validationError)
            this.field.removeDecorations();

        return t.validationError;
    }
});





Tapestry.ErrorPopup = Class.create(Tapestry.ErrorPopup, {
    BUBBLE_HEIGHT: '58px',
    BUBBLE_VERT_OFFSET: -60,
    BUBBLE_HORIZONTAL_OFFSET: 0,

    initialize : function($super, field)    {
        $super(field);

        this.outerDiv.setAttribute('class','t-error-popup');

        var fieldY = field.cumulativeOffset().top;
        diff = fieldY-parseInt(this.BUBBLE_HEIGHT);

        if (diff < 0) {
        	this.outerDiv.addClassName('below');
        	this.outerDiv.setStyle({
        		marginTop: (-1*diff+field.getLayout().get('border-box-height')+fieldY)+'px'
        	});
        }
      }
});

function showCenterContent(id) {
	var popupEl  = $('registerBackground');
	var popupContent  = $(id);
	var win = windowSize();
	var winHeight = win[1];
	
	popupEl.setStyle({
    	display:'block'
    }); 
	var myHeight = Math.max(
		Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
		Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
		Math.max(document.body.clientHeight, document.documentElement.clientHeight)
	);
	var myWidth = Math.max(
		Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
		Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
		Math.max(document.body.clientWidth, document.documentElement.clientWidth)
	);
	popupEl.setStyle({
    	height:myHeight + 'px', 
    	width:myWidth + 'px'
    });
	
	
	
	var contentTop = winHeight/2 -(popupContent.getHeight()/2);
	var viewportHeight = document.viewport.getHeight();
	var viewportoffsetH = document.viewport.getScrollOffsets()[1];    	
	contentTop =  viewportoffsetH + viewportHeight/2 -(popupContent.getHeight()/2);   	
	if(contentTop < 0) contentTop = 0;
	
	
//	var contentTop = win[1]/2 -(popupContent.getHeight()/2);
//	if(contentTop < 0) contentTop = 0;
	
	
	/*popupEl.setStyle({display:'block'});*/
	popupContent.setStyle({top:contentTop+"px"});
	popupContent.setStyle({left:document.viewport.getWidth()/2 -(popupContent.getWidth()/2) +'px'});
	popupContent.appear();
}


Tapestry.ElementEffect.modal = function(n) {
	var popupContent = $('popupContent');
	var popupEl  = $('changeZone');
	
	if(popupContent) {
		var win = windowSize();
		var winHeight = win[1];
		var myHeight = Math.max(
			Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
			Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
			Math.max(document.body.clientHeight, document.documentElement.clientHeight)
		);
		var myWidth = Math.max(
			Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
			Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
			Math.max(document.body.clientWidth, document.documentElement.clientWidth)
		);
		popupEl.setStyle({
			top:'0px',
			left:'0px',
	    	height:myHeight + 'px', 
	    	width:myWidth + 'px',
	    	display:'block'
	    });
    	var contentTop = winHeight/2 -(popupContent.getHeight()/2);
    	var viewportHeight = document.viewport.getHeight();
    	var viewportoffsetH = document.viewport.getScrollOffsets()[1];    	
    	contentTop =  viewportoffsetH + viewportHeight/2 -(popupContent.getHeight()/2);   	
    	if(contentTop < 0) contentTop = 0;
   	  	popupContent.setStyle({top:contentTop+'px'});
   	    popupContent.setStyle({left:document.viewport.getWidth()/2 -(popupContent.getWidth()/2) +'px'});
	}
	else {		
		popupEl.setStyle({
	    	height:'0px', 
	    	width:'0px'
	    });   
	}
};


Tapestry.ElementEffect.highlight = function(n) {
};

Tapestry.ElementEffect.warenkorb = function(n) {
        $$('.t-error-popup').each(function(item) {
            item.remove();
        });
        if($('cartError')) {
            var button = $('cartError').getAttribute('rel');
            button = $(button);
            var text = $('cartError').childNodes[0].nodeValue;
            showErrorPopup(button, text);
        }
        else {
        if($('sprechblase')) {
                var button = $('sprechblase').getAttribute('rel');
                button = $(button);
                Effect.Appear($('sprechblase'));
                positionBubble(button);
            }
            }
};

Tapestry.ElementEffect.feedback = function(n) {

      var feedbackbox = $('feedbackbox');
      if(feedbackbox) {
        var h = 400;
        var w05 = 500;
        h = feedbackbox.getHeight();
        w05 = feedbackbox.getWidth()/2;
        var position = Position.cumulativeOffset($('showFeedbackForm'));
        var infoLayerPosX = position[0] - w05 + 10;
            var infoLayerPosY = position[1] - h;
            $('feedbackZone').setStyle({left:infoLayerPosX + 'px', top:infoLayerPosY + 'px'});
      }


 };


 function hideFeedbackForm() {
        if($('feedbackZone')) {
            $('feedbackZone').hide();
        }
 }








    function showSuccessMsg() {
        /*$$('#successMsg').each(function(item) {
            item.setStyle({width:"0px",height:"0px",visibility:"hidden"});
            var successText = "";
            if(item.childNodes.length>0) {
                successText = item.childNodes[0].nodeValue;
            }
            load: {
                if(successText) {
                    showNotice(item, successText);
                }
            }
            item.setStyle({width:"",height:"",visibility:"normal"});
        });*/
    }

Event.observe(window, 'load', function() {
    init();
});

function windowSize() {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' )
    {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return new Array(myWidth, myHeight);
}


function showPopup(url){
    new Ajax.Updater('popup', url, {
        method: 'get',
        onComplete: function(transport) {
            var win = windowSize();
            $('popup').setStyle({height:$('positionCenter').getHeight()+'px'});
            $('popup').setStyle({display:'block'});
            $('popup').setStyle({width:'none'});
            var popupContent = $('popup').firstDescendant();
            popupContent.setStyle({top:win[1]/2 -(popupContent.getHeight()/2) +'px'});
            popupContent.setStyle({left:win[0]/2 -(popupContent.getWidth()/2) +'px'});
            var firstInnerDiv = $('popup').getElementsByTagName('div')[0];
            $('closePopup').setStyle({marginLeft:firstInnerDiv.getWidth()-50+'px'});
            var popupY = win[1]/2 -(firstInnerDiv.getHeight()/2);
            if(popupY <0) {
                popupY = 0;
            }
            firstInnerDiv.setStyle({top:popupY+'px'});
            firstInnerDiv.setStyle({left:win[0]/2 -(firstInnerDiv.getWidth()/2) +'px'});
            firstInnerDiv.setStyle({position:'absolute'});
        }

    });
}



function sendNewsletterSubscribe(email, gender) {

    new Ajax.Updater('ajaxInout', "/php/newsletter/subscribe.php5", {
            method: 'post',
            parameters: {mail: email, gender: gender},
            onComplete: function(transport) {
            /*    if(transport.status .......) */
                $('ajaxInout').update('OK.');
            }
    });

}


function display_effect(id){
    $(id).setOpacity(0);
    $(id).setStyle({display:'block'});
    new Effect.Opacity($(id), { from: 0, to: 1, duration: 0.5 });
}

/*
function showZoom(){

    $('detailsPic').setStyle({display:'none'});
    display_effect('origImage');

    //if($('mainSlide')) $('mainSlide').setStyle({display:"none"});
    display_effect('zoomImage');

    if($('detailsZoomOn') && $('detailsZoomOff')) {
        $('detailsZoomOn').setStyle({display:"none"});
        $('detailsZoomOff').setStyle({display:"block"});
    }
    glassOn(1);
}

function hideZoom(){

    $('origImage').setStyle({display:"none"});
    $('zoomImage').setStyle({display:"none"});
    $('detailsPic').setStyle({display:'block'});
   if($('detailsZoomOff')) $('detailsZoomOff').setStyle({display:"none"});

    display_effect('detailsPic');
    if($('mainSlide')) display_effect('mainSlide');
    if($('detailsZoomOn'))$('detailsZoomOn').setStyle({display:"block"});
    glassOn(0);
}
 */

function displayRegisterInfo(){
	showCenterContent('doRegisterHelpDiv');
    Event.observe($('closeRegisterHelp'),"click", function(e){
        $('doRegisterHelpDiv').hide();
        $('registerBackground').hide();
    });
}

var displayedRegInfoAlready = false;

function displayRegisterInfoOnClick(element){
	var elem = $(element);
    if(!elem) return false;
    Event.observe(elem, 'click', function(e){
    	if(!displayedRegInfoAlready){
    		displayRegisterInfo();
    	}
    	displayedRegInfoAlready = true;
    }, false);
}


function registerMessageToggle(element,message) {
    var elem = $(element);
    if(!elem) return false;
    elem.setValue(message);
    Event.observe(elem, 'click', function(e){
            if(elem.getValue()==message){
                elem.setValue('');
            }
        }, false);
   Event.observe(elem, 'blur', function(e){
       if(elem.getValue()==''){
        elem.setValue(message);
       }
   }, false);
}

function fireAJAXForm(element){
	element = $(element);
    if (!element) {
        Tapestry.error('Could not find form to trigger AJAX submit on');
        return;
    }
    element.fire(Tapestry.FORM_PROCESS_SUBMIT_EVENT);
}

function init(){
	
	if($('searchInput')){
		Autocompleter.Base.prototype.fixIEOverlapping = function(){
				Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
				this.iefix.style.zIndex = 79;
				this.update.style.zIndex = 80;
				Element.show(this.iefix);
		}
	}
	
	
		jQuery('ul.sf-menu').superfish({
			animation: {opacity:'show'},   // slide-down effect without fade-in 
            delay:     300,
            dropShadows: false
		});
	
	
    var mouseleaveTimeoutId = 0;

    jQuery('#showMinicartPopup').mouseenter(function(event){
        var slash = '/';
        var divtag =$('minicartPopup');
        timeOutId = window.setTimeout( function() {
        new Ajax.Updater('minicartPopup', '/shop/minicartPopup',{
            method: 'get',
            onComplete: function(transport) {
                $('minicartPopup').setStyle({display:'block'});
                positionMinicartPopup();
            }
        })},500);

    }).mouseleave(function(event) {
        mouseleaveTimeoutId = window.setTimeout( function() {
            $('minicartPopup').hide();
            },600);
    });

    jQuery('#minicartPopup').mouseenter(function(event){
        window.clearTimeout(mouseleaveTimeoutId);
        jQuery('#showMinicartPopup').mouseleave(function(event){
            event.stop();
        });

    }).mouseleave(function(event) {
        jQuery('#showMinicartPopup').mouseleave(function(event){
            window.setTimeout( function() {
                $('minicartPopup').hide();
                },500);
        });
        window.setTimeout( function() {
            $('minicartPopup').hide();
            },600);
    });


    /*
    $$('#size a').each(function(item){
        item.observe('click',function(e){
            window.setTimeout( function() {
                var smallUrl = $('productImage').getAttribute('src');
                var imgname = smallUrl.substring(smallUrl.lastIndexOf('/'));
                Tapestry.debug('imgname is: ' + imgname);
                var largeUrl = '/images/products/zoom'+imgname;
                Tapestry.debug('largeurl is: ' + largeUrl);
                if($$('.MagicZoomBigImageCont img')[0]) { // the zoomer is present
                    $$('.MagicZoomBigImageCont img')[0].setAttribute('src', largeUrl);
                }
            },50);
            return true;
        });
    });
    */

    /*preloadImages('.preloadImage');*/

    $$('.todo').each(function(item) {
        Event.observe(item, 'click', function(e){
                window.alert('STILL TODO');
            }, false);
     });


    registerMessageToggle('nlEmailAddress','E-Mail-Adresse');
    registerMessageToggle('searchInput','');
    registerMessageToggle('loginUSERNAME','Login-Id');
    //displayRegisterInfoOnClick('loginUSERNAME');
}


function clearInfoLinks() {
    $('info').select('a').each(function(item){
        item.setStyle({color:'#0f0f0f',backgroundColor:'#ffffff'});
    });
}


function toggleDetailPopup(linkEl, openid, xdiff) {
    clearInfoLinks();
    var tipElement = $(openid);
    if(tipElement.getStyle('display') != 'none') { //already showing
        tipElement.toggle();
        return false;
    }
    window.setTimeout( function() {
    var position = linkEl.cumulativeOffset();
    $$('.detailpopup').each(function(item) {
        if(item.id != openid)  item.setStyle({display:'none'});
       });
    if($('popupContent') && $('popupContent').visible) {
        position = linkEl.positionedOffset($('popupContent'));
    }
    var infoLayerPosLeft = position[0] ;
    var infoLayerPosTop = position[1] ;
    var linkHeight = linkEl.getHeight()/2;
    var linkWidth = linkEl.getWidth();
    var elemHeight = tipElement.getHeight()/2;
    tipElement.setStyle({left: infoLayerPosLeft + linkWidth + 10 + 'px'});
    tipElement.setStyle({top: infoLayerPosTop - elemHeight + linkHeight + 'px'});
    tipElement.toggle();
    if(tipElement.getStyle('display') != 'none') {
        linkEl.setStyle({color:'#ffffff',backgroundColor:'#0f0f0f'});
    }
    },10);
    Event.observe($('positionCenter'), 'click', function() {
        $(openid).setStyle({display:'none'});
            clearInfoLinks();
        }, false);
        Event.observe(document.body, 'click', function() {
            $(openid).setStyle({display:'none'});
            clearInfoLinks();
        }, false);

    return false;
}


function positionElement(popupid, openid, xdiff, ydiff) {
    var element = $(openid);
    var popup = $(popupid);
    var position = Position.cumulativeOffset(element);
    var infoLayerPosX = position[0] + xdiff;
    var infoLayerPosY = position[1] - ydiff;
    popupid.setStyle({left: infoLayerPosX + 'px'});
    popupid.setStyle({top: infoLayerPosY + 'px'});


}




function showNotice(element,message) {
    var errorPopup = new Tapestry.ErrorPopup(element);
    errorPopup.showMessage(message);
    errorPopup.outerDiv.setStyle({backgroundImage:'none'});
    errorPopup.outerDiv.setStyle({backgroundColor:'#FF9A00'});
    errorPopup.outerDiv.setStyle({height:'30px'});
    errorPopup.innerSpan.setStyle({backgroundImage:'none'});
    errorPopup.innerSpan.setStyle({height:'20px'});
    errorPopup.innerSpan.setStyle({fontWeight:'bold'});
    setTimeout('this.errorPopup.fadeOut()', 2000);
}

/* show the standard clientside-validation-popup manually with a custom error message */
function showErrorPopup(element,message) {
    Tapestry.currentFocusField = element;
    var errorPopup =  $(element.id+':errorpopup');
    if(errorPopup) errorPopup.remove();
    errorPopup = new Tapestry.ErrorPopup(element);
    errorPopup.showMessage(message);
}


function showError(element,message) {
    var errorPopup = new Tapestry.ErrorPopup(element);
    errorPopup.showMessage(message);
    errorPopup.outerDiv.setStyle({backgroundImage:'none'});
    errorPopup.outerDiv.setStyle({backgroundColor:'red'});
    var count = this.errorPopup.innerSpan.getElementsByTagName('br').length;
    errorPopup.outerDiv.setStyle({height:30*count+ 'px'});
    errorPopup.innerSpan.setStyle({backgroundImage:'none'});
    errorPopup.innerSpan.setStyle({minHeight:'20px'});
    errorPopup.innerSpan.setStyle({fontWeight:'bold'});
    setTimeout('this.errorPopup.stopAnimation()',1000);
//    setTimeout("this.errorPopup.fadeOut()", 5000);
}

function closePopup(){
    $('popup').setStyle({display:'none'});
    $('popupContent').remove();
}


function positionBubble(button) {
    var BUBBLE_VERT_OFFSET = -72;
    if(button.id == 'addToCartButton') BUBBLE_VERT_OFFSET = -60;
    var BUBBLE_HORIZONTAL_OFFSET = 0;
     var BUBBLE_WIDTH = 'auto';
     var BUBBLE_HEIGHT = '58px';

    var button_x = Position.positionedOffset(button)[0];
    var button_y = Position.positionedOffset(button)[1];

    $('sprechblase').setStyle ({
            top: (button_y + BUBBLE_VERT_OFFSET) + 'px',
            left: (button_x + BUBBLE_HORIZONTAL_OFFSET) + 'px',
            //width: BUBBLE_WIDTH,
            height: BUBBLE_HEIGHT
    });
    setTimeout(function() {Effect.Fade($('sprechblase'));}, 3000);
}

function hideBubble() {
    $('sprechblase').toggle();
}



function preloadImages(id){

    $$(id).each(function(image) {
        var orig_src = image.src;

        if (image.complete) {
                image.setStyle({visibility: 'visible' });
        } else {
            image.setStyle({visibility: 'hidden' });
            image.onload = function() {
                image.setStyle({visibility: 'visible' });
            }.bind(this);
        }
        image.src         = '/images/product_blank.gif';
        image.setStyle({ backgroundImage: 'url(' + '/images/spinner.gif' + ')', backgroundPosition: '50% 50%', backgroundRepeat: 'no-repeat'});
        var newImage     = null;
        newImage         = new Image();
        newImage.src     = orig_src;

        if (newImage.complete) {
            new Effect.Opacity(image, { from: 1, to: 0, duration: 0.5, afterFinish:function(){
                image.src     = newImage.src;
                new Effect.Opacity(image, { from: 0, to: 1, duration: 0.5 });
            } });

        } else {
            newImage.onload = function() {
                new Effect.Opacity(image, { from: 1, to: 0, duration: 0.5, afterFinish:function(){
                    image.src     = newImage.src;
                    if (image.complete) {
                            new Effect.Opacity(image, { from: 0, to: 1, duration: 0.5 });
                    } else {
                        image.onload = function() {
                            new Effect.Opacity(image, { from: 0, to: 1, duration: 0.5 });
                        }
                    }
                } });
            }.bind(this);
        }
    });

}


function display_effect(id){
    new Effect.Opacity($(id), { from: 1, to: 0, duration: 0 });
    $(id).setStyle({display:'block'});
    new Effect.Opacity($(id), { from: 0, to: 1, duration: 0.5 });
}




function showSlider(slide){
    if($('origImage').getStyle('display') != 'block'){
        $(slide).setOpacity(0);

        var topPos = Position.positionedOffset($('detailsIcos'))[1] + 30;
        $(slide).setStyle({top:topPos+'px'});

        $(slide).setStyle({display:'block'});
        new Effect.Opacity($(slide), { from: 0, to: 1, duration: 0.5 });
    }
}

function hideSlider(){
    if($('origImage').getStyle('display') != 'block'){
        if($('fitSlide') && $('fitSlide').getStyle('display') == 'block'){
            new Effect.Opacity($('fitSlide'), { from: 1, to: 0, duration: 0.5, afterFinish: function(){
                $('fitSlide').setStyle({display:'none'});
            } });
        }
        if($('detailsSlide') && $('detailsSlide').getStyle('display') == 'block'){
            new Effect.Opacity($('detailsSlide'), { from: 1, to: 0, duration: 0.5, afterFinish: function(){
                $('detailsSlide').setStyle({display:'none'});
            } });
        }
        if( $('pflegehinweiseSlide') && $('pflegehinweiseSlide').getStyle('display') == 'block'){
            new Effect.Opacity($('pflegehinweiseSlide'), { from: 1, to: 0, duration: 0.5, afterFinish: function(){
                $('pflegehinweiseSlide').setStyle({display:'none'});
            } });
        }
    }
}


function handle(delta) {
    bigSlider.setValueBy(delta*20*(-1));
}

function wheel(event){
    var delta = 0;
    if (!event) event = window.event;
    if (event.wheelDelta) {
        delta = event.wheelDelta/120;
        if (window.opera) delta = -delta;
    } else if (event.detail) {
        delta = -event.detail/3;
    }
    if (delta)
        handle(delta);
        if (event.preventDefault)
                event.preventDefault();
        event.returnValue = false;
}

var globalErrorFlag = false;

// @sk
// eventhandler of prototype chcken

function errorEvent3d() {
    if($('3dproductImage')) {
        $('3dproductImage').setStyle({display:'none'});
    }
    $('productImage').setStyle({display:'block'});
    $('productImage').setAttribute('src','/images/products/medium/noproduct.gif');
    var vrDiv = $('vr');
    if(vrDiv){
        vrDiv.remove();
    }
    globalErrorFlag = true;
}

function alt3dproductImage(prodId) {
    if(!prodId) return false;
    var mediumImgEl2 = $('3dproductImage');
    if(!mediumImgEl2) {
        mediumImgEl2 = document.createElement('img');
        mediumImgEl2.setAttribute('id','3dproductImage');
        $('detailsPic').appendChild(mediumImgEl2);
    }
    var pathPrefix = '/images/products/3d/';
    var pathSuffix = '-01.jpg';
    mediumImgEl2.setAttribute('src', pathPrefix + prodId + pathSuffix);
    mediumImgEl2.addClassName('rotate');
    mediumImgEl2.setAttribute('height', '420');
    mediumImgEl2.setAttribute('width', '280');
    //mediumImgEl2.observe('error',errorEvent3d());
    if(globalErrorFlag) return false;
    mediumImgEl2.setStyle({display:'block'});
    $('productImage').setStyle({display:'none'});
    if($('productZoomed')) {
        hideZoom();
    }
    jQuery(document).ready(function($) {
        jQuery('.rotate').myclip360();
    });
    //jQuery('.rotate').myclip360();
    /*
    $('3dproductImage').observe('mouseover',function(){
        var magicZoomContent = $$('.MagicZoomBigImageCont')[0];
        if(magicZoomContent) {
            var pos_x = $('productview').cumulativeOffset()[0];
            var pos_y = $('productview').cumulativeOffset()[1];
            //var pos_x = Position.positionedOffset($('productview'))[0];
            //var pos_y = Position.positionedOffset($('productview'))[1];
            Tapestry.debug('Set height and width to: ' + pos_y +', ' + pos_x);
            magicZoomContent.setStyle({
                top:pos_y  +'px',
                left:pos_x +'px'
            });
        }
    });
    */
}


function altImageSelected(smallUrl) {
    //var mediumImgEl1 = $('productMain');
    var mediumImgEl2 = $('productImage');
    var theParentA = mediumImgEl2.up();
    //var largeImgEl = $('productZoomed');
    var imgname = smallUrl.substring(smallUrl.lastIndexOf('/'));
    var mediumUrl = '/images/products/detail'+imgname;
    //mediumImgEl1.setAttribute('src', mediumUrl);
    mediumImgEl2.setAttribute('src', mediumUrl);
    mediumImgEl2.addClassName('preloadImage');
    var largeUrl = '/images/products/zoom'+imgname;
    theParentA.setAttribute('href', largeUrl);
    //largeImgEl.setAttribute('src', largeUrl);

    if($$('.MagicZoomBigImageCont img')[0]) { // the zoomer is present
        $$('.MagicZoomBigImageCont img')[0].setAttribute('src', largeUrl);
    }
    MagicZoom.start(theParentA);
    MagicZoom.refresh();

    //MagicZoom.update(theParentA);
    if($('3dproductImage')) {
        $('3dproductImage').setStyle({display:'none'});
    }
    var vrDiv = $('vr');
    if(vrDiv){
        vrDiv.remove();
    }
    mediumImgEl2.setStyle({display:'block'});
    if($('detailsZoomOn')) $('detailsZoomOn').show();

    //var wrappingA = mediumImgEl2.up('a');
    //wrappingA.setAttribute('onclick','showZoom()');
    //wrappingA.observe('click',showZoom);
}

function refreshMagicZoom(elem) {
    /*var imgsrc = $('productImage').src;
    var largeUrl = '/images/products/zoom' + imgsrc.substring(imgsrc.lastIndexOf('/'));
    var theparentA = $('productZoomImage');
    theparentA.setAttribute('href',largeUrl);*/
    MagicZoom.refresh();
}

function onImgErrorSmall(source) {
    var parent = source.parentNode;
    source.src = '/images/product_small_blank.gif?' + source.src.substring(source.src.lastIndexOf('/')+1);
    source.onerror = '';
    if(parent) {
        parent.href='#';
    }
    $(parent).remove();
    return true;

}

function onImgErrorMiniCart(source) {
    source.src = '/images/product_small_blank.gif?' + source.src.substring(source.src.lastIndexOf('/')+1);
    source.onerror = '';
    return true;
}

function onImgErrorMedium(source) {
    source.src = '/images/product_medium_blank.gif?' + source.src.substring(source.src.lastIndexOf('/')+1);
    source.onerror = '';
    return true;
}

function onImgError3D(source) {
    source.src = '/images/product_blank.gif?' + source.src.substring(source.src.lastIndexOf('/')+1);
    return true;
}

function onImgErrorDetail(source) {
    var parent = source.parentNode;
    parent.onclick = function() {};
    source.src = '/images/product_detail_blank.gif?' + source.src.substring(source.src.lastIndexOf('/')+1);
    source.onerror = '';
    return true;
}

function showMinicartPopup(event) {
    if(event) {
        event.stop();
    }
    var slash = '/';
    var divtag =$('minicartPopup');
    timeOutId = window.setTimeout( function() {
    new Ajax.Updater('minicartPopup', '/shop/minicartPopup',{
        method: 'get',
        onComplete: function(transport) {
            $('minicartPopup').setStyle({display:'block'});
            positionMinicartPopup();
        }
    })},500);
    if($('maindetail')) {
        Event.observe($('maindetail'), 'click', function() {
            $('minicartPopup').setStyle({display:'none'});
        }, false);
    }
    if($('mainstart')) {
        Event.observe($('mainstart'), 'click', function() {
            $('minicartPopup').setStyle({display:'none'});
        }, false);
    }
    Event.observe($('positionCenter'), 'click', function() {
        $('minicartPopup').setStyle({display:'none'});
    }, false);
    Event.observe(document.body, 'click', function() {
        $('minicartPopup').setStyle({display:'none'});
    }, false);
}

function positionMinicartPopup() {
    if($('minicartPopup').getStyle('display') == 'none') {
        return false;
    }
    var linkEl = $('showMinicartPopup');
    var linkElTop = linkEl.cumulativeOffset()[1];
    var linkElLeft = linkEl.cumulativeOffset()[0];
    var linkElWidth = linkEl.getWidth();
    var linkElHeight = linkEl.getHeight();
    var innerDiv = $('minicartPopup').down();
    var innerDivWeight = innerDiv.getWidth();
    innerDiv.setStyle({
        top : linkElTop + linkElHeight + 5 + 'px',
        left: linkElLeft - (innerDivWeight- linkElWidth) + 'px'
    });
}

function openSizeTable(href) {
    $$('.detailpopup').each(function(item) {
        item.setStyle({display:'none'});
    });
    var popupWidth = 500;
    var popupHeight = 500;
    var win = windowSize();
    var winHeight = win[1];
    var winWidth = win[0];
    var leftVal = (winWidth/2) - (popupWidth/2);
    var topVal = (winHeight/2) - (popupHeight/2);
    if(topVal < 250) topVal = 250;
    var popupAttributes = 'statusbar=no,scrollbars=yes,resizable=no,menubar=no,toolbar=no,personalbar=no,locationbar=no';
    popupAttributes = popupAttributes + ',width=' + popupWidth + ',height='+popupHeight+',left='+leftVal+',top='+topVal;
    var sizeTablePopup = window.open(href,'sizeTable',popupAttributes);

}

function removeMagnifier() {
	$('smallMagnifier').hide();
}


	/**
	 * opens the zzl preview in a popup window (see http://www.office.zyres.net/wiki/DRK_Beschriftungs_Preview_Skript)
	 * 
	 * @param zzl the ZZL type
	 * @param artno the prepared product id
	 * @returns {Boolean} always false
	 */
	function openZzlPreview(zzl,artno){
			var v1e=document.getElementById('zzlFrontLine1Text');
			var v2e=document.getElementById('zzlFrontLine2Text');
			var h1e=document.getElementById('zzlBackLine1Text');
			var h2e=document.getElementById('zzlBackLine2Text');
			var v1='';
			var v2='';
			var h1='';
			var h2='';
			if(v1e)v1=escape(v1e.value);
			if(v2e)v2=escape(v2e.value);
			if(h1e)h1=escape(h1e.value);
			if(h2e)h2=escape(h2e.value);
		var wndPopUp = window.open('/cgi-bin/zzl/preview.pl?zzl=' + zzl + '&artno=' + artno +'&v1=' + v1 + '&v2=' + v2 + '&h1=' + h1 + '&h2='+h2,'preview','width=600,height=900,scrollbars=no,toolbar=no');
		wndPopUp.focus();
		return false;
		}


	function enableJSelect(){
        $$('div.jselect').each(function(element) {
        	new JSelect(element);
		});
	}
