var allEffects = new Array();

function effectExists(effectType) {
	for (var i=0;i<allEffects.length;++i)
		// if finished, remove from queue
		if (allEffects[i].status=='finished') {
			delete allEffects[i]
			allEffects.splice(i--,1);
		// otherwise, is it the one we're looking for?
		} else if (allEffects[i].options.type==effectType) {
			return true;
		}
		
	// didn't find it:
	return false;
}

function removeDupEffects(newEffect) {
	for (var i=0;i<allEffects.length;++i)
		if ( (allEffects[i].element && (allEffects[i].element == newEffect.element) && (allEffects[i].options.type == newEffect.options.type))
			 || ((allEffects[i].element == 'undefined') && (allEffects[i].options.type == newEffect.options.type))
			 || (allEffects[i].status=='finished')) {
			 
			allEffects[i].cancel();
			delete allEffects[i];
			allEffects.splice(i--,1);
		}
}
function addEffect( newEffect ) {
	//alert("new "+newEffect.options.type+" effect on "+newEffect.element.id);
	// check for duplicates;
	// cancel any running effects
	removeDupEffects( newEffect );
	
	// add to effects array so we
	// can keep track of it
	allEffects.push( newEffect );
}


Event.observe(window,"load",function(e) {

if (window && window.location) {
	var addr = window.location.toString();
	var hostname = window.location.host.replace('www.','');
	if (hostname != 'comfortstation.co.uk') {
		bodies=document.getElementsByTagName('body');
		b = bodies[0];
		b.style.background = 'white';
		b.style.padding = '1em';
		b.style.fontFamily="Arial, Helvetica, Sans-Serif";
		b.innerHTML = '<h1 style="border-bottom:1px solid black">Illegal access request</h1><p>The site you are attempting to access ('+hostname+') has <strong>illegally pirated</strong> the content of <a href="http://comfortstation.co.uk/">Comfort Station</a>. Please alert the <a href="mailto:webmaster@'+hostname+'">webmaster</a> of '+hostname+' so that he or she may correct this copyright infringement.</p>';
		
		orig = addr.replace( hostname, 'comfortstation.co.uk' );
		b.innerHTML += 	'<p>In the meantime, you might have a look at the original site: <a href="'+orig+'">'+orig+'</a></p>';
		

	}
	
}
});


function Appear(obj, options) {
	addEffect( new Effect.Appear( obj, Object.extend( {type: 'opacity', duration:.3}, options ) ) );
}
function Disappear(obj, options) {
	addEffect( new Effect.Fade( obj, Object.extend( {type: 'opacity', duration:.3}, options ) ) );
}

function Fade( obj, options ) {
//	if (options.to && options.to>0)
//		addEffect( new Effect.Appear( obj, Object.extend( {type: 'opacity', duration:.3}, options ) ) );
//	else
		addEffect( new Effect.Opacity( obj, Object.extend( {type: 'opacity', duration:.3}, options ) ) );
}	
function FadeIn( obj, options ) {
	Fade( obj, Object.extend( {to: 1}, options ) );
}
function FadeOut( obj, options ) {
	Fade( obj, Object.extend( {to: 0}, options ) );
}
function Slide( obj, options ) {
	addEffect( new Effect.Move( obj, Object.extend( {type: 'move', duration:.3}, options ) ) );
}
function SlideY( obj, options ) {
	// Uses current 'x' value
	Slide( obj, Object.extend( {mode:'absolute', x:$(obj).offsetLeft }, options ) );
}
function SlideX( obj, options ) {
	// Uses current 'y' value
	Slide( obj, Object.extend( {mode:'absolute', y:$(obj).offsetTop }, options ) );
}
function ExplodeW( obj, w, options ) {
	addEffect( new Effect.Scale( obj, 100, Object.extend( {type:'scale',duration:.3,scaleY:false, scaleContent:false, scaleFrom:0, scaleMode: { originalHeight: $(obj).getDimensions().height, originalWidth: w } }, options ) ) );
}
function ImplodeW( obj, options ) {
	var dims = $(obj).getDimensions();
	addEffect( new Effect.Scale( obj, 0, Object.extend( {type:'scale',duration:.3,scaleY:false, scaleContent:false, scaleFrom:100, scaleMode: { originalHeight: dims.height, originalWidth: dims.width } }, options ) ) );
}