 $(document).ready(function() {

    $(".dontShowMeFromBeginning").hide();
    $("#manuSku").hide();


    // ****************************************************************************************************************************	
 
  
 



  
 
  
    // ***************************************************************************************************
    // ***************************************************************************************************
    /*---------------------*/
    /* CATALOGUE MAGNIFIER */
    /*---------------------*/


    $(".catalogueMagnifier").tawImagePreview({
        "targetContainerId": "magnifierPopup",
        "targetImageContainerId": "magnifierPopupImage",
        "targetImageContainerErrorClass": "magnifierPopupImageOnError",
        "targetImageContainerErrorMessage": "No Image available<br /><br />Kein Bild vorhanden",
        "targetDescriptionId": "magnifierPopupSizes",
        "max_width": "300px",
        "max_height": "250px",
        "offsetRight": "25px",
        "offsetLeft": "100px",
        "offsetTop": "18px",
        "offsetBottom": "18px",
        "float": "dynamic",
        "substractCssSize": false,
        "delay": 250
    });



 
	 
	
 



});


 



(function($) {
    $.fn.tawImagePreview = function(options) {

        var defaults = {
            targetContainerId: '',
            targetImageContainerId: '',
            targetImageContainerErrorClass: '',
            targetDescriptionId: '',
            max_width: '100px',
            max_height: '100px',
            offsetLeft: '0px',
            offsetRight: '0px',
            offsetTop: '0px',
            offsetBottom: '0px',
            substractCssSize: false,
            substractPadding: false,
            substractBorder: false,
            float: "right",
            delay: 0
        };

        var options = $.extend(defaults, options);

        return this.each(function() {

            var alt = $(this).attr("alt");
            var title = $(this).attr("title");
            var longdesc = $(this).attr("longdesc");


            var resizePreloadingBox = function(magnifier, image) {

                var offset = $(magnifier).offset();
                var offset_left = offset.left+30;
                var offset_top = offset.top - parseInt(options.max_height);


                $("#" + options.targetImageContainerId).width(options.max_width).height(options.max_height);

                $("#" + options.targetContainerId).css({
                    "position": "absolute",
                    "top": offset_top + "px",
                    "left": offset_left + "px",
                    "width": options.max_width,
                    "height": "auto"
                });

                var tmp_height = $("#" + options.targetContainerId).height();
                offset_top = offset.top - tmp_height;
                $("#" + options.targetContainerId).css({ "top": offset_top + "px" });

                $("#" + options.targetContainerId).show();

            }



            var resizeLoadedBox = function(magnifier, image) {

                $(image).width("auto").height("auto");
                var img_width = $(image).width()+50;
                var img_height = $(image).height()+50;

                if (img_width > parseInt(options.max_width)) {
                    var factorX = parseInt(options.max_width) / img_width;
                    img_width = Math.round(parseInt(options.max_width));
                    img_height = Math.round(img_height * factorX);
                }
                if (img_height > parseInt(options.max_height)) {
                    var factorY = parseInt(options.max_height) / img_height;
                    img_height = Math.round(parseInt(options.max_height));
                    img_width = Math.round(img_width * factorY);
                }

                if (img_width <= 0) img_width = options.max_width;
                if (img_height <= 0) img_height = options.max_height;

                var infobox_width = img_width - parseInt($("#" + options.targetDescriptionId).css("paddingLeft")) - parseInt($("#" + options.targetDescriptionId).css("paddingRight"))

                $(image).width(img_width + "px").height(img_height + "px");
                $("#" + options.targetImageContainerId).width(img_width + "px").height(img_height + "px");
                $("#" + options.targetDescriptionId).width(infobox_width + "px");
                $("#" + options.targetContainerId).width(img_width);

                var offset = $(magnifier).offset();
                var offset_left = checkFloatDirection(offset, img_width);
                var offset_top = offset.top - parseInt(options.max_height);

                $("#" + options.targetContainerId).height("auto").css({ "top": (offset.top - $("#" + options.targetContainerId).height()) + "px" });
                $("#" + options.targetContainerId).show();
            }


            var checkFloatDirection = function(offset, img_width) {
                if (options.float == "right") {
                    var offset_left = offset.left + parseInt(options.offsetRight);

                } else if (options.float == "left") {
                    var offset_left = offset.left - parseInt(options.offsetLeft) - img_width;

                } else if (options.float == "dynamic") {
                    if (offset.left < ($(window).width() / 2)) {
                        var offset_left = offset.left + parseInt(options.offsetRight);
                    } else {
                        var offset_left = offset.left - parseInt(options.offsetLeft) - img_width;
                    }
                }
                return offset_left;
            }


            var stillMouseOver = false;
			
            $(this).hover(
				function() {
					
					stillMouseOver = true;
					
				    $("#" + options.targetContainerId).hide();
				    $(this).attr("title", "");
				    var magnifier = this;
				    var image = $("#" + options.targetImageContainerId + " img");

				    window.tawImagePreviewTimer = setTimeout(function() {

				        resizePreloadingBox(magnifier, image);

				        $("#" + options.targetDescriptionId).html("");
				        $.post(longdesc, function(data) {
							if(stillMouseOver == true){
								$("#" + options.targetDescriptionId).replaceWith('<div id="' + options.targetDescriptionId + '">' + data + "</div>");
								resizeLoadedBox(magnifier, image);
							}
				        });
 $("#" + options.targetDescriptionId).html('<div class= "test">'+longdesc+'</div>')

				        $(image).attr("src", title);
				        $(image).bind('load', function() {
				            $(image).unbind('load');
				            resizeLoadedBox(magnifier, image);
				        }).error(function() {
				            $("#" + options.targetImageContainerId).html('<div class="' + options.targetImageContainerErrorClass + '">' + options.targetImageContainerErrorMessage + '</div>')
				        });
				    }, options.delay);

				},
				function() {
				    clearTimeout(window.tawImagePreviewTimer);
					stillMouseOver = false;
				    $(this).attr("title", title);
				    $("#" + options.targetContainerId).hide();
				    $("#" + options.targetImageContainerId).html('<img src="" alt="" />');
				}
			);
        });
    };
})(jQuery);

(function($){
	$.fn.tawPreloadImages = function(options, func) {
				
		var defaults = {
			image_path: 'ajax-loader.png',
			css_background_class: 'tawImagePreloaderContainer',
			css_background_class_on_error: 'tawImagePreloaderContainerOnError',
			width: "100%",
			height: "100%",
			image_fade_in_time: 200,
			jqSize: false,
			substractCssSize: false,
			substractPadding: false,
			substractBorder: false
		};
		
		
		
		var options = $.extend(defaults, options);		
		
		return this.each(function() {
								  
			var imgs = $('img', this);
			
			if(imgs.length === 0){
				return false;
			} else {
				
     			var loadedImages = [];
				var i = 0;
				
				imgs.each(function(i, val){	
							   
					if(options.jqSize == false) {
						if($(this).width() > 0){
							var rslt_width = $(this).width() + "px";
						} else {
							var rslt_width = options.width;
						}
						if($(this).height() > 0){
							var rslt_height = $(this).height() + "px";	
						} else {
							var rslt_height = options.height;
						}
					} else {
						var rslt_width = options.width;
						var rslt_height = options.height;
					}
					$(this).css({ "visibility": "hidden" });
					$(this).wrap('<div class="' + options.css_background_class + '"></div>');
					
					cssWidth = $(this).parent().css("width");
					cssHeight = $(this).parent().css("height");
					if(cssWidth != "auto" && cssWidth != "0px") rslt_width = cssWidth;
					if(cssHeight != "auto" && cssHeight != "0px") rslt_height = cssHeight;
					
					
					$(this).parent().width(rslt_width).height(rslt_height);
					
					var or_width = $(this).width();
					var or_height = $(this).height();
					
					$(this).bind('load', function () {
												   
						$(this).css({ "visibility": "visible", "display": "none" });
						var randomID = "tawImagePreloaderRandomId" + (Math.floor(Math.random() * 100001));
						$(this).addClass(randomID);
						$(this).parent().replaceWith($(this).parent().html());
						
						if(options.jqSize === true) $("." + randomID).width(options.width).height(options.height);
						
						$("." + randomID).fadeIn(options.image_fade_in_time, function(){
							$(this).removeClass(randomID);
						});
						
						if($.inArray(i, loadedImages) == -1){
							loadedImages.push(i);
							if(loadedImages.length == imgs.length){
								if(func) setTimeout(function(){ func() }, options.image_fade_in_time + 50);								
							}
						}
						
						
					}).error(function() {					
						
						if($(this).width() > 0 && options.jqSize == false){
							if(or_width > 0){
								var rslt_width = or_width + "px";
							} else {
								var rslt_width = $(this).width() + "px";
							}
						} else {
							var rslt_width = options.width;
						}
						if($(this).height() > 0 && options.jqSize == false){
							if(or_width > 0){
								var rslt_height = or_height + "px";
							} else {
								var rslt_height = $(this).height() + "px";
							}
						} else {
							var rslt_height = options.height;
						}
						
						var randomID = "tawImagePreloaderRandomId" + (Math.floor(Math.random() * 100001));
						$(this).parent().replaceWith('<div id="' + randomID + '" class="' + options.css_background_class_on_error + '">' + $(this).attr("alt") + '<div>');
						$("#" + randomID).hide();
											
						cssWidth = $("#" + randomID).css("width");
						cssHeight = $("#" + randomID).css("height");
						if(cssWidth != "auto" && cssWidth != "0px") rslt_width = cssWidth;
						if(cssHeight != "auto" && cssHeight != "0px") rslt_height = cssHeight;
						
						if(options.substractCssSize){
							options.substractPadding = true;
							options.substractBorder = true;
						}						
						if(options.substractPadding === true){
							var paddingTop = parseInt($("#" + randomID).css("paddingTop"));
							var paddingRight = parseInt($("#" + randomID).css("paddingRight"));
							var paddingBottom = parseInt($("#" + randomID).css("paddingBottom"));
							var paddingLeft = parseInt($("#" + randomID).css("paddingLeft"));
							
							rslt_width = (parseInt(rslt_width) - paddingLeft - paddingRight) + "px";
							rslt_height = (parseInt(rslt_height) - paddingTop - paddingBottom) + "px";
						}
						if(options.substractBorder === true){
							var borderTopWidth = parseInt($("#" + randomID).css("borderTopWidth"));
							var borderRightWidth = parseInt($("#" + randomID).css("borderRightWidth"));
							var borderBottomWidth = parseInt($("#" + randomID).css("borderBottomWidth"));
							var borderLeftWidth = parseInt($("#" + randomID).css("borderLeftWidth"));
							
							rslt_width = (parseInt(rslt_width) - borderLeftWidth - borderRightWidth) + "px";
							rslt_height = (parseInt(rslt_height) - borderTopWidth - borderBottomWidth) + "px";
						}
						
						$("#" + randomID).width(rslt_width).height(rslt_height);	
						
						$("#" + randomID).fadeIn(options.image_fade_in_time);
						$("#" + randomID).removeAttr("id");
						
						
						if($.inArray(i, loadedImages) == -1){
							loadedImages.push(i);
							if (navigator.appName == "Netscape") imgslength = imgs.length - 1;
							else imgslength = imgs.length;
							if(loadedImages.length == imgslength){
								if(func) setTimeout(function(){ func(); }, options.image_fade_in_time + 50);
							}
						}
						
					});
						
				}).each(function(){
					  if(this.complete || this.complete === undefined){ this.src = this.src; } //needed for potential cached images
					  
					  i++
					  if(i == imgs.length){
					 	 if(func) setTimeout(function(){ func() }, options.image_fade_in_time + 50);
						 i = 0;
					  }
					  /*
					  if($.inArray(i, loadedImages) == -1){
						  loadedImages.push(i);
						  if(loadedImages.length == imgs.length){
						     if(func) setTimeout(function(){ func() }, options.image_fade_in_time + 50);								
						  }
					  }
						*/
					  $(this).css("visibility", "visible");
					  $(this).parent().removeAttr("id").removeClass();
				});
			}
		});
	};
})(jQuery);



 