// global flag to indicate the availability of touch controls (i.e. on tablet or or mobile phone)
// if true, we apply several fixes to optimize the ui-handling for touch devices
var gHasTouchControls = typeof document.documentElement.ontouchstart !== 'undefined';

/* START main.js */

var layerTimer;
var d_layerName;

jQuery(function() {
    jsUI.tabBox('.tabNav');
    jsUI.toggleService();
});

window.jsUI = {

	tabBox: function(selection) {
		if (selection) {
			jQuery(function() {
				var $ = jQuery;

				$(selection).each(function(_, tabBox) {
					var tabBar = $(tabBox).find('> :first');
					var tabs = $(tabBar).children();
					var contents = $(tabBox).find('> :not(:first)').find('> div');

					var update = function() {
						tabs.each(function(i, elem) {
							var content = $(contents.get(i));

							// Check whether current content is empty, if yes
							// hide it including its related tab.
							if (content.html() && content.html()
									.replace(/<(img|object|embed)\s+[^>]*>/g, '*')
									.replace(/<[^>]*>|&nbsp;/g, '')
									.replace(/^\s+|\s+$/g, '') !== '') {
								$(tabs.get(i)).removeClass('hide').show();
							} else {
								$(tabs.get(i)).hide();
								content.hide();
							} // end: if
						});

						// Determinate active tab.
						var active = tabBar.find('.active:visible:first');

						if (active.size() == 0) {
							active = $(tabs.filter(':visible:first'));
						} // end: if

						// Determinate index of active tab.
						activeIdx = 0;

						tabs.each(function(i, elem) {
							if (elem == active.get(0)) {
								activeIdx = i;
							} // end: if
						});

						// Update tab styles.
						active.removeClass('inactive').addClass('active').css('cursor', 'default');
						tabs.not(active).removeClass('active').addClass('inactive').css('cursor', 'pointer');

						// Show active content, hide non-active content.
						var activeContent = $(contents.get(activeIdx));
						contents.not(activeContent).hide();
						activeContent.removeClass('hide').show();
					}

					update();

					tabs.each(function(_, tab) {
						$(tab).click(function() {
							tabs.not(tab).removeClass('active').addClass('inactive');
							$(tab).removeClass('inactive').addClass('active');
							update();
						});
					});
				});
			});
		} // end: if
	}, // end: function tabBox

	/**
	 * enables slide down for service information elements
	 */
	toggleService: function() {
		var $ = jQuery;
		
	    $(".toggle_container").hide();

		$("h2.trigger").click (function(){
			if (!$(this).hasClass("active")) {
				$(this).addClass("active");
				$(this).next(".toggle_container").slideDown("fast");
			} else {
				$(this).removeClass("active");
				$(this).next(".toggle_container").slideUp("fast");
			}
		});
	},

	/**
	 * ---------------------------------------------------------
	 */
	hoverMenuSimple: function(itemsSelector, hoverClass, delayTimeIn, delayTimeOut) {
		var $ = jQuery;

		if ($.trim(itemsSelector) !== '' && $.trim(hoverClass) !== '') {
			$(function() {
				var delayIn = 0;
				var delayOut = 0;

				if (delayTimeIn > 0) {
					delayIn = delayTimeIn;
				} // end: if

				if (delayTimeOut > 0) {
					delayOut = delayTimeOut;
				} // end: if

				var items = $(itemsSelector);

				// Timer1 is responsible to delay the
				// showing up of the submenus.
				var timer1 = null;

				// Safe version of clearTimeout.
				var clearTimer = function(timer) {
					try {
						clearTimeout(timer)
					} catch (_) {
					} // end: try
				} // end: function clearTimer

				items.each(function(idx, item) {
					// Add event handlers for each main item.
					item = $(item);

					item.mouseover(function() {
						clearTimer(timer1);

						// ---

						timer1 = setTimeout(function() {
							// --- edited by dmc |gm
							if($.browser.msie && parseFloat($.browser.version.substr(0,1)) < 7){
								$('select').css("visibility", "hidden");
							}
							items.not(item).removeClass(hoverClass);
							item.addClass(hoverClass);
						}, delayIn);
					}); // end: mouseover

					item.mouseout(function() {
						clearTimer(timer1);

						// ---

						timer1 = setTimeout(function() {
							items.removeClass(hoverClass);
							// --- edited by dmc |gm
							if($.browser.msie && parseFloat($.browser.version.substr(0,1)) < 7){
								$('select').css("visibility", "");
							}
						}, delayOut);

					}); // end: mouseout
				}); // end: items.each
			});
		} // end: if
	} // end: function hoverMenu
};

/* END main.js */

/* START header.js */

jQuery(function(){
	initHeader();
});

var cont;

function showWKFlyout() {
	if(!jQuery('.headerFunctions .more-basket').hasClass('loaded')) {
		jQuery.get('/store/html/modules/base/header/warenkorb.html', function(data) {
			jQuery('.headerFunctions .more-basket').html(data);
			jQuery('.headerFunctions .more-basket').addClass('loaded');
			jQuery('.headerFunctions .more-basket').show();
			jQuery('#warenkorb_slider').jcarousel({
				vertical: true,
				scroll: 1
			});
		});
	} else {
		jQuery('.headerFunctions .more-basket').show();
	}
}

function hideWKFlyout() {
	jQuery('.headerFunctions .more-basket').hide();
}

var timer = {
	timeout: 400,
	showTask: null,
	hideTask: null,
	showFunc: showWKFlyout,
	hideFunc: hideWKFlyout,
	show: function() {
		if (this.hideTask) {
			window.clearTimeout(this.hideTask);
			this.hideTask = null;
		}

		if (!this.showTask) {
			this.showTask = window.setTimeout(function() { timer.showTask = null; timer.showFunc(); }, this.timeout);
		}
	},
	hide: function() {
		if (this.showTask) {
			window.clearTimeout(this.showTask);
			this.showTask = null;
		}

		if (!this.hideTask) {
			this.hideTask = window.setTimeout(function() { timer.hideTask = null; timer.hideFunc(); }, this.timeout);
		}
	}
};


/**
 * Autosuggestion helper that creates a keyboard-controlled autosuggestion pulldown
 * from a given input and a set of data sources/containers. This module supports an
 * unlimited number of content sources/containers and offers very high flexibility.
 *
 * by Rico Pfaus | dmc
 */
var Autosuggest = (function($) {

    // private fields
    var _input = null,					// target input to use as base
            _popup = null,					// autosuggest popup container
            _curSelection = null,			// currently selected entry in list(s)
            _curContainerId = null,			// array index (!!) of currently active content container (as defined in sources)
            _minChars = null, 				// minimum chars to be entered before autosuggest triggers (default = 2)
            _sources = null,				// list with initialization objects (containerId/url/onBeforeUpdate)
            _defaultText = null,			// initial text in pulldown

        // init function, initializes core attributes and sets up event handling
            _init = function (inputId, popupId, sources, opts) {
                if (!opts)
                    opts = {};
                // init properties
                _input = $(inputId);
                if (_input.data('isAutosuggest') == true) {
                    // only initialize once per input
                    return;
                }
                _popup = $(popupId);
                _sources = sources;
                _minChars = opts.maxChars ? opts.maxChars : 2;
                _defaultText = opts.defaultText ? opts.defaultText : '';
                _curContainerId = 0;
                // setup event handling
                _input
                        .focusin(_onFocusIn)
                        .focusout(_onFocusOut)
                        .keydown(_onKeyDown)
                        .keyup(_onKeyUp)
                        .val(_defaultText)
                        .data('isAutosuggest', true);
                // store array indexes in container elements (needed on mouseover of item li)
                $(sources).each(function (i, d) {
                    $(d.containerId).data('index', i);
                });
            },

        // move the keyboard focus down
            _down = function () {
                if (!_curSelection) {
                    _curSelection = _getContainer().find('li').first().addClass('highlight');
                } else {
                    _curSelection = _curSelection.removeClass('highlight').next().addClass('highlight');
                    if (_curSelection.length == 0) {
                        _nextContainer();
                        _curSelection = null;
                        _down();
                    }
                }
            },

        // move the keyboard focus up
            _up = function () {
                if (!_curSelection) {
                    _prevContainer();
                    _curSelection = _getContainer().find('li').last().addClass('highlight');
                } else {
                    _curSelection = _curSelection.removeClass('highlight').prev().addClass('highlight');
                    if (_curSelection.length == 0) {
                        _curSelection = null;
                        _up();
                    }
                }
            },

        // returns the currently active container element
            _getContainer = function () {
                return _popup.find(_sources[_curContainerId].containerId);
            },

        // returns the previous container element (as defined in sources parameter on init), or the last if already at position 1
            _prevContainer = function () {
                _curContainerId--;
                if (_curContainerId < 0) {
                    _curContainerId = _sources.length - 1;
                }
                if (_getContainer().find('li').length == 0) {
                    // if prev container is empty, skip one
                    return _prevContainer();
                }
                return _getContainer();
            },

        // returns the next container element (as defined in sources parameter on init), or the first if alaready at last posiiton
            _nextContainer = function () {
                _curContainerId++;
                if (_curContainerId == _sources.length) {
                    _curContainerId = 0;
                } else if (_getContainer().find('li').length == 0) {
                    // if next container is empty, skip one
                    return _nextContainer();
                }
                return _getContainer();
            },

        // reset state and remove selection
            _reset = function () {
                if (_curSelection) {
                    _curSelection.removeClass('highlight');
                    _curSelection = null;
                }
                _curContainerId = 0;
            },

        // send a request for the given query and containerId, if "callback" is
        // defined it gets passed the received data and is expected to return it (modified or unmodified)
            _sendRequest = function (url, query, containerId, callback) {
                _input.addClass('loading');
                $.getJSON(url + encodeURIComponent(query), function (data) {
                    _updateContent($.isFunction(callback) ? callback(data) : data, containerId);
                    _input.removeClass('loading');
                });
            },

        // update the content of the first ul within the given container with the supplied JSON data,
        // hides container parent if data is empty
            _updateContent = function (data, containerId) {
                var ul = $(containerId).find('ul').html(''),
                        re = new RegExp($.trim(_input.val()), 'i');
                $.each(data, function(index, item) {
                    var highlightedText = item.value.replace(re, '<strong>' + item.value.match(re) + '</strong>');
                    li = $('<li id="product-' + index + '"><a href="' + item.href + '">' + highlightedText + '</a></li>')
                            .mouseover(function() {
                                var me = $(this);
                                if (_curSelection) {
                                    _curSelection.removeClass('highlight');
                                }
                                _curSelection = me.addClass('highlight');
                                // set current container index to this <li>'s parent container's index
                                _curContainerId = $(containerId).data('index');
                            });
                    ul.append(li);
                });
                if (data.length > 0) {
                    _reset();
                    ul.parent().show();
                } else {
                    ul.parent().hide();
                }
            },

        // focus handler, removes default text
        // TODO: show popup if value not empty ...
            _onFocusIn= function (e) {
                if (!_input.hasClass('focus')) {
                    _input.val('').addClass('focus');
                }
                if (_input.val().length >= _minChars) {
                    _popup.show();
                }
            },

        // blur handler, hides popup after short delay
            _onFocusOut = function (e) {
                window.setTimeout(function() {
                    _popup.hide();
                    _reset();
                    if (_input.val().length == 0) {
                        _input.val(_defaultText).removeClass('focus');
                    }
                }, 200);
            },

        // keydown handler, does most of the magic
            _onKeyDown = function (e) {
                var v = $.trim(_input.val());
                switch (e.keyCode) {
                    case 13:
                        if (_curSelection) {
                            // prevent any kind of form submit
                            e.stopPropagation();
                            e.preventDefault();
                            // open href
                            window.location.href = _curSelection.find('a').attr('href');
                            return false;
                        }
                        break;
                    case 38:
                        _up();
                        break;
                    case 40:
                        _down();
                        break;
                }
            },

        // keyup handler, TOOD: remove
            _onKeyUp = function (e) {
                var v = $.trim(_input.val()),
                        k = e.keyCode;
                _popup.show();
                // if value is at least minChars long and we have a useful keycode
                if (v.length >= _minChars && (e.keyCode < 37 || e.keyCode > 40)) {
                    // load suggestions for all sources
                    $(_sources).each(function(i, d) {
                        _sendRequest(d.url, v, d.containerId, d.onBeforeUpdateContent);
                    });
                }  else if (v.length == 0) {
                    _popup.hide();
                    _reset();
                }
            };

    // return public interface
    return {
        init		: _init,
        up			: _up,
        down		: _down,
        reset		: _reset,
        sendRequest	: _sendRequest
    };

}(jQuery));

function initHeader() {

	jQuery('.headerBasket').hover(
		function(){
			jQuery(this).addClass('hover');
			timer.show();
		},
		function(){
			jQuery(this).removeClass('hover');
			timer.hide();
		}
	);

	jQuery('.headerFunctions .more-basket').hover(
		function(){
			timer.show();
		},
		function(){
			timer.hide();
		}
	);

	/**
	 * Initialize autosuggest input
	 * 
	 * INFO:
	 * the Autosuggest expects returned JSON data to be in a form of 
	 * [
	 * 	   {value:'Keyword 1', href:'/some/url/to/load/when/keyword1/selected?a=1&b=2'},
	 * 	   {value:'Keyword 2', href:'/some/url/to/load/when/keyword2/selected?a=1&b=2'}
	 * ]
	 * 
	 * Where "value" is the value to be shown in the list and "href" the url to open when this
	 * item is selected. To force data into this notation you can use the onBeforeUpdateContent 
	 * calllback within the sources list. See below for an example of how to do this.
	 */
    Autosuggest.init(
            '#topSearch',						// input
            '.headerSearch .auto_suggest',		// popup
            [									// data sources and containers
                {
                    url : '/store/html/modules/base/header/autosuggest.html?channel=products&query=',
                    containerId : '.autosuggest_list',
                    onBeforeUpdateContent : function (data) {
                        // pre-parse data before passing it to updateContent handler
                        var vals = [];
                        jQuery.each(data, function (key, val) {
                            vals.push({'value':val, 'href':'/store/view/search?channel=products&query=' + encodeURIComponent(val)});
                        });
                        return vals;
                    }
                },
                {
                    url : '/store/html/modules/base/header/autosuggest.html?channel=content&query=',
                    containerId : '.autosuggest_red',
                    onBeforeUpdateContent : function (data) {
                        // pre-parse data before passing it to updateContent handler
                        var vals = [];
                        jQuery.each(data, function (key, val) {
                            vals.push({'value':val, 'href':'/store/view/search?channel=content&query=' + encodeURIComponent(val)});
                        });
                        return vals;
                    }
                }
            ],
            {									// options
                maxChars : 2,
                defaultText : 'Suchbegriff oder Best.-Nr.'
            }
    );
}

/* author: ingo dueppe
* This function updates the basket header information after adding new items to the cart.
*/
function updateBasketInHeader()
{
	jQuery('.headerFunctions div.more-basket').removeClass('loaded');
	jQuery.get('/store/html/modules/base/header/warenkorb.html?q=' + Math.random(), function(data) {
		jQuery('.headerFunctions .more-basket').html(data);
		jQuery('.headerFunctions .more-basket').addClass('loaded');
	  jQuery('#warenkorb_slider').jcarousel({
	      vertical: true,
	      scroll: 1
	  });
		jQuery('.headerFunctions .more-basket').hide();
	});
}

/* END header.js */

/* START mainNavigation.js */

jQuery(function(){
	initMainNav();
});

function initMainNav() {

	jQuery('#navBar .navItem')
		.mouseenter(function() {
			showFlyout(this);
		})
		.mouseleave(function() {
			hideFlyout();
		});
	
	var allFlyouts = jQuery('#mainNavigation #flyouts .flyout')
		.mouseenter(function() {
			showFlyout(null);
		})
		.mouseleave(function() {
			hideFlyout();
		});
 
	// touch-enabled-devices: hide flyout if click target is not a flyout or one of it's children or a mainmenu button 
	if (gHasTouchControls) {
		jQuery(document.body).bind('touchend', function(e) {
			var t = jQuery(e.target);
			if (allFlyouts.find(t).length == 0 && t.closest('#flyouts .flyout').length == 0 && t.closest('#navBar').length == 0) {
				hideFlyout();
			}
		});
	}
	
	/*
	 * Kategorien gleichmäßig verteilen
	 */

	if (jQuery('#navBar').length){

		var navItemsWidth = 0;
		jQuery('#navBar li.navItem').each( function(){
			navItemsWidth += jQuery(this).width();
		});
		
		if ((jQuery.browser.chrome || jQuery.browser.safari || jQuery.browser.webkit) && jQuery('#navBar li.navItem img').length){
			jQuery('#navBar li.navItem img').each(
				function(){
					if( jQuery(this).width() == 0 ){
						navItemsWidth += 21;
					}
				}
			);	
		};				

		var countSeparators = jQuery('#navBar li.seperator, #navBar li.firstLeft, #navBar li.lastRight').length;
		var separatorsWidth = jQuery('#navBar li.seperator').width() * countSeparators;
		var menuWidth = jQuery('#navBar').width();
		var countNavItems = jQuery('#navBar li.navItem').length;
		var extraSpace = menuWidth - separatorsWidth - navItemsWidth;

		var paddingAmount = Math.floor(extraSpace/(countNavItems*2));
		jQuery('#navBar li.navItem')
			.css('padding-left', paddingAmount)
			.css('padding-right', paddingAmount);

		var paddingAmountRight = extraSpace % (countNavItems*2);
		jQuery('#navBar li.lastItem')
			.css('padding-left', paddingAmount + Math.floor(paddingAmountRight/2) - 1)
			.css('padding-right', paddingAmount + Math.floor(paddingAmountRight/2) + (paddingAmountRight%2));
	}
}


var flyoutStatus = 0;  // 0 = hidden, 1 = showing, 2 = visible, 3 = hiding
var flyoutTask = null;
var flyoutNode = null;

function showFlyout(node) {
	if (node) {
		flyoutNode = node;
	}
	// 1. cleanup timer
	// 2. update status
	// 3. perform immediate update
	// 4. perform deferred update
	if (flyoutStatus == 0) {
		flyoutStatus = 1;
		flyoutTask = window.setTimeout(function() { updateFlyout(); flyoutStatus = 2; }, 400);
	} else if (flyoutStatus == 1) {
		// do nothing
	} else if (flyoutStatus == 2) {
		updateFlyout();
	} else if (flyoutStatus ==  3) {
		window.clearTimeout(flyoutTask);
		updateFlyout();
		flyoutStatus = 2;
	}
}

function hideFlyout() {
	// 1. cleanup timer
	// 2. update status
	// 3. perform immediate update
	// 4. perform deferred update
	if (flyoutStatus == 0) {
		// do nothing
	} else if (flyoutStatus == 1) {
		window.clearTimeout(flyoutTask);
		flyoutStatus = 0;
	} else if (flyoutStatus == 2) {
		flyoutStatus = 3;
		flyoutTask = window.setTimeout(function() { flyoutNode = null; updateFlyout(); flyoutStatus = 0; }, 400);
	} else if (flyoutStatus ==  3) {
		// do nothing
	}
}

function updateFlyout() {
	jQuery('#mainNavigation #flyouts .flyout').hide();
	jQuery('#navBar li.hover').removeClass('hover');
	jQuery('#navBar li.hoverLeft').removeClass('hoverLeft');
	jQuery('#navBar li.hoverRight').removeClass('hoverRight');

	if (!flyoutNode) {
		return
	}

	jQuery(flyoutNode).addClass('hover');
	var id = jQuery(flyoutNode).index();
	jQuery(jQuery(flyoutNode).parent().find('li').get(id-1)).addClass('hoverLeft');
	jQuery(jQuery(flyoutNode).parent().find('li').get(id+1)).addClass('hoverRight');

	var current_flyout = jQuery(jQuery('#mainNavigation #flyouts .flyout').get((((id+1)/2)-1)));

	var new_left = jQuery(flyoutNode).position().left-11;
	jQuery(jQuery(flyoutNode).parent().find('li').get(id-1)).addClass('hoverLeftStraight');

	if((new_left+current_flyout.width()) > (jQuery('#navBar').width()+13)) {
		new_left = jQuery('#navBar').width()-current_flyout.width()+13;
		jQuery(jQuery(flyoutNode).parent().find('li').get(id-1)).removeClass('hoverLeftStraight');
	}
	if(new_left<15) {
		new_left = 15;
	}
	current_flyout.css('margin-left',new_left);

	current_flyout.show();
}

/* END mainNavigation.js */

/* START footer.js */

jQuery(function() {
	initializeFooter();
});

function initializeFooter() {
	var $ = jQuery;
	
	// Check if the Last Seen Products and the Top Seller Products areas are defined
	var lastSeenProducts = $("#last_seen_articles").length;
	var topSellerProducts = $("#topseller").length;

	// Carousel flags:
	// Default: no carousel is needed
	// Any othe value than 0 will activate the Carousel
	var lastSeen_Slider = 0;
	var topSeller_Slider = 0;

	var lastSeen_SliderWidth = 0;
	var topSeller_SliderWidth = 0;
	
	$('#articles_container').show();
	
	if ( lastSeenProducts == 0) { // Last Seen Products undefined

		if ( topSellerProducts == 0) { // Last Seen Products and Top Seller Products undefined
			$('#articles_container').hide(); // hide the articles container area

		} else { // Last Seen Products undefined, Top Seller Products defined

			var topSellerItemsWidth = $("#topseller li").outerWidth() * $("#topseller li").length;
			var topSellerExtraSpace = $("#topseller").parent().outerWidth() - $("#topseller").parent().width();

			topSeller_SliderWidth =  $("#articles_container_inner").outerWidth() - topSellerExtraSpace;

			if ( topSeller_SliderWidth < topSellerItemsWidth ){
				topSeller_Slider = 1;
				jQuery('#topseller').css('width', topSeller_SliderWidth );
			}

		}

	} else { // Last Seen Products defined
		if ( topSellerProducts != 0) {	// Last Seen Products defined, Top Seller Products defined

			var lastSeenExtraSpace = $("#last_seen_articles .article_list").outerWidth() - $("#last_seen_articles .article_list").width() ;

			if( $("#last_seen_articles li").length > 4) { // Activate Carousel if there are more than 4 Products in the History
				lastSeen_SliderWidth = 430;
				lastSeen_Slider = 1;
			} else {
				lastSeen_SliderWidth = lastSeenExtraSpace + $("#last_seen_articles li").outerWidth() * $("#last_seen_articles li").length;
			}

			jQuery('#last_seen_articles').css('width', lastSeen_SliderWidth);

			var topSellerItemsWidth = $("#topseller li").outerWidth() * $("#topseller li").length;
			var topSellerExtraSpace = $("#topseller").parent().outerWidth() - $("#topseller").parent().width();

			topSeller_SliderWidth = $('#articles_container_inner').outerWidth() - $('#articles_container_inner .articles').filter(':first').outerWidth() - topSellerExtraSpace;

			if( topSeller_SliderWidth  <  topSellerItemsWidth ) {
				topSeller_Slider = 1;
				jQuery('#topseller').css('width', topSeller_SliderWidth );
			}
		}
	}


	if ( lastSeen_Slider != 0) {
		jQuery('#last_seen_articles .slider-container ul').jcarousel({
			scroll: 1,
			animation: 1000
		});

		jQuery('#last_seen_articles .jcarousel-next').css('left',(jQuery('#last_seen_articles .slider-container').width()-jQuery('#last_seen_articles .jcarousel-next').width()-1));

		if(jQuery('#last_seen_articles div.slider-container ul').children().length == 1) {
			jQuery('#last_seen_articles .jcarousel-next, #last_seen_articles .jcarousel-prev').hide();
		} else if (!gHasTouchControls) {
			jQuery('#last_seen_articles .jcarousel-next, #last_seen_articles .jcarousel-prev').animate({ opacity:0},500);
		}
	}


	if (topSeller_Slider != 0 ){
		jQuery('#topseller .jcarousel-next').css('left',(jQuery('#topseller .slider-container').width()-jQuery('#topseller .jcarousel-next').width()-1));

		jQuery('#topseller .slider-container ul').jcarousel({
			scroll: 1,
			animation: 1000
		});

		if(jQuery('#topseller div.slider-container ul').children().length == 1) {
			jQuery('#topseller .jcarousel-next, #topseller .jcarousel-prev').hide();
		} else if (!gHasTouchControls) {
			jQuery('#topseller .jcarousel-next, #topseller .jcarousel-prev').animate({ opacity:0},500);
		}
	}

	// Recommendation Layer
	jQuery('#last_seen_articles a, #topseller a').mouseover(function (e) {
		var d_className = jQuery(this).attr('class');
		window.clearTimeout(layerTimer);
		layerTimer = window.setTimeout(function() {
			jQuery('#toolTips').load('layers/' + d_className+'.html', function() {
				kachel3er_init();

				var mousePoint = e.pageX+20;
				var viewportWidth = jQuery(window).width();
				var layerWidth = 236;
				var checkSize = mousePoint + layerWidth + 25 - viewportWidth;

				if ( checkSize > 0){
					mousePoint = mousePoint - layerWidth - 40;
					jQuery('#toolTips').css('left',mousePoint);
				}

				jQuery('#toolTips').css('display','block');
				jQuery('#toolTips').removeClass('hidden');
			});
		}, 500);
	});

	jQuery('#last_seen_articles a, #topseller a').mousemove(function (e) {
		var new_left = e.pageX+20;
		var new_top = e.pageY+20;

		temp_top_diff = e.pageY - jQuery(document).scrollTop();
		temp_viewport_bottom = jQuery(window).height() + jQuery(document).scrollTop();
		temp_viewport_top = jQuery(document).scrollTop();
		temp_element_height = jQuery('#toolTips',this).height();

		if((new_top+temp_element_height)>(temp_viewport_bottom-358)) {
			new_top = temp_viewport_bottom-358-temp_element_height;
		}
		if(new_top<(temp_viewport_top+10)) {
			new_top = temp_viewport_top+10;
		}

		var viewportWidth = jQuery(window).width();
		var layerWidth = 236;
		var checkSize = new_left + layerWidth + 25 - viewportWidth;

		if ( checkSize > 0){
			new_left = new_left - layerWidth - 40;
		}

		jQuery('#toolTips').css('left',new_left);
		jQuery('#toolTips').css('top',new_top);
	});

	jQuery('#last_seen_articles a, #topseller a').mouseout(function () {
		window.clearTimeout(layerTimer);
		jQuery('#toolTips').addClass('hidden');
		jQuery('#toolTips').empty();
	});

	jQuery('#footer div.sitemap .column').each(function(){

		jQuery(this).height(jQuery(this).parent().height());

	});

}

/* END footer.js */

function initializeToolTip(element, className) {
	$(element).tooltip({
		track: true,
		delay: 0,
		showURL: false,
		fixPNG: true,
		extraClass: className,
		top: -15,
		left: 5
	});
}

// initialize hover effect for all jCarousel slider buttons
function initSliderControlsHoverEffect () {
	jQuery('.jcarousel-container').hover(function (){
		var prevnext = jQuery(this).find('.jcarousel-prev, .jcarousel-next');
		prevnext.stop(true, false);
		prevnext.animate({ opacity: 0.2 }, 500);
	},function (){
		var prevnext = jQuery(this).find('.jcarousel-prev, .jcarousel-next');
		prevnext.stop(true, false);
		prevnext.animate({ opacity: 0 }, 500);
	});
}
if (!gHasTouchControls) {
	jQuery(window).load(initSliderControlsHoverEffect);
}

