$(document).ready(function(){
  
  $("#circle_center_dull").hover(function(){
    //$("div[id^='circle']").stop();
    $("#circle_center").fadeIn(200, function(){
      $("#circle_1_dull").fadeIn(200, function(){
        $("#circle_2_dull").fadeIn(200, function(){
          $("#circle_3_dull").fadeIn(200);
        });
      });
    });
  },function(){
    
  });
  
  $("#circleContainer").hover(function(){}, function(){
    //$("div[id^='circle']").stop(1,1);
    $("#circle_1").fadeOut(100);
    $("#circle_2").fadeOut(100);
    $("#circle_3").fadeOut(100);
    $("#circle_3_dull").fadeOut(500, function(){
      $("#circle_2_dull").fadeOut(400, function(){
        $("#circle_1_dull").fadeOut(300, function(){
          $("#circle_center").fadeOut(200);
        });
      });
    });
  });
  
  $("#circle_center").hover(function(){
    $("#circle_center").fadeIn(200);
  }, function(){});
  $("#circle_center").hover(function(){}, function(){
    $("#circle_center").fadeOut(100);
  });
  
  $("#circle_1_dull").hover(function(){
    $("#circle_1").fadeIn(200);
  }, function(){});
  $("#circle_1").hover(function(){}, function(){
    $("#circle_1").fadeOut(100);
  });
  
  $("#circle_2_dull").hover(function(){
    $("#circle_2").fadeIn(200);	
  }, function(){});
  $("#circle_2").hover(function(){}, function(){
    $("#circle_2").fadeOut(100);
  });
  
  $("#circle_3_dull").hover(function(){
    $("#circle_3").fadeIn(200);
  }, function(){});
  $("#circle_3").hover(function(){}, function(){
    $("#circle_3").fadeOut(100);
  });
  
  
  $("#circle_center").click(function(){
    goToPage("", 300);
    $("div[id^='circle']").each(function(i){
      $(this).animate({
        left: "50%",
        top: "30%"
      }, { queue:true, duration:700 });
    });
  });
  $("#circle_2").click(function(){
    goToPage("links", 400);
    $("div[id^='circle']").each(function(i){
      $(this).animate({
        left: "90%",
        top: "12%"
      }, { queue:true, duration:700 });
    });
  });
  $("#circle_1").click(function(){
    goToPage("biography", 600);
    $("div[id^='circle']").each(function(i){
      $(this).animate({
        left: "90%",
        top: "88%"
      }, { queue:true, duration:700 });
    });
  });
  $("#circle_3").click(function(){
    goToPage("music", 500);
    $("div[id^='circle']").each(function(i){
      $(this).animate({
        left: "10%",
        top: "88%"
      }, { queue:true, duration:700 });
    });
  });
  
  $("#musicPlayer").slideDown('slow');
  
  countdown();
});
function loadAjaxPage(t_vars, t_div){
  
  $.post("ajaxPages.php", t_vars,
  function(data){
    $("#"+t_div).html(data);
    $("#ajaxContent").show();
    rebind();
  }, "html");
  
}//end loadAjaxPage
function rebind(){
  
  $(".fadeInDiv").each(function(i){
  	$(this).fadeIn("500").animate({opacity: 1.0}, 300);
  });
  
}//end rebind
function goToPage(page, twidth){
  
  document.location = "#"+page;
  $("#ajaxContent").hide("fast", function(){
    $("#ajaxContent").width(twidth);
    loadAjaxPage("p="+page, "ajaxContent");
  });
  
}//end goToPage





/// player
var myListener = new Object();
myListener.onInit = function(){
	this.position = 0;
};
myListener.onUpdate = function(){
	var isPlaying = this.isPlaying;
 		var url = this.url;
 		var volume = this.volume;
 		var position = this.position;
  	var duration = this.duration;
  	
  	var id3_artist = this.id3_artist;
  	var id3_album = this.id3_album;
  	var id3_songname = this.id3_songname;
  	var id3_genre = this.id3_genre;
  	var id3_year = this.id3_year;
  	var id3_track = this.id3_track;
  	var id3_comment = this.id3_comment;
  	
  	position = position/1000;
  	duration = duration/1000;
  	pos_mins = Math.floor(position/60);
  	pos_secs = Math.round( (position/60 - Math.floor(position/60)) * 60);
  	dur_mins = Math.floor(duration/60);
  	dur_secs = Math.round( (duration/60 - Math.floor(duration/60)) * 60);
  	if(pos_secs<10){
      pos_secs = "0"+pos_secs; 
    }
    if(pos_mins<10){
      pos_mins = "0"+pos_mins; 
    }
    if(dur_secs<10){
      dur_secs = "0"+dur_secs; 
    }
    if(dur_mins<10){
      dur_mins = "0"+dur_mins; 
    }
  	
  	$("#songInfo").text(pos_mins+":"+pos_secs+"/"+dur_mins+":"+dur_secs);
};
function getFlashObject(){
	return document.getElementById("myFlash");
}
function play(){
  $("#playerplay").hide();
	$("#playerpause").show();
  if(myListener.position == 0){
    getFlashObject().SetVariable("method:setUrl", "medias/Off_The_Bridge.mp3");
    $("#songTitle").text("Off The Bridge");
  }
  getFlashObject().SetVariable("method:play", "");
  getFlashObject().SetVariable("enabled", "true");
}
function pause() {
	$("#playerplay").show();
	$("#playerpause").hide();
  getFlashObject().SetVariable("method:pause", "");
}
function stop() {
	$("#playerplay").show();
	$("#playerpause").hide();
  getFlashObject().SetVariable("method:stop", "");
  $("#songTitle").text("");
}






function countdown(){
  
  today  = new Date();
  todayEpoch  = today.getTime();
  
  target = new Date("20 April, 2010"); 
  targetEpoch = target.getTime();
  
  diff = targetEpoch - todayEpoch;
  
  d = Math.floor((diff)/60/60/24/1000);
  h = Math.floor((((diff)/60/60/24/1000)*1 - Math.floor((diff)/60/60/24/1000)) * 60);
  m = Math.floor((((diff)/60/60/1000)*1 - Math.floor((diff)/60/60/1000)) * 60);
  s = Math.floor((((diff)/60/1000)*1 - Math.floor((diff)/60/1000)) * 60);
  
  display = d + "d " + h + "h " + m + "m " + s +"s";
  if(d >= 0){
  
    $("#countdown").text(display);
    setTimeout("countdown();", 500);
  }
}