/*
 * APEX Themes - Themes, Templates & Skins for Oracle APEX Applications
 * http://www.apex-themes.com
 *
 * Copyright (c) 2009 Creative Mode
 * This file is protected by copyright law and provided under license. 
 * Unauthorised copying of this file is strictly prohibited.
 * http://www.apex-themes.com/docs/contact.php
 *
 * Series: BRAVO
 */
 
 $(document).ready(function(){	
	// Fix for Value Attribute Pair pagination incorrect colspan
	$(".bravo_ValueAttributePairs td.pagination").closest("td:not(.pagination)").each(function(i){
		$(this).closest("table").attr("align", $(this).attr("align"));					   
	});
	
	// Fix for calendar templates non-day close
	$("div.bravo_Calendar td.bravo_CalendarNonDay").append("</td>");
	
	// Report row highlighting
	$("tr.bravo_ReportData td:not(.bravo_ReportDivider)").live("mouseover", function(){
		$(this).parent().toggleClass("bravo_RowHighlight");
	});
	$("tr.bravo_ReportData td:not(.bravo_ReportDivider)").live("mouseout", function(){
		$(this).parent().toggleClass("bravo_RowHighlight");
	});
	
	// HIDE SHOW REGIONS
	// Hide all hide/show containers  
	$("div.bravo_HideShowContainer").hide();  
	//create hide/show toggle functionality
	$("div.bravo_HideShowRegion div.bravo_RegionTitle").click(function(event){
		$(this).next().slideToggle("slow");
	}); 
	
	// PULL DOWN MENUS
	// Hide all pull down menus  
	$("ul.bravo_PullDownMenuSublist").hide();
	// Set a global menu hide
	$(document).click(function(event) {
		// Hide all open menus
		$("ul.bravo_PullDownMenuSublist").hide();
		// For benefit of IE:
		// Reset z-index of position:relative regions
		// See http://mahzeh.org/?p=23
		$("div.bravo_Region").css("z-index", 0);
	}); 
	// Open top level menus (opens to bottom)
	$("li.bravo_PullDownMenuOpen a:not(.bravo_PullDownMenuSublist a)").mouseover(function(event){
		// Hide all open menus
		$("ul.bravo_PullDownMenuSublist").hide();
		// For benefit of IE:
		// Reset z-index of position:relative regions
		// See http://mahzeh.org/?p=23
		$("div.bravo_Region").css("z-index", 0);
		//Set this menu's containing region to have the highest z-index of all regions
		$(this).closest("div.bravo_Region").css("z-index", 10000);
		
		if($(this).nextAll("ul.bravo_PullDownMenuSublist").css("display") == "none") {
			$(this).nextAll("ul.bravo_PullDownMenuSublist").css("left", 0);
			$(this).nextAll("ul.bravo_PullDownMenuSublist").css("top", $(this).parent().outerHeight());
			$(this).nextAll("ul.bravo_PullDownMenuSublist").show();
			$(this).nextAll("ul.bravo_PullDownMenuSublist").css("z-index", 99);
		}
	});
	// Open sub menus (opens to right)
	$("li.bravo_PullDownMenuExpand a").mouseover(function(event){
		if($(this).nextAll(".bravo_PullDownMenuSublist").css("display") == "none") {
			$(this).closest("ul").find(".bravo_PullDownMenuSublist").hide();
			$(this).nextAll("ul.bravo_PullDownMenuSublist").css("left", $(this).parent().outerWidth());
			$(this).nextAll("ul.bravo_PullDownMenuSublist").css("top", 0);
			$(this).nextAll("ul.bravo_PullDownMenuSublist").show();
			$(this).nextAll("ul.bravo_PullDownMenuSublist").css("z-index", 99);
		}
	});
	// Collapse cascading sub menus
	$("li.bravo_PullDownMenuClose a").mouseover(function(event){
		$(this).closest("ul").find("ul.bravo_PullDownMenuSublist").hide();
	});
	
	// HIERARCHICAL EXPANDING LIST
	// Hide all sublists  
	$("ul.bravo_HierarchicalExpandingSublist").hide();
	// Expand/collapse
	$("div.bravo_HierarchicalExpandingList img.bravo_TreeExpand").click(function(event){
		var m = $(this).nextAll("ul.bravo_HierarchicalExpandingSublist");
		if(m.css('display') == 'none') {
			m.show("fast");
		} else {
			m.hide("fast");
		}
		//swap image
		var t = $(this).attr('longdesc');
		$(this).attr('longdesc', $(this).attr('src'));
		$(this).attr('src', t);
	});
	
	// VERTICAL SIDEBAR LIST
	// Hide all sublists  
	$("ul.bravo_VerticalSidebarSublist").hide();
	// Expand/collapse
	$("div.bravo_VerticalSidebarList img.bravo_TreeExpand").click(function(event){
		var m = $(this).nextAll("ul.bravo_VerticalSidebarSublist");
		if(m.css('display') == 'none') {
			m.show("fast");
		} else {
			m.hide("fast");
		}
		//swap image
		var t = $(this).attr('longdesc');
		$(this).attr('longdesc', $(this).attr('src'));
		$(this).attr('src', t);
	});
	// Keep open
	$("div.bravo_VerticalSidebarList a.current").parents("ul.bravo_VerticalSidebarSublist").show();
	$("div.bravo_VerticalSidebarList a.current").nextAll("ul.bravo_VerticalSidebarSublist").show();
	// Update images for menus kept open
	$("div.bravo_VerticalSidebarList .bravo_TreeExpand").each(function(i) {
		if( $(this).nextAll("ul.bravo_VerticalSidebarSublist").css("display") == "block" ) {
			//swap image
			var t = $(this).attr('longdesc');
			$(this).attr('longdesc', $(this).attr('src'));
			$(this).attr('src', t);
		}
	});
	
	// REGION CORNERS
	$("div.bravo_Region").append("<div class=\"corner TL\"></div><div class=\"corner TR\"></div><div class=\"corner BL\"></div><div class=\"corner BR\"></div>");
	
	// FIX DODGY APEX IR MENUS
	$("#apexir_rollover").appendTo("body");
	
});
