/* © Patersons 2000-2009. All Rights Reserved.*/
//var blinding_base_speed = 10.869565217; //how long does the blinding take
var blinding_base_speed = 5;
var blinding_goto = {'top': 0, 'bottom' : 0}; //the heights of the items before we tamper with them
var zero_point =1; //this is one at the moment because of a strange bug/feature with IE where setting it to 0 causes it to reset to visible
var height_set;
var height_blind;
$(document).ready(function(){
	$('.blind').blind_setup();
});
$.fn.blind_setup = function() {
	height_set =40;
	blinding_goto['top'] = height_top = $(this).children('.top').height() + 10;
	if (height_top > 600)  {
		$(this).children('.top').css({height: '600px'});
		$(this).children('.top').children('.cont').css({'overflow-x': 'scroll',height: '600px'});
		blinding_goto['top'] = height_top = 625;
	}
	blinding_goto['bottom'] = height_bottom = $(this).children('.bottom').height();

	
	if (height_top > height_bottom) {
		height_set += height_top;
		height_set += height_bottom/4;
	}
	else {
		height_set += height_bottom;
		height_set += height_top/4;
	}
	height_set += $(this).children('.bar').height();
	$(this).height(height_set);
	
	
	$(this).height(height_blind);
	$(this).children('.top').hide().height(zero_point);
	
	
	$(this).children('.bar').click(function() { $(this).blind_scroll() });	
	$(this).children('.top').click(function() { $(this).blind_scroll() });	
	//to start  we dont have Hide bar or the title bar
	$('.blind .hide_bar').hide();
} 
$.fn.blind_scroll = function() {
	$item = $(this).parent('div');

	if ($item.children('.top:visible').length == 0 || $item.children('.top').height() == zero_point) {  //in case of over zellos user interupting things
		$('.blind .hide_bar').show();
		$('.blind .show_bar').hide();
		$item.children('.top').show().animate({'height' : blinding_goto['top']},blinding_base_speed*blinding_goto['top']);
		$item.children('.bottom').animate({'height' : zero_point},blinding_base_speed*blinding_goto['bottom'],function(){$(this).hide()});
	}
	else {
		$('.blind .hide_bar').hide();
		$('.blind .show_bar').show();
		$('.blind').animate({'height' : height_set},blinding_base_speed*blinding_goto['top']);
		$item.children('.top').animate({'height' : zero_point},blinding_base_speed*blinding_goto['top'],function(){
			$(this).hide();
			
		})
		$item.children('.bottom').show().animate({'height' : blinding_goto['bottom']},blinding_base_speed*blinding_goto['bottom']);
	}
}

