// JavaScript Document

jQuery(document).ready(function(){
	var current_item;
	function after_reveal() {
		 jQuery(this).find('.tl-close').show('fast');
		  jQuery(this).find('.tl-full').show('fast', function() {
															  
				 jQuery('.tl-item').each(function() {
					if (jQuery(this).attr('id') != 'tl-item-' + current_id) {
						if (jQuery.browser.msie) {
							
							jQuery(this).css('width', 600).css('opacity', 0.3);	
						} else {
							jQuery(this).fadeTo('slow', 0.3);	
						}
					}
				});
				jQuery('.tl-bg').each(function() {
					if (jQuery(this).attr('id') != 'tl-bg-' + current_id) {
						if (jQuery.browser.msie) {
							jQuery(this).css('opacity', 0.3);	
						} else {
							jQuery(this).fadeTo(300, 0.3);
						}
					}
				});
				jQuery('.tl-more').each(function() {
					jQuery(this).hide();
				});	
			});
	}
	function after_hide() {
		current_item = jQuery(this).parents('.tl-item');
		id_split = current_item.attr('id').split("-");
		current_id = id_split[2];
		jQuery(this).siblings('.tl-more').show('fast');
		jQuery('.tl-more').each(function() {
			jQuery(this).show();
		});
		jQuery('.tl-item, .tl-bg').each(function() {
			if (jQuery(this).attr('id') != 'tl-item-' + current_id) {
				jQuery(this).fadeTo('fast', 1);	
			}
		});
	}
	jQuery('.tl-more').click(function() {
		highz++;
		
		current_item = jQuery(this).parents('.tl-item');
		id_split = current_item.attr('id').split("-");
		current_id = id_split[2];
		jQuery(this).parents('.tl-item').css('zIndex',highz);
		if (jQuery(this).hide().parents('.tl-item').hasClass('tl-kennan')) {
			jQuery(this).hide().parents('.tl-item').find('.tl-body').animate({width: "250px", left: "-150px"}, 'fast' , after_reveal);
		} else {
			jQuery(this).hide().parents('.tl-item').find('.tl-body').animate({width: "250px"}, 'fast' , after_reveal);
		}
	});
	jQuery('.tl-close').click(function() {
		jQuery(this).hide().parents('.tl-item').find('.tl-full').hide('fast', function() {
			if (jQuery(this).parents('.tl-item').hasClass('tl-kennan')) {
				jQuery(this).parents('.tl-body').animate({width: "100px", left: "0px"}, 'fast', after_hide);	
			} else {
				jQuery(this).parents('.tl-body').animate({width: "100px"}, 'fast', after_hide);	
			}
		});	
		
		
	});
	
});