jQuery(document).ready(function(){

	//alert("Render mode: "+ document.compatMode + "\nUser Agent: " + navigator.userAgent);
	
	
	//First, some css that couldn't be achieved with css selectors
	jQuery("table:not(.ds-includeSet-metadata-table) tr td:has(span[class=bold])").css({ textAlign:"right", verticalAlign:"top" });
	jQuery("table.ds-includeSet-metadata-table tr td:has(span[class=bold])").css({ textAlign:"left", verticalAlign:"top" });
	jQuery("td.ds-table-cell:has(strong)").css({ backgroundColor:"#DDDDDD", padding:"3px" });
	jQuery("form#aspect_submission_Submissions_div_submissions div#aspect_submission_Submissions_div_start-submision p.ds-paragraph a").css({fontWeight:"bold", color:"#374F5D"});
	jQuery("div#aspect_artifactbrowser_CollectionViewer_div_collection-view div.detail-view + p.ds-paragraph a").css({backgroundColor:"#2E6DA2", color:"white", border:"3px outset white", padding:"3px"});
	jQuery("div#aspect_artifactbrowser_CollectionViewer_div_collection-view div.detail-view + p.ds-paragraph").css({marginTop:"15px"});
	
	/* added in order to fix disappearing text in IE8 compatibility-mode */
    jQuery("div#aspect_artifactbrowser_CommunityViewer_div_community-view li.ds-artifact-item").css("position", "relative");

	
	//eliminate empty menus; div.menuslider div.ds-option-set whose ul contains no li - was used for the unpopular hover-accordion menu sliders
	/*
	jQuery("div.menuslider:has(div.ds-option-set:has(ul.ds-option-list:not(:has(li))))").remove();
	jQuery("div.menuslider:has(div:has(ul:not(:has(li))))").css({ border:"5px solid red"});
	*/
	
	//eliminate ListPlus and ListMinus for the community/collection hierarchy when there is no ul contained in the li.
	//replace them with spacers to make the hierarchy look flush
	//div#aspect_artifactbrowser_CommunityViewer_div_community-view
	//div#aspect_artifactbrowser_CommunityBrowser_div_comunity-browser	
	jQuery("div.ds-static-div li:not(:has(ul))").children("img.ListPlus").after("<p class=\"ListEmpty\"></p>");
	jQuery("div.ds-static-div li:not(:has(ul))").children("img.ListMinus, img.ListPlus").remove();
	
	//close the community/collection hierarchy by default
	jQuery(document).hideAllCommColl();
	//close to second level the community/collection hierarchy on community view page.
	//jQuery(document).hideCommCollInCommViewTo2ndLevel();
	
	//show the Expand All link
	jQuery("div#aspect_artifactbrowser_CommunityBrowser_div_comunity-browser img#expand_all_clicker").show();
	jQuery("div#aspect_artifactbrowser_CommunityViewer_div_community-view img#expand_all_clicker").show();
	
	//eliminate the expansion clickers when they appear in the context of the front page
	jQuery("div#right_content_column div#aspect_artifactbrowser_CommunityBrowser_div_comunity-browser img#expand_all_clicker, div#right_content_column div#aspect_artifactbrowser_CommunityBrowser_div_comunity-browser img#collapse_all_clicker").remove();
	
	//open "Browse" menu option by default
	/*
	jQuery("h3#menu_heading_0").removeClass("closed");
	jQuery("h3#menu_heading_0").addClass("open");
	jQuery("h3#menu_heading_0").next().show()
	jQuery("h3#menu_heading_0").find("img.menu_nav_icon_open").show();
	jQuery("h3#menu_heading_0").find("img.menu_nav_icon_closed").hide();*/
	jQuery("h3#menu_heading_0").siblings("div.ds-option-set").slideDown("fast");
	jQuery("h3#menu_heading_0").addClass("open");
	jQuery("h3#menu_heading_0").removeClass("closed");
	jQuery("h3#menu_heading_0").find("img.menu_nav_icon_open").show();
	jQuery("h3#menu_heading_0").find("img.menu_nav_icon_closed").hide();
	
	jQuery("h3#menu_heading").siblings("div.ds-option-set").slideDown("fast");
	jQuery("h3#menu_heading").addClass("open");
	jQuery("h3#menu_heading").removeClass("closed");
	jQuery("h3#menu_heading").find("img.menu_nav_icon_open").show();
	jQuery("h3#menu_heading").find("img.menu_nav_icon_closed").hide();
	
	//close "Search" menu option by default
	
	jQuery("h3#menu_heading_search").siblings("div.ds-search-option-set").slideUp("fast");
	jQuery("h3#menu_heading_search").addClass("closed");
	jQuery("h3#menu_heading_search").removeClass("open");
	jQuery("h3#menu_heading_search").find("img.menu_nav_icon_closed").show();
	jQuery("h3#menu_heading_search").find("img.menu_nav_icon_open").hide();
	//The unpopular hover-sliding collapsable menus on left navigation bar
	/*
	jQuery("div.menuslider h3.closed").bind("mouseover",function(){
	    //hide any open sub-menu
	    jQuery("h3.open").next().slideUp("slow");
		jQuery("h3.open").find("img.menu_nav_icon_open").hide();
		jQuery("h3.open").find("img.menu_nav_icon_closed").show();
	    jQuery("h3.open").addClass("closed");
	    jQuery("h3.open").removeClass("open");
	    
	    //show this sub-menu
	    jQuery(this).next("div.ds-option-set").slideDown("slow");
	    jQuery(this).addClass("open");
	    jQuery(this).removeClass("closed");
		jQuery(this).find("img.menu_nav_icon_open").show();
		jQuery(this).find("img.menu_nav_icon_closed").hide();
		
		jQuery(document).myReBind();
	});*/
		
	
	

	//Click to open sliders on the left menu
	jQuery("h3.closed").toggle(function(){
	    jQuery(this).addClass("open");
		jQuery(this).removeClass("closed");
		jQuery(this).next().slideDown("fast");
		jQuery(this).find("img.menu_nav_icon_open").show();
		jQuery(this).find("img.menu_nav_icon_closed").hide();
	},function(){					
	    jQuery(this).addClass("closed");
	    jQuery(this).removeClass("open");
		jQuery(this).next().slideUp("fast");
		jQuery(this).find("img.menu_nav_icon_open").hide();
		jQuery(this).find("img.menu_nav_icon_closed").show();
	});
	jQuery("h1.closed").toggle(function(){
	    jQuery(this).addClass("open");
		jQuery(this).removeClass("closed");
		jQuery(this).next().slideDown("fast");
		jQuery(this).find("img.menu_nav_icon_open").show();
		jQuery(this).find("img.menu_nav_icon_closed").hide();
	},function(){					

	    jQuery(this).addClass("closed");
	    jQuery(this).removeClass("open");
		jQuery(this).next().slideUp("fast");
		jQuery(this).find("img.menu_nav_icon_open").hide();
		jQuery(this).find("img.menu_nav_icon_closed").show();
	});
	//Additionally, handle the guys that starts off open.				
	jQuery("h3.open").toggle(function(){
		jQuery(this).addClass("closed");
	    jQuery(this).removeClass("open");
		jQuery(this).next().slideUp("fast");
		jQuery(this).find("img.menu_nav_icon_open").hide();
		jQuery(this).find("img.menu_nav_icon_closed").show();
	},function(){					
	    jQuery(this).addClass("open");
		jQuery(this).removeClass("closed");
		jQuery(this).next().slideDown("fast");
		jQuery(this).find("img.menu_nav_icon_open").show();
		jQuery(this).find("img.menu_nav_icon_closed").hide();
	});
	
	//Additionally, handle the guys that starts off open.				
	jQuery("h1.open").toggle(function(){
		jQuery(this).addClass("closed");
	    jQuery(this).removeClass("open");
		jQuery(this).next().slideUp("fast");
		jQuery(this).find("img.menu_nav_icon_open").hide();
		jQuery(this).find("img.menu_nav_icon_closed").show();
	},function(){					
	    jQuery(this).addClass("open");
		jQuery(this).removeClass("closed");
		jQuery(this).next().slideDown("fast");
		jQuery(this).find("img.menu_nav_icon_open").show();
		jQuery(this).find("img.menu_nav_icon_closed").hide();
	});
	//The navigation hover text contextual feedback at the top of the page	- these got removed from the design for aesthetic reasons.
	/*
	jQuery("a.top-icon").hover(function(){
		jQuery(this).find("span").each(function() {
			jQuery(this).addClass("top-icon-text-shown");
		});
	},function(){
		jQuery(this).find("span").each(function() {
			jQuery(this).removeClass("top-icon-text-shown");
		});
	});
	*/
	
	
	
	//community/collection hierarchy
	//expansion with the plus sign (or horizontal arrow)
	jQuery("img.ListPlus").click(function(){
		jQuery(this).hide();
		jQuery(this).next("img.ListMinus").show();
		jQuery(this).parent().children("ul").slideDown("fast");
		});	
		
	//contraction with the minus sign (or vertical arrow)
	jQuery("img.ListMinus").click(function(){
		jQuery(this).hide();
		jQuery(this).prev("img.ListPlus").show();
		jQuery(this).parent().children("ul").slideUp("fast");
		});
		
       jQuery("span.toggle-list2").toggle(function(){
        jQuery(document).showAllCommColl();
        jQuery("img#expand_all_clicker").hide();
        jQuery("img#collapse_all_clicker").show();
        jQuery(this).find("h4.open").show();
		jQuery(this).find("h4.closed").hide();
        },
        function(){
        jQuery(document).hideAllCommColl();
        jQuery("img#collapse_all_clicker").hide();
        jQuery("img#expand_all_clicker").show();
        jQuery(this).find("h4.closed").show();
		jQuery(this).find("h4.open").hide();
        });

	/*jQuery("img#expand_all_clicker").click(function(){
        jQuery(document).showAllCommColl();
        jQuery("img#expand_all_clicker").hide();
        jQuery("img#collapse_all_clicker").show();
        jQuery(this).find("h4.open").show();
		jQuery(this).find("h4.closed").hide();
        });*/
        
    //jQuery("img#collapse_all_clicker").click(function(){
   /* jQuery("img#collapse_all_clicker").click(function(){
        jQuery(document).hideAllCommColl();
        jQuery("img#collapse_all_clicker").hide();
        jQuery("img#expand_all_clicker").show();
        jQuery(this).find("h4.closed").show();
		jQuery(this).find("h4.open").hide();
        });*/
        
//	jQuery("p#expand_list_clicker").click(function(){
//        jQuery(document).showAllCommColl();
//        jQuery("p#expand_list_clicker").hide();
//        jQuery("p#collapse_list_clicker").show();
//        });
//    jQuery("p#collapse_list_clicker").click(function(){
//        jQuery(document).hideAllCommColl();
//        jQuery("p#collapse_list_clicker").hide();
//        jQuery("p#expand_list_clicker").show();
//        });
        
        
	//The metadata popups for ds-artifact-item-with-popup's
    jQuery("span.toggle-list").toggle(function(){
		jQuery("body").css({overflow:"hidden"});
		jQuery("div.artifact-description").hide();
		jQuery("div.box").hide();
		jQuery("input.myitem").hide();
		jQuery("a.artifact-preview").css({float:"none"});
		jQuery("img.previewimg").css({ height:"75px"});
		jQuery("ul#filelist2").css({overflow: "hidden"});
		jQuery("li.ds-artifact-item").css({float:"none"});
		//jQuery(this).addClass("closed");
		//jQuery(this).removeClass("open");
		jQuery(this).find("img.menu_nav_icon_open").show();
		jQuery(this).find("img.menu_nav_icon_closed").hide();
		jQuery(this).find("h4.open").show();
		jQuery(this).find("h4.closed").hide();
		//jQuery(this).find("img_open").show();
		//jQuery(this).find("img_closed").hide();
		//jQuery(this).addClass("open");
		//jQuery(this).removeClass("closed");
		
		
	},function(){
		jQuery("body").css({overflow:"visible"});
		jQuery("div.artifact-description").show();
		jQuery("div.box").show();
		jQuery("input.myitem").show();
		jQuery("a.artifact-preview").css({float:"left"});
		jQuery("img.previewimg").css({height:"29px"});
		jQuery("ul#filelist2").css({overflow: "auto"});
		jQuery("li.ds-artifact-item").css({float:"left"});
		//jQuery(this).addClass("open");
		//jQuery(this).removeClass("closed");
		jQuery(this).find("img.menu_nav_icon_closed").show();
		jQuery(this).find("img.menu_nav_icon_open").hide();
		jQuery(this).find("h4.closed").show();
		jQuery(this).find("h4.open").hide();
		//jQuery(this).find("img_closed").show();
		//jQuery(this).find("img_open").hide();
		//jQuery(this).removeClass("open");
		//jQuery(this).addClass("closed");
	});
	
	
	//The metadata popups for ds-artifact-item-with-popup's
    jQuery("div.item_metadata_more").toggle(function(){
		jQuery(this).children(".item_more_text").hide();
		jQuery(this).children(".item_less_text").show();
		jQuery(this).next().slideDown();
	},function(){
		jQuery(this).children(".item_more_text").show();
		jQuery(this).children(".item_less_text").hide();
		jQuery(this).next().slideUp();
	});


	
	//slider for filter search
	jQuery("div#collapsible-filter-search-fields div.more_text").click(function(){
		jQuery("div#collapsible-filter-search-fields div.more_text").hide();
		jQuery("div#collapsible-filter-search-fields div.less_text").show();
		jQuery("div#collapsible-filter-search-fields-table-container").slideDown("fast");
		});
	jQuery("div#collapsible-filter-search-fields div.less_text").click(function(){
		jQuery("div#collapsible-filter-search-fields div.more_text").show();
		jQuery("div#collapsible-filter-search-fields div.less_text").hide();
		jQuery("div#collapsible-filter-search-fields-table-container").slideUp("fast");
		});



    //the about text slider	
	jQuery("p#rotating_header_more").click(function(){
		jQuery("p#rotating_header_para").slideUpShow("slow");
		jQuery("p#rotating_header_less").show();
		jQuery(this).hide();
		});
	
	jQuery("p#rotating_header_less").click(function(){
		jQuery("p#rotating_header_para").slideDownHide("slow");
		jQuery("p#rotating_header_more").show();
		jQuery(this).hide();
		});
});



jQuery.fn.extend({
  slideDownHide: function(speed){
  	return this.animate({height: "hide", top: "0px"}, speed);
  },
  slideUpShow: function(speed,callback){
  	return this.animate({height: "show", top: "-50px"}, speed);
  },
  hideAllCommColl: function(){
  	jQuery("div#aspect_artifactbrowser_CommunityBrowser_div_comunity-browser img.ListPlus").show();
  	jQuery("div#aspect_artifactbrowser_CommunityBrowser_div_comunity-browser img.ListMinus").hide();
  	jQuery("div#aspect_artifactbrowser_CommunityBrowser_div_comunity-browser img.ListMinus + span.bold ~ ul").hide();
  },
  showAllCommColl: function(){
    jQuery("div#aspect_artifactbrowser_CommunityBrowser_div_comunity-browser img.ListMinus").show();
  	jQuery("div#aspect_artifactbrowser_CommunityBrowser_div_comunity-browser img.ListPlus").hide();
  	jQuery("div#aspect_artifactbrowser_CommunityBrowser_div_comunity-browser img.ListMinus + span.bold ~ ul").show();
  },
  hideSomeCommColl: function(){
    jQuery("div#aspect_artifactbrowser_CommunityViewer_div_community-view img.ListPlus").show();
  	jQuery("div#aspect_artifactbrowser_CommunityViewer_div_community-view img.ListMinus").hide();
  	jQuery("div#aspect_artifactbrowser_CommunityViewer_div_community-view img.ListMinus + span.bold ~ ul").hide();
  },
  showSomeCommColl: function(){
    jQuery("div#aspect_artifactbrowser_CommunityViewer_div_community-view img.ListMinus").show();
  	jQuery("div#aspect_artifactbrowser_CommunityViewer_div_community-view img.ListPlus").hide();
  	jQuery("div#aspect_artifactbrowser_CommunityViewer_div_community-view img.ListMinus + span.bold ~ ul").show();
  },
  hideCommCollInCommViewTo2ndLevel: function(){
    jQuery("div#aspect_artifactbrowser_CommunityViewer_div_community-view > ul.ds-artifact-list > li > ul.ds-artifact-list img.ListPlus").show();
    jQuery("div#aspect_artifactbrowser_CommunityViewer_div_community-view > ul.ds-artifact-list > li > ul.ds-artifact-list img.ListMinus").hide();
    jQuery("div#aspect_artifactbrowser_CommunityViewer_div_community-view > ul.ds-artifact-list > li > ul.ds-artifact-list img.ListMinus + span.bold ~ ul").hide();
  }/*,
  //was used for the unpopular hover-sliders on the left menu
  myReBind: function(){
      jQuery("div.menuslider h3.open").unbind("mouseover");
      
      jQuery("div.menuslider h3.closed").bind("mouseover",function(){
	    //hide any open sub-menu
	    jQuery("h3.open").next().slideUp("slow");
		jQuery("h3.open").find("img.menu_nav_icon_open").hide();
		jQuery("h3.open").find("img.menu_nav_icon_closed").show();
	    jQuery("h3.open").addClass("closed");
	    jQuery("h3.open").removeClass("open");
	    
	    //show this sub-menu
	    jQuery(this).next("div.ds-option-set").slideDown("slow");
	    jQuery(this).addClass("open");
	    jQuery(this).removeClass("closed");
		jQuery(this).find("img.menu_nav_icon_open").show();
		jQuery(this).find("img.menu_nav_icon_closed").hide();
		
		jQuery(document).myReBind();
	});
  }*/
});

