// Toggle contents
/*
function toggleContent(opt_name) {
	if (typeof(($('#'+opt_name+' .scroll-pane')[0].scrollTo)) == 'function')
		$('#'+opt_name+' .scroll-pane')[0].scrollTo(0);
		
	$('#'+opt_name).css('z-index', '10000');
	$('.content-2').slideUp('slow');
	$('.content-2').css('z-index', '10001');
	$('#'+opt_name).slideDown('slow');
};


function showOption (opt_name, left_pos, ini_left, ini_width) {
	$('#'+opt_name).animate({marginLeft: left_pos}, 'slow', srollToTop(opt_name));
	$('#'+opt_name).animate({width: ini_width}, 'slow', function () {
		srollToTop(opt_name);
		$('#'+opt_name+' div').show();
		toggleOption(opt_name);
	});
}

// Toggle contents
function toggleContent(opt_name, left_pos, ini_pos, ini_width) {
	if ($('#arquitectura-text').css('margin-left') != ini_pos) {
		$('#arquitectura-text div').hide();
		$('#arquitectura-text').animate({width: 0}, 'slow');
		$('#arquitectura-text').animate({marginLeft: ini_pos}, 'slow', function() {
			showOption (opt_name, left_pos, ini_pos, ini_width);
		});
	} else if ($('#obra-propia').css('margin-left') != ini_pos) {
		$('#obra-propia div').hide();
		$('#obra-propia').animate({width: 0}, 'slow');
		$('#obra-propia').animate({marginLeft: ini_pos}, 'slow', function() {
			showOption (opt_name, left_pos, ini_pos, ini_width);
		});
	} else if ($('#colaboraciones').css('margin-left') != ini_pos) {
		$('#colaboraciones div').hide();
		$('#colaboraciones').animate({width: 0}, 'slow');
		$('#colaboraciones').animate({marginLeft: ini_pos}, 'slow', function() {
			showOption (opt_name, left_pos, ini_pos, ini_width);
		});
	}
};

function srollToTop(opt_name) {
	if (typeof(($('#'+opt_name+' .scroll-pane')[0].scrollTo)) == 'function')
		$('#'+opt_name+' .scroll-pane')[0].scrollTo(0);
}


// Toggle navigation options submenu level1
function toggleOption(opt_name) {
    list = $('li.'+opt_name).parent();
    jQuery.each(list.children(), function() {
        $(this).removeClass('active');	
    });
    jQuery.each($('.nav-hidden ul').children(), function() {
        $(this).removeClass('active');	
    });
    $('.nav-hidden').hide();
    jQuery.each($('.nav-hidden2 ul').children(), function() {
        $(this).removeClass('active');	
    });
    $('.nav-hidden2').hide();

    $('a.'+opt_name).addClass("active");
    $('li.'+opt_name).addClass("active");
    $('#nav-'+opt_name).show('slow');
};

// Toggle navigation options submenu level2
function toggleOption2(opt_name) {
    list = $('li.'+opt_name).parent();
    jQuery.each(list.children(), function() {
        $(this).removeClass('active');	
    });
    jQuery.each($('.nav-hidden2 ul').children(), function() {
        $(this).removeClass('active');	
    });
    $('.nav-hidden2').hide();

    $('a.'+opt_name).addClass("active");
    $('li.'+opt_name).addClass("active");
    $('#nav-'+opt_name).show('slow');
};

$(document).ready(function () {
	$('.nav-hidden').css('display','none');
	$('.nav-hidden2').css('display','none');

	// Setup Contents
	var left_pos = $('.content-2').css('margin-left');
	var ini_pos = '-' + (($('.content-2').width()*1)+20)+'px';
	var ini_width = $('.content-2').width();

	if (location.hash == '') {
		$('#obra-propia').width('0px');
		$('#obra-propia div').hide();
		$('#obra-propia').css('margin-left', ini_pos);
		$('#colaboraciones').width('0px');
		$('#colaboraciones div').hide();
		$('#colaboraciones').css('margin-left', ini_pos);
	} else {
		$('#arquitectura-text').css('margin-left', ini_pos);
		if (location.hash == '#obra-propia') {
		   	toggleOption('obra-propia'); 
			$('#colaboraciones').width('0px');
			$('#colaboraciones div').hide();
		   	$('#colaboraciones').css('margin-left', ini_pos);
		}
		if (location.hash == '#colaboraciones') {
		   	toggleOption('colaboraciones'); 
			$('#obra-propia').width('0px');
			$('#obra-propia div').hide();
		   	$('#obra-propia').css('margin-left', ini_pos);
		}
	}

	// Setup menus level0
    $('a.arquitectura').attr({ href: "javascript://"});
    $('a.arquitectura').click(function() {
    	// toggleOption('servicios'); 
    	toggleContent('arquitectura-text', left_pos, ini_pos, ini_width); 
    	jQuery.each($('#nav-arquitectura ul').children(), function() {
        	$(this).removeClass('active');	
    	});
    });

	// Setup menus level1	
    $('a.obra-propia').attr({ href: "javascript://"});
    $('a.obra-propia').click(function() {
    	toggleContent('obra-propia', left_pos, ini_pos, ini_width); 
    });

    $('a.colaboraciones').attr({ href: "javascript://"});
    $('a.colaboraciones').click(function() { 
    	toggleContent('colaboraciones', left_pos, ini_pos, ini_width); 
    });

	// Setup menus level2 - Obra propia
    $('a.vivienda-unifamiliar').attr({ href: "javascript://"});
    $('a.vivienda-unifamiliar').click(function() { toggleOption2('vivienda-unifamiliar'); });

    $('a.vivienda-plurifamiliar').attr({ href: "javascript://"});
    $('a.vivienda-plurifamiliar').click(function() { toggleOption2('vivienda-plurifamiliar'); });

    $('a.urbanismo').attr({ href: "javascript://"});
    $('a.urbanismo').click(function() { toggleOption2('urbanismo'); });

    $('a.concursos-premios').attr({ href: "javascript://"});
    $('a.concursos-premios').click(function() { toggleOption2('concursos-premios'); });

	// Setup menus level2 - Colaboraciones
    $('a.equipamiento').attr({ href: "javascript://"});
    $('a.equipamiento').click(function() { toggleOption2('equipamiento'); });

    $('a.plurifamiliar').attr({ href: "javascript://"});
    $('a.plurifamiliar').click(function() { toggleOption2('plurifamiliar'); });

    $('a.unifamiliar').attr({ href: "javascript://"});
    $('a.unifamiliar').click(function() { toggleOption2('unifamiliar'); });
});*/
