var speed1 = 500;
var speed2 = 700;
var filtersShowing = false;        

$(document).ready(function() {                
        $('a.toggle-label').bind("click", function() {return false;});        
        // When a.toggle-label is clicked, toggle the corresponding div
        $('a.toggle-label').click(function() {		
                if (this.parentNode.nodeName != 'LI') {							
                        /*var title = $(this).attr('title');
                        var str = '#'+title;
                        $(str).slideToggle(speed1);*/
			var href = $(this).attr('href');
			var pos = href.indexOf('#',href);
			var id = href.substr(pos);
			$(id).slideToggle(speed1);
                }
        });
		//Toggle whole row of a.toggle-label at once
		$('.toggle-row').click(function(){
			var row = $(this).parents('tr:first');
			//Find whether the first toggle box is showing or hidden
			var first_toggle_href = $(row).find('a.toggle-label').attr('href');
			var first_toggle_id = first_toggle_href.substr(1);
			var show = !($('#'+first_toggle_id).css('display') != 'none');
			//Hide or show each instance
			$(row).find('.toggle-label').each(function(){
				var toggle_href = $(this).attr('href');
				var toggle_id = toggle_href.substr(1);
				if (show) {
					$('#'+toggle_id).show(speed1);
				} else {
					$('#'+toggle_id).hide(speed1);
				}
			});
			return false;
		});

		$('.hover-show-label').mouseover(function(){
			var idString = $(this).attr('id');
			var pos = idString.indexOf('target_',idString);
			var id = idString.substr(pos+7);			
			$('div#'+id).show();
			var theParent = $('div#'+id).parent()[0];
			theParent.oldZ = $(theParent).css('z-index');
			$(theParent).css('z-index','10');
		});
		$('.hover-show-label').mouseout(function(){
			var idString = $(this).attr('id');
			var pos = idString.indexOf('target_',idString);
			var id = idString.substr(pos+7);
			$('div#'+id).hide();
			var theParent = $('div#'+id).parent()[0];
			$(theParent).css('z-index',theParent.oldZ);
		});

		/*$('a.hover-show-label').mouseover(function(){
			var href = $(this).attr('href');
			var pos = href.indexOf('#',href);
			var id = href.substr(pos);			
			$(id).show();
			var theParent = $(this).parent()[0];
			theParent.oldZ = $(theParent).css('z-index');
			$(theParent).css('z-index','10');
		});
		$('a.hover-show-label').mouseout(function(){
			var href = $(this).attr('href');
			var pos = href.indexOf('#',href);
			var id = href.substr(pos);			
			$(id).hide();
			var theParent = $(this).parent()[0];
			$(theParent).css('z-index',theParent.oldZ);
		});*/

        // Attach the behavior of the above function to toggle-labels inside li's                
        $('li').find('a.toggle-label').each(function () {                                
                $(this).click(function() {
                        var li = $(this).parent();
			var div = $(this).siblings('div').filter('.collapse');
                        if (li.hasClass('open') != true) {                                
                                li.addClass('open');				
                        } else {                                
                                li.removeClass('open');				
                        }
			div.slideToggle(speed1);			
                });
        });

        // Show all toggles in cart
        $('.show-details').bind("click", function() {return false;});
        $('.show-details').click(function() {
		var title = $(this).attr('title');		
		var target = document.getElementById(title);		
                $(target).find('div.collapse').each(function(){
                        if (this.parentNode.nodeName == 'LI' && $(this).parent().hasClass('open') == false) {
                                $(this).parent().addClass('open');
                        }
                        $(this).slideDown(speed1);
                });
        });
        
        // Hide all toggles in cart
        $('.hide-details').bind("click", function() {return false;});
        $('.hide-details').click(function() {
		var title = $(this).attr('title');		
		var target = document.getElementById(title);	
                $(target).find('div.collapse').each(function(){
                        if (this.parentNode.nodeName == 'LI' && $(this).parent().hasClass('open') == true) {
                                $(this).parent().removeClass('open');
                        }
                        $(this).slideUp(speed1);
                });
        });
                    
});