// <![CDATA[

	var GigHeadColor = '';
	var GigBodyColor = '';
	var previewwindow = '';
	


	Effect.Accordian = function(element) 
	{
		element = $(element);
		var options = Object.extend
		(
			{
				headingSelector: 'h2',
				sectionSelector: 'div',
				showSection: 1,
				duration: 0.5
			}, 
			arguments[1] || {}
		);

		headings = $$('#' + element.id + ' ' + options.headingSelector);
		sections = $$('#' + element.id + ' ' + options.sectionSelector);

		function showSection(section)
		{
			hideallgigreviews();
			if(section.visible())
			{
				return false;
			}
			
			sections.each
			(
				function(e)
				{
					if(e == section) 
					{
						e.visualEffect('blind_down', {duration: options.duration});
					} 
					else 
					{
						e.visualEffect('blind_up', {duration: options.duration});
					}
				}
			);
		}

		headings.each
		(
			function(e, index)
			{
				e.style.cursor = 'pointer';
				e.onclick = function()
				{ 
					headings.each
					(
						function(h)
						{ 
							h.removeClassName('active');
						}
					)
					this.addClassName('active');
					showSection(sections[index]);
				};
			}
		);

		sections.each
		(
			function(s, ind)
			{
				if(!options.showSection || (ind + 1 != options.showSection))
				{
					s.hide();
				}
				else
				{
					s.show();
				}
			}
		);

		if(options.showSection) 
		{
			headings[options.showSection - 1].addClassName('active');
		}
	}
	
	
 	function LoadFlyerDiv(band_uid, gig_uid, loading_text)
 	{
    	// Show loading notification
    	var loadingdiv = $('loadingdiv');
    	loadingdiv.innerHTML = loading_text;
    	Appear(0, 'loadingdiv');
		ajax = new Ajax.Updater(
			'uploaddiv',
			'/Volumes/mars_002/Webdata/global/bands/gigs/flyer_edit.php',
			{
				method: 'get',
				parameters: 'band_uid=' + band_uid + '&gig_uid=' + gig_uid,
				asynchronous: true,
				evalScripts: true,
				onSuccess: function(t) 
				{
					Disappear(0, 'loadingdiv');
			 		Appear(0.5, 'uploaddiv');
				}
			}
		);
	}



	function delGigChanges(giguid) 
	{
		var HiddenField = $('GigChanged[' + giguid + ']');
		var DelCheckbox = $('DeleteGig[' + giguid + ']');
		var GigHead = $('GigHead[' + giguid + ']');
		var GigBody = $('GigInfoBody[' + giguid + ']');

		if(HiddenField)
		{
			HiddenField.value = 1;
		}

		if (DelCheckbox.checked)
		{
			GigHeadColor = GigHead.style.backgroundColor;
			GigHead.style.backgroundColor = '#4F4F4F';
			GigBodyColor = GigBody.style.backgroundColor;
			GigBody.style.backgroundColor = '#808080';
		}
		else
		{
			GigHead.style.backgroundColor = GigHeadColor;
			GigBody.style.backgroundColor = GigBodyColor;
		}
		editGigChanges(giguid);
	}


	function editGigChanges(giguid)
	{
		var HiddenField = $('GigChanged[' + giguid + ']');

		if(HiddenField)
		{
			HiddenField.value = 1;
		}
	}


	function gigFlyerUploaded(linktext, giguid, loading_text)
	{
		// Show loading notification
		var loadingdiv = $('loadingdiv');
		loadingdiv.innerHTML = loading_text;
		Appear(0.1, 'loadingdiv');

		if(giguid == 0)
		{
			var FlyerLink = $('postGigAddFlyerLink');
		}
		else
		{
			var FlyerLink = $('editFlyerLink_' + giguid);
		}

		if(FlyerLink)
		{
			FlyerLink.innerHTML = linktext;
		}

		Disappear(0, 'loadingdiv');
		Appear(0.5, 'overdiv');
		previewwindow.close();
	}


	function getParentSize()
	{
		var myWidth = 0;
		var myHeight = 0;

		if(typeof(window.innerWidth ) == 'number')
		{
			// Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		}
		else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
		{
			// IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		}
		else if(document.body && (document.body.clientWidth || document.body.clientHeight))
		{
			// IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		return myWidth;
	}


	function popflyerup(giguid, basicdir, width, height)
	{
		var previewwindow = '';

		var url = basicdir + giguid + '.jpg';

		var openerWidth = getParentSize();
		var positionX = openerWidth/2 - width/2;

		var options = 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=0, height=' + height + ', width=' + width;
		previewwindow = window.open(url, '', options);
		previewwindow.moveTo(positionX, 300);

		if(!previewwindow.opener)
		{
			previewwindow.opener = self;
		}

		if(window.focus) 
		{
			previewwindow.focus();
		}
		
		return false;
	}


	function checkgigreview(page_id, band_uid, sub_page_id, option_id, alert_text, save_text, e, loading_text, gallery_id, siteurl, gig_uid) 
	{
		// Show checking notification
		var notdiv = $('notificationdiv');
		notdiv.innerHTML = alert_text;
		Appear(0.1, 'notificationdiv');
		ajax = new Ajax.Request(
			 siteurl + 'checkpage' + page_id + sub_page_id + option_id + '.php',
			 {
				method: 'post',
				parameters: Form.serialize($('form' + page_id + sub_page_id + option_id)) + '&option_id=' + option_id + '&gig_uid=' + gig_uid+ '&band_uid=' + band_uid,
				asynchronous: false,
				onSuccess: function(t) 
				{
					var errdiv = $('errordiv');
					errdiv.innerHTML = t.responseText;

					if(t.responseText && t.responseText.length > 0)
					{
						Disappear(1.5, 'notificationdiv');
						Appear(0.2, 'errordiv');
						return false;
					}
					else
					{
						Disappear(0.1, 'errordiv');
						document.form330.submit();
					}
				},
				onFailure: servererror
			 }
		);
	}


	function savegigreview(page_id, band_uid, sub_page_id, option_id, save_text, e, loading_text, gallery_id, siteurl, gig_uid)
	{
	var notdiv = $('notificationdiv');
		notdiv.innerHTML = save_text;
		Appear(0.1, 'notificationdiv');

		ajax = new Ajax.Updater(
			 'notificationdiv',
			 siteurl + 'savepage' + page_id + sub_page_id + option_id + '.php',
			 {
				method: 'post',
				parameters: Form.serialize($('form' + page_id + sub_page_id + option_id)) + '&option_id=' + option_id + '&gig_uid=' + gig_uid+ '&band_uid=' + band_uid,
				asynchronous: true,
				onSuccess: function(t)
				{
					Disappear(1.5, 'notificationdiv');
					if(gallery_id > 1) { option_id = gallery_id; }
					getInfo(page_id, band_uid, sub_page_id, e, loading_text, option_id);
				},
				onFailure: servererror
			 }
		);
	}


	function GigReviewAppear(newreview, speed, giguid, fixIE)
	{
		if(newreview)
		{
			// NewReview
			active_o = 'New';
			inactive_o = 'Show';
		}
		else
		{
			active_o = 'Show';
			inactive_o = 'New';
		}

		showelements = new Array(
			document.getElementById(active_o + 'Review_' + giguid),
			document.getElementById(inactive_o + 'ReviewLink_' + giguid)
		);

		hideelements = new Array(
			document.getElementById(inactive_o + 'Review_' + giguid),
			document.getElementById(active_o + 'ReviewLink_' + giguid)
		);

		for(var i = 0; i < showelements.length; i++)
		{
			if (showelements[i])
			{
				// IE Does not work with blinddown/-up
				if (fixIE)
				{
					Appear(1.0, showelements[i]);
				}
				else
				{
					Effect.BlindDown(showelements[i], {duration: speed});
				}
			}
		}

		for(var i = 0; i < hideelements.length; i++)
		{
			if(hideelements[i])
			{
				if(fixIE)
				{
					Effect.Fade(hideelements[i], {duration: speed});
				}
				else
				{
					Effect.BlindUp(hideelements[i], {duration: speed});
				}
			}
		}
	}


	function SpikeGigFinished( giguid, reviewuid, banduid,siteurl )
	{
		reviewbody = 'ReviewItemBody_' +  giguid + '_' + reviewuid;
		Effect.Squish(reviewbody, {duration: 1});
	}


	function SpikeGig(giguid, reviewuid, banduid, siteurl)
	{
		// Call the Spike-Script
		ajax = new Ajax.Request(
			 siteurl + 'spikegig.php',
			 {
				method: 'post',
				parameters: 'gig_uid=' + giguid+ '&review_uid=' + reviewuid+ '&band_uid=' + banduid,
				asynchronous: true,
				onSuccess: SpikeGigFinished(giguid, reviewuid, banduid, siteurl),
				onFailure: servererror
			 }
		);
	}


	function GigDisappear(speed, element)
	{
		Effect.Fade(element, {duration: speed});
	}


	function GigShowVoteStars(value, giguid)
	{
		var savefield = $('votefield_' + giguid);
		savefield.value=value;

		element = $('startrack_' + giguid);

		var finalwidth = 200 / 5 * value;
		element.style.width = finalwidth + 'px';
	}


	function hideallgigreviews()
	{
		var gigreviews = document.getElementsByClassName('gigreviewbody');
		for(var i = 0; i < gigreviews.length; i++)
		{
			Disappear(0, gigreviews[i]);
		}

		var gigreviewLinks = document.getElementsByClassName('ReviewLink');
		for(var i = 0; i < gigreviewLinks.length; i++)
		{
			Appear(0, gigreviewLinks[i]);
		}
	}


	function CreateGigSlider(giguid)
	{
		var sliderVote = new Control.Slider('voteselect_' + giguid, 'votetrack_' + giguid, {range: $R(1, 5), values: [1, 2, 3, 4, 5]});

		sliderVote.options.onSlide = function(value)
		{
			GigShowVoteStars(value, giguid)
		}

		sliderVote.options.onChange = function(value)
		{
			GigShowVoteStars(value, giguid)
		}
	}

 // ]]>  
