(function($) {
    $.fn.extend({
        collapsiblePanel: function() {
            // Call the ConfigureCollapsiblePanel function for the selected element
            return $(this).each(ConfigureCollapsiblePanel);
        }
    });

})(jQuery);

function ConfigureCollapsiblePanel() {
	$(".nav").find("LI:first").css("border-top", "1px solid #7e7c78");
    
	$(this).addClass("ui-widget");

    // Check if there are any child elements, if not then wrap the inner text within a new div.
    if ($(this).children().length == 0) {
        $(this).wrapInner("<div></div>");
    }

    // Wrap the contents of the container within a new div.
    $(this).children().wrapAll("<div class='collapsibleContainerContent ui-widget-content'></div>");
   
    // Create a new div as the first item within the container.  Put the title of the panel in here.
    
   // $("<div class='collapsibleContainerTitle ui-widget-header'><div>" + $(this).attr("title") + "</div></div>").prependTo($(this));
      //$("<div class='collapsibleContainerTitle ui-widget-header'><div>" + $(this).attr("title") + "</div></div>").prependTo($(this));


    // Assign a call to CollapsibleContainerTitleOnClick for the click event of the new title div.
    //$(".collapsibleContainerTitle", this).click(CollapsibleContainerTitleOnClick);
   
   /////////////////do i need this?
    $(this).parent().click(CollapsibleContainerTitleOnClick);
    
    ////////////////////////////
    //NOTE:   Parent is the LI tag
    ///////////////////////////
    //var stitle = $(this).attr("id");
    //var parentTag = $(this).parent().get(0).tagName;
	var parentID = $(this).parent().attr('id');
    //$(this).parent().html("hmm");
    //alert(parentID);
    ///////////////////////////////
    //more notes:
    //collapsibleContainerContent is the container for the SUB
    
    //This calls each one in order
	
	
	//get the page
	 var pathname = window.location.pathname;
	 ///alert(pathname);
	 pp_collections=pathname.indexOf(parentID);
	 //alert(pp_collections);
	 //var ddiv = $(this).next('.collapsibleContainerContent');
	 //alert(ddiv.attr('id'));
	  //window.location.replace("http://stackoverflow.com");
	  
	// if (pp_collections >0){gotit=0;alert('gotit');}else{$(this).find('.collapsibleContainerContent').slideUp();}
     if (pp_collections >0){
		 gotit=1;
			if ($(this).is(":hidden")) {
      				//$("div").show("slow");
			//		alert ("hidden");
    				} 
			//		alert(parentID);
			if (  $(this).find(".collapsibleContainerContent").is(":hidden")) {
     // alert("changed it");
      $(this).find('.collapsibleContainerContent').show();
			//$(this).find('.collapsibleContainerContent').Show();
			}	 
	 }else{
	/*$(this).find('.collapsibleContainerContent').slideUp();*/
		nada=0;
		//alert(parentID);
//		collapsibleContainerContent ui-widget-content
		
    $(this).find('.collapsibleContainerContent').hide();
		
	}
    
	//if (pp_collections >0){nada=0;}else{$("div.collapsibleContainerContent").slideUp();}
    
    //
    $('.container').wrap('<div class="cwrap" />');
}

function CollapsibleContainerTitleOnClick() {
    // The item clicked is the title div... get this parent (the overall container) and toggle the content within it.
 //is actually the content area is clicked
 //alert ($(this).attr("id"));
   ///////////////////////
   ///////NOTES:
   ///////This is normally the LI that is clicked. We can read the ID of the title like this:
   ///////                  $(this).attr("id");
   /////////////////////
   // $(".collapsibleContainerContent", $(this).parent()).slideToggle();
  var this_id = $(this).attr("id");
  //if (this_id !="locations"){this_id = "collections";}
  //alert(this_id);
  //alert ($(this).html());
  //alert ($(this).parent().html());
  // if (parentID=="collections"){window.location.replace("http://jennyjo.com/clients/metrodesign/hokanson/main_collections_alexander.html");} 
	 
	 //do I really need this
     // $(".collapsibleContainerContent").slideUp();
	 
      if (  $(this).find(".collapsibleContainerContent").is(":hidden")) {
      				//$("div").show("slow");
	//				alert ("hidden");
		if (this_id=="collections"){
		//alert ("hide locations this is "+this_id);
		if (  $("#locations").find(".collapsibleContainerContent").is(":hidden")  ){ 
		$("#locations").find(".collapsibleContainerContent").slideUp();
		
		}
		//border-top: 1px solid #7A7A7A;
		//css({'background-color' : 'yellow', 'font-weight' : 'bolder'});
		//css({'background-color' : 'yellow');
		
		//$("#img_prj").css({'border-top': '1px solid #7A7A7A'});	
		$("#con_space").css({'border-top': 'none'});	
		
		//window.location.href = "http://jennyjo.com/clients/metrodesign/hokanson_centered/main_collections_alexander.html";
        
        
        //-----------------------------------------------------------------------------
        //Location to collections main - used by all collection pages (イアン　シュー)
        //-----------------------------------------------------------------------------
		window.location.href = "main_collections_alexander.html";
        //window.location.href = "main_collections_sale.html";
        //--//
		
		
		
		}else{
		//alert ("hide_collections this is "+this_id);	
		if (  $("#collections").find(".collapsibleContainerContent").is(":hidden")  ){ 
		$("#collections").find(".collapsibleContainerContent").slideUp();
		}
		
		//$("#collections").find(".collapsibleContainerContent").slideUp();
		
		
		$("#img_prj").css({'border-top': 'none'});	
		$("#con_space").css({'border-top': '1px solid #7A7A7A'});	
		
		//	window.location.href = "http://jennyjo.com/clients/metrodesign/hokanson_centered/main_locations_houston.html";
window.location.href = "/main_locations_houston.html";
		
		}
		
    	//$(".collapsibleContainerContent", $(this)).slideDown();	
				
					} else{
			
			//		alert("not hidden");	
		//$(".collapsibleContainerContent").hide();
		if (this_id=="collections"){//alert("col");
		}
		if (this_id=="locations"){//alert("loc");
		}
					
					}
			
//	  $(".collapsibleContainerContent", $(this)).slideToggle();

}
