// JavaScript Document
$(document).ready(function(){

	
	if ( document.getElementById('state_id') ) { // if the element exists
		if ( document.getElementById('state_id').value != '' ) {
			
			if ( window.location.toString().match('/directory/') ) {
				getCityMenu(true);
			} else {
				getCityMenu(false);
			}
		}
	
	}
// set admin sort default to descending
//if(!$.cookie('order')){	
//$.cookie('order', 'desc');
//}

 $(".reveal:visible").hide();
//if(!$.cookie('sort_type')){	
//$.cookie('sort_type', 'alpha');
//$("#admin_sort_alpha").addClass("sort_arr_down");
//}

	
if(!$.cookie('test')){	
//alert("there is no cookie set");
$(".catlist>a").html("collapse");
}
	
if($.cookie('test')=='expand'){
$(".trial:hidden").show();
//if($('.trial').is(':visible')){
$('.catlist').children().removeClass("arr_down");
$('.catlist').children().addClass("arr_up");
$('.catlist').children().html("collapse");
//}
//$(".catlist>a").html("collapse");


}else if($.cookie('test')=='collapse'){
 $(".trial:visible").hide();
if($('.trial').is(':hidden')){
$('.catlist').children().removeClass("arr_up");
$('.catlist').children().addClass("arr_down");
$('.catlist').children().html("expand");
}
 //$(".catlist>a").html("expand");
 
}




//////// BEGIN ADMIN EXPAND/COLLAPSE
$(".reveal_btn").click(function(){
if($(this).parent().find('.reveal').is(':visible')){
$(this).children().removeClass("arr_up");
$(this).children().addClass("arr_down");
$(this).children().html("expand");
$(this).parent().find('.reveal').slideUp();
return false;
};
if($(this).parent().find('.reveal').is(':hidden')){
$(this).children().removeClass("arr_down");
$(this).children().addClass("arr_up");
$(this).children().html("collapse");
$(this).parent().find('.reveal').slideDown();
return false;
 };
 });
//////// END ADMIN EXPAND/COLLAPSE


	
	
	
 //set inital links to read "collapse"
 //$(".catlist>a").html("collapse");
 // show hide a single item
$(".catlist").click(function(){
if($(this).parent().find('.trial').is(':visible')){
$(this).children().removeClass("arr_up");
$(this).children().addClass("arr_down");
$(this).children().html("expand");
$(this).parent().find('.trial').slideUp();
return false;
};
if($(this).parent().find('.trial').is(':hidden')){
$(this).children().removeClass("arr_down");
$(this).children().addClass("arr_up");
$(this).children().html("collapse");
$(this).parent().find('.trial').slideDown();
return false;
 };
 });
 
 
$("#showAll").click(function(){
$.cookie('test', 'expand', { expires: 7 });									 
$(".trial:hidden").slideDown();
$(".catlist>a").html("collapse");
$(".catlist>a").removeClass("arr_down");
$(".catlist>a").addClass("arr_up");
 });
  
 // Hide all
 $("#hideAll").click(function(){ 
$.cookie('test', 'collapse', { expires: 7 });		
 $(".trial:visible").slideUp();
 $(".catlist>a").html("expand");
 $(".catlist>a").html("expand");
 $(".catlist>a").removeClass("arr_up");
 $(".catlist>a").addClass("arr_down");
 return false; 
 });




////////////////////////////////////
//if there is a promotion underneath the search field on the homepage, set this to true. false if there is no promo

var perfPromo= true;

////////////////////////////////////



//if(document.location!="http://premier-showcase.com/directory/search_results.php"){

if( !document.location.toString().match("/search_results.php") ){
	//alert("ASD");
	//close items
	$("#accordion-menu > div.wrap").find("div.accordion-items").hide();
	$("#accordion-menu2 > div.wrap").find("div.accordion-items").hide();
	//add toggle graphic
	$("#accordion-menu > #acc_tab").addClass("closed");
	$("#accordion-menu2 > #acc_tab").addClass("closed");
	$("#accordion-menu > #acc_tab").click( function( ev ) {
		ev.preventDefault();
		if (perfPromo==true){$("#perf_promo").hide();};
		$("div.wrap > div.accordion-items").slideDown("fast");
		$("div.wrap > div.accordion-items").removeClass("closed");
		$("#accordion-menu > #acc_tab").addClass("hideTab");
		$("#accordion-menu > #acc_tab_state2").removeClass("hideTab");
		$("#accordion-menu > #acc_tab_state2").addClass("acc_tab_state2 a");
	});




	$("#accordion-menu > #acc_tab_state2").click(function( ev ) {
		ev.preventDefault();
		$("#accordion-menu > div.wrap >div.accordion-items").slideUp("fast", function(  ) {
    	if (perfPromo==true){ $("#perf_promo").show();}
  });
		
		
	
		
		$(this).find("#accordion-menu > div.wrap >div.accordion-items").removeClass("closed");
		$("#accordion-menu > #acc_tab_state2").addClass("hideTab");
		$("#accordion-menu > #acc_tab").removeClass("hideTab");
		$("#accordion-menu > #acc_tab").addClass("#acc_tab a");
	});
} else {
	
	$("#accordion-menu > #acc_tab").addClass("hideTab");
	$("#accordion-menu > #acc_tab_state2").removeClass("hideTab");
	$("#accordion-menu > #acc_tab").click(function() {
		$(this).find("#accordion-menu > div.wrap >div.accordion-items").slideDown("fast");
		$(this).find("#accordion-menu > div.wrap >div.accordion-items").removeClass("closed");
		$("#accordion-menu > #acc_tab").addClass("hideTab");
		$("#accordion-menu > #acc_tab_state2").removeClass("hideTab");
		$("#accordion-menu > #acc_tab_state2").addClass("#acc_tab_state2 a");
	});

	$("#accordion-menu > #acc_tab_state2").click(function() {
		$(this).find("#accordion-menu > div.wrap >div.accordion-items").slideUp("fast");
		$(this).find("#accordion-menu > div.wrap >div.accordion-items").removeClass("closed");
		$("#accordion-menu > #acc_tab_state2").addClass("hideTab");
		$("#accordion-menu > #acc_tab").removeClass("hideTab");
		$("#accordion-menu > #acc_tab").addClass("#acc_tab a");
	});
	
} // end if else we're on the search results page


  


});