// menu settings
var active_menu_id;
var prev_active_menu_id;
var active_sub_menu_id;
var prev_active_sub_menu_id;

try { console.log('init console... done'); } catch(e) { console = { log: function() {} } }

$(document).ready(function()
{  	
	//Text tag search
  	$("#search_phase").fieldtag(); 
	
});

$(function()
{
   $("#searchbox_clear").click(function() {
	  $("#search_phase").val("");
	  return false;
   });
});

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
// Usage:

jQuery.preLoadImages("../wp-content/themes/pdi/assets/img/view_products_btn-over.jpg", "../wp-content/themes/pdi/assets/img/send_btn-over.jpg");

////////////////////////////////////////////////////////////////
// for accordian menu

function activateMenu (id)
{
	//console.log("activateMenu called "+id);
	prev_active_menu_id = active_menu_id;
	active_menu_id = id;
	
	if ($("#"+id+" ul:first").css("display") == "none")
	{
		// showing
		
		// point arrow down
		$("#"+active_menu_id+" div:first").children('.arrow').css("background-image", "url(../wp-content/themes/pdi/assets/img/arrow_purple_down.png)");			
  	    showSubMenu(id);
	}
	else
	{
		// hiding
				
		// point arrow up
		$("#"+active_menu_id+" div:first").children('.arrow').css("background-image", "url(../wp-content/themes/pdi/assets/img/arrow_brown_normal.png)");
		$("#"+id).find('.arrow').css("background-image", "url(../wp-content/themes/pdi/assets/img/arrow_brown_normal.png)");			
		
		hideSubMenu(id);
		
		// delay 2 seconds and then hide all ULs
		setTimeout("hideAllMenus()",2000);
	}	
}

// hide sub menu
function hideSubMenu (id)
{
	$("#"+id+" ul:first").hide("slow");
}

// show sub menu
function showSubMenu (id)
{
	$("#"+id+" ul:first").show("slow");
}

// hide all open ULs on close
function hideAllMenus ()
{
	$("#"+active_menu_id).find('ul').css("display", "none");
}

// set all open ULs and set the arrow active
function setAllArrows()
{
	//console.log('setAllArrows')
	//$('#vert_menu ul", display:block').children('.arrow').css("background-image", "url(../wp-content/themes/pdi/assets/img/arrow_purple_down.png)");
	$('#vert_menu ul, display:block').parent('li').css('display', 'none');
}

// set all open ULs and set the arrow active
function setArrow(id)
{
	//console.log('set arrows - '+id)
	//console.log('id = '+$("#"+id).closest('ul').attr('id'));
	$("#"+id).children('ul').css("display", "block");
	$("#"+id+" div:first").children('.arrow').css("background-image", "url(../wp-content/themes/pdi/assets/img/arrow_purple_down.png)");
}




