/****************************************
 * Ccube.com JavaScript
 ****************************************/

/***** General Purpose Functions *****/

// Attach an event
function addEvent(obj, type, fn) {
	if(obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if(obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); };
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

/***** Transition Effects (moo.fx) *****/

// Default duration of a transition effect (in ms)
var effectDuration = 250;

// Extend the fx.Height class to allow expand() and collapse() functions
Object.extend(fx.Height.prototype, {
	expand: function() {
		if (this.el.offsetHeight == 0) this.custom(0, this.el.scrollHeight);
	},

	collapse: function() {
		if (this.el.offsetHeight > 0) this.custom(this.el.offsetHeight, 0);
	}
});

/***** Popup Functions *****/

// Default pop parameters
var _POPUP_FEATURES = 'location=0, statusbar=0, menubar=0, width=420, scrollbars=1, height=400';

// Pop up a window
function raw_popup(url, target, features) {
	if (typeof features == 'undefined') {
		features = _POPUP_FEATURES;
	}
	if (typeof target == 'undefined') {
		target = '_blank';
	}
	var theWindow =
	window.open(url, target, features);
	theWindow.focus();
	return theWindow;
}

// For use like this: <a href="popup.html" onclick="popup(this); false;">
function popup(src, features) {
	raw_popup(
		src.getAttribute('href'),
		src.getAttribute('target') || '_blank',
		features
	);
	
	return false;
}

// Apply popup function to all links with class="popup"
addEvent(window, 'load', function() {
	popupLinks = document.getElementsByClassName('popup');

	for(var i = 0; i < popupLinks.length; i++) {
		popupLinks[i].onclick = function() {
			popup(this);
			return false;
		};
	}
});