var browser = BrowserDetect.browser + " " + BrowserDetect.version

$(document).ready(function() {
			
	//$('#header').css({opacity:0});		
	if(browser !== "Explorer 6" ){
	$(function(){	  
	  $('.text .apply-columns').columnize({
	    width:330,
	    height:290,
	    doneFunc: function(){
	  	  $('#posts').jScrollPane();
	    } 
	  });
	});		
	} else {
	$(function(){	  
	  $('.text .apply-columns').columnize({
	    width:310,
	    height:320,
	    doneFunc: function(){
	  	  $('#posts').jScrollPane();
	    } 
	  });
	});			
	}
	
	if($('#list-of-walk').is(':visible')){
	  $('#list-of-walk').columnize({ width:190, height:265 });	
	}
                                                                                                      
  $('.post-82 div.text a').lightbox(); // Select all links that contains lightbox in the attribute rel
  
  $('.post-82 div.text img').each(function() {
    var maxWidth = 200; // Max width for the image
    var maxHeight = 200;    // Max height for the image
    var ratio = 0;  // Used for aspect ratio
    var width  = $(this).width();    // Current image width
    var height = $(this).height();  // Current image height

    // Check if the current width is larger than the max
    if(width > maxWidth){
        ratio = maxWidth / width;   // get ratio for scaling image
        $(this).css("width", maxWidth); // Set new width
        $(this).css("height", height * ratio);  // Scale height based on ratio
        height = height * ratio;    // Reset height to match scaled image
        width = width * ratio;    // Reset width to match scaled image
    }
  });
	                                                
	$('#posts').jScrollPane();
                                           
  if (window.location.pathname!="/gallery"){	
	  $('#content').draggable();
  }
    //$('#content').animate({ top : -425 },1000)	
	//animateBoxIn();
	
	
	$('#content-toggle').click(function(){
	  contentHandler();
	});
	
    var h  = $(window).height();   
    var position = (h/2) - 300;
    $('#timeline-container').css({ top: position });
    
    var width = $(window).width();    

    $(window).resize(function(){
    var width = $(window).width();    
	mouseHandler(width);    
    });
    
    centerTimeline();
	centerTimelineHorizontally();
	mouseHandler(width);
	contentLoader();
    walkImageOver();		
	
	//centerContent();	
    
    // setup the timeline position
    //var w = $(window).width();   
    //var position = (w/2) - 200;
 	//var columnWidth = (w/10)/2;
	//var middleCol = columnWidth/2;    
    $('#timeline-container').css({ left:0 });
    //$('#header').animate({opacity:"0"},2900);
    //$('#header').animate({opacity:"1"},500); 
     
       
        
}); // end of document.ready function

$(window).load(function () {

}); // jquery that loads when the window loads (i.e. before the content is ready)...\

/** 
* ------------------------------------------------------------------
* WALK IMAGE ANIMATION
* ------------------------------------------------------------------
*/
function walkImageOver() {
  $('.walk-image').hover(function(){
	$(this).animate({top:70},200);
  },
  function(){
    $(this).animate({top:80},200);
  });
}

/** 
* ------------------------------------------------------------------
* MOUSE MOVEMENTS
* ------------------------------------------------------------------
*/
function mouseHandler(width) {
  $('#timeline-container').hover(
  function() {
  $('#timeline-container').stop(); 
  var timelineWidth = $('#timeline').width(); 
  var divCentre = (width/10)/2;
  var fig = (timelineWidth/width)/1.97;
  
  $('#timeline-container').mousemove(function(e){ 
    $('#timeline-container').css({ left:(divCentre-(e.pageX*fig)) });
  });
  
  },function(){
    //$('#timeline-container').stop(); 
    //$('#timeline-container').animate({left:0},1600);
  });
   
}
/** 
* ------------------------------------------------------------------
* MOUSE OUT HANDLER
* ------------------------------------------------------------------
*/
function timelineMouseOut() {

/*
  $('#header').hover(
  function(){
    $('#timeline-container').animate({left:0},1500);
  });
  
  $('#content').hover(
  function(){
    $('#timeline-container').animate({left:0},1500);
  });
*/  
}

/** 
* ------------------------------------------------------------------
* CENTER THE TIMELINE WHEN THE WINDOW RESIZES (Horizontally)
* ------------------------------------------------------------------
*/
function centerTimelineHorizontally(){
  var w = $(window).width();   
  var position = (w/2) - 200;
  var columnWidth = w/10;
  var middleCol = columnWidth/2;    
  $('#timeline-container').css({ left: middleCol });
}


/** 
* ------------------------------------------------------------------
* CONTENT HANDLER
* ------------------------------------------------------------------
*/
function contentHandler() {


  var h  = $(window).height();   
  var position = (h/2) - 200; 
      
  if($.cookie('box-open') == "true"){
    $.cookie('box-open',false);
    animateBoxOut();
  } else {
    $.cookie('box-open',true);
    animateBoxIn();
  }
}

/** 
* ------------------------------------------------------------------
* CONTENT LOADER
* ------------------------------------------------------------------
*/
function contentLoader() {
  var h  = $(window).height();   
  var position = (h/2) - 200;     
  if($.cookie('box-open') == "true"){
    $('#content').animate({ top : "-425" },2000);      
    animateBoxIn();
  }
}

/** 
* ------------------------------------------------------------------
* ANIMATE BOX IN
* ------------------------------------------------------------------
*/
function animateBoxIn() {
  $('#content').show();
  var h  = $(window).height();   
  var position = (h/2) - 200;  
  $('#content').animate({ top : position },600)
    .animate({ top : position-20 },400);
    
  // Set the box open cookie
  $.cookie('box-open',true);
  $.cookie('box-closed',false);     
}

/** 
* ------------------------------------------------------------------
* ANIMATE BOX OUT
* ------------------------------------------------------------------
*/
function animateBoxOut() {
  $('#content').animate({ top : "-435" },600)
  .animate({ top : "-425" },400);

  // Set the box open  
  $.cookie('box-open',false);
  $.cookie('box-closed',true);
}

/** 
* ------------------------------------------------------------------
* CENTER THE TIMELINE WHEN THE WINDOW RESIZES
* ------------------------------------------------------------------
*/
function centerTimeline(){
  $(window).resize(function(){
    var h  = $(window).height();   
    var position = (h/2) - 300;
    $('#timeline-container').css({ top: position });
  });
}

/** 
* ------------------------------------------------------------------
* CENTER THE CONTENT WHEN THE WINDOW RESIZES
* ------------------------------------------------------------------
*/
function centerContent(){
  if($.cookie('box-open') == "true"){
    $(window).resize(function(){
      var h  = $(window).height();   
      var position = (h/2) - 200;
      $('#content').css({ top: position-20 });
    });
  }
}
