// initialise plugins
$(document).ready(function(){
	$('#bookmark').bookmark({compact: true, sites: ['delicious', 'digg','misterwong','google']});
	
	/*jQuery('#navigation-global > ul').superfish({ 
        delay:       800,                            // one second delay on mouseout 
		animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
        speed:       100,                          // faster animation speed 
        autoArrows:  false,                           // disable generation of arrow mark-up 
        dropShadows: false                            // disable drop shadows 
    });*/
	var location = document.location.toString();
	
	var info_switch  	= '.info  > ul > li > a';
	var info_switch2  	= '.next a';
	var info_container 	= '.info > ul > li';
	var info_content 	= '> ul > li'; //relative2container
	
	if (location.match('#')) { 
		var url	   =  location.split('#')[0];
		var anchor =  location.split('#')[1];
	}else {
		var url 	= location;
		var anchor 	= '';
	}
	
    var selectInfo = function(e){
		e.preventDefault();
		//document.location.href = url+'#'+e.data['id'];
		id = e.data['id'];
		
		container = $(info_container).find('*[id='+id+']').parents('.container:first');
		if(container.length == 0) {
			container = $(info_container).parent().find('.container:first'); 
		}		
		
		if ($(container).hasClass('cur')) return false;
		
		$(info_container+'.container').removeClass('cur');
		$(container).addClass('cur');
		
		$(container).find(info_content+':first').css('opacity',0).animate({ 
    		opacity: 1
		},500);
	};	
	
	
		
	//alert(url);
	
	$(info_container).addClass('container');
	$(info_container).removeClass('cur');
		
	
	$(info_switch).each(function (i,obj) {
		data = new Object();
		data['id']= $(this).attr('href').split('#')[1];
		var next_id = i+2;
		
		if ($(info_switch).length == i+1) {
			next_id = 1; 
		}
		
		if ($(info_switch).length > 1) {
		var container = $(info_container).find('*[id='+data['id']+']').parents('.container:first');
		$(container).find(info_content+':first').prepend('<p class="next"><a href="#info-'+next_id+'" title="weiter &gt;">weiter zu <span class="nr-bg">'+(next_id)+'</span></a></p>');
		/*$(container).find('p.next a').hover(
	      function () {
	        $(info_container).find('> a[href=#info-'+next_id+']:first').addClass('hover');
	      }, 
	      function () {
	        $(info_container).find('> a[href=#info-'+next_id+']:first').removeClass('hover');
	      }
	    );*/
		}

		$(obj).bind("click", data, selectInfo);
	});
	$(info_switch2).each(function (i,obj) {
		data = new Object();
		data['id']= $(this).attr('href').split('#')[1];
		$(obj).bind("click", data, selectInfo);
	});
	$(info_switch+':first').trigger('click');
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 40, /* padding for each side of the picture */
			opacity: 0.8, /* Value betwee 0 and 1 */
			showTitle: true, /* true/false */
			allowresize: true, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'dark_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
		});
});