// Variable for site lightboxes; allows us to access them globally
var pageWide = null;

function newWindow(detailpage)  {
	detailWindow= window.open(detailpage,'detailWin','toolbar=no, location=no, scrollbars=yes,width=400,height=550');
	detailWindow.focus();
}

// e-junkie configuration
function EJEJC_lc(th) {
	return false;
}
function EJEJC_config() {
	EJEJC_BGCOLOR = "#643b25";
	EJEJC_OPACITY = 85;
	EJEJC_POSTCALL = true;
	EJEJC_WIDTH = 600;
}
var EJEJC_show;
function EJEJC_shown() {
	jQuery("#imgHeader").attr("src", "http://balancesf.com/images/layout/cart_logo.png").css('width', 'auto').css('height', 'auto');
	jQuery("#btnEJ").attr("src", "http://balancesf.com/images/layout/checkout.png").css('width', 'auto').css('height', 'auto');
	jQuery("#btnPP").attr("src", "http://balancesf.com/images/layout/paypal.png").css('width', 'auto').css('height', 'auto');
	if (location.pathname.indexOf('/workshops_and_events/') == -1) {
		jQuery("#btnContShop").unbind('click').attr("onclick", "").click(function() {
			location.href = '/workshops_and_events/';
			return false;
		});
	}
}

window.addEvent('domready', function() {
	// In order to modify the box prior to it being displayed, we have to override EJEJC_show
	var overridden = EJEJC_show.create();
	EJEJC_show = function(a, b, c) {
		pageWide.close();
		overridden(a, b, c);
	}
	outterE= $E('div.scroller');
	innerE= $E('div.content');
	
	if ($type(outterE) && $type(innerE)) {
		if (innerE.offsetHeight >= outterE.offsetHeight){
			new MooScroller($E('div.scroller div.entry'), $E('div.scroller .scrollKnob'), {
				scrollLinks: {
					forward: $E('div.scroller div.scrollForward'),
					back: $E('div.scroller div.scrollBack')
				}
			});
		}
		else {
			$E('div.scrollarea').setStyles({
				'display': 'none' 
			});
		}
	}
	// Lightbox defaults
	lightboxDefaults = {
		baseHref: 'images/layout/',
		useWaiter: true,
		waiterOptions: {
			containerProps: {
				styles: {
					top: 'auto',
					left: 'auto',
					bottom: '0px',
					right: '0px'
				}
			},
			img: {
				src: 'loading.gif',
				styles: {
					width: 'auto', height: 'auto',
					position: 'absolute',
					bottom: '5px',
					right: '5px'
				}
			},
			layer: { styles: { 'background-color': '#fff1c7', opacity: .4 } }
		},
		useUI: true,
		uiOptions: {
			width: '400px',
			cssClassName: 'popup',
			cssId: 'proPopup'
		},
		useModal: true,
		modalOptions: {
			modalStyle: {
				'background-color':'#3b2316',
				'opacity':.85
			}
		}
	}
	pageWide = new TILightbox('a[rel*=lightbox]', lightboxDefaults);
	
	$$('a[rel*=newwindow]').addEvent('click', function(e) {
		e.stop();
		newWindow(this.get('href'));
	});
	
	$$('.accordion').each(function(el) {
		new TIAccordion(el);
	});
});