(function($) {

/**
 * Track Action Box Links if available
 * pid-212582 = HKG Deutschland
 * pid-213276 = HKG International
 */
if ($('body').hasClass('pid-212582') || $('body').hasClass('pid-213276')) {
	$('#main a[href*="abId"]').bind('click', function() {
		if (wm_group_name) {
			var href = $(this).attr('href').split('?');
			
			if (href.length > 1) {
				href = href[1].split('=');
				if (href.length > 1) {
					var projectpath = wm_group_name.split('/');
					wiredminds.trackEvent(projectpath[0] + '/' + projectpath[1] + '/actionbox-' + href[1]);
				}
			}
		}
	});
}

/**
 * trigger color change for h1 and h2 if page is loaded into an iframe
 */
if (parent !== this) {
	var v = this.location.search.split('&');
	var s = v[0].split('=');

	if(s[0] =='?color'){
		//var s = this.location.search.split('='),
		var color = '#' + ((1 < s.length) ? s[1] : '000000');
		$('#page_iframe h1, #page_iframe h2').css('color', color);
	}
}

/**
 * Toolbar Navi Layer
 */
$('#toolbar li:has(> div), #language > ul > li, #worldwide > ul > li')
	.bind('mouseenter', function() {
		$(this).find('> div').show();
	})
	.bind('mouseleave', function() {
		$(this).find('> div').hide();
	});

/**
 * Stage Navi (Home)
 */
var interval = window.setInterval(changeTab, 8000);
$('#stageNavi li').bind('mouseenter', function() {
	window.clearInterval(interval);
	
	var $this = $(this),
		$panes = $('#stage li'),
		_class = 'active';
	
	$this
		.siblings()
		.add($panes)
		.removeClass(_class);
	
	$this
		.add($panes.eq($this.index()))
		.addClass(_class);
})
$('#stageNavi').bind('mouseout', function() {
	window.clearInterval(interval);
	interval = window.setInterval(changeTab, 8000);
});

/**
 * Dynamic Link Lists
 */
$('.dynamic .open span, .dynamic .closed span').bind('click', function() {
	$(this).parent()
		.toggleClass('open')
		.toggleClass('closed');
});

/**
 * URL Dropdowns
 */
$('button:submit').each(function() {
	var $this = $(this),
		_elem = 'select',
		$parent = $this.parent(),
		$selects = $this.siblings(_elem); // Look for <select> elements next to the button
	
	if (!$selects.length) { // No <select> next to the button?
		$selects = $parent.siblings(_elem); // Look for <select> elements next to the button's parent
	}
	
	if (!$selects.length) { // No <select> next to the button's parent?
		$selects = $parent.siblings().find(_elem); // Look for <select> elements inside the button's parent
	}
	
	if ($selects.length == 1) { // Exactly 1 <select> element found?
		$selects.bind('change', function() {
			window.location.href = $(this).val();
		});
		$this.bind('click', function(event) {
			event.preventDefault();
			window.location.href = $selects.val();
		});
	}
});

/**
 * Ajax Layer
 */
$('.layer-mini-open, .layer-small-open, .layer-big-open, .layer-bigWidth-open, .layer-special-open').ajaxLayer();

/**
 * Accordion
 */
$('#accordion').accordion({
	header: '.accordion-toggle'
});
$('#accordion_un').accordion({
	animated: false,
	header: '.accordion_un-toggle'
});
$('#accordion_asia').accordion({
	animated: false,
	header: '.accordion_asia-toggle'
});
$('#accordion_hkg').accordion({
	animated: false,
	header: '.accordion_hkg-toggle'
});
$('#accordion_adv').each(function() {
	var index = $('.accordion_asia-toggle').index($('.active',this));
	
	$(this).accordion({
		animated: false,
		header: '.accordion_asia-toggle',
		autoHeight: false,
		active: index
	});
});

/**
 * Carousel
 */
$('#carousel ul').jcarousel({
	scroll: 4,
	initCallback: function(carousel) {
		carousel
			.list
			.parents('.container')
			.parent()
			.delegate('.next_button:not(.next_button_disabled)', 'click', function() {
				carousel.next();
			})
			.delegate('.previous_button:not(.previous_button_disabled)', 'click', function() {
				carousel.prev();
			});
	},
	itemLoadCallback: {
		onBeforeAnimation: function(carousel, state) {
			if (state !== 'init') {
				carousel.list.fadeTo('fast', .5);
			}
		},
		onAfterAnimation: function(carousel, state) {
			carousel.list.fadeTo('fast', 1);
		}
	},
	buttonNextCallback: function(carousel, elem, enabled) {
		var _nextDisabled = 'next_button_disabled',
			$next = carousel.list.parents('.container').siblings('.next_button');
		
		if (enabled) {
			$next.removeClass(_nextDisabled);
		} else {
			$next.addClass(_nextDisabled);
		}
	},
	buttonPrevCallback: function(carousel, elem, enabled) {
		var _prevDisabled = 'previous_button_disabled',
			$prev = carousel.list.parents('.container').siblings('.previous_button');
		
		if (enabled) {
			$prev.removeClass(_prevDisabled);
		} else {
			$prev.addClass(_prevDisabled);
		}
	},
	buttonNextHTML: null,
	buttonPrevHTML: null
});

/**
 * Content Switcher
 */
$('#carousel:not(.ajax) li').contentSwitcher();

/**
 * Ajax Switcher
 */
$('#carousel.ajax li').ajaxSwitcher();

/**
 * Image Chooser (.dlc and .sgl)
 */
$('.dlc-2').imageChooser();
if ($('.sgl-2').length) {
	var $imageChooserElements = $('.sgl-2 .sgl-2-img img');
	if ($imageChooserElements.length > 1 ) {
		$('.sgl-2').addClass('slideshow').find('.sgl-2-ctrl').append('<ul class="slideshow-nav"></ul>');
		$imageChooserElements.unwrap().wrapAll('<div class="slideshow"></div>');
		$('.sgl-2 .slideshow').cycle({
			activePagerClass: 'active',
			fx: 'fade',
			height: '200px',
			next: '.sgl-forward',
			pager: '.slideshow-nav',
			pagerAnchorBuilder: function(index) {
				return '<li>' + (index + 1) + '</li>'; 
			},
			pauseOnPagerHover: 1,
			prev: '.sgl-back',
			slideResize: 0,
			timeout: 0
		});
	}
}

/**
 * Table Switcher
 */
$('.dl-tbl').tableSwitcher();
$('.messe-tbl').tableSwitcher();

/**
 * FAQ Switcher
 */
$('.faq-4 .faq-q, .faq-2 .faq-q, .trouble-4 .trouble-head, .cements .head')
	.not('.empty-faq-element')
	.faqSwitcher();

/**
 * Slider/Scroller
 */
var $slider = $('#track').slider({
	slide: slideContent,
	change: slideContent
});
$('#scroller #button-up')
	.bind('mousedown', function(event) {
		window.sliderTimer = setInterval(function() {
			var val = $slider.slider('option', 'value');
			
			if (val < 0) {
				return;
			}
			
			$slider.slider('option', 'value', val - 2);
		}, 50);
	})
	.bind('mouseup', function(event) {
		clearTimeout(window.sliderTimer);
	});
$('#scroller #button-down')
	.bind('mousedown', function(event) {
		window.sliderTimer = setInterval(function() {
			var val = $slider.slider('option', 'value'),
				max = $slider.slider('option', 'max');
			
			if (max < val) {
				return;
			}
			
			$slider.slider('option', 'value', val + 2);
		}, 50);
	})
	.bind('mouseup', function(event) {
		clearTimeout(window.sliderTimer);
	});
function slideContent(event, ui) {
	var $container = $('#scroll-container'),
		$content = $('#scroll-content ul');
	
	if ($container.width() < $content.width()) {
		$content.css('margin-left', Math.round(ui.value / 100 * ($container.width() - $content.width())));
	} else {
		$content.css('margin-left', 0);
	}
}
function displayInterface() {
	var $interface = $slider
		.add($slider.nextAll())
		.hide();
	
	if ($('#scroll-container').width() < $('#scroll-content ul').width()) {
		$interface.show();
	}
}
function displayContainer(selector, idx) {
	$('.scroller-container-4 > .container-4, .scroller-container2-4 > .container-4, .scroller-container-init-4').hide();
	$(selector)
		.hide()
		.eq(idx)
		.show();
}
$('#scroller .container li').bind('click', function() {
	var _idx = $(this).index(),
		_filter = _filters[_idx],
		$elems = $('#scroll-content li').hide();
	
	for (var i = 0, ii = _filter.length; i < ii; i++) {
		$elems.eq(_filter[i]).show();
	}
	
	displayInterface();
	displayContainer('.scroller-container2-4 > .container-4', _idx);
});
$('#scroll-content a').bind('click', function(event) {
	event.preventDefault();
	displayContainer('.scroller-container-4 > .container-4', $(this).parent().attr('class').split('-')[1]);
});
displayInterface();

/**
 * Large World Map
 */
if ($('#hk-wmmaps').length) {
	$.each({
		'world': ['europe', 'america', 'asia', 'australia'],
		'america': ['canada', 'usa', 'brazil', 'mexico'],
		'europe': ['benelux', 'germany', 'france', 'greatbritain', 'italia', 'austria', 'swiss', 'scandinavia', 'spain', 'centraleasteurope', 'southeasteurope', 'commonindependantstates'],
		'asia': ['combination', 'china', 'japan', 'singapore', 'korea']
	}, function(continent, countries) {
		$.each(countries, function(idx, country) {
			$('<div/>')
				.attr('id', 'hk-wm' + country + '-high')
				.appendTo($('#hk-wmmap-' + continent + '-hl'));
		});
		if (continent != 'world') {
			$('<div/>')
				.attr('class', 'hk-back-map-high')
				.appendTo($('#hk-wmmap-' + continent + '-hl'));
		}
	});
	$('area[href=#].hk-wmmap-continent:not(.hk-back-map)')
		.bind('click', function(event) {
			event.preventDefault();
			$('#' + this.className.split(' ')[1]).css('left', 0);
		})
		.add($('area.hk-wmmap-country, area[href!=#]'))
		.bind('mouseenter mouseleave', function() {
			var _class = this.className.split(' ')[1];
			$('#' + _class + '-high').toggle();
			$('a.' + _class + '').toggleClass('hilite');
		});
	$('area.hk-wmmap-continent.hk-back-map').bind('click', function(event) {
		event.preventDefault();
		$('#' + this.className.split(' ')[2]).css('left', -1000);
	});
}


/**
 * Small World Map
 */
if ($('.worldmap').length) {
	$('#wm-continent li a').each(function() {
		var $this = $(this),
			$parent = $this.parent(),
			$siblings = $parent.siblings().find('a'),
			$world = $('#wm-countries'),
			$continents = $world.find('.wm-country'),
			$continent = $($this.attr('href')),
			$connector = $('#wm-line'),
			_position = $parent.position(),
			_connectorTop = Math.round(_position.top + $parent.outerHeight() / 2 - $connector.outerHeight() / 2),
			_connectorLeft = _position.left + $parent.outerWidth() - 1,
			_over = 'over',
			_current = 'current';
		
		$this
			.bind('click', function(event) {
				event.preventDefault();
				$('.worldmap .wm-contacts').hide();
				$('.worldmap .wm-country li a').removeClass('bold');
				$siblings
					.removeClass(_current)
					.removeClass(_over);
				$this
					.addClass(_current);
				$continents.hide();
				$continent.show();
				$connector
					.css({
						left: _connectorLeft,
						top: _connectorTop,
						width: $world.position().left - _connectorLeft + 1
					})
					.show();
			})
			.bind('mouseover', function() {
				$this.addClass(_over);
				$world.show();
				if (!$siblings.hasClass(_current)) {
					$continent.show();
				}
			})
			.bind('mouseout', function() {
				if (!$this.hasClass(_current)) {
					$this.removeClass(_over);
					if (!$siblings.hasClass(_current)) {
						$world
							.add($continent)
							.hide();
					}
				}
			});
	});
	$('.worldmap .wm-country li a').bind('click', function(event) {
		var $this = $(this);
		event.preventDefault();
		$('.worldmap .wm-contacts').hide();
		$this
			.addClass('bold')
			.parent()
			.siblings()
			.find('a')
			.removeClass('bold');
		$($this.attr('href')).show();
	});
}

/**
 * News Rotator (
 */
if($('#rotator_pager').length){
	$('#rotator_pager')
	.append('<div id="nav">')
	.cycle({
		pager: '#nav',
			slideExpr:'.contentWrapper_voll',
		timeout: 4000,
		speed: 1,
		pagerAnchorBuilder: function(index){
			return '<a href="#"></a>';
		}
	});
}else{
	// rotator_pager with Pager (PALA))
	if($('#rotator_pager_index').length){
		$('#rotator_pager_index')
		.append('<div id="nav">')
		.cycle({
			pager: '#nav',
				slideExpr:'.contentWrapper_voll',
			timeout: 4000,
			speed: 1,
			pagerAnchorBuilder: function(index){
				return '<a href="#">'+(index+1)+'</a>';
			}
		});
	}else{
		$('.rotator').cycle({
			speed: 1
		});
	}
}

/**
 * Dia Slider
 */
$('#dia').diaSlider();
$('#diaContainer .textBoxWrapper').each(function() {
	var $this = $(this),
		_height = $this.height(),id=""
		$link = $this.find('a'),
		_linkHeight = $link.height();
	if (_linkHeight < _height) {
		$link.css('margin-top', Math.round((_height - _linkHeight) / 2));
	}
});

/**
 * Lightbox for images
 */
$('a[rel^=lightbox]').slimbox({
	captionAnimationDuration: 1,
	counterText: false,
	imageFadeDuration: 1,
	overlayFadeDuration: 1,
	overlayOpacity: .5,
	resizeDuration: 1
});

/**
* Colorbox for html-pages - Chart-Lightbox
*/
$('a.charticon').colorbox({ 
	inline: true, 
	href: "#chart-wrapper", 
	opacity: 0.7, 
	close: "Schlie&szlig;en",
	onOpen: function() {
		var $this = $(this).parent();
		//find all pre-selected items and display them
		var selected = $this.parents('table').find('*[data-sel=true]');
		if($this.attr('data-cat') != undefined && $this.attr('data-cat') != '') {
			selected = selected.filter('*[data-cat='+$this.attr('data-cat')+']');
			selected = selected.add($('.charttable thead th[data-sel=true]'));
		}
		$('.legend input').removeAttr("checked");
		selected.each(function() {
			var name = $.trim($(this).text());
			
			$('.legend label span').each(function() {
				//has same text => then check input
				var label = $(this).text();
				if(label.indexOf(' [') > -1) {
					label = label.substr(0,label.indexOf(' ['));
				}
				if(label == name) {
					$(this).prevAll('input').attr("checked","checked");
				}
			});
		});
		
		updateChart();
	}
});

/**
* Design Chart 
* More Infos: Stofi-Wiki
**/
$('#chart-container').each(function() {
	$(this).initChart();
});
//Changes Charttype from column to line
$('.chart-nav li').live('click',changeChartType);
//Highlight row on mouseover
$('.charttable td').live('mouseover',function() {
	var line = $(this).add($(this).prevAll("td")).add($(this).nextAll("td"));
	line.css("background-color","#7D8890");
	line.css("color","#ffffff");
}).live('mouseout', function() {
	var line = $(this).add($(this).prevAll("td")).add($(this).nextAll("td"));
	line.css("background-color","");
	line.css("color","");
});
//only for two-column-tables
$('#donutchart').each(function() {
	$(this).initDonutChart();
});
//init piechart
$('a.donuticon').colorbox({ 
	inline: true, 
	href: "#chart-wrapper", 
	opacity: 0.7, 
	close: "Schlie&szlig;en",
	onOpen: function() {
		var $this = $(this).parent();
		//set data-sel-Attribute for clicked country
		$('.charttable td span.country').attr("data-sel", "");
		$('.country', $this).attr("data-sel", "true");
		
		var selected = $this.parents('table').find('*[data-sel=true]');
		selected = selected.add($('.charttable tbody td[data-value=true]'));
		
		$('.legend input').removeAttr("checked");
		selected.each(function() {
			var name = $(this).text();
			
			$('.legend label span').each(function() {
				//has same text => then check input
				var label = $(this).text();
				if(label.indexOf(' [') > -1) {
					label = label.substr(0,label.indexOf(' ['));
				}
				if(label == name) {
					$(this).prevAll('input').attr("checked","checked");
				}
			});
		});
		updateChart();
	}
});


/**
 * Breadcrumb
 */
var $breadcrumb = $('#breadcrumb'),
	bcCount = 1;
$breadcrumb
	.find('li:not(.firsec)')
	.removeClass('active')
	.addClass('open')
	.last()
	.removeClass('open')
	.addClass('active');
while (29 < $breadcrumb.outerHeight()) {
	$breadcrumb
		.find('li:eq(' + (++bcCount) + ') a')
		.html('...');
}

/**
 * Wired Minds Download Counter
 */
$('.file-link').bind('click', function() {
	if (window.wiredminds && typeof wiredminds.count == 'function') {
		wiredminds.count(this.href.replace(/^http:\/\/[a-zA-Z0-9\.\-_\/]*[\/]/g, ''));
	}
});

/**
 * print_page from functions.js
 */
$('#metaNavi .print a ,  #garantie a.print, .sidebar-1 .print a').bind('click', function(event) {
	event.preventDefault();
	
	var loc = window.location,
		newLoc = loc.href + ((loc.search) ? '' : '?') + '&print=1',
		printWin = window.open(newLoc, 'printWindow', 'width=664, height=700, left=300, top=150, scrollbars=1');
	
	printWin.focus();
});

/**
 * und_weg from functions.js
 */
$('#not_visible_print a').bind('click', function(event) {
	event.preventDefault();
	
	$(this).parent().hide();
	window.print();
});

/**
 * A to Z wo DB
 */
$('.atozlistitem').hide();
$('#indizes a').bind('click', function(event) {
	event.preventDefault();
});
$('#indizes a:not(.wolink)').bind('click', function(event) {
	$('#atoz' + this.id.split('-')[1])
		.show()
		.siblings()
		.hide();
});

/**
 * Remove flash inside accordeon on window unload
 */
$(window).bind('beforeunload', function(event) {
	$('.accordion-content object').remove();
});


/**
 * set_black_bar_height from functions.js (Venus, Flexitime; IBOND, Hera = noBar)
 */
var $leftCol = $('#left_column, #leftCol'),
	$rightCol = $('#right_column, #rightCol'),
	$noBar = $('.noBar');


if ($leftCol.length && $rightCol.length && $noBar.length == 0 ) {
	var leftColHeight = $leftCol.height(),
		rightColHeight = $rightCol.height(),
		newRightColHeight = 0,
		diff = 0;
	if (leftColHeight <= rightColHeight) {
		newRightColHeight = rightColHeight + 95;
	} else {
		diff = leftColHeight - rightColHeight;
		if (diff < 95) {
			newRightColHeight = rightColHeight + diff;
		} else {
			newRightColHeight = leftColHeight;
		}
	}
	if (rightColHeight <= 453) {
		newRightColHeight = 525;
	}
	$rightCol.height(newRightColHeight);
}

/**
 * check from functions.js
 */
var colready = "doesnotexist";
	colready = $('#background_right').html();
	if (colready == "x"){
		var allElems = document.getElementsByTagName('*');
		for (var i = 0; i < allElems.length; i++) {
			var thisElem = allElems[i];
			if (thisElem.className && thisElem.className == 'col') {
				var myElem = thisElem; 
			}
		}
		myElem.setAttribute("id","image-bild")
	}

/**
 * empfehlen from functions.js
 */
$('.recomend').bind('click', function(event) {
	$('.recomend-layer').css("display","block");	
});

/**
 * empfehlenSchliessen from functions.js
 */
$('.layer-close').bind('click', function(event) {
	$('.recomend-layer').css("display","none");	
});

/**
 * deuterium from functions.js
 */	
if (!$('#result_deuterium table').length) {
	$('#result_deut').hide();
}

if (!$('#res_content').length) {
	$('#result_hc').hide();
}

/**
 * HNG Worldmap w Contactform from functions.js
 */	
try{
var recready = $('#formrecipient');
if (recready.length){
	var getselectedcountry = document.getElementById("ctrlContactUs_ddl2Panel").value;
	var selecteddivisionready = $('#ctrlContactUs_ddl3Panel');
	
	var geturl = window.location.href;
	var mysplit = geturl.split("//");
	mysplit = mysplit[1];
	mysplit = mysplit.split("/");
	mysplit = mysplit[1];
	if(mysplit == "de"){
		$('.formrecipient').html("Kontaktformular");
	}
	
	if (!selecteddivisionready == null || !selecteddivisionready == ""){
		var getselecteddivision = document.getElementById("ctrlContactUs_ddl3Panel").value;
		getselectedcountry = getselecteddivision;
		if(mysplit == "de"){
			$('.formrecipient').attr('href','?recipient='+getselectedcountry+'');						
		}else{
			$('.formrecipient').attr('href','?recipient='+getselectedcountry+'');
		}
	}
	else{
		if(mysplit == "de"){
			$('.formrecipient').attr('href','?recipient='+getselectedcountry+'');
		}else{
			$('.formrecipient').attr('href','?recipient='+getselectedcountry+'');
		}
	}
	

}
}catch(err){}		

/*End*/

/**
 * zweiter klick im contact formular unterbinden 
 */
//(nur fuer formulare die mit .net validieren und nicht mit js) 
if($('.nojs').length){
	$('.submitButton').bind('click', function() {
			this.disabled=true;
			this.form.submit();		
	});
} 	

/** 
 * formhandling - user does not use javascript  
 */
if($('.form-grp #_recipients').length){
	 $('.form-grp #_recipients').change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str += $(this).text();
              });
          if($('.rcp-aspx-id').length){
			$('.rcp-aspx-id').attr('value',str);
		  }
        })
        .change();
}

/**
 * free snippets from functions.js
 */	
try {
var arrow = document.getElementById('promoArrow');
var action_pos = 0;
	
if(arrow){
	action_pos = getYpos(arrow)-110;
	arrow.style.top = action_pos+"px";
	window.setTimeout(function(){
		arrowHide(arrow);
	}, 5000);
}
}catch(err){}
		
function arrowHide(element){
	element.style.display = 'none';
}

function getYpos(element){
	return (element.offsetParent) ? element.offsetTop + getYpos(element.offsetParent) : element.offsetTop;
}


$('#play-button').bind('click', function(event) {
			play();
	});
	

/**
 * Start Coverflow 
 */
if($('#coverflow').length){
	var $coverflow = $('#coverflow').coverflow({
			select: function(event, item) {
				var $item = $(item.item);
				var $current = $item.find('div > img');
				var $siblings = $item.siblings().find('div > img');
				
				$current.attr('src', $current.attr('src').replace('.','_a.'));
				$siblings.each(function() {
					$(this).attr('src', $(this).attr('src').replace('_a.','.'));
				});
			}
		}),
		$cfItems = $coverflow.find($coverflow.coverflow('option', 'items')),
		$cfSlider = $('<div id="coverflow-slider"><a class="bullet"></a></div>')
			.appendTo(
				$('<div id="coverflow-slider-wrapper"></div>').insertAfter($('#coverflow-wrapper'))
			),
		$cfBack = $('<span id="coverflow-back"></span>')
			.insertAfter($coverflow)
			.bind('click', function(event) {
				if($coverflow.coverflow('option', 'isAnimated')) {
					return false;
				}
				$coverflow.coverflow('select', $coverflow.find('.current').index() - 1);
				window.clearInterval(cfTimeout);
			}),
		$cfForward = $('<span id="coverflow-forward"></span>')
			.insertAfter($cfBack)
			.bind('click', function(event) {
				if($coverflow.coverflow('option', 'isAnimated')) {
					return false;
				}
				$coverflow.coverflow('select', $coverflow.find('.current').index() + 1);
				window.clearInterval(cfTimeout);
			});
	var slideElemWidth = 0;
if($coverflow.find('.current div img').length>0) {
	$coverflow.find('.current div img').attr('src', $coverflow.find('.current div img').attr('src').replace('.','_a.'));
}
	var cfTimeout = window.setInterval(function() {
		$coverflow.coverflow('select', $coverflow.find('.current').index() + 1);
	}, 5000);
	
	if($.browser.msie) {
		var v = $.browser.version;
		if(v=='7.0') {
			$('#coverflow-wrapper').addClass('ie7');
		}
	}

	/*$('#slider > li').each(function() {
		$(this).width( $(this).parent().parent().width() / ($(this).parent().find('li').length ) );
	});
	$('#coverflow-slider a').width($('#coverflow-content > li').width());
	$('#coverflow-slider').width($('#coverflow-slider').width() - $('#coverflow-content > li').width());*/
}
/* End Coverflow */	

/* Coverflow Startseite Noblelight */
$('#cycle').cycle({ 
    fx: 'scrollHorz', 
	activePagerClass: 'active',
    speed: 1200, 
    timeout: 7000, 
    pause: 1,
	pauseOnPagerHover: 1,
	pager: '#cyclenav',
	pagerEvent: 'mouseover',
	pagerAnchorBuilder: function(idx, slide) { 
        return '#cyclenav li:eq(' + idx + ') a'; 
    }
});
	
/* Heraeus Dental Header Toolbar */	
var xmlLocation = "/controls/XmlProxy.aspx?remoteUrl=http://hkg-international.pre.heraeus.com/en/_technik/toolbar_xml.xml";

if ($('#heraeusdental-toolbar').length != 0) {
	function parseTabContent(obj, type) {
		var xpath = "";
		if (type == "dent") {
			xpath = "company[dent=true]";	
		}
		else if (type == "lab") {
			xpath = "company[lab=true]";	
		}
		else {
			xpath = "company";	
		}
		var html = '<ul>';		
		var itemCount = 1;
		var rowCount = 1;
		var cellCount = 1;
		obj.find(xpath).each(function() {					
			html += '<li class="r' + rowCount + '-c' + cellCount + '">';
			html += '<a href="' + $(this).find('link').text() + '" title="' + $(this).find('name').text() + '">';
			html += '<img src="' + $(this).find('logo').text() + '" alt="' + $(this).find('name').text() + '" />';
			html += '<span>' + $(this).find('description').text() + '</span></a></li>';	
			if (itemCount % 12 == 0) {
				html += '</ul><ul>';
				cellCount = 0;
				rowCount = 1;
			}
			cellCount++;
			itemCount++;
			if (cellCount > 4) {
				rowCount++;
				cellCount = 1;
			}
		});
		itemCount--;
		do{
			html += '<li class="r' + rowCount + '-c' + cellCount + ' empty"></li>';
			cellCount++;
			itemCount++;
			if (cellCount > 4) {
				rowCount++;
				cellCount = 1;
			}
		} while (itemCount % 12 != 0);
		html += '</ul>';
		return html;
	}
	if($.getUrlVar('lang') !== undefined) {
		var lang = $.getUrlVar('lang');	
	}
	else {
		if ($('meta[name=toolbar_lang]').length > 0 ) {
			var lang = $('meta[name=toolbar_lang]').attr("content");
		}
		else {
			var lang = "en_en";
		}	
	}
	if (lang.indexOf('_') < 1) {
		lang = lang + '_' + lang;
	}
	
	
	$('body').append('<div id="heraeusdental-toolbar-pagelock"></div>');
	$.ajax({
        type: "GET",
		url: xmlLocation,
		dataType: "xml",
		success: function(xml) {
			$(xml).find('language[type=' + lang + ']').each(function() {
				//HTML parsen
				var html = '<div id="heraeusdental-toolbar-content">';
				html += '<ul class="worldmap"><li class="first">Heraeus Dental</li><li><a href="' + $(this).find('languageLink').text() + '" alt="">' + $(this).find('languageName').text() + '</a></li>';
				html += '<li><a href="' + $(this).find('wolrdwideLink').text() + '" alt="">' + $(this).find('wolrdwideName').text() + '</a></li></ul>';
				html += '<ul class="tabs"><li id="tabs-all" class="active">' + $(this).find('nameTabAll').text() + '</li><li id="tabs-dent">' + $(this).find('nameTabDent').text() + '</li><li id="tabs-lab">' + $(this).find('nameTabLab').text() + '</li></ul>';
				html += '<div class="tabs-move left"></div><div class="tabs-move right"></div><div class="tabs-content">';				
				html += '<div id="tabs-all-content" >';		
				html += parseTabContent($(this), "all");
				html += '</div>';
				html += '<div id="tabs-dent-content" >';		
				html += parseTabContent($(this), "dent");
				html += '</div>';
				html += '<div id="tabs-lab-content" >';		
				html += parseTabContent($(this), "lab");
				html += '</div></div></div>';				
				$('body').append(html);			
				//Events binden
				$('#heraeusdental-toolbar').click(function() {
					if (! $('#heraeusdental-toolbar-pagelock').hasClass('open')) {
						$('#heraeusdental-toolbar-pagelock').fadeTo(200, 0.5, function() {
							$(this).addClass('open');				
						});
						$('#heraeusdental-toolbar-content').slideDown(300);
						$('#heraeusdental-toolbar').addClass('open');
					}
					else {
						$('#heraeusdental-toolbar-pagelock').fadeTo(200, 0, function() {
							$(this).removeClass('open');
							$(this).hide();
						});
						$('#heraeusdental-toolbar-content').slideUp(300, function() {
							$('#heraeusdental-toolbar').removeClass('open');
						});
					}	
					return false;
				});
				$('#heraeusdental-toolbar-pagelock').click(function() {
					$('#heraeusdental-toolbar-pagelock').fadeTo(200, 0, function() {
						$(this).removeClass('open');
						$(this).hide();
					});
					$('#heraeusdental-toolbar-content').slideUp(300, function() {
						$('#heraeusdental-toolbar').removeClass('open');
					});
				})	
				
				var activeTab = $('#heraeusdental-toolbar-content .tabs li.active').attr('id');
				var activePage = 1;
				//Tabs umschalten
				$('#heraeusdental-toolbar-content .tabs li').click(function() {
					if (! $(this).hasClass('active')) {
						$('#heraeusdental-toolbar-content .tabs li').removeClass('active');
						$(this).addClass('active');
						$('#' + activeTab + '-content').hide();
						activeTab = $(this).attr('id');
						$('#' + activeTab + '-content').show();
						activePage = 1;
						$('#' + activeTab + '-content').css('left', '0px');
						$('#heraeusdental-toolbar-content .tabs-move.left').hide();
						if ($('#' + activeTab + '-content>ul').length > 1) {
							$('#heraeusdental-toolbar-content .tabs-move.right').show();
						}
						else {
							$('#heraeusdental-toolbar-content .tabs-move.right').hide();
						}
					}
				});				
				//Tab-Inhalte bl�ttern
				var moveStep = $('#heraeusdental-toolbar-content .tabs-content ul').width();
				var locked = false;
				if ($('#' + activeTab + '-content>ul').length > 1) {
					$('#heraeusdental-toolbar-content .tabs-move.right').show();
				}
				$('#heraeusdental-toolbar-content .tabs-move.right').click(function() {	
					if (!locked) {
						locked = true;
						$('#' + activeTab + '-content').animate({left: '-' + (moveStep * activePage) + 'px'}, 300, function() {
							locked = false;
						});
						activePage++;
						if (activePage >= $('#' + activeTab + '-content>ul').length) {
							$('#heraeusdental-toolbar-content .tabs-move.right').hide();
						}
						if (activePage > 1) {
							$('#heraeusdental-toolbar-content .tabs-move.left').show();
						}
					}
				});	
				$('#heraeusdental-toolbar-content .tabs-move.left').click(function() {	
					if (!locked) {
						locked = true;
						activePage--;
						$('#' + activeTab + '-content').animate({left: '-' + (moveStep * activePage - moveStep) + 'px'}, 300, function() {
							locked = false;
						});	
						if (activePage == 1) {
							$('#heraeusdental-toolbar-content .tabs-move.left').hide();			
						}
						if (activePage < $('#' + activeTab + '-content>ul').length) {
							$('#heraeusdental-toolbar-content .tabs-move.right').show();
						}
					}
				});	
				//Hover �ber Kachel
				$("#heraeusdental-toolbar-content .tabs-content li a").hover(
				  function () {
					$(this).fadeTo(0,0.95)
				  }, 
				  function () {
					$(this).fadeTo(0,1)
				  }
				);
			});
		}
	});	
}	
	
	
/**
 ** Heraeus Pala - Systemkreis *
 */
$('#slideWrapper .slider').cycle({
	timeout: 0,
	prev: '#prev',
	next: '#next',
	pager: '#slideNav',
	after: onAfter,
	cleartypeNoBg: true,
	pagerAnchorBuilder: function(idx, slide) {
		if(idx==0) {
			return '<div class="start"><a href="#">'+$(slide).attr("data-name")+'</a></div>';
		} else {
			return '<div><a href="#">'+$(slide).attr("data-name")+'</a></div>'; 
		}
	}
}); 
$('#slideNav div').each(function() {
	if(navigator.appVersion.indexOf('MSIE 7.')>-1) {
		$('a',$(this)).css('margin-top',($(this).height()-$('a',$(this)).height())/2 + 'px')
			.css('display','block');
	}
});
// Button "Zurueck zur Uebersicht" 
$('#slideWrapper .slide').each(function(idx) {
	if(idx>0) {
		var overview = $('<a href="#" id="overview">'+$('#slideWrapper .slide:eq(0)').attr('data-name')+'</a>')
		$(this).prepend(overview);
		overview.bind('click', function() {
			$(this).parents('.slider').cycle(0); 
			return false; 
		});
	}
});

function onAfter(curr, next, opts) {
	var index = opts.currSlide;
	$('#prev')[index == 0 ? 'hide' : 'show']();
	$('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
} 	

/*END Heraeus Pala - Systemkreis */	


 
}(jQuery));

// http://code.google.com/p/doctype/wiki/ArticleFixingFlashExternalInterface#Internet_Explorer_Page_Unload_Bug
(function(){var s=function(){window.__flash__removeCallback=function(i,n){if(i)i[n]=null;};window.setTimeout(s,10);};s();})();

/**
 * Start: Cara und HeraCeram
 */

/**
 * rollierende Teaser f�r Cara und HeraCeram
 */
function rollTeasers() {
	$('.teaser-main-content .teasers').each(function() {
		var contentWidth = $('.teaser-main-content').width();	
		if($(this).find('>li').length > 1) {
			if (! $(this).parents('.teaser-main').hasClass('locked')) {
				if ($(this).parents('.teaser-main').find('.controls .position .active').nextAll().length > 0) {
					$(this).fadeTo(500,0,function() {
						$(this).css('margin-left', ((($(this).parents('.teaser-main').find('.controls .position .active').prevAll().length +1) * contentWidth * -1) + $(this).parents('.teaser-main').find('.teaser-main-content').scrollLeft()) + 'px');
						$(this).fadeTo(500,1);
						$(this).parents('.teaser-main').find('.controls .position .active').removeClass('active').next().addClass('active');
					});
				}
				else {
					$(this).fadeTo(500,0,function() {
						$(this).css('margin-left', ($(this).parents('.teaser-main').find('.teaser-main-content').scrollLeft()) + 'px');
						$(this).fadeTo(500,1);
						$(this).parents('.teaser-main').find('.controls .position .active').removeClass('active');
						$(this).parents('.teaser-main').find('.controls .position li:first').addClass('active');							
					});						
				}
				
			}
		}
	});
	window.setTimeout("rollTeasers()", 5000);
}
function randomId() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;	
}

var playerRef = null;
var playerSwfObjectRef = null;

function mediaPlayerControl(e) {
 playerRef = e.ref;
 jwplayer(playerRef).onComplete(function() {
	$('.player-controls-bg').fadeTo(0,0.7);
	$('.player-controls').show();
 });
}
function bindMovieplayer () {
	if ($('div#player').length > 0) {
		var flashvars = {};
		var params = {};
		var attributes = {};
		flashvars.file = $('#player .video-src').attr('href');
		flashvars.stretching = "uniform";
		flashvars.autostart = "true";
		flashvars.image = $('#player .flash-img').attr('href');			
		params.wmode = 'transparent';
		params.allowfullscreen = 'true';
		params.allowscriptaccess = 'always';
		params.width="720";
		params.height="405";
		var playerId = randomId();
		var swfSrc = $('#player .swf-src').attr('href');
		$('div#player').attr('id',playerId);
		attributes.id=playerId;
		attributes.name=playerId;		
		playerSwfObjectRef = swfobject.embedSWF(swfSrc, playerId, "720", "405", "9.0.0","flash/expressInstall.swf", flashvars, params, attributes, mediaPlayerControl);
		$(playerId).css('padding','0').css('width','720px').css('height','405px');
	}
	$('.replay a').click(function(event) {
		event.preventDefault();
		$('.player-controls-bg').hide();
		$('.player-controls').hide();
		jwplayer(playerRef).play();
	});
	if ($('#movie-player .player-controls ul li').length == 1) {
		$('#movie-player .player-controls ul').css('padding-top','120px');
	}
	else if ($('#movie-player .player-controls ul li').length == 2) {
		$('#movie-player .player-controls ul').css('padding-top','53px');
	}
}
function destroyMovieplayer() {
	swfobject.removeSWF("player");
}

$(document).ready(function() {	
	/* 
	 * NO-JS Fallback Deaktivieren
	 */
	$(document).removeClass('no-js');

/**
 * Hauptteaser
 */	 
	var contentWidth = $('.teaser-main-content').width();	
	if (window.location.hash != "") {
		if ($('.teaser-main ' + window.location.hash).length == 1) {
			$('.teaser-main a[href="' + window.location.hash + '"]').parents('.position').find('li').each(function() {
				$(this).removeClass('active');			
			});			
			$('.teaser-main a[href="' + window.location.hash + '"]').parent().addClass('active');
			if ($('.teaser-main a[href="' + window.location.hash + '"]').parent().prevAll().length == 0) {
				$('.teaser-main a[href="' + window.location.hash + '"]').parents('.controls').find('.prev').hide();
			}
			else {
				$('.teaser-main a[href="' + window.location.hash + '"]').parents('.controls').find('.prev').show();	
				$('.teaser-main a[href="' + window.location.hash + '"]').parents('.controls').find('.prev').attr('href',$('.teaser-main a[href="' + window.location.hash + '"]').parent().prev().find('a').attr('href'));				
			}
			if ($('.teaser-main a[href="' + window.location.hash + '"]').parent().nextAll().length == 0) {
				$('.teaser-main a[href="' + window.location.hash + '"]').parents('.controls').find('.next').hide();
			}
			else {
				$('.teaser-main a[href="' + window.location.hash + '"]').parents('.controls').find('.next').show();
				$('.teaser-main a[href="' + window.location.hash + '"]').parents('.controls').find('.next').attr('href',$('.teaser-main a[href="' + window.location.hash + '"]').parent().next().find('a').attr('href'));
			}
		}
	}	
	
	var setTimer = false
	$('.teaser-main-content .teasers').each(function() {
		if($(this).find('>li').length > 1) {
			setTimer = true;
		}
	});	
	if (setTimer === true) {
		window.setTimeout("rollTeasers()", 5000);
	}

	$('.teaser-main-content .teasers').each(function() {
		if($(this).find('>li').length < 2) {
			$(this).parent().children('.controls').hide();		
		}
		else {
			$(this).parent().children('.controls').css('height','35px');
		}
	});
	$('.teaser-main .controls .position a').click(function(event) {
		if (! $(this).parent().hasClass('active')) {
			$(this).parents('.position').find('>li').each(function() {
				$(this).removeClass('active');
			});	
			$(this).parent().addClass('active');
		}
		$(this).parents('.teaser-main').find('.teasers').css('margin-left', (($(this).parent().prevAll().length * contentWidth * -1) + $(this).parents('.teaser-main').find('.teaser-main-content').scrollLeft()) + 'px');
		event.preventDefault()
	});	
	$('.teaser-main .controls .next').click(function(event) {
		if ($(this).parent().find('.position .active').nextAll().length == 0) {
			$(this).parent().find('.position .active').removeClass('active');
			$(this).parent().find('.position li:first').addClass('active');
			$(this).parents('.teaser-main').find('.teasers').css('margin-left', ($(this).parents('.teaser-main').find('.teaser-main-content').scrollLeft()) + 'px');
		}
		else if ($(this).parent().find('.position .active').nextAll().length > 0) {
			$(this).parent().find('.position .active').removeClass('active').next().addClass('active');
			$(this).parents('.teaser-main').find('.teasers').css('margin-left', ((($(this).parent().find('.position .active').prevAll().length) * contentWidth * -1) + $(this).parents('.teaser-main').find('.teaser-main-content').scrollLeft()) + 'px');
		}		
		event.preventDefault()
	});	
	$('.teaser-main .controls .prev').click(function(event) {
		if ($(this).parent().find('.position .active').prevAll().length > 0) {			
			$(this).parents('.teaser-main').find('.teasers').css('margin-left', ((($(this).parent().find('.position .active').prevAll().length -1) * contentWidth * -1) + $(this).parents('.teaser-main').find('.teaser-main-content').scrollLeft()) + 'px');
			$(this).parent().find('.position .active').removeClass('active').prev().addClass('active');
		}
		else if ($(this).parent().find('.position .active').prevAll().length == 0) {
			$(this).parents('.teaser-main').find('.teasers').css('margin-left', ((($(this).parent().find('.position .active').nextAll().length) * contentWidth * -1) + $(this).parents('.teaser-main').find('.teaser-main-content').scrollLeft()) + 'px');				
			$(this).parent().find('.position .active').removeClass('active');
			$(this).parent().find('.position li:last').addClass('active');
		}		
		event.preventDefault()
	});
	
/**
 * Bilderzoom
 */	 
	$('.img a.zoom').hoverIntent(
		function() {
			$(this).children('.zoom').animate({height: '25px'}, 150);
		},
		function() {
			$(this).children('.zoom').animate({height: '0'}, 150);
		},
		500
	);
	
/**
 * Ancor Scrolling
 */
	$('.faq-topics ul li a').click(function(event) {
		var posY = $($(this).attr('href')).offset().top;		
		$('html, body').animate({scrollTop: posY}, 300);
		event.preventDefault();
	});	
	$('.faq-topic li.last a.green').click(function(event) {		
		$('html, body').animate({scrollTop: 0}, 300);
		event.preventDefault();
	});
	$('.comment a.green').click(function(event) {
		var posY = $($(this).attr('href')).offset().top;		
		$('html, body').animate({scrollTop: posY}, 300);
		event.preventDefault();
	});	
	 
/**
 * FAQ Autocomplete
 */
	$(".faq-search form .text").autocomplete("/controls/CaraFaqAutoComplete.aspx", {
		width: 493,
		highlight: false,
		selectFirst: false,
		scroll: false
	});
/**
 * Default Texte (Contact und FAQ)
 */	
	$('#contact .row').each(function() {
		if ($(this).find('.text').length > 0) {
			$(this).find('.text').each(function () {
				$(this).attr('value',$(this).attr('data-default')).addClass('default');
			});
		}
		if ($(this).find('textarea').length > 0) {
			$(this).find('textarea').attr('value',$(this).find('textarea').attr('data-default')).addClass('default');
		}
	});
	$('#contact .text, #contact textarea').focus(function() {
		if ($(this).val() == $(this).attr('data-default')) {
			$(this).val('');
			$(this).removeClass('default');
		}		
	});
	$('#contact .text, #contact textarea').blur(function() {
		if ($(this).val() == '') {
			$(this).val( $(this).attr('data-default'));
			$(this).addClass('default');
		}
	});
	$('.submit').bind('click', function(){
		if($('#contact .text, #contact textarea').val() == $('#contact .text, #contact textarea').attr('data-default')){
			$('#contact .text, #contact textarea').val('');
			this.form.submit();
		}
	
	});
	
	//Placeholder-Plugin statt manuell - (C.Koenig 23.1.2012)
	$('.faq-search form input.text.autoComplete').placeholder();
		
	
	//JS-Checkboxen
	$('.row.checkbox .checkbox').addClass('js').each(function() {
		if ($(this).children('input:checked').length > 0) {
			$(this).addClass('checked');	
		}
	});
	$('.row.checkbox .checkbox').click(function () {
		if ($(this).hasClass('checked')) {
			$(this).removeClass('checked');
			$(this).children('input').attr('checked', false);
		}
		else {
			$(this).addClass('checked');
			$(this).children('input').attr('checked', true);
		}
	});
		
/**
 * Dropdowns
 */
	$('#contact .select').append('<div class="value hidden">' + $('#contact .select select option:first').html() + '</div>')
	$('#contact .select select option:first').remove();
	$('#contact select.dropdown').MyDropdown();
	$('#contact .select .genHeader').html($('#contact .select .value').html());
	if ($('#contact .select select').hasClass('error')) {
		$('#contact .select .genHeader').addClass('error');
	}
	
/**
 * QapTcha
 */
	$('.qaptcha').QapTcha({});
	
/**
 * Movieplayer
 */
	bindMovieplayer();
	
/**
 * Flashcontent in Teaser
 */
	$('.teasers .flash').each(function() {
		if ($(this).find('.flash-src').attr('href') != "" && $(this).find('.flash-src').attr('href') != "#" && $(this).find('.flash-src').attr('href') != null) {
			$(this).attr('id',randomId());
			var flashvars = {};
			var params = {};
			var attributes = {};
			params.wmode = 'transparent';
			params.width=$(this).width();
			params.height=$(this).height();		
			attributes.id=$(this).attr('id');
			attributes.name=$(this).attr('id');		
			playerSwfObjectRef = swfobject.embedSWF($(this).find('.flash-src').attr('href'), $(this).attr('id'), $(this).width(), $(this).height(), "9.0.0","flash/expressInstall.swf", flashvars, params, attributes);
		}
	});
	 
	
/**
 * Colorbox 
 */
	$('a.lightbox.video').colorbox({
		onComplete: function() {
			$('#cboxClose').css('top','-11px');
		}, 
		onCleanup: function() {
			$('#cboxClose').css('top','-110000px');
			destroyMovieplayer();			
		},
		iframe: true,
		opacity: 0.3, 
		innerHeight: 473,
		innerWidth: 720,
		scrolling: false
	});
	$('a.lightbox.zoom').colorbox({		
		speed: 200,
		opacity: 0.3, 
		onComplete: function() {	
			$('#cboxClose').css('top','-11px');
			window.setTimeout("$('#cboxClose').css('top','-11px');", 200);					
			if ($(this).attr('data-lightboxtext') != "" && $(this).attr('data-lightboxtext') != null) {
				$('#cboxLoadedContent').append('<p class="lightbox-text">' + $(this).attr('data-lightboxtext') + '</p>');
			}
			else if ($(this).parent().parent().find('p').html() != "" && !$(this).parent().parent().parent().hasClass('teaser-product')) {
				$('#cboxLoadedContent').append('<p class="lightbox-text">' + $(this).parent().parent().find('p').html() + '</p>');
			}			
			$('p.lightbox-text').css('width',$('#cboxLoadedContent img').width() + 'px');
			$('p.lightbox-text').show();
			$.colorbox.resize();
		},
		onCleanup: function() {
			$('#cboxClose').css('top','-110000px');
		}
	});
});
/**
 * End: Cara und HeraCeram
 */
