var timer;

var duration = 30000;

var cur = 0;

var total = 0;

//var id

var id = '#left dl dt';

var show  = 2;

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

$(document).ready(function(){
		
	var count = 0;
	
	//hide what needs to be hidden...
	
	$(id).each(function() {
		
		var item = $(this);
		
		count++;
		
		if (count > show) {
			
			$('.'+ this.className).hide();
		}
		
	});
	
	
	total = $(id).length;
		
	//set up a timer to rotate....
	
	timer = setInterval(rotate,duration);
	
	var count = 0;
	
	//now the prev
	
	$(id2).each(function() {
		
		var item = $(this);
		
		count++;
		
		if (count > 3) {
			
			$('.'+ this.className).hide();
		}
		
	});
	
	total2 = $(id2).length;
	
	timer2 = setInterval(rotate_prev,duration);

});

function rotate() {
	
	cur++;
	
	if (cur >= total) {
		
		cur = 0;
		
	}
	
	//show the image for that one... and apply the correct class!
	
	var count = 0;
	
	$(id).each(function(index) {
		
		var slide = $(this);
				
		if (index >= cur ) {
			
			count++;
			
			if (count > show) {
				
				//$('.'+ this.className).hide();
				$('.'+ this.className).slideUp("slow");

			} else {
				
				//$('.'+ this.className).show();
				$('.'+ this.className).slideDown("slow");
				
			} 
			
		} else {
			
			//$('.'+ this.className).hide();
			$('.'+ this.className).slideUp("slow");	
		}
		
	});
	
}

var cur2 = 0;

var total2 = 0;

var id2 = '#case-studies dl dt';

var timer2;

var show2 = 3;

function rotate_prev() {
	
	cur2++;
	
	if (cur2 >= total2) {
		
		cur2 = 0;
		
	}
	
	//show the image for that one... and apply the correct class!
	
	var count = 0;
	
	$(id2).each(function(index) {
		
		var slide = $(this);
				
		if (index >= cur2 ) {
			
			count++;
			
			if (count > show2) {
				
				//$('.'+ this.className).hide();
				$('.'+ this.className).slideUp("slow");

			} else {
				
				//$('.'+ this.className).show();
				$('.'+ this.className).slideDown("slow");
				
			} 
			
		} else {
			
			//$('.'+ this.className).hide();
			$('.'+ this.className).slideUp("slow");	
		}
		
	});
	
}
