$(document).ready(function(){
	initMenu();
	initCollapse();
});
var initMenu = function()
{
	$('#main_menu li ,:submit').hover(
		function(){
			$(this).addClass('hover');
		},//over
		function(){
			$(this).removeClass('hover');
		}//out
	);
}
var initCollapse = function()
{
	$('ul.plants > li > a').parents('li').find('ul').hide();
	$('ul.plants > li > a.active').parents('li').find('ul').show();
	$('ul.plants > li > a').click(function(e){
		e.preventDefault();
		$(this).next().toggle();
		$(this).toggleClass('active');
	});
	
	$('ul.supplier_results > li > a.expander').parents('li').find('ul').hide();
	$('ul.supplier_results > li > a.expander_active').parents('li').find('ul').show();
	$('ul.supplier_results > li > a.expander').click(function(e){
		e.preventDefault();
		$(this).nextAll('ul').toggle();
		$(this).toggleClass('expander_active');
	});
	
	$('div.hide_search strong').css({'cursor':'pointer'}).click(function(e){
		e.preventDefault();
		$(this).html( $(this).text()=='HIDE QUICK SEARCH' ? '<a href="#">SHOW QUICK SEARCH</a>' : '<a href="#">HIDE QUICK SEARCH</a>' );
		$(this).parents('div.hide_search').next().slideToggle('slow');
		var text = $(this).text();
		if (text == "HIDE QUICK SEARCH" ) {
			$('.left_column_search input.search_button').show();
			$('.left_column_search input.clear_button').show();
			$(this).addClass('arrow_up');
		} else {
			$('.left_column_search input.search_button').hide();
			$('.left_column_search input.clear_button').hide();
			$(this).removeClass('arrow_up');
		}
	});
	
	if (signed_in || allow_advanced_nologin) {
		$('div.quick_search a').click(function(e){
			e.preventDefault();
			$(this).parents('div.row').prev().slideToggle('slow');
			$('div.hide_search').slideToggle('slow');
			$(this).html( $(this).html()=='QUICK SEARCH' ? 'ADVANCED SEARCH' : 'QUICK SEARCH');
			if ($(this).html() == "QUICK SEARCH") {
				//alert("up");
				$("div.form div.quick_search a").addClass('arrow_up');
				$("div.form div.quick_search a").removeClass('arrow_down');
			} else {
				//alert("down");
				$("div.form div.quick_search a").removeClass('arrow_up');
				$("div.form div.quick_search a").addClass('arrow_down');
			}
			var scrollVal = $(this).parents('div.row').prev().height();
			if(($(document).height() - $(this).parents('div.row').prev().height()) < $(document).scrollTop()+$(window).height()){
				$(document).scrollTo('-='+scrollVal,400);
			}
		});
	}
	if ($('body').attr("class")=="home") {
		$('.left_column_search input.search_button').show();
		$('.left_column_search input.clear_button').show();
	} else {
		$('.left_column_search input.search_button').hide();
		$('.left_column_search input.clear_button').hide();
	}
	
	//	popup suppliers hide/show
	$('.supplier_heading').css({'cursor':'pointer'}).click(function(e){
		e.preventDefault();
		$(this).next().slideToggle('slow');
		$(this).toggleClass('arrow_down');
	});
}

function updateActiveProject(strLabel,strDelete) {
	if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1 && navigator.userAgent.toLowerCase().indexOf('msie 7') == -1) { // ie6
		strURL = window.opener.location.href;
		deletePos = strURL.indexOf('delete=');
		if(deletePos>-1) {
			strURL = strURL.substring(0,(deletePos-1));
		}
		strURL = strURL + strDelete;
		strText = window.opener.$('.recent_plants_list ul').html();
		window.opener.$('.recent_plants_list ul').html('<li><label>'+strLabel+'</label><a href="'+strURL+'" class="subclose closebutton"></a></li>' + strText);
		window.opener.$('p#no_plants').hide();
	} else {
		strURL = top.document.URL;
		deletePos = strURL.indexOf('delete=');
		if(deletePos>-1) {
			strURL = strURL.substring(0,(deletePos-1));
		}
		strURL = strURL + strDelete;
		strText = $('.recent_plants_list ul', top.document).html();
		$('.recent_plants_list ul', top.document).html('<li><label>'+strLabel+'</label><a href="'+strURL+'" class="subclose closebutton"></a></li>' + strText);
		$('p#no_plants', top.document).hide();
	}
}
