/* List Ticker by Alex Fish 
// www.alexefish.com
//
// options:
//
// effect: fade/slide
// speed: milliseconds
*/
(function($){
  $.fn.list_ticker = function(options){
    
    var defaults = {
      speed:4000,
	  effect:'slide'
    };
    
    var options = $.extend(defaults, options);
    
    return this.each(function(){
      
      var obj = $(this);
      var list = obj.children();
      list.not(':first').hide();
      
      setInterval(function(){
        
        list = obj.children();
        list.not(':first').hide();
        
        var first_li = list.eq(0)
        var second_li = list.eq(1)
		
		if(options.effect == 'slide'){
			first_li.slideUp();
			second_li.slideDown(function(){
				first_li.remove().appendTo(obj);
			});
		} else if(options.effect == 'fade'){
			first_li.fadeOut(function(){
				second_li.fadeIn();
				first_li.remove().appendTo(obj);
			});
		}
      }, options.speed)
    });
  };
})(jQuery);

/**
 * 
 * Does a bit more now.....
 * 
 */

var sbi;

$(document).ready(function(){
	
	//FIX THE MENU IE6
	/*
	//navRoot = $('#nav');
	navRoot = document.getElementById("nav");
		
	for (i=0; i<navRoot.childNodes.length; i++) {
		
		node = navRoot.childNodes[i];
			
		if (node.nodeName=="LI") {
						
			node.onmouseover=function() {
				//alert(this);
				this.className+=" over";
			}
			
			node.onmouseout=function() {
				
				this.className=this.className.replace(" over", "");
				
			}
		}
	  }	
	*/
	$('#message ul').list_ticker({
		speed:5000,
		effect:'fade'
	});	
	
	sbi = $('#search input:text[name=findtext]');
	
	if (sbi.val() == '') {
		
		sbi.val('Keyword Search');
		
		sbi.focus(function() {
			
			if (sbi.val() == 'Keyword Search') {
			
				sbi.val('');
			}
			
		});
		
		sbi.blur(function() {
			
			if (sbi.val() == '') {
			
				sbi.val('Keyword Search');
			}
			
		});
		
	}
	
	//check to see if they are online for the live help!
	
	var live = $('#liveHelp a');
			
	if (live.length < 1) {
		
		$('#liveHelp').css('display','none');
		
	}
	
	//if on the product page hide all the section boxes and make select state class active!
	
	 var sections = $('.group-detail');
	 	 
	 for (var x = 0 ; x < sections.length; x++ ) {
		 
		 //do not hide the first one....
		 
		 if (x > 0) {
			 
			 sections[x].style.display = 'none';
			 
		 } 
		 
	 }
	 
	 //now add the onclick function to each section
	 
	 var section = $('#group-header a');
	 	 
	 for (var x = 0 ; x < section.length; x++ ) {		 
				 
		 if (x == 0) {
			
			section[x].parentNode.className = 'selected';
			 
		 }
		 
		 section[x] = $(section[x]);
		 
		 section[x].click(function(){
			 			 
			 var id  = this.href.substr((this.href.lastIndexOf('#')+ 1));
			 
			 //get the sections
			 
			 var sections = $('.group-detail');
		 	 
			 var section = $('#group-header a');
			 
			 //console.log(section);
			 
			 //console.log(sections);
			 
			 for (var y = 0 ; y < sections.length; y++ ) {
				 				 				 
				 if (sections[y].id != id) {
					 
					 sections[y].style.display = 'none';
					 
					 //console.log(section[y].parentNode);
					 
					 section[y].parentNode.className = '';
					 
				 } else {
					 
					 sections[y].style.display = 'inline';
					 
					 section[y].parentNode.className = 'selected';
					 
				 }
				 
			 }
			 
			 //put last on the last!
			 
			 section[sections.length - 1].parentNode.className = section[sections.length - 1].parentNode.className + ' last';
			 
			 return false;
			 
		 });
		 
	 }
	
});
