$().ready(function()
{
	if ($.browser.safari) {
		$("#NodePad span span span span span span").css("padding-bottom", "0.2em");
		$("#GroheShop span span span span span span").css("padding-bottom", "0.2em");
		$("#LoginBtn span span span span").css("padding-bottom", "0.45em");
		$("#RegisterBtn span span span span").css("padding-bottom", "0.45em");
		$("#Search button").css("margin-top", "0px !important");

		if (navigator.platform.indexOf('mac') != -1)
		{
			$("#Search button span span span span span span").css("font-size", "1em !important");
			$("#Search button.more").css("background-position-x", "0px !important");
			$("#Search button").css("padding-right", "0.25em !important");
		}
	}
	else if ($.browser.mozilla) {
		$("#NodePad span span span span span span").css("padding-bottom", "0.11em");
		$("#GroheShop span span span span span span").css("padding-bottom", "0.11em");
		$("#LoginBtn span span span span").css("padding-bottom", "0.11em");
		$("#RegisterBtn span span span span").css("padding-bottom", "0.11em");
	}

	$('a[target="coffeetable"]').removeAttr("onclick");
	$('a[target="coffeetable"]').click(function() {
		TB_show('', $(this).attr('href') + '?TB_iframe=true&width=865&height=605', false);
		return false;
	});

	thickbox_opener = {};
	thickbox_img_opener = {};

	$('a[target="thickbox"]').each(function(i) {
		result 			= $(this).attr('onclick').toString().match(/width=(\d*),height=(\d*)/i);
		thickbox_opener[i]	= $(this).attr('href') + '&width=' + result[1] + '&height=' + (parseInt(result[2])) + '&TB_iframe=true';

		$(this).removeAttr('onclick');

		$(this).click(function() {
			TB_show('', thickbox_opener[i], false);
			return false;
		});
	});

	$("img[onclick*='flv']").each(function (i) {

		result = $(this).attr('onclick').toString().match(/width=(\d*),height=(\d*)/i);
		href = $(this).attr('onclick').toString().match(/\"[\/A-z0-9\.\?\=]*\"/i);
		href = new String(href);
		href = href.substr(1, href.length-2);

		thickbox_img_opener[i]	= href + '&width=' + result[1] + '&height=' + (parseInt(result[2])) + '&TB_iframe=true';
		
		$(this).removeAttr('onclick');
		
		$(this).click(function() {
			TB_show('', thickbox_img_opener[i], false);

			return false;
		});
	});


	if (typeof sIFR == 'function') {
		if(GroheIsRTL) {
			sIFR.replaceElement(
				named({
					bHideBrowserText: true,
					sSelector: '#SpecProductLine h2, #TabbedContent h2, #ContentHead h1, #Main div.container>h1',
					sFlashSrc: '/page/inc/sifr/Universe.swf',
					sColor: '#525252',
					sLinkColor: '#000000',
					sBgColor: '#FFFFFF',
					sHoverColor: '#CCCCCC',
					nPaddingTop: 0,
					nPaddingBottom: 0,
					sFlashVars: 'textalign=right&offsetTop=0&selectable=false',
					sWmode: 'transparent',
					selectable: false
				})
			);
		}
		else {
			sIFR.replaceElement(
				named({
					bHideBrowserText: true,
					sSelector: '#SpecProductLine h2, #TabbedContent h2, #ContentHead h1, #Main div.container>h1, #Main h1 span',
					sFlashSrc: '/page/inc/sifr/Universe.swf',
					sColor: '#525252',
					sLinkColor: '#000000',
					sBgColor: '#FFFFFF',
					sHoverColor: '#CCCCCC',
					nPaddingTop: 0,
					nPaddingBottom: 0,
					sFlashVars: 'textalign=left&offsetTop=0&selectable=false',
					sWmode: 'transparent',
					selectable: false
				})
			);
		}
		sIFR.replaceElement(
			named({
				bHideBrowserText: true,
				sSelector: '#HomePageContainer .quickNavBox h3, .stockistsSearch .dark h3, #HomePageContainer .myGrohe .dark h3, #HomePageContainer .phoneBox h3',
				sFlashSrc: '/page/inc/sifr/Universe.swf',
				sColor: '#525252',
				sLinkColor: '#000000',
				sBgColor: '#FFFFFF',
				sHoverColor: '#CCCCCC',
				nPaddingTop: 0,
				nPaddingBottom: 0,
				sFlashVars: 'textalign=left&offsetTop=0&selectable=false',
				sWmode: 'transparent',
				selectable: false
			})
		);
		/*sIFR.replaceElement(
			named({
				bHideBrowserText: true,
				sSelector: '#Main h1.ext-headline',
				sFlashSrc: '/page/inc/sifr/Universe.swf',
				sColor: '#525252',
				sLinkColor: '#000000',
				sBgColor: '#FFFFFF',
				sHoverColor: '#CCCCCC',
				nPaddingTop: 5,
				nPaddingBottom: 5,
				sFlashVars: 'textalign=left&offsetTop=0&selectable=false',
				sWmode: 'transparent',
				selectable: false
			})
		);*/
		sIFR.replaceElement(
			named({
				bHideBrowserText: true,
				sSelector: '#HomePageContainer .myGrohe h3,#HomePageContainer .stockistsSearch h3, #HomePageContainer .loginBox h3, #HomePageContainer #right-cell h3',
				sFlashSrc: '/page/inc/sifr/Universe.swf',
				sColor: '#FFFFFF',
				sLinkColor: '#000000',
				sBgColor: '#FFFFFF',
				sHoverColor: '#CCCCCC',
				nPaddingTop: 0,
				nPaddingBottom: 0,
				sFlashVars: 'textalign=left&offsetTop=0&selectable=false',
				sWmode: 'transparent',
				selectable: false
			})
		);
		sIFR.replaceElement(
			named({
				bHideBrowserText: true,
				sSelector: '#Main h1.infoPanel',
				sFlashSrc: '/page/inc/sifr/Universe.swf',
				sColor: '#525252',
				sLinkColor: '#000000',
				sBgColor: '#FFFFFF',
				sHoverColor: '#CCCCCC',
				nPaddingTop: 0,
				nPaddingBottom: 0,
				sFlashVars: 'textalign=left&offsetTop=0&selectable=false',
				sWmode: 'transparent',
				selectable: false
			})
		);
		sIFR.replaceElement(
			named({
				bHideBrowserText: true,
				sSelector: '#HomePageContainer .trans-box-light .ff-headline h1, #HomePageContainer #ff-bl-cont-lo .ff-inner h1',
				sFlashSrc: '/page/inc/sifr/Lino340.swf',
				sColor: '#525252',
				sLinkColor: '#000000',
				sBgColor: '#FFFFFF',
				sHoverColor: '#CCCCCC',
				nPaddingTop: 0,
				nPaddingBottom: 0,
				sFlashVars: 'textalign=left&offsetTop=0&selectable=false',
				sWmode: 'transparent',
				selectable: false
			})
		);
        sIFR.replaceElement(
			named({
				bHideBrowserText: true,
				sSelector: '#HomePageContainer .trans-box-dark .ff-headline h1,#HomePageContainer #ff-br-cont-lo .ff-inner h1',
				sFlashSrc: '/page/inc/sifr/Lino340.swf',
				sColor: '#FFFFFF',
				sLinkColor: '#000000',
				sBgColor: '#FFFFFF',
				sHoverColor: '#CCCCCC',
				nPaddingTop: 0,
				nPaddingBottom: 0,
				sFlashVars: 'textalign=left&offsetTop=0&selectable=false',
				sWmode: 'transparent',
				selectable: false
			})
		);
        sIFR.replaceElement(
			named({
				bHideBrowserText: true,
				sSelector: '#HomePageContainer #ff-bl-subline,#HomePageContainer #ff-bl-headline h1',
				sFlashSrc: '/page/inc/sifr/Lino340.swf',
				sColor: '#FFFFFF',
				sLinkColor: '#000000',
				sBgColor: '#FFFFFF',
				sHoverColor: '#CCCCCC',
				nPaddingTop: 0,
				nPaddingBottom: 0,
				sFlashVars: 'textalign=center&offsetTop=0&selectable=false',
				sWmode: 'transparent',
				selectable: false
			})
		);
        sIFR.replaceElement(
			named({
				bHideBrowserText: true,
				sSelector: '#HomePageContainer #ff-br-teaser span, #ffw-db-headline h1, #ffw-lb-headline h1',
				sFlashSrc: '/page/inc/sifr/Lino340.swf',
				sColor: '#FFFFFF',
				sLinkColor: '#000000',
				sBgColor: '#FFFFFF',
				sHoverColor: '#CCCCCC',
				nPaddingTop: 0,
				nPaddingBottom: 0,
				sFlashVars: 'textalign=left&offsetTop=0&selectable=false',
				sWmode: 'transparent',
				selectable: false
			})
		);
        sIFR.replaceElement(
			named({
				bHideBrowserText: true,
				sSelector: '#FFWppContainer .ffw-db-headline-welcome h1',
				sFlashSrc: '/page/inc/sifr/Lino340.swf',
				sColor: '#FFFFFF',
				sLinkColor: '#000000',
				sBgColor: '#FFFFFF',
				sHoverColor: '#CCCCCC',
				nPaddingTop: 0,
				nPaddingBottom: 0,
				sFlashVars: 'textalign=left&offsetTop=0&selectable=false',
				sWmode: 'transparent',
				selectable: false
			})
		);
	}
});

$().ready(function()
{
	$('span[class="buttonlist"]').each(function()
	{
		var id = this.id;

		var button_timer = 0;
		var button_orignal_width = "";
		var button_width = "";
		var button_height = "";
		var button_hover_padding = "";

		$("#" + id + " .button").mouseover(function()
		{
			clearTimeout(button_timer);

			if (button_width == "" && button_hover_padding == "")
			{
				var w1 = $(this).width();
				var w2 = $("#" + id + " .buttonhover").width();

				button_orignal_width = w1;
				button_height = $("#" + id + " .buttonhover").height();

				if (w2 > w1 + 23)
				{
					button_width = w2 - 23 + 8;
					button_hover_padding = $("#" + id + ".buttonlist").width() - button_width - 23;

					$("#" + id + " .buttonhover").css("width", (button_width+23-8)+"px");
				}
				else
				{
					button_width = w1;
					button_hover_padding = $("#" + id + ".buttonlist").width() - w2 - 23 + 8 + 1;

					if ($.browser.safari) {
						button_hover_padding += 1;
					}

					$("#" + id + " .buttonhover").css("width", (w1+23-8)+"px");
				}
			}

			$("#" + id + " .button").addClass("button-active");
			$("#" + id + " .button").css("width", button_width);
			$("#" + id + " .buttonhover").css("display", "block");
			$("#" + id + " .buttonhover").css("left", button_hover_padding+"px");
		});

		$("#" + id + " .button").mouseout(function()
		{
			clearTimeout(button_timer);
			button_timer = setTimeout(function()
			{
				$("#" + id + " .button").css("width", button_orignal_width+"px");
				$("#" + id + " .button").removeClass("button-active");
				$("#" + id + " .buttonhover").css("display", "none");

			}, 50);

			$("#" + id + " .buttonhover").mouseover(function(){
				clearTimeout(button_timer);
			});

			$("#" + id + " .buttonhover").mouseout(function()
			{
				clearTimeout(button_timer);
				button_timer = setTimeout(function()
				{
					$("#" + id + " .button").css("width", button_orignal_width+"px");
					$("#" + id + " .button").removeClass("button-active");
					$("#" + id + " .buttonhover").css("display", "none");
				}, 50);
			});
		});
	});
});

String.prototype.convertToUnicode = function() {
	return this.replace(
		/&#(([0-9]{1,7})|(x[0-9a-f]{1,6}));?/gi,
		function(match, p1, p2, p3, offset, s) {
			return String.fromCharCode(p2 || ("0" + p3));
	});
}

/**
 *  tccPopupResize
 *  Popupfenster Größe auf Bildgröße anpassen
 *  @since  30.08.2010
 *  @author HF
 *  @param  __popup  Popupfenster (window.open Rückgabewert)
 *  @return false
 */
function tccPopupResize(__popup) {
    try {
        if ($.browser.msie) {
            
            if (__popup.location.pathname.search(/\.(jpe?g|png|gif|bmp)$/) != -1) {
                
                var image = new Image();
                image.onload = function () {
                    __popup.moveTo(0, 0);
                    __popup.resizeTo(image.width + 75, image.height + 125);
                }
                
                image.src = __popup.location.href;
                
            }
            
            __popup.focus();
            
        } else {
            
            __popup.onload = function () {
                if (__popup.location.pathname.search(/\.(jpe?g|png|gif|bmp)$/) != -1) {
                    
                    var image = new Image();
                    image.onload = function () {
                        var offs_y = __popup.outerHeight - __popup.innerHeight + 20;
                        var offs_x = __popup.outerWidth  - __popup.innerWidth + 20;
                        __popup.moveTo(0, 0);
                        __popup.resizeTo(image.width + offs_x, image.height + offs_y);
                    }
                    
                    image.src = __popup.location.href;
                    
                }
                
                __popup.focus();
            }
        }
        
    } catch (e) {
    }
    
    return false;
}

