// ************************************************************************************************************
// *  PLEASE DO NOT USE THESE SCRIPTS FOR PRODUCTION. THIS IS JUST A DEMO. PLEASE EVALUATE BEFORE USING THESE *
// ************************************************************************************************************
function buildAccordion( accordionID, direction, firstOpenNumber) {
	// ACCORDION SCRIPT
	firstOpenNumber--;
	var top_venues_accordion = new accordion(accordionID, {
		resizeSpeed : 8,
		classNames : {
			toggle : 'accordion-item',
			toggleActive : 'accordion-open',
			content : 'accordion-content'
		},
		direction : direction
	});
	if( firstOpenNumber >= 0 ) {
		// activate first item
		top_venues_accordion.activate($$('.accordion-item')[firstOpenNumber]);
	}
}

function startWeekShowsScript() {
	// Shows This Week module script
	$$('.tabs a').each( function(tab, index) {
		tab.observe('click', function() {
			$$('.tabs a').each( function(e) {
				e.removeClassName('selected');
			});
			tab.addClassName('selected');
			$$('.tab-content ul').invoke('hide');
			$$('.tab-content ul')[index].show();
		});
	});
}

function startNoteclipGallery(arrImages) { 
  // Preload all images to load in cache
	var hiddenImagePreloader = document.createElement("div");
	hiddenImagePreloader.style.position = "absolute";
	hiddenImagePreloader.style.top = "-10000px";
	
	for(x=0; x<arrImages.length; x++) {
		var newImg = document.createElement("img");
		newImg.src = arrImages[x];
		newImg.alt = "Gallery Preloaded Image "+ (x+1);
		hiddenImagePreloader.appendChild(newImg);
	}
	document.body.appendChild(hiddenImagePreloader);
	// use the pointer to point in the array.
	var pos = 0;
	var limit = arrImages.length-1;
	Event.observe($$(".noteclip-gallery .prev")[0], "click", function(){ 
		pos--;
		if(pos<0) { pos=limit; }
		$$(".noteclip-gallery .current-image")[0].style.backgroundImage = "url('" + arrImages[pos] + "')";						
	});
	Event.observe($$(".noteclip-gallery .next")[0], "click", function(){  
		pos++;
		if(pos>limit) { pos=0; } 
		$$(".noteclip-gallery .current-image")[0].style.backgroundImage = "url('" + arrImages[pos] + "')";
	});
}
// **************************************************************************
// *  THE FOLLOWING SCRIPT IS TO FORCE THE FOOTER TO THE BOTTOM OF THE PAGE *
// **************************************************************************
function forceFooterBottom(){
	var viewportheight = document.viewport.getHeight();
	// IF THE PAGE HEIGHT IS LESS THAN THE VIEWPORTHEIGHT, ADJUST THE MAIN HEIGHT.
	if ( $("page").getHeight() < viewportheight) {
		$("main").style.height = (viewportheight - 318) + "px";
	}
}
Event.observe(window, "resize", forceFooterBottom );

// *************************************************
// *  THE FOLLOWING SCRIPT IS TO CREATE THE POPUP  *
// *************************************************

function createPopup(popupID, linkID) {
	if($(popupID) != null) {
		new Popup( popupID, {
				close_id: $$(".popup .close")[0].id,
				links: [{
					link_id: linkID,
					anchor_align: {
						x: 1,
						y: 1
					},
					popup_align: {
						x: 0,
						y: -1
					},
	
					offset: {
						x: 0,
						y: 5
					}
	
				}]
			});
	}
}

