//creates the ajax calls from page
function ajax ( parameters, updateID )
{
	//note parameters is an array or the required values
	var myRequest = new Request.JSON(
		{
			useSpinner:true,
			spinnerTarget: updateID,
			onRequest: function() 
			{ 
				// $(document.body).setStyle("cursor", "url(/images/spinner.gif), auto" ) ;
			}, 
			onSuccess: function(responseJSON, responseText ) 
			{
				eval ( responseText ) ;
				// $(document.body).setStyle("cursor", "auto" ) ;
			},
			onFailure: function(responseJSON, responseText) 
			{ 
				// $(document.body).setStyle("cursor", "auto" ) ;
			}
		}
	).get( parameters ); 
}

var guide = 
{
	setUpFxTargets: function()
	{
		$$('div.fxTarget').each(function(target)
		{
			target.makeDraggable();
		});
	},
	
	showFxTarget: function(target)
	{
		$(target).setStyles({
			'display': 'block',
			'visibility':'visible'
		});
	},
	
	/* accordion */
	makeAccordion: function ()
	{
		$$('ul.Accordion').each( function(el)
		{
			new Accordion(el.getElements('a.stretchtoggle'),el.getElements('ul.stretcher'), 
				{ 
						start:'all-close',
						alwaysHide:true ,
						onActive: function(toggler, element)
						{
							toggler.setStyle('color', '#ff3300');
						},
					 
						onBackground: function(toggler, element)
						{
							toggler.setStyle('color', '#222');
						}
				} 
			);	
			
			// Mouse effects
			el.addEvents(
			{
				'mouseover': function()
				{ // Tab hover
					if (!el.hasClass('selected')) 
					{					
						//also need to check the height of the toggler (parent parent element. . )
						for ( i=0; i<10; i++ )
						{
							posID = document.getElementById( a_menu[i] ) ;	
							if ( posID != null )
							{
								posID = document.getElementById( a_menu[i] ) ;	
								height = parseInt ( posID.style.height ) ;
								if ( height > 0 )
									posID.style.height='auto'; 
							}
						}
					}
				}
			});	
		});
	},
	
	
	// slider V1 
	makeSlider: function()
	{
		this.sliders = $$('.slider').map( function(ul)
		{
			return new Fx.Slide(ul, 
				{ 
					mode: 'vertical', 
					onComplete: function()
					{
						//this.wrapper.setStyle('height', 'auto');
					}
				} 
			).hide();
			
		});
		
		
		$$('.slideOpener').each(function(lnk, index)
		{
			lnk.addEvent('click', function()
			{
				this.sliders.each(function(slider, sliderIndex)
				{
					if (sliderIndex == index) this.sliders[sliderIndex].toggle();
				}, this);   //	Here's the bind "this" for .each	
			}.bind(this)); //	and here's the explicit .bind(this) for .addEvent's function	
		}, this); // and this is the last .each, so it has a "this" too	
		
	},

	makeSliderAuto: function()
	{
		this.slidersAuto = $$('.sliderAuto ul').map(function(ul)
		{
			return new Fx.Slide(ul, 
				{ 
					mode: 'horizontal', 
					onComplete: function()
					{
						if (this.now[0] >= 0) this.wrapper.setStyle('height', '-5');
					}					
				} 
			).hide();
		});
		$$('.sliderAuto a.slideAutoOpener').each(function(lnk, index)
		{
			lnk.addEvent('click', function()
			{
				this.slidersAuto.each(function(slider, sliderIndex)
				{
					if (sliderIndex == index) this.slidersSubs[sliderIndex].toggle();
				}, this);  //	Here's the bind "this" for .each	
			}.bind(this)); //	and here's the explicit .bind(this) for .addEvent's function	
			
			lnk.addEvent('mouseover', function()
			{
				this.slidersAuto.each(function(slider, sliderIndex)
				{
					if (sliderIndex == index) this.slidersAuto[sliderIndex].toggle();
				}, this);   //	Here's the bind "this" for .each	
			}.bind(this));
			
			lnk.addEvent('mouseout', function()
			{
				this.slidersAuto.each(function(slider, sliderIndex)
				{
					if (sliderIndex == index) this.slidersAuto[sliderIndex].toggle();
				}, this);  //Here's the bind "this" for .each	
			}.bind(this));
			
		}, this);   // and this is the last .each, so it has a "this" too	
	},

	get_tips: function ()
	{
		var as = [];
		$$('.tip').each(function(a)
			{
		  	if (a.getAttribute('title')) as.push(a);
			}
		);

		new Tips(as, 
		{
		  maxTitleChars: 100,
		  onShow: function(tip)
		  {
			tip.setStyle('opacity', '0.8');
		  },
		  onHide: function(tip)
		  {
			tip.setStyle('visibility', 'hidden');
		  },
		  offsets: {'x': -10, 'y': 15}
		});
	},
	
		
	init: function()
	{
		this.setUpFxTargets();
		this.makeSlider();
		this.makeAccordion();
		this.get_tips();
		this.makeSliderAuto();
	}
}

window.addEvent('domready', guide.init.bind(guide));

	//used to call alert in admin for deletion
function remove_confirm (id)
{
	if ( confirm ( 'Delete This Item?') )
	{
		$("ID_"+id).dispose();
		// delete item from DB and page..
		xajax_remove(id);
	}
}

function toggleHeight(id)
{
	new Fx.Slide("ID_"+id ).toggle() ;
}

function toggleHeight_raw(id)
{
	new Fx.Slide(id ).toggle() ;
}



function pop_open (url, height, width, b_scroll )
{
	newwindow=window.open(url,'Venue Image', 'height='+height+', width='+width+'location=0, status=1, scrollbars='+b_scroll+', toolbar=0' );
	s_width = screen.width ;
	s_height = screen.height - 50;
	
	y = (s_height - height )/2;
	x = (s_width - width)/2 ;
	
	//newwindow.moveTo(x,y);
	if ( window.focus ) 
	{
		newwindow.focus()
	}
}


	function load_init ( )
	{
		
		//run these functions when dom is ready 
		if (typeof page_functions=="function")
		{	
			page_functions ();
		}
	/*
		// auto slisder for one form on the page..
		if ( document.getElementById("mainForm-opener") != null )
		{
			Slide_myforms = new Fx.Slide('mainForm', { 'duration': 1000, 'transition': Fx.Transitions.circOut  } );
			Slide_myforms.hide();
	
			$('mainForm-opener').addEvent('click', function(e)
			{
				e = new Event(e);
				Slide_myforms.toggle();
				e.stop();
			});	
		}
		*/
		if (typeof h2_fade == "function")
		{
			h2_fade ( '#FC0' );
		}
	}
		
	var alreadyrunflag=0 //flag to indicate whether target function has already been run

	if (document.addEventListener)
	  document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1; load_init() }, false)
	else if (document.all && !window.opera)
	{
	  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
	  var contentloadtag=document.getElementById("contentloadtag")
	  contentloadtag.onreadystatechange=function()
	  {
		if (this.readyState=="complete")
		{
		  alreadyrunflag=1;
		  load_init();
		}
	  }
	}
	
	window.onload=function()
	{
		setTimeout("if (!alreadyrunflag){ load_init();}", 0) ;
	}
	
	function submitMe ( id )
	{	
		$(id).submit();
	}
	
	function fade_text ( c1, id )
	{
		el =  $(id);
		var myTween = new Fx.Tween (el, { 'duration': 8000, 'link':'chain',
					onComplete: function()
					{
						 var myHide = new Fx.Slide (el, {duration: 1500, onComplete: function ( id ) { el.dispose(); } } ).toggle();
					}
			} ) ;
		myTween.start( 'color', c1 );
	}
	