/*---------------------------------
indexTabs.js (C) 2009 Visual Blaze

Author: Andy Sherman
Company: Visual Blaze
Descript: client-side logic 
for home page tabs
--------------------------------*/

//initialize vars for btn logic -> uses id of parent li of a
var lastBtn = "vMarketBtn";


jQuery(document).ready(function() {
	
	//find all .panelTitle headers and remove
	$('.panelTitle').css('display','none');
	
	//assign active state logic to all buttons
	var links = $('#tabs a');
	for(i=0; i<= (links.length-1); i++) {
		$(links[i]).click(function(){
			$("#"+lastBtn).removeClass("active")//removes previous active
			$(this).parent().addClass("active");//sets newly clicked link with .active
			lastBtn = $(this).parent().attr('id');//sets new lastBtn val
			resizeScroller($(this).attr('href'));//sends panel id [which is being used as anchor in href]
      $.cookie('tabJump', $(this).attr('href'), { expires: 365 }); // set cookie with an expiration date 1 year in the future
		});
	}
	
	//set initial height of scroller
	resizeScroller($("#"+lastBtn+" a").attr('href'));
	
	
	//localScroll finds all anchors inside of #tabs container -> uses these for action to scroll to corresponding content [assigns nec click logic]
	//target: #scroller defines scroller as the piece of content that scrolls
	
	$('#tabs').localScroll({target:'#scroller', axis:'y',queue:true //,one axis at a time
		   //onAfter:function(){ resizeScroller($("#"+lastBtn+ " a").attr('href'));} //use if applying scroller resize after animation
	});
	
	//function to resize #scroller -> !NEEDS TO BE SMOOTHER -> ANIMATE SIZE/DO AFTER SCROLLER DONE
	function resizeScroller(panelId) {
		
		//use panelId to obtain panel height
		//var panelHeight = $(panelId).css("height");-> failed in ie [read as auto]
		var panelHeight = document.getElementById(panelId.substr(1)).offsetHeight;
		
		//use panelHeight to change scroller height
		$('#scroller').css('height',panelHeight);
		//$('#scroller').animate({"height": panelHeight}, 500);//doesn't work
		
	}
  
  if($.cookie('tabJump') != null){ //RJJ
    $('a[href$="'+$.cookie('tabJump')+'"]').click();
  }
});
