
InitPopin = function() {
	/* We find all items with the linkpopin class */
//alert('init popin');
	var els = YAHOO.util.Dom.getElementsByClassName('linkpopin', 'a');
	for( var i=0; i < els.length; i++ )
	{
		var link = els[i]; //.getEl();
		YAHOO.util.Event.addListener(els[i], "click", cgClick);
		link.setAttribute('hrefold', link.getAttribute('href'), false);
		link.setAttribute('href', '#');
	}
}

function cgClick() {
	return cgClickI(this.getAttribute('hrefold'));
}

function cgClickT(el) {
	return cgClickI(el.getAttribute('href'));
}
function cgClickI(spopinurl)
{
	var spopin = document.getElementById( 'popinframe' ); 
	var sblackout = document.getElementById( 'blackout' ); 
	
	if (spopin) {
		try {
			spopin.src = spopinurl;
		} catch(e) {
			// if href is invalid => do not popin
			return true;
		}
		if (sblackout) {
			YAHOO.util.Dom.setStyle( sblackout , 'opacity', '0');
			YAHOO.util.Dom.setStyle( sblackout , 'display', 'block');
			var animOut = new YAHOO.util.Anim( sblackout, { opacity: { to: 0.5 } }, 1, YAHOO.util.Easing.easeOut);
			animOut.animate();
		}
		return false;
	}
	return true;
}


function showpopin() {
	var spopin = document.getElementById( 'popinframe' ); 

	if (spopin) {
		YAHOO.util.Dom.setStyle( spopin , 'opacity', '0');
		YAHOO.util.Dom.setStyle( spopin , 'display', 'block');
		

		var animOut = new YAHOO.util.Anim( spopin, { opacity: { to: 1 } }, 1, YAHOO.util.Easing.easeOut);
		animOut.animate();
	}
}

function resizepopin(w, h) {
	var spopin = document.getElementById( 'popinframe' ); 

	if (spopin) {

		var animWidth = new YAHOO.util.Anim( spopin, { width: { to: w } }, 0.5, YAHOO.util.Easing.easeOut);
		animWidth.animate();

		var animHeight = new YAHOO.util.Anim( spopin, { height: { to: h } }, 0.5, YAHOO.util.Easing.easeOut);
		animHeight.animate();
	}
}

function closepopin()
{
	var spopin = document.getElementById( 'popinframe' ); 
	
	var sblackout = document.getElementById( 'blackout' ); 

	if (sblackout) {
		var animOut = new YAHOO.util.Anim( sblackout, { opacity: { to: 0 } }, 1, YAHOO.util.Easing.easeOut);
		animOut.onComplete.subscribe( popinHide );
		animOut.animate();
	}	
	
	if (spopin) {
		YAHOO.util.Dom.setStyle( spopin , 'opacity', '0');
		YAHOO.util.Dom.setStyle( spopin , 'display', 'block');
		
		var animOut = new YAHOO.util.Anim( spopin, { opacity: { to: 1 } }, 1, YAHOO.util.Easing.easeOut);
		animOut.onComplete.subscribe( popinHide );
		animOut.animate();
	}
}

function popinHide() {
	var spopin = document.getElementById( 'popinframe' ); 
	if (spopin) {
		YAHOO.util.Dom.setStyle( spopin , 'display', 'none');
	}
	var sblackout = document.getElementById( 'blackout' ); 
	if (sblackout) {
		YAHOO.util.Dom.setStyle( sblackout , 'display', 'none');
	}
}



function enablePopinInDocument() {
	try {
		YAHOO.util.Event.onDOMReady(InitPopin);
	} catch(e) {
		window.setTimeout(200,'enablePopinInDocument()');
	}
}


function insertcontent() {
	var spopinc = document.getElementById( 'popincontent' ); 
	var spopini = document.getElementById( 'popinframe' ); 
	if (spopini.document)
	spopinc.innerHTML = spopini.document.body.innerHTML;
}




/*** POPIN PAGE **/

function popin_show() {
	if (this.parent)
		if (this.parent.showpopin) {
			this.parent.showpopin();
		}
		if (this.parent.resizepopin) {
			var popin_container = document.getElementById( 'popin_container' ); 
			if (popin_container) {
				this.parent.resizepopin(popin_container.scrollWidth,popin_container.scrollHeight);
				//this.parent.resizepopin(popin_container.scrollWidth,popin_container.innerHeight);			
			} else {
				this.parent.resizepopin(this.document.body.scrollWidth,this.document.body.scrollHeight);
				//this.parent.resizepopin(popin_container.scrollWidth,popin_container.innerHeight);			
			}
		}
}

function popin_close() {
	if (this.parent)
		if (this.parent.closepopin)
			this.parent.closepopin();
}


function pageIsPopin() {
	try {
		YAHOO.util.Event.onDOMReady(popin_show);
	} catch(e) {
		window.setTimeout(200,'pageIsPopin()');
	}
}

