var object = new ArgumentURL(); 

function showHeight(ele, h) {
      //$("div").text("The height for the " + ele + 
        //            " is " + h + "px.");
		alert("The height for the " + ele +  " is " + h + "px.")
    }
	
// easing function
$.easing.elasout = function(x, t, b, c, d) {
	var s=1.70158;var p=0;var a=c;
	if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
	if (a< Math.abs(c)) { a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
};

jQuery(function( $ ){
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://flesler.demos.com/jquery/scrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */
	// The default axis is 'y', but in this demo, I want to scroll both
	// You can modify any default like this
	$.localScroll.defaults.axis = 'xy';
	
	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: '#content', // Could be a selector or a jQuery object too.
		queue:true,
		duration:1500
	});
	
	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to scroll.
	 */
	//$('#content').attr({scrollTop:0,scrollLeft:0});
	$.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
			//alert(e);
			//alert(anchor);
			//alert($target);
			//alert($(anchor).attr('id') );
			//showHeight("text", $("li[class=sub]").text().length);
			//var length =  $("li[id="+$(anchor).attr('id')+"]").text().length;
			//var height = ((length *13) / 620) *14 + 20;
			//$($(anchor).attr('id')).load('areas/arquitectura.html');
			
			switch($(anchor).attr('id'))
			{
				case 'section1'://arquitectura
					height = 430;
					//$('#section1').html( '<p class="loading">Cargando...</p>' ).load('areas/arquitectura.html');
					//alert(height);
					break;
				case 'section1b'://arte
					height = 255;
					//alert(height);
					//$('#section1b').html( '<p class="loading">Cargando...</p>' ).load('areas/arte_antiguedades.html');
					break;
				case 'section1c'://forenses
				case 'section1c_1'://propiedad intelectual
				case 'section1c_2'://propiedad industrial
				case 'section1c_3'://grafologia
				case 'section1c_5'://musicologia
				case 'section1c_7'://balistica				
					height = 255;
					//alert(height);
					//$('#section1c').html( '<p class="loading">Cargando...</p>' ).load('areas/arte_antiguedades.html');
					break;
				case 'section1c_6'://linguistica
					height = 310;
					break;
				case 'section1d'://economicas
					height = 345;
					//alert(height);
					//$('#section1d').html( '<p class="loading">Cargando...</p>' ).load('areas/economicas_empresariales.html');
					break;
				case 'section1e'://ingenieria
					height = 345;
					//alert(height);
					//$('#section1e').html( '<p class="loading">Cargando...</p>' ).load('areas/ingenieria.html');
					break;
				case 'section1f'://medicina
					height = 750;//crap in ie7
					//alert(height);
					//$('#section1f').html( '<p class="loading">Cargando...</p>' ).load('areas/medicina.html');
					break;				
				case 'section1g'://quimica
					height = 530;
					//alert(height);
					//$('#section1g').html( '<p class="loading">Cargando...</p>' ).load('areas/quimica.html');
					break;
				case 'section1c_4'://documentoscopia
					height = 420;
					break;
				case 'section1h'://teleco/inf
					height = 450;
					//alert(height);
					//$('#section1h').html( '<p class="loading">Cargando...</p>' ).load('areas/telecomunicaciones_informatica.html');
					break;			
			}
			//alert(height);
			//showHeight("text", $("li[id="+$(anchor).attr('id')+"]").text().length); 
			//showHeight("text", length);
			//$target.height($("p").height()).css({cursor:"auto", backgroundColor:"green"});
			$target.height(height).css({cursor:"auto", backgroundColor:"white"});
			//$('#' +$(anchor).attr('id')).height(height).css({cursor:"auto", backgroundColor:"white"});
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
			//alert($(anchor).attr('id'));
			//$.ScrollTo($(anchor).attr('id'));
			//$.scrollTo( 'li[id=section1c]', 1900 );
			//load text ajax way
			//$('#section1').load('areas/arquitectura.html #section1');
		
			$.scrollTo( 'li[id=section1g]', 1000 );
		}
	});
	
	
	//toggle through arguments
	if (object != null)
	{
		if (object.size()>0)
		{
			var lnk = object.getArgument('link');
			
			if (lnk != null)
			{
				//alert(lnk);
				//tree.toggle_branch("#" + lnk);
				//$.ScrollTo("#" + lnk);
				//$.scrollTo( 'li[id='+lnk+']', 800 );
				//$('#content').scrollTo( $('ul').get(1).childNodes[0], 1000 );
				
				switch(lnk)
				{
					case 'section1'://arquitectura
						height = 430;
						//$('#section1').html( '<p class="loading">Cargando...</p>' ).load('areas/arquitectura.html');
						//alert(height);
						break;
					case 'section1b'://arte
						height = 255;
						//alert(height);
						//$('#section1b').html( '<p class="loading">Cargando...</p>' ).load('areas/arte_antiguedades.html');
						break;
					case 'section1c'://forenses
				case 'section1c_1'://propiedad intelectual
				case 'section1c_2'://propiedad industrial
				case 'section1c_3'://grafologia
				case 'section1c_5'://musicologia
				case 'section1c_7'://balistica	 intelectual
						height = 255;
						//alert(height);
						//$('#section1c').html( '<p class="loading">Cargando...</p>' ).load('areas/arte_antiguedades.html');
						break;
					case 'section1c_6'://linguistica
						height = 280;
						break;
					case 'section1d'://economicas
						height = 345;
						//alert(height);
						//$('#section1d').html( '<p class="loading">Cargando...</p>' ).load('areas/economicas_empresariales.html');
						break;
					case 'section1e'://ingenieria
						height = 345;
						//alert(height);
						//$('#section1e').html( '<p class="loading">Cargando...</p>' ).load('areas/ingenieria.html');
						break;
					case 'section1f'://medicina
						height = 750;//crap in ie7
						//alert(height);
						//$('#section1f').html( '<p class="loading">Cargando...</p>' ).load('areas/medicina.html');
						break;
					case 'section1g'://quimica
						height = 530;
						//alert(height);
						//$('#section1g').html( '<p class="loading">Cargando...</p>' ).load('areas/quimica.html');
						break;
					case 'section1c_4'://documentoscopia
						height = 420;
						break;
					case 'section1h'://teleco/inf
						height = 450;
						//alert(height);
						//$('#section1h').html( '<p class="loading">Cargando...</p>' ).load('areas/telecomunicaciones_informatica.html');
						break;			
				}
				
				$('#content').height(height).css({cursor:"auto", backgroundColor:"white"});
			    
				$('#content').scrollTo( $('li[id='+lnk+']'), 2000, {easing:'elasout'} );
				
				//$.scrollTo( 'li[id=section1g]', 1000 );
				
				//'li[id=section1g]'
				
			}
		}
	}
	
});

/*$(function(){
			$("div[id=sub]").each(function(){
				$(this).height(100)});
});*/



/*$(document).ready(function() {
  $('a[href*="#"]').click(function() {
     //if (location.pathname == this.pathname && location.host == this.host) {
	 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
	  //alert(location.hostname);
       var target = $(this.hash);
       target = target.size() && target || $("[name=" + this.hash.slice(1) +']');
       if (target.size()) {
           target.ScrollTo(200);
           return false;
       }
    };
  });
});*/
