Cufon.set('fontFamily', 'HelveticaNeueLight');
Cufon.replace('.text-teaser-professionals strong, .institute-finder-selectors h2, .header-v12 h2, #right-col h2, #mainNavi > ul > li > a, .centerpage-header h2, .doctor-babor-centerpage-header h2, .doctor-babor-sub-header h3, .doctor-babor-sub-header h2, .beratung-centerpage-header h2, .default-header h2, .slider-header h2, .products-overview-sub-header .teaser-content h2, .dates-container h2 span, .teaserset-item h2');

function resizeBG() {
	img = jQuery('#backgroundImage');

	var vm	= jQuery(window).width() / jQuery(window).height();
	var im	= jQuery('#backgroundImage').width() / jQuery('#backgroundImage').height();

	if (vm > im)
	{
		jQuery('#backgroundImage').css('width', '100%');
		jQuery('#backgroundImage').css('height', 'auto');
	}
	if (vm < im)
	{
		jQuery('#backgroundImage').css('width', 'auto');
		jQuery('#backgroundImage').css('height', '100%');
	}
}

function addslashes(str) {
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\0/g,'\\0');
return str;
}

(function(jQuery) {

    jQuery.fn.replaceSelect = function (fn) {
         jQuery(this).each(function (index, el) {
            var self = this;
            this.element =  jQuery(el);
            this.callback = fn ||  jQuery.noop;
            this.prepare = function () {
                var opt = this.element.find('option');
                var inp = '<div class="select-container">';
               	  // aw
                inp += '<input type="hidden" name="' + this.element.attr('name') + '" value="' + this.element.val() + '" />';
                inp += '<div class="dropdown-container clearfix">';
                inp += '<div class="dropdown-select">';
                inp += '<a class="selector" href="#">' + opt.filter(':selected').text() + '</a>';
                inp += '</div>';
                inp += '<ul class="dropdown-options hide">';
                opt.each(function (i, o) {
                    var c = '';
                    if (i == 0) c += ' first';
                    if (i == opt.length - 1) c += ' last';
                    inp += '<li class="' + c + '"><a href="javascript: void(0);" rel="' + jQuery(o).val() + '">' + jQuery(o).text() + '&#160;</a></li>';
                });
                inp += '</ul>';
                inp += '</div>';
                inp += '</div>';
                return  jQuery(inp);
            }
            this.element = this.prepare().replaceAll(this.element).dropdown();
            this.element.find('li a').click(function () {
                self.element.find('input:hidden').val( jQuery(this).attr('rel'));
                //eval(onch); // aw
                self.element.find('a.selector').text( jQuery(this).text());
                 jQuery(this).parents('.dropdown-options').hide();

                self.callback(self);
            });
        });
    }



// !jQuery.fn.dropdown
	jQuery.fn.dropdown = function(opts) {
		jQuery(this).each(function(index, el) {
			var self = this;
			this.timeout = false;
			this.element = jQuery(el);
			this.options = jQuery.extend({
				'select': '.dropdown-select .selector',
				'options': '.dropdown-options',
				'timeout': 1250,
				'duration': 250
			}, opts || {});

			this.element.find(this.options.select).click(function(ev) {
				ev.preventDefault();
				self.element.find(self.options.options).toggle();
			});
			
			// aw 11.10.
/*
			this.element.find(this.options.select).mouseleave(function(ev2){
				ev2.preventDefault();
				self.timeout = window.setTimeout(function() {
    				self.element.find(self.options.options).fadeOut(self.options.duration);
    			}, self.options.timeout);			
			});
*/
			// /
			
			// aw 19.10.
			this.element.find(this.options.select).hover(
				function() {
					if (self.timeout)
						window.clearTimeout(self.timeout);
				},
				function() {
					self.timeout = window.setTimeout(function() {
	    				self.element.find(self.options.options).fadeOut(self.options.duration);
	    			}, self.options.timeout);
				}
			);	
			// /			
			
			this.element.find(this.options.options).hover(
				function() {
					if (self.timeout)
						window.clearTimeout(self.timeout);
				},
				function() {
					self.timeout = window.setTimeout(function() {
	    				self.element.find(self.options.options).fadeOut(self.options.duration);
	    			}, self.options.timeout);
				}
			);	
		
			

			
	
			
			
			
		});

		return this;
	}

// !jQuery.fn.slider
	jQuery.fn.slider = function(opts) {
		jQuery(this).each(function(index, el) {
			var self = this;
			this.idle = false;
			this.current = 0;
			this.element = jQuery(el);
			this.options = jQuery.extend({
				'container': '.slider-inner',
				'item': '.item',
				'next': '.next',
				'prev': '.prev',
				'nums': '.number',
				'offset': 1,
				'onstart': function() {},
				'onstop': function() {}
			}, opts || {});
			this.items = this.element.find(self.options.container + ' ' + this.options.item).each(function(i, el) {
				jQuery(el).addClass('item-' + i);
			});

			this.activateRelated = function() {
				this.element.find(this.options.nums).removeClass('active').eq(self.current).addClass('active');
			}
			this.scrollTo = function(offset) {
				if (!self.idle) {
					self.idle = true;
					self.options.onstart(self);
					self.activateRelated();
					self.element.find(self.options.container).animate({ 'scrollLeft': offset }, self.options.duration, function() {
						self.idle = false;
						self.options.onstop(self);
					});
				}
			}
			this.getOffset = function(index) {
				return self.element.find(self.options.container).scrollLeft() + jQuery(self.items[index ? index : self.current]).position().left
			}
			this.scrollNext = function() {
				self.current = (self.current + self.options.offset >= self.items.size()) ? 0 : self.current + self.options.offset;
				self.scrollTo(self.getOffset());
			}
			this.scrollPrev = function() {
				self.current = (self.current - self.options.offset < 0) ? self.items.size() - self.options.offset : self.current - self.options.offset;
				self.scrollTo(self.getOffset());
			}

			this.element.find(this.options.next).click(function(ev) {
				ev.preventDefault();
				self.scrollNext();
			});
			this.element.find(this.options.prev).click(function(ev) {
				ev.preventDefault();
				self.scrollPrev();
			});
			this.element.find(this.options.nums).each(function(index, el) {
				jQuery(el).addClass('number-' + index).removeClass('active').click(function(ev) {
					ev.preventDefault();
					self.current = index;
					self.scrollTo(self.getOffset());
				})
			});
			this.activateRelated();
		});

		return this;
	}

// !jQuery.fn.tabs
	jQuery.fn.tabs = function(opts) {
		jQuery(this).each(function(index, el) {
			var self = this;
			this.current = 0;
			this.element = jQuery(el);
			this.options = jQuery.extend({
				'handlers': '.tab-list li',
				'contents': '.tab-content',
				'active': 'active',
				'direction': false,
				'leftside': 'left-border',
				'rightside': 'right-border',
				'leftsideactive': 'left-active',
				'rightsideactive': 'right-active',
				'current': false,
				'ajax': false,
				'callback': function() {}
			}, opts || {});

			this.setDirections = function() {
				self.handlers.removeClass(self.options.leftside + ' ' + self.options.rightside + ' ' + self.options.leftsideactive + ' ' + self.options.rightsideactive);
				self.handlers.filter(':lt(' + self.current + ')').addClass(self.options.leftside);
				self.handlers.filter(':gt(' + self.current + ')').addClass(self.options.rightside);
				switch (self.options.direction) {
					case 'ltr':
						if (self.current == 0)
							self.handlers.eq(self.current).addClass(self.options.leftsideactive);
						else self.handlers.eq(self.current).addClass(self.options.rightsideactive);
						break;
					case 'rtl':
						if (self.current == self.handlers.length - 1)
							self.handlers.eq(self.current).addClass(self.options.rightsideactive);
						else self.handlers.eq(self.current).addClass(self.options.leftsideactive);
						break;
					default: return;
				}
			}
			this.load = function(num) {
				var num = num || self.current;
				var url = self.handlers.eq(num).is('a') ? self.handlers.eq(num).attr('href') : self.handlers.eq(num).find('a:first').attr('href');
				self.contents.eq(num).addClass('loading').load(
					'js.tabs.php',
					{ 'tab': url },
					function(res) {
						self.contents.eq(num).removeClass('loading');
						self.options.callback(self);
					}
				);
			}
			this.activate = function(num) {
				self.handlers.removeClass(self.options.active);
				self.handlers.eq(num).addClass(self.options.active);
				self.contents.hide();
				self.contents.eq(num).show();
				self.current = num;
				if (self.options.direction)
					self.setDirections();
				if (self.options.ajax)
					self.load(num);
				else self.options.callback(self);
			}
			this.activateHandler = function(ev) {
				ev.preventDefault();
				self.activate(jQuery(this).data('num'));
			}

			this.handlers = this.element.find(this.options.handlers).each(function(index) { jQuery(this).addClass('num-' + index).data({ 'num': index }); }).click(this.activateHandler);
			this.contents = this.element.find(this.options.contents).each(function(index) { jQuery(this).addClass('num-' + index).data({ 'num': index }); });
			this.current = this.contents.index(this.contents.filter(':visible'));
			this.activate(this.options.current ? this.options.current : this.current);
		});

		return this;
	}
// !jQuery.fn.menuHoverDelay
	jQuery.fn.menuHoverDelay = function(opts) {
		var self = this;
		this.options = jQuery.extend({
			'speed': 250,
			'delayIn': 250,
			'delayOut': 500,
			'holder': '> div',
			'property': 'opacity',
			'from': function() { return 0; },
			'to': function() { return 100; }
		}, opts || {});
		this.elements = jQuery(this);

		this.elements.each(function(i, el) {
			var wrapper = jQuery(el).find(self.options.holder);
			var objFrom = {};
				objFrom[self.options.property] = self.options.from(jQuery(el), wrapper, self);
			var objTo = {};
				objTo[self.options.property] = self.options.to(jQuery(el), wrapper, self);
//				wrapper.data('hover' + self.options.property, wrapper.css(self.options.property));
				wrapper.css(objFrom);

			this.over = function(ev) {
				ev.preventDefault();
				jQuery(this).addClass('hover');
				var active = self.elements.filter('.idle').not(jQuery(this)).find(self.options.holder);
				if (active.length)
					active.stop(false, true).delay(100).dequeue('fx').clearQueue('fx');
				wrapper.stop(true, true);
//				wrapper.css(objFrom);
				wrapper.css('overflow', 'hidden');
				wrapper.delay(active.length ? self.options.speed + self.options.delayIn : self.options.delayIn);
				wrapper.animate(objTo, {
					'duration': self.options.speed,
					'complete': function() {
						wrapper.css('overflow', 'visible');
					}
				}).css('overflow', 'hidden');
			}
			this.out = function(ev) {
				ev.preventDefault();
				el = jQuery(this).addClass('idle').removeClass('hover');
				if (wrapper.length) {
					wrapper.stop(true, true);
//					wrapper.css('overflow', 'visible');
//					if (parseInt(wrapper.css(self.options.property).replace(/px|%|em|pt/g, '')) > 0)
					wrapper.delay(self.options.delayOut).animate(objFrom, {
						'duration': self.options.speed,
						'complete': function() {
							wrapper.css('overflow', 'hidden');
							el.removeClass('idle');
						}
					});
				} else el.removeClass('idle');
			}

			jQuery(el).mouseenter(this.over).mouseleave(this.out);
		});

		return this
	}
})(jQuery);

jQuery.noConflict();
jQuery(document).ready(function() {
	jQuery('.tab-container').tabs({
		'handlers': '.tabs li',
		'contents': '.tabs-target-container',
		'active': 'active-tab'
	});


	jQuery('.slider-header').slider({
		'container': '.slider-visuals-container',
		'duration': 1000
	});

	jQuery('.dropdown-container:not(#footerServiceNavi .dropdown-container)').dropdown();
	
	resizeBG();
	jQuery(window).resize(function() {
		resizeBG();
	});	
	
	jQuery(".moreinfo").click(function () {
		jQuery(".product-info ul li.hide").toggle(50);
		jQuery(".moreinfo").toggleClass("moreinfo-active");
	});	
	jQuery('.accordion').accordion({ 
	    active: 0, 
	    header: '.selector', 
	    collapsible: true,
	    animated: 'easeslide',
	    autoHeight: true
	});
	
/*
	jQuery('.institute-finder-selectors select').each(function(i, el){
		var oc = jQuery(el).attr('rel');
		jQuery(el).replaceSelect(function (obj) {
	 		var oci = oc.split(',');
	 		IFC.handleStep(el, oci[0], oci[1]);
		});	
	});
*/

/*
	var oc = jQuery('.institute-finder-selectors select').attr('rel');
	jQuery('.institute-finder-selectors select').replaceSelect(function (obj) {
 		alert(oc);
	});
*/
	
		jQuery('#searchInWebsite').addClass('selected');
		jQuery('#searchInShop').hide();
		jQuery('#searchInWebsite').click(function(){
			jQuery('#searchInWebsite').addClass('selected');
			jQuery('#searchInShop').removeClass('selected');
			jQuery('.searchInSelector:not(.selected)').hide();
		});
		jQuery('#searchInShop').click(function(){
			jQuery('#searchInShop').addClass('selected');
			jQuery('#searchInWebsite').removeClass('selected');
			jQuery('.searchInSelector:not(.selected)').hide();
		});
		jQuery('.searchInSelectorHolderInner').hover(
			function(){jQuery('.searchInSelector:not(.selected)').show()},
			function(){jQuery('.searchInSelector:not(.selected)').hide()}
		);

	
	
	
	
	
});
