// Version 1.02 (16.1.2009)

$(document).ready(function() {
						   
	
	
	$('#sidebar dl> dd> dl> dd').hide();
	$('#bodytext dl> dd').hide();
	$('#slide_0').siblings().hide();
	
	var url = document.location.toString();
    // look at the URL to see if it contains an anchor
    if (url.match('#')) {
    	// if so, get it from the URL
    	var urlAnchor = url.split('#')[1];
    	if(!url.split('#')[0].match(urlAnchor))
    	{
//		alert('#slide_'+urlAnchor);
		$('#slide_0').hide();
		$bodyitem = $('#slide_'+urlAnchor);
		$bodyitem.next('dd').toggle('normal');
		$bodyitem.parent().show();
		$bodyitem.siblings().next('dd:visible').toggle('normal');
		$bodyitem.siblings().hide();
    	$bodyitem.show();
		$bodyitem.children().show();
		$bodyitem.children('div').filter('.slide').hide();
		$bodyitem.children('dl').children('dd').slideUp('normal');
		}
		
	}
	
	$('.ug_xref').click(function() {
	   // alert("click "+$(this).attr("href"));
	    var urlHtml=$(this).attr("href").split('#')[0];
	    var urlCurrent=document.location.toString();
	    
	    if(urlCurrent.match("/"))
	     urlCurrent=urlCurrent.substr(urlCurrent.lastIndexOf("/")+1);
	    if(urlCurrent.match("#"))
	     urlCurrent=urlCurrent.split('#')[0];
	    if(urlHtml.indexOf("?")==0)
	      urlCurrent=urlCurrent.substr(urlCurrent.lastIndexOf("?"));	
	   // alert(urlHtml+"="+urlCurrent);
	    document.location=$(this).attr("href");
	    if(urlHtml==urlCurrent || urlCurrent.indexOf("?")==0)
	    {
	        var urlAnchor = $(this).attr("href").split('#')[1];
    	//	alert('#slide_'+urlAnchor);
		    $('#slide_0').hide();
		    $bodyitem = $('#slide_'+urlAnchor);
		    $bodyitem.next('dd').toggle('normal');
		    $bodyitem.parent().siblings().hide();
		    $bodyitem.parent().show();
		    $bodyitem.siblings().next('dd:visible').toggle('normal');
		    $bodyitem.siblings().hide();
    	    $bodyitem.show();
		    $bodyitem.children().show();
		    $bodyitem.children('div').filter('.slide').hide();
		    $bodyitem.children('dl').children('dd').slideUp('normal');
	    }
	});
	
	$('#sidebar .selected').click(function() {
		//alert("Selected Click");								   	
		$('#bodytext dl> dd').hide();
		$('#bodytext .slide').hide();
		$('#slide_0').show();
		$(this).addClass('active');
		$(this).next('dd').children('dl').children('dt').removeClass('active');
		$(this).next('dd').children('dl').children('dt').children('a').removeClass('selected');
		$(this).next('dd').children('dl').children('dd').slideUp('normal');
	});

	$('#sidebar dl> dd> dl> dt').click(function() {
		
		$childs = $(this).next('dd').children('ul').children('li');
		$childs.removeClass('active');
		$childs.children('a').removeClass('selected');
		$(this).next('dd').slideToggle('normal').siblings('dd:visible').slideUp('normal');
		$bodyitem=$('#slide_'+$(this).children('a')[0].id.substr(6,$(this).children('a')[0].id.length));
		//alert('#sidebar dl> dd> dl> dt:'+'#slide_'+$(this).children('a')[0].id.substr(6,$(this).children('a')[0].id.length) );
		$bodyitem.siblings().hide();
		$bodyitem.show();
		$bodyitem.children().show();
		$bodyitem.children('div').filter('.slide').hide();
		$bodyitem.children('dl').children('dd').slideUp('normal');

		$(this).addClass('active');
		$(this).children('a').addClass('selected');
		$(this).siblings('dt:visible').removeClass('selected active');
		$(this).siblings('dt:visible').children('a').removeClass('selected');
		$('#sidebar> dl>.selected').removeClass('active');
		$('#slide_0').hide();

		$(this).siblings('dt').next('dd').children('ul').children('li').removeClass('active');
		$(this).siblings('dt').next('dd').children('ul').children('li').children('a').removeClass('selected');
		$(this).siblings('dt').next('dd').slideUp('normal');

	});
	
	$('#sidebar dl> dd> dl> dd> ul> li').click(function() {
		
	//	alert('#sidebar dl> dd> dl> dd> ul> li');
		$(this).parent().parent().prev('dt').removeClass('active');
		$bodyitem = $('#slide_'+$(this).children('a')[0].id.substr(6,$(this).children('a')[0].id.length));
		$bodyitem.next('dd').toggle('normal');
		$bodyitem.siblings().next('dd:visible').toggle('normal');
		$bodyitem.siblings().hide();
		$bodyitem.show();
		$bodyitem.children('dl').children('dd').slideUp('normal');
		$(this).addClass('active');
		$(this).children('a').addClass('selected');
		$(this).siblings().removeClass('active');
		$(this).siblings().children('a').removeClass('selected');
	});

	$('.liftholder dl> dt').click(function() {
		
	    alert('#liftholder dl> dt');
		$('#sidebar dl> dd> dl> dd> ul> li> a').removeClass('selected');
		$('#sidebar dl> dd> dl> dd> ul> li').removeClass('active');
		$navitem = $('#topic_'+this.id.substr(6,this.id.length));
		$navitem.parent().parent().parent().prev('dt').removeClass('active');
		$navitem.parent().parent().parent().slideDown('normal');
		$navitem.addClass('selected');
		$navitem.parent().addClass('active');
		$navitem.siblings().removeClass('selected');
		$(this).next('dd').toggle('normal').siblings('dd:visible').toggle('normal');//toggle();
	});
	
	
	$('.liftholder ul> li').click(function() {
	    $bodyitem = $('#slide_'+$(this).children('a')[0].id.substr(6,$(this).children('a')[0].id.length));
	    $bodyitem.siblings().hide();
	    $bodyitem.show();
	    $bodyitem.children().show();
	    $bodyitem.children('div').filter('.slide').hide();
	});
	
	$('.liftholder ul> liasdasd').click(function() {
		
		alert('#liftholder ul> li');
		$('#sidebar dl> dd> dl> dd> ul> li> a').removeClass('selected');
		$('#sidebar dl> dd> dl> dd> ul> li').removeClass('active');
		
		$bodyitem = $('#slide_'+$(this).children('a')[0].id.substr(6,$(this).children('a')[0].id.length));
		$bodyitem.siblings().hide();
		$bodyitem.show();
		$bodyitem.children().show();
		$bodyitem.children('div').filter('.slide').hide();
		$bodyitem.children('dl').children('dd').slideUp('normal');
		
		$bodyitem.next('dd').toggle('normal');
		$bodyitem.siblings().next('dd:visible').toggle('normal');
		$bodyitem.siblings().hide();
		$bodyitem.show();
		$bodyitem.children('dl').children('dd').slideUp('normal');
		
		$navitem = $('#topic_'+this.id.substr(6,this.id.length));
		$navitem.parent().parent().parent().prev('dt').removeClass('active');
		$navitem.parent().parent().parent().slideDown('normal');
		$navitem.addClass('selected');
		$navitem.parent().addClass('active');
		$navitem.siblings().removeClass('selected');
		$(this).next('dd').toggle('normal').siblings('dd:visible').toggle('normal');//toggle();
	});
	
 
});
