(function(A){A.fn.jSuggest=function(D){var F=A.extend({},A.fn.jSuggest.defaults,D);var G=".jSuggestHover";var H="jSuggestHover";var E=this.value;var I=this;var C=this.value;var B="#jSuggestContainer";A("body").append('<div id="jSuggestContainer"></div>');A(B).hide();A(this).bind("keyup click",function(K){I=this;C=this.value;if(this.value.length>=F.minchar&&A.trim(this.value)!="Search Terms"){var J=A(this).offset();A(B).css({position:"absolute",top:J.top+A(this).outerHeight()+"px",left:J.left,width:A(this).outerWidth()-2+"px",opacity:F.opacity,zIndex:F.zindex}).show();if(K.keyCode==27){A(B).hide()}else{if(K.keyCode==13){if(A(G).length==1){A(I).val(A(G).text())}A(B).hide();E=I.value}else{if(K.keyCode==40){if(A(G).length==1){if(!A(G).next().length==0){A(G).next().addClass(H);A(".jSuggestHover:eq(0)").removeClass(H);if(F.autoChange){A(I).val(A(G).text())}}}else{A("#jSuggestContainer ul li:first-child").addClass(H);if(F.autoChange){A(I).val(A(G).text())}}}else{if(K.keyCode==38){if(A(G).length==1){if(!A(G).prev().length==0){A(G).prev().addClass(H);A(".jSuggestHover:eq(1)").removeClass(H);if(F.autoChange){A(I).val(A(G).text())}}else{A(G).removeClass(H);A(I).val(E)}}}else{if(I.value!=E){E=I.value;if(A(".jSuggestLoading").length==0){A('<div class="jSuggestLoading"><img src="'+F.loadingImg+'" align="bottom" /> '+F.loadingText+"</div>").prependTo("#jSuggestContainer")}A(".jSuggestLoading").show();A(B).find("ul").remove();if(F.data==""){F.data=A(this).serialize()}else{F.data=F.data+"="+A(this).val()}setTimeout(function(){A.ajax({type:F.type,url:F.url,data:F.data,success:function(L){A(B).find("ul").remove();A(B).append(L);A("#jSuggestContainer ul li").bind("mouseover",function(){A(G).removeClass(H);A(this).addClass(H);C=A(this).text();if(F.autoChange){A(I).val(A(G).text())}});A("#jSuggestContainer ul li").click(function(){A(this).addClass(H);A(I).val(C)});A(".jSuggestLoading").hide()}})},F.delay)}}}}}}else{A(G).removeClass(H);A(B).hide()}return false});A(document).bind("click",function(){A(B).hide();E=I.value})};A.fn.jSuggest.defaults={minchar:3,opacity:1,zindex:20000,delay:2500,loadingImg:"ajax-loader.gif",loadingText:"Loading...",autoChange:false,url:"",type:"GET",data:""}})(jQuery);
jQuery.fn.autoEllipsis = function(options) {
    var get_AutoEllipsisScroller = function(id) {
        var aeScrollerId = "WingooliAutoEllipsisScroller_" + id
        if (!document.getElementById(aeScrollerId)) {
            var div = document.createElement("div");
            div.id = aeScrollerId + "_Container";
            div.innerHTML = "<span id=\"" + aeScrollerId + "\" style=\"overflow: visible; position: absolute; top: -2000px; color: orange\"></span>";
            document.body.appendChild(div);
        }
        return document.getElementById(aeScrollerId);
    };

    var StringEllipsesByMaxLetters = function(element, originalText, maxLettersAllowed) {
        element.title = "";
        var langText = "legga tutta la info";
        if (window.location.href.match(/\/de\//)) langText = "lesen Sie mehr";
        var text = originalText;
        if (text == null || text == "") text = element.innerHTML;
        var maxAllowedLatterIndex = text.length - maxLettersAllowed;
        if (maxAllowedLatterIndex > 0) {
            element.title = text;
            if (originalText == null)
                originalText = text;
            element.innerHTML = text.substr(0, maxLettersAllowed - 18) + " &hellip; <strong>" + langText + "</strong>";
        } else {
            element.innerHTML = text;
        }
    };

    var _this = this;

    var settings = jQuery.extend({}, options);
    this.each(function(i) {
        var aeScroller = get_AutoEllipsisScroller(i);
        var langText = "legga tutta la info";
        if (window.location.href.match(/\/de\//)) langText = "lesen Sie mehr";
        saeScroller = jQuery(aeScroller);
        sthis = jQuery(this);
        saeScroller.text(sthis.text());

        var origText = sthis.text();

        var element = this;
        var elementBounds = { width: element.offsetWidth, height: element.offsetHeight };

        var jAeScroller = jQuery(aeScroller);
        var jElement = jQuery(element);

        var props = ["font-size", "font-weight", "font-family", "font-style", "padding"];

        for (var i = 0; i < props.length; i++) {
            try {
                jAeScroller.css(props[i], jElement.css(props[i]));
            } catch (ex) { }
        }
        jElement.css("overflow", "visible");


        jAeScroller.width(jElement.width());

        var isIe = (document.all != undefined);
        var scrollerWidth = jAeScroller.width();
        var scrollerHeight = jAeScroller.height();
        var fitText = saeScroller.html();

        while (scrollerHeight > elementBounds.height && fitText != "") {
            fitText = fitText.substr(0, fitText.length - 8);
            var autoScrollerInnerHTML = fitText + " &hellip; <strong>" + langText + "</strong>";
            saeScroller.html(autoScrollerInnerHTML);
            scrollerHeight = jAeScroller.height();
        }
        if (fitText == "") {
            fitText = origText;
            saeScroller.html(fitText);
            jElement.css("whiteSpace", "nowrap");
            jAeScroller.width("");
            var scrollerWidth = jAeScroller.width();
        }
        while (scrollerWidth > elementBounds.width && fitText != "") {
            fitText = fitText.substr(0, fitText.length - 8);
            var autoScrollerInnerHTML = fitText + " &hellip; <strong>" + langText + "</strong>";
            saeScroller.html(autoScrollerInnerHTML);
            scrollerWidth = jAeScroller.width();
        }
        var scrollerHeight = aeScroller.offsetHeight;
        var r = (Math.ceil(elementBounds.height / scrollerHeight) - 1);
        r += (r == 0) ? 1 : 0;
        var maxLettersAllowed = fitText.length * r;

        StringEllipsesByMaxLetters(element, origText, maxLettersAllowed + (r + 1));
    });
}
function checkcompany(sender) {
	if (jQuery('.stateinput0').val() == 'Italy' || jQuery('.stateinput1').val() == 'Italien' || jQuery('.stateinput2').val() == 'Italia') {
		jQuery('#taxcodetd').show();
	}
	else jQuery('#taxcodetd').hide();
	if (sender.checked) {
		jQuery('#companyadditional1').show();
		jQuery('#companyadditional2').show();
		var text = jQuery('#firstnameinput').val() + jQuery('#lastnameinput').val();
		jQuery('#companyadditional1 input').val(text);
	}
	else {
		jQuery('#companyadditional1').hide();
		jQuery('#companyadditional2').hide();
	}
}

function tip () {
	var ind = Math.floor(Math.random() * 3) + 1;
	var content = document.getElementById("a" + ind);
	if(content) content.style.display = "block";
}
function setwindow () {
	MeinFenster =
	window.open("/index.php?id=anfahrt", "Anfahrt", "width=600,height=439,scrollbars=false");
	MeinFenster.focus();
}
function changecolor(sender) {
	var title = sender.title;
	var fontselect = document.getElementById('menu2color');
	if (fontselect) {
		for (var i = 0; i < fontselect.options.length; i++) {
			if (fontselect.options[i].value == title) fontselect.selectedIndex = i;
		}
	}
}
function callLink(sender) {
	var html = sender.innerHTML;
	var ergebnis = html.match(/href="(.*)">/);
	if (ergebnis.length > 0) {
		var chunks = ergebnis[0].split("\"");
		if (chunks.length > 1) {
			var newurl = unescape(chunks[1]);
			newurl = newurl.replace(/&amp;/, "&");
			window.location.href = "/" + newurl;
		}
	}
}

function tx_ratings_submit(ext, rating, type, id) {
	jQuery('#'+id).val(rating);
	var width = 11 * (6 - rating);
	jQuery('.tx-ratings-display .tx-ratings-gold-bar').css('width', width + 'px');
}

function loadspinner(sender) {
	jQuery('#tx-ttproducts-pi1-list').html('<div class="spinner"><img src="fileadmin/templates/pic/spinner.gif" alt="wait a moment" /></div>');
}

window.setTimeout("tip()", 1000);

jQuery(document).ready(function() {
    if (jQuery('.tx-comments-form-top-message').length > 0) {
        jQuery('#c4810 p').css('visibility', 'hidden');
        jQuery('#c4809 p').css('visibility', 'hidden');
        jQuery('#c4808 p').css('visibility', 'hidden');
    }
	if (navigator.userAgent.toLowerCase().match('chrome') || navigator.userAgent.toLowerCase().match('safari')) {
		jQuery('.tx-ratings-display').css('top', '18px');
	}
	jQuery("a[rel]").overlay({
		expose: {
			color: '#333',
			loadSpeed: 200,
			opacity: 0.9
		},
		closeOnClick: true 
	});
	jQuery("a[rel]").css('text-decoration', 'underline');
	if (document.getElementById('thePrice')) jQuery("ul#sizetabs").hide();
	else {
		jQuery("ul#sizetabs").tabs("#tx-ttproducts-pi1-list", {effect: 'ajax'});
	}
	size = gup('tx_ttproducts_pi1[size]');
	if (size != '') {
		//activate tab
		jQuery('#sizetabs .current').removeClass('current');
		jQuery('#sizetabs li').each(function(i) {
			text = jQuery(this).html();
			if (text.indexOf(size) > 0) {
				jQuery(this).find('a').addClass('current');
			}
		});
		//activate right option in select
		jQuery('#menu3sizes option').each(function(i) {
			text = jQuery(this).html();
			if (text.indexOf(size) != -1) jQuery(this).attr('selected', 'selected');
		});
		calcPrice('menu3');
	}
	jQuery('.stateinput0').jSuggest({
         url: "/fileadmin/templates/countries-en.html",
         type: "GET",
         autoChange: true,
         minchar: 1,
         delay: 0
   });
   jQuery('.stateinput1').jSuggest({
         url: "/fileadmin/templates/countries-de.html",
         type: "GET",
         autoChange: true,
         minchar: 1,
         delay: 0
   });
   jQuery('.stateinput2').jSuggest({
         url: "/fileadmin/templates/countries-it.html",
         type: "GET",
         autoChange: true,
         minchar: 1,
         delay: 0
   });
   if (jQuery.trim(jQuery('#realcompanydata').text()) != '') jQuery('#companydata').show();
   jQuery('.lupe').each(function(i) {
        if (!jQuery(this).prev().attr('href')) jQuery(this).remove();
   });
   jQuery('.lupe').click(function() {
        jQuery(this).prev().click();
   });
   jQuery(".autoellipsis").autoEllipsis();
   //jQuery(".tx-ratings-textual").tooltip();
});

function gup(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

