jQuery(function( $ ){

  // The default easing is 'swing', but I want to use a nicer one
  jQuery.easing.def = "easeInOutCirc";
  
	// The default axis is 'y', but in this demo, I want to scroll both
	$.localScroll.defaults.axis = 'yx';
	
	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: '#content', 
		queue: true,
		duration: 1500
	});

  /**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I also effect all cross links
	 */	 
	$.localScroll({
		target: '#content', // could be a selector or a jQuery object too.
		queue: true,
		duration: 1000,
		hash: true,

		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});
	
	// Hover-Effect for navigation
  submenus = $('ul#navigation > li ul');
	function openMenu(section){
    submenus.hide();
	  $(section).parent('li:first').find('ul').fadeIn('fast');
	}
	
	//Attach action to navigation
	sectionlinks = $('ul#navigation > li > a');
	sectionlinks.bind('click', function(evt){
	  openMenu(this);
	});
	
	// go find the navigation link that has this target and select the nav
  function trigger(data) {
    // Find the categorie by using the part BEFORE -, if "-" is not present the whole string will be used
    name = data.id.split("-")[0]; 
    var el = $('ul#navigation').find('a[href$="' + name + '"]');
    openMenu(el);
  }
  
	if (window.location.hash) {
    trigger({ id : window.location.hash.substr(1) });
  } else {
    openMenu($('ul#navigation a:first'));
  }  
  
  // Language-Switch 
  if( typeof lang == 'undefined'){ //if undefined use 'de' as default
    lang = 'de';
  }   
  other_lang = lang == 'de' ? 'en' : 'de'; // determine the other language
  page = lang == 'de' ? 'index.en.html' : 'index.html'; // determine the other page
  text = lang == 'de' ? 'Switch to english' : 'Zu Deutsch wechseln';
  
  section_headings = $('div#content div.section > ul > li.sub'); // take all subsections
  section_headings.each(function(sub_item){ //prepend a link to switch language
    obj = $(this)        
    id = obj.attr('id');    
    link = $('<a href="'+page+'#'+id+'" class="lang_link" title="'+text+'"><img src="images/'+other_lang+'.gif" alt="'+other_lang+'"></a>"');
    obj.prepend(link);
  });
  
}); 

$(function(){

		// Accordion
		$(".accordion").accordion({ 
		  header: "h3",    
		  autoHeight: false,
		  collapsible: true,
		  active: false
		});
		
		//hover states on the static widgets
		$('#dialog_link, ul#icons li').hover(
			function() { $(this).addClass('ui-state-hover'); }, 
			function() { $(this).removeClass('ui-state-hover'); }
		);
			 
});    
