$(document).ready(function(){
  var time = 300;
  var slide_offset = 1100;
  $('#nav a').click(function(){
    var num = $(this).attr('id');
   	//window.location.hash = "default.htm" + num*1 + "";
		set_proper_hash(num*1);
    $('#track').animate({marginLeft:-1*num*slide_offset}, time);
    strip_active();
    $(this).addClass('active');
    return false;
  });

  $('#low_nav a').click(function(){
    var num = $(this).attr('id');
    $('#track').animate({marginLeft:-1*num*slide_offset}, time);
    strip_active();
    if(num + "" == num*1 + ""){ // top links
      $('#low_nav #0' + num).addClass('active');
    }else{ // bottom links
      $('#nav #' + num*1).addClass('active');
      //window.location.hash = "default.htm" + num*1;
			set_proper_hash(num*1);
    }
    return false;
  });
  
	if(window.location.hash){
  	time = 0;
	var position = get_page_from_hash(window.location.hash);
  	$('#nav #' + String(position)).trigger('click');
  	time = 300;
	}
  
  

  var about_nav_loc = 1;
  var about_nav_offset = 740;

 $('#about_psico a').click(function(){
    about_nav_loc = $(this).attr('id');
    move_about_psico(about_nav_loc, about_nav_offset);
    select_about_psico(about_nav_loc);
    return false;
  });


 $('#about_dietetica a').click(function(){
    about_nav_loc = $(this).attr('id');
    move_about_dietetica(about_nav_loc, about_nav_offset);
    select_about_dietetica(about_nav_loc);
    return false;
  });

 
 $('#about_masaje a').click(function(){about_subframe_sex
    about_nav_loc = $(this).attr('id'); 
    move_about_masaje(about_nav_loc, about_nav_offset);
    select_about_masaje(about_nav_loc);
    return false;
  });
  
   $('#about_sex a').click(function(){
    about_nav_loc = $(this).attr('id'); 
    move_about_sex(about_nav_loc, about_nav_offset);
    select_about_sex(about_nav_loc);
    return false;
  });


 $('#about_nav a').click(function(){
    about_nav_loc = $(this).attr('id');
    move_about_track(about_nav_loc, about_nav_offset);
    select_about_active(about_nav_loc);
    return false;
  });


  $('#about_arrow_left_sex').click(function(){
   
    about_nav_loc--;
    if(about_nav_loc == 0) about_nav_loc = 4;
    move_about_track(about_nav_loc, about_nav_offset);
    select_about_active("00" + about_nav_loc);
    return false;
  });


  $('#about_arrow_right_sex').click(function(){

    about_nav_loc++;
    if(about_nav_loc == 5) about_nav_loc = 1;
    move_about_track(about_nav_loc, about_nav_offset);
    select_about_active("00" + about_nav_loc);
    return false;
  });


  $('#about_arrow_left_masaje').click(function(){
    about_nav_loc--;
    if(about_nav_loc == 5) about_nav_loc = 8;
    move_about_masaje(about_nav_loc, about_nav_offset);
    select_about_active("00" + about_nav_loc);
    return false;
  });



  $('#about_arrow_right_masaje').click(function(){


    about_nav_loc++;

	//alert(about_nav_loc);

    if(about_nav_loc == 5) about_nav_loc = 1;
    move_about_masaje(about_nav_loc + 4, about_nav_offset);
    select_about_masaje("00" + about_nav_loc + 4);
    return false;
  });



  $('#about_arrow_left_psico').click(function(){
    about_nav_loc--;
    if(about_nav_loc == 0) about_nav_loc = 13;
    move_about_track(about_nav_loc, about_nav_offset);
    select_about_active("00" + about_nav_loc);
    return false;
  });


  $('#about_arrow_right_psico').click(function(){
    about_nav_loc++;
    if(about_nav_loc == 5) about_nav_loc = 1;
    move_about_track(about_nav_loc, about_nav_offset);
    select_about_active("00" + about_nav_loc);
    return false;
  });




  $('#about_arrow_right_dietetica').click(function(){
    about_nav_loc++;
    if(about_nav_loc == 13) about_nav_loc = 9;
    move_about_track(about_nav_loc, about_nav_offset);
    select_about_active("00" + about_nav_loc);
    return false;
  });


  $('#about_arrow_left_dietetica').click(function(){
    about_nav_loc--;
    if(about_nav_loc == 8) about_nav_loc = 12;
    move_about_track(about_nav_loc, about_nav_offset);
    select_about_active("00" + about_nav_loc);
    return false;
  });




  
  $('#about_arrow_left').click(function(){
    about_nav_loc--;
    if(about_nav_loc == 0) about_nav_loc = 6;
    move_about_track(about_nav_loc, about_nav_offset);
    select_about_active("00" + about_nav_loc);
    return false;
  });


  $('#about_arrow_right').click(function(){
    about_nav_loc++;
    if(about_nav_loc == 7) about_nav_loc = 1;
    move_about_track(about_nav_loc, about_nav_offset);
    select_about_active("00" + about_nav_loc);
    return false;
  });



	$('#store_music_link').click(function(){
		$('#store_subtrack').animate({marginLeft:0}, 300);
		$(this).parent().addClass('active');
		$('#store_apparel_link').parent().removeClass('active');
		return false;
	});
	$('#store_apparel_link').click(function(){
		$('#store_subtrack').animate({marginLeft:-500}, 300);
		$(this).parent().addClass('active');
		$('#store_music_link').parent().removeClass('active');
		return false;
	});
	
	$('#email').focus(function(){
		if($(this).val() == "EMAIL") $(this).val('');
	});
	$('#email').blur(function(){
		if($(this).val() == "") $(this).val('EMAIL');
	});
	
	if($.browser.msie){
		$('#slide_pete .desc p').css({'overflow':'auto'});
	}else{
		$('#slide_pete .desc p').jScrollPane();
	}
	
	$('img#sb-content').click(function(){
		alert('hi');
		Shadowbox.next();
	});
	
	// gallery sliders
	var images_gallery_pos = 0;
	var gallery_time = 300;
	var gallery_offset = 800;
	var num_image_sets = $('#images_arrow_right').attr('rel');
	$('#image_track').css({width:(num_image_sets+1)*gallery_offset});
	$('#images_arrow_right').click(function(){
		images_gallery_pos++;
		if (images_gallery_pos > num_image_sets) images_gallery_pos = 0;
		$('#image_track').animate({marginLeft:-1*gallery_offset*images_gallery_pos}, gallery_time);
		return false;
	});
	$('#images_arrow_left').click(function(){
		images_gallery_pos--;
		if (images_gallery_pos < 0) images_gallery_pos = num_image_sets;
		$('#image_track').animate({marginLeft:-1*gallery_offset*images_gallery_pos}, gallery_time);
		return false;
	});
	
	var videos_gallery_pos = 0;
	var num_video_sets = $('#videos_arrow_right').attr('rel');
	$('#video_track').css({width:(num_video_sets+1)*gallery_offset});
	if(num_video_sets == 0){
		$('#videos_arrow_right').css({visibility:'hidden'});
		$('#videos_arrow_left').css({visibility:'hidden'});
	}
	$('#videos_arrow_right').click(function(){
		videos_gallery_pos++;
		if (videos_gallery_pos > num_video_sets) videos_gallery_pos = 0;
		$('#video_track').animate({marginLeft:-1*gallery_offset*videos_gallery_pos}, gallery_time);
		return false;
	});
	$('#videos_arrow_left').click(function(){
		videos_gallery_pos--;
		if (videos_gallery_pos < 0) videos_gallery_pos = num_video_sets;
		$('#video_track').animate({marginLeft:-1*gallery_offset*videos_gallery_pos}, gallery_time);
		return false;
	});
	
	$('#mailer_form').submit(function(){
    //$.post("http://www.reverbnation.com/fan_reach/add_email_direct_internal/artist_436135", {email: $('#email').val()});
		$.post("fan_email.php.htm", {email: $('#email').val()});
    alert('Thanks!');
    return false;
  });
});

function strip_active(){
  $('#nav a, #low_nav a').removeClass('active');
}

function move_about_track(a, b){
  a = a-1;
  $('#about_subtrack').animate({marginLeft:-1*a*b}, 300);
}

function select_about_active(a) {
  $('#about_nav li').removeClass('active');
  $('#' + a).parent().addClass('active');
}

function move_about_masaje(a, b){
  a = a-5;
  $('#about_subtrack_masaje').animate({marginLeft:-1*a*b}, 300);
}

function select_about_masaje(a) {
	
  $('#about_masaje li').removeClass('active');
  $('#' + a).parent().addClass('active');
}


function move_about_psico(a, b){
  a = a-13;
  $('#about_subtrack_psico').animate({marginLeft:-1*a*b}, 300);
}

function select_about_psico(a) {
	
  $('#about_psico li').removeClass('active');
  $('#' + a).parent().addClass('active');
}


function move_about_sex(a, b){
  a = a-1;
  $('#about_subtrack_sex').animate({marginLeft:-1*a*b}, 300);
}

function select_about_sex(a) {
	
  $('#about_sex li').removeClass('active');
  $('#' + a).parent().addClass('active');
}


function move_about_dietetica(a, b){
  a = a-9;
  $('#about_subtrack_dietetica').animate({marginLeft:-1*a*b}, 300);
}

function select_about_dietetica(a) {
	
  $('#about_dietetica li').removeClass('active');
  $('#' + a).parent().addClass('active');
}



function set_proper_hash(num){
	var new_hash;
	switch(num){
		case 0: new_hash = "contacto"; break;
		case 1: new_hash = "nutricion"; break;
		case 2: new_hash = "psicologia"; break;
		case 3: new_hash = "sexologia"; break;
		case 4: new_hash = "corporales"; break;
		case 5: new_hash = "coaching"; break;
	}
	window.location.hash = new_hash;
}
function get_page_from_hash(string){
	switch(string){
		case "#contacto": return 0;
		case "#nutricion": return 1;
		case "#psicologia": return 2;
		case "#sexologia": return 3;
		case "#corporales": return 4;
		case "#coaching": return 5;

	}
	window.location.hash = "";
	return 0;
}






