$(document).ready(function(){
	
//SETUP
			$('p.step_no').hide(0);

	
	$('#pflownavlist a').attr(
"href",
function( index ){
  
 // Return the value that we want to store into
 // the ID attribute.
return $('#pflownavlist a:eq('+index+')').attr('href')+'#1';

  
 });
//Functions
	
	var pageTitle = document.title;
	var pt= $('.flow_inner h1').html();

	$.ajaxHistory.init(makeActive, '');
	$.ajaxHistory.addCallback(makeActive, '');
	//$.ajaxHistory.addHistory(1,pageTitle+' - 1');

	
	function changePath(k){
		
		$('.flow_inner h1').html($('.selector #c'+k).html());
		
		$('#o'+k).show(0);
		var i =0;
		$('#o'+k).children().attr(
"id",
function( index ){
  
 // Return the value that we want to store into
 // the ID attribute.
 return( "f" + (index + 2) );
  
 });
		
		$('#o'+k).siblings('.path').hide(0);
		
		$('#o'+k).siblings('.path').children().attr({id:'u'});
		
		
		var alt = $('#o'+k).html();
		
		buildsteps(k);
		
		$('p#navigator').show(0);
		
		$.ajaxHistory.addHistory('2',pageTitle+' - 2');
	
		makeActive(2);
		
	
		
	}
	
	
	function makeActive(k){
		
			
			if(k){
				
				var number = parseInt(k);
			}else{
			k=1;	
			}
			if(k==1){
			$('.flow_inner h1').html(pt);	
			}
			//Hide
			
			$('ul.step .active').removeClass('active');
			$('.frame').removeClass('visible');
			
	
			//Show
			$('ul.step #'+k).addClass('active');
			$('#f'+k+'.frame').addClass('visible');
			$('#cur').html(k);
			
			if($('#cur').html()==1){
				$('#previous').addClass('inactive');
			}
			else{
				$('#previous').removeClass('inactive');	
			}
			if($('#cur').html()==$('#total').html()){
				$('#next').addClass('inactive');
			}
			else{
				$('#next').removeClass('inactive');	
			}
			if($('#f'+k).hasClass('selector')){
				$('.image').hide(0);	
			}
			else if($('#f'+k).hasClass('end')){
					$('.image').hide(0);	
			}
			else{
				$('.image').show(0);
			}
		
	
	}
	
//Build Steps

	function buildsteps(path){
		
		if(path){
		var np= '#o'+path;	
		}
		else{
		var np='';	
		}
		
		
		
		var i;
		var j = $(np+' .frame:last').attr('id').substr(1);
		
		
		$('#total').html(j);
		
		$('ul.step').html('');
		
		for(i=1; i<=j; i++){
			
			$('ul.step').append('<li id="'+i+'">'+i+'</li>');	
			
			if(i==1){$('ul.step #1').addClass('first');}
			if(i==j){$('ul.step #'+j).addClass('last');}
		
		}
		
		$('p.step_no').show(0);
		
		
		$('ul.step li').click(function(){
			
				
			if(this.id==1){
					
					
				window.location.reload();
					
			}
			else{
	
	
				$.ajaxHistory.addHistory(this.id,pageTitle+' - '+this.id);
		
				makeActive(this.id);
						
				//	return false;
			}
			
		});
	}
	
	
	
	// SELECTOR SETUP
	
	if($('#o1').length){
		
		$('p#navigator').hide(0);
		
		$('.selector .nextbutton a').click(function(){
			
			var t = (this.id).substr(1);
			if(!t){
				t=1;	
			}
			//$.ajaxHistory.addHistory(t,pageTitle+' - '+t);
			
			changePath(t);	
				
			return false;

			
			//return false;

		});
		
		
		

	}
	else{
		
		
		buildsteps();	
	}
	
	
	
	
	
	
	
	
	

	
	//Activate
	
	makeActive(1);
	
	
	
	
	$('#previous').click(function(){
		if($('#cur').html()==1){
	
		$.ajaxHistory.addHistory('1',pageTitle+' - 1');

		makeActive(1);
		return false;
	
		}
		if($('#o1').length&$('#cur').html()==2){
			
			
				window.location.reload();
			
		}
		else{
		var t =String(parseInt($('#cur').html())-1);
		//alert(k);
		$.ajaxHistory.addHistory(t,pageTitle+' - '+t);

		makeActive(t);
		return false;
		}
	
	});
	$('#next').click(function(){
		if($('#cur').html()==$('#total').html()){
		
		$.ajaxHistory.addHistory($('#total').html(),pageTitle+' - '+$('#total').html());

		makeActive($('#total').html());
		return false;
		
		}
		else{
		var t =	String(parseInt($('#cur').html())+1);
		//alert(k);
		$.ajaxHistory.addHistory(t,pageTitle+' - '+t);
		
		makeActive(t);
		return false;
		}
	
	});
	
	
	
	
	
	

});