var moreInfo = 'Bitte klicken für mehr Info...';
var url = document.location.toString();
var myAnchor = '';
if( url.match('#') ){
	myAnchor = url.split('#')[1];
}

/*function changetitle(myid){
	var oldtitle = $('title').text();
	var newtitle = 'Kaufladen » "'+myid+'" » www.wondertom.de - Tom Arnold, Illustration, Frankfurt am Main';
	if(oldtitle != newtitle){
		$('title').text(newtitle);
	}
};*/ 

$('document').ready(function(){
	Shadowbox.init({skipSetup:true});
	Shadowbox.setup('a.thickbox',{
		overlayOpacity: 0.9,
		overlayColor: '#567'
	});
	$('.item h3').each(function(){
		var text = $(this).text();
		var myAnchor = $(this).parent().attr('id');
		$(this).addClass('active');
		$(this).html('<a href="#'+myAnchor+'">'+text+'</a>');
		if( !$(this).hasClass('active') ){
			$(this).attr('title',moreInfo);
		}
	});
	
	$('.item h3 a').click(function(){
		myid = $(this).attr('href');
		$(this).parent()
			.toggleClass('active')
			.next().slideToggle('normal',function(){
			if( !$(this).prev().hasClass('active') ){
				$(this).prev().attr('title',moreInfo);
			} else {
				$(this).prev().attr('title','');
				// history veraendern (hachja)
				if (history.pushState){
					history.pushState(
						{ id:myid },
						'Kaufladen » "'+myid+'" » www.wondertom.de - Tom Arnold, Illustration, Frankfurt am Main', '/shop/'+myid
					);
				}
			}
		});
		return false;
	});
	
	var myContent = $('.item .content');
	myContent.each( function(i){
		if( myAnchor !== '' ){
			if( $(this).parent().attr('id') == myAnchor ){
				$(this).prev().addClass('active');
				$(this).show();
			} else {
				$(this).prev().removeClass('active');
				$(this).hide();
			}
		}
	});
	
});

