var places=[{lat:-33.3614067,lng:-70.5042855,city:"Santiago",cc:"rep2000"},{lat:45.3642609,lng:7.7257367,city:"Castellamonte – Torino",cc:"rep2001"},{lat:38.6973923,lng:-9.2026918,city:"Lissabon",cc:"rep2002"},{lat:55.6274330,lng:13.0376596,city:"Malmö",cc:"rep2018"},{lat:-28.0764180,lng:153.3365080,city:"Queensland",cc:"rep2004"},{lat:43.2640611,lng:-2.9388228,city:"Bilbao",cc:"rep2019"},{lat:-26.1078700,lng:28.0537000,city:"Sandton",cc:"rep2020"},{lat:39.2097610,lng:117.7635985,city:"Tianjin",cc:"rep2008"},{lat:24.1501874,lng:120.6429991,city:"Taichung",cc:"rep2021"},{lat:-23.6254586,lng:-46.6668967,city:"São Paulo",cc:"rep2009"},{lat:48.8765465,lng:2.3546474,city:"Paris",cc:"rep2025"},{lat:60.2891254,lng:24.9516840,city:"Vantaa",cc:"rep2010"},{lat:49.2995329,lng:-0.9855510,city:"Thionville",cc:"rep2012"},{lat:56.4906712,lng:-4.2026458,city:"Scotland, U.K.",cc:"rep2013"},{lat:32.3066000,lng:35.0076000,city:"Netanya",cc:"rep2014"},{lat:51.5455315,lng:4.2270385,city:"Tholen",cc:"rep2015"},{lat:52.2644763,lng:6.7981521,city:"Hengelo",cc:"rep2016"},{lat:59.6933139,lng:10.2687215,city:"Drammen",cc:"rep2017"},{lat:40.9298820,lng:29.1246510,city:"Maltepe-Istanbul",cc:"rep2022"},{lat:41.0307378,lng:28.9768793,city:"Beyoglu-Istanbul",cc:"rep2023"},{lat:40.0091729,lng:-83.1103620,city:"Columbus, Ohio",cc:"rep2024"}];

(function($) {
	var opts,holder;
	var counter = 1;
	var defaults = {
		wait:2000,
		duration:1000,
		circular:true
	};
	$.fn.roatating_gallery = function(options){
		opts = $.extend(defaults,$.fn.roatating_gallery.defaults,options);
		return this.each(function(){
			holder = $(this);
			show_next_slide();
		});
	};
	function show_next_slide(){
		$(holder).find('li:last')
			.animate({opacity:1},{duration:opts.wait})
			.animate({opacity:0},{
				duration:opts.duration,
				complete:function(){
					$(this).parent().prepend($(this).css('opacity',1));
					if(counter>=$(holder).children('li').length && opts.circular==false)
						return false;
					else
						show_next_slide();
				}
			})
		counter++;
	/*	$(holder).append($(holder).find('li:firsts')
			.css({opacity:0})
			.animate({opacity:0},{duration:opts.wait})
			.animate({opacity:1},{
				duration:opts.duration,
				complete:function(){
					if(counter>=$(holder).children('li').length && opts.circular==false)
						return false;
					else
						show_next_slide();
				}
			})
			);
		counter++;
	*/
	}
	$.fn.roatating_gallery.defaults = {}
})(jQuery);

function htmlentities (string, quote_style) {
    // Convert all applicable characters to HTML entities  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/htmlentities    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: nobbler
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Ratheous
    // -    depends on: get_html_translation_table
    // *     example 1: htmlentities('Kevin & van Zonneveld');    // *     returns 1: 'Kevin &amp; van Zonneveld'
    // *     example 2: htmlentities("foo'bar","ENT_QUOTES");
    // *     returns 2: 'foo&#039;bar'
    var hash_map = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();    
    if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
    hash_map["'"] = '&#039;';    for (symbol in hash_map) {
        entity = hash_map[symbol];
        tmp_str = tmp_str.split(symbol).join(entity);
    }
        return tmp_str;
}


function CoordinateFromLongLat(longLat, worldRect){
	var maxY = (worldRect.Height*.5)/90;
	var maxX = (worldRect.Width*.5)/180;
	var coordinate = {};
	coordinate.Y = worldRect.Y+((worldRect.Height*.5)-(maxY*longLat.Y));
	coordinate.X = worldRect.X+((worldRect.Width*.5)+(maxX*longLat.X));
	return coordinate;
}
function showTT(text){
	/*$('body').bind('mousemove',function(event){
		$('#tt').css({left:event.pageX+10,top:event.pageY+10})	
	});*/
	$('#tt').animate({opacity:1},{queue:false})
	$('#tt .inner').text(text);	
}
function hideTT(){
	$('body').unbind('mousemove',function(event){
		$('#tt').css({left:event.pageX+10,top:event.pageY+10})	
	});
	$('#tt').animate({opacity:0},{queue:false})	
}

$(document).ready(function(){
	var tt = $('<div />')
		.attr('id','tt')
		.css({zIndex:999})
		.append(
			$('<div />')
			.addClass('ydsf')
			.append($('<div />')
				.addClass('inner')
			)
		)
		.css({opacity:0});
	$('body').prepend(tt);
});
$(document).ready(function(){
	$('.partnerdetail:not(.DE)').hide();
	if($('#map').length){
		$('#map').wrap($('<div />').attr('id','mapholder'));
		var i = places.length;
		while(i--){
			var coords = CoordinateFromLongLat({X:places[i].lng,Y:places[i].lat},{X:-5,Y:-20,Width:583,Height:340});
			$('#mapholder').append(
				$('<a />')
					.attr('href','/kontakt/#'+places[i].cc)
					.data('city',places[i].city)
					.data('cc',places[i].cc)
					.addClass('mapmarker')
					.addClass(places[i].cc)
					.css({top:coords.Y-2.5,left:coords.X-2.5})
					.mouseover(function(){
						showTT($(this).data('city'));
						$('#tt').css({left:$(this).offset().left+10,top:$(this).offset().top+10})	
						$('.product_list a').animate({color:'#8D8791'},{queue:false});
						$('.'+$(this).data('cc')).animate({color:'#e74011'},{queue:false});
					})
					.mouseout(function(){
						$('.product_list a').animate({color:'#8D8791'},{queue:false});
						hideTT();
					})
					.click(function(){
						$('.partnerdetail').hide();
						$('.partnerdetail.'+$(this).attr('href').toString().replace('#','.')).show();
					})
			);	
		}	
	}	
	$('#countries a')
		.mouseover(function(){
			$('#mapholder a'+$(this).attr('href').toString().replace('#','.')).trigger('mouseover');
		})
		.mouseout(function(){
			$('#mapholder a'+$(this).attr('href').toString().replace('#','.')).trigger('mouseout');
		})
		.click(function(){
			$('.partnerdetail').hide();
			$('.partnerdetail.'+$(this).attr('href').toString().replace('#','.')).show();
		});
});


$.fn.neighbours = function(){
	return $(this).nextAll().add($(this).prevAll());
}
$.fn.hideBetter = function(){
	$(this).hide().css({height:0});
}
$.fn.slideUpBetter = function(){
	
}
$.fn.slideDownBetter = function(){
	
}

$(document).ready(function(){
	$(this).find('.image a').fancybox({'overlayShow':false,'titlePosition':'outside','cyclic':false,'hideOnContentClick':true,'onStart':function(){
			showonstart = setTimeout(function(){
				$('#fancybox-left, #fancybox-right').removeClass('hover');
			},4000);
			$('#fancybox-right')
			.addClass('hover')
			$('#fancybox-left, #fancybox-right')
			.mouseover(function(){
				clearTimeout(showonstart);
				$(this).addClass('hover');	
			})
			.mouseout(function(){
				clearTimeout(showonstart);
				$('#fancybox-left, #fancybox-right').removeClass('hover');	
			});
	}});

	var hopper = $('<div />').addClass('hopper').css({opacity:0});
	$('#navi').mouseover(function(){
		$('.hopper').animate({opacity:.8},{queue:false});	
	}).mouseout(function(){
		$('.hopper').animate({opacity:0},{queue:false});	
	}).mousemove(function(e){
		$('.hopper').css({top:e.pageY - this.offsetTop - parseInt($('.hopper').css('height'))*.5});
	}).css({position:'relative'}).prepend(hopper);
	
	$('#navi li a').mouseover(function(){
		$('.hopper').css({visibility:'hidden'});	
	}).mouseout(function(){
		$('.hopper').css({visibility:'visible'});	
	});
	
});
$(document).ready(function(){
	$('ul.acco h3').each(function(i,e){
		$(e).html(
			$('<a />')
				.attr('href','#')
				.text($(e).text())
				.click(function(){
					$(this).parent().next('.accoco').slideDown();
					$(this).parent().parent().neighbours('li').find('.accoco').slideUp();
					return false;	
				})
			);
		$(e).next('div').hide();	
	});
});
$(document).ready(function(){
	var act = 0;
var oldsrc = $('#content').find('img:last').attr('src');
 $('#content').find('img:last').bind('load',function(){
	$(this).fadeIn();
});
	if(window.location.hash!=''){
		act = ($('div.collapsible>h3').index($('a:attr[href='+window.location.hash+']').parent()));
	}
	$('h4:contains(ugehörige Qualitäten)').parent('div').find('a').each(function(i,e){
		var str = $(e).text().toString();
		$(e).attr('href',$(e).attr('href')+'#'+str.substr(-(str.length-(str.indexOf(' ')+1))).replace(' ','-'));
	});
	$('div.collapsible').accordion({autoHeight:false,collapsible:true,active:act})
.bind('accordionchangestart', function(event, ui){


	if($('#content').find('img:last').attr('src')!=$(ui.newContent).filter('.tofoot').attr('src') && $(ui.newContent).filter('.tofoot').attr('src')!=undefined){
		src = $(ui.newContent).filter('.tofoot').attr('src')
	} else {
		src = oldsrc;
	}
	$('#content').find('img:last').attr({src:src}).removeAttr('height').removeAttr('width')
	/*.hide();*/

});

$(document).scrollTop($('a:attr[href='+window.location.hash+']').parent().offset().top);
/*each(function(i,e){
		$(e).html(
			$('<a />')
				.attr('href','#')
				.text($(e).text())
				.click(function(){
					$(this).parent().next('div').slideDown();
					$(this).parent().parent().neighbours('li').find('div').slideUp();
					return false;	
				})
			);
		$(e).next('div').hide();
	});*/
});

/*$(document).ready(function(){
if(window.location.hash!='')
	$('a:attr[href='+window.location.hash+']:not(:first-child)').trigger('click');
	$('h4:contains(ugehörige Qualitäten)').parent('div').find('a').each(function(i,e){
		var str = $(e).text().toString();
		$(e).attr('href',$(e).attr('href')+'#'+str.substr(-(str.length-(str.indexOf(' ')+1))).replace(' ','-'));
	});
});
$(document).ready(function(){
	//$('.imagerotation li:not(:first-child)').hide();
});*/
$(document).ready(function(){
	$('#applicationmapholder a')
		.css({opacity:0})
		.mouseover(function(){
			showTT($(this).find('img').attr('alt'))
			$('#tt').css({left:$(this).offset().left+30,top:$(this).offset().top+30})
			$(this).parent().find('a[href='+$(this).attr('href')+']').animate({opacity:1},{queue:false})
			$('.applicationmaplist a[href='+$(this).attr('href')+']').animate({color:'#E74011'},{queue:false});
		})
		.mouseout(function(){
			hideTT();
			$(this).parent().find('a[href='+$(this).attr('href')+']').animate({opacity:0},{queue:false})
			$('.applicationmaplist a').animate({color:'#8D8791'},{queue:false});
		})
		$('.applicationmaplist a')
			.mouseover(function(){
				$('#applicationmapholder a[href='+$(this).attr('href')+']:first').trigger('mouseover');
			})
			.mouseout(function(){
				$('#applicationmapholder a[href='+$(this).attr('href')+']:first').trigger('mouseout');
			})
});

$(document).ready(function(){
	$('.imagerotation').each(function(i,e){
		$(e).data('i',1);
		if($(e).children().length>1){
			$(e)
				.prepend(
					$('<a href="javascript:;" />')
					.addClass('btn_fwd')
					.hide()
					.fadeIn()
					.click(function(){
						var ii = $(this).parent().data('i');
						ii--;
						if(ii<=0) ii = $(this).parent().children('li').length;
						$(this).parent().append(
							$(this).parent().parent().find('.kid-'+ii)
						)
						$(this).parent().data('i',ii);
$('#kid-'+ii).css({color:'#000',fontWeight:'bold'});
$('#kid-'+ii).prevAll('a').add($('#kid-'+ii).nextAll('a')).css({color:'#000',fontWeight:'normal'});
					})
				)
				.prepend(
					$('<a href="javascript:;" />')
					.addClass('btn_bwd')
					.hide()
					.fadeIn()
					.click(function(){
						var ii = $(this).parent().data('i');
						ii++;
						if(ii>$(this).parent().children('li').length) ii = 1;
						$(this).parent().append(
							$(this).parent().parent().find('.kid-'+ii)
						)
						$(this).parent().data('i',ii);
$('#kid-'+ii).css({color:'#000',fontWeight:'bold'});
$('#kid-'+ii).prevAll('a').add($('#kid-'+ii).nextAll('a')).css({color:'#000',fontWeight:'normal'});
					})
				)
			$(e).children('li').each(function(il,el){
				$(el).addClass('kid-'+($(e).children('li').length-il));
			});
			var i = 0;
			$(e).after($('<div>Abbildungen: </div>').css({fontWeight:'normal',textAlign:'right',fontSize:'12px'}).addClass('rotnav'));
			while(i++<$(e).children('li').length){
				$(e).next('div.rotnav').append(
					$('<a href="javascript:;">'+(i)+'</a>')
						.css({fontWeight:(i==1)?'bold':'normal'})
						.attr('id','kid-'+(i))
						.data('i',i)
						.click(
							function(){
								$(this).parent().prev('.imagerotation').append(
									$(this).parent().prev('.imagerotation').find('.'+$(this).attr('id'))
								)
$(this).css({color:'#000',fontWeight:'bold'});
$(this).prevAll('a').add($(this).nextAll('a')).css({color:'#000',fontWeight:'normal'});
								$(this).parent().prev('.imagerotation').data('i',$(this).data('i'));
							})
				)
				if(i<$(e).children('li').length){
					$(e).next('div.rotnav').append(' ')
				}
			}
		}
	});
});
$(document).ready(function(){
	$('.rotator').roatating_gallery({circular:false});
});

