var Em = {};
Em.lyricsPage = Class.create();
Em.lyricsPage.prototype = {
	initialize: function(name, options){
		this.name = name;
		this.options = Object.extend({
			lyricsDest: 'lyricsContent',
			lyricsSource: 'lyrics',
			css: '/music/lyrics/styles/print.css',
			js: '/music/lyrics/js/lyricsProtect.js'
		}, options || {});
		this.dest = $(this.options.lyricsDest);
		this.source = $(this.options.lyricsSource);
		this.createIframe();
		this.move();
		this.reveal();
	},
	createIframe: function(){
		this.iFrame = new Element('iframe', {
			id: 'lyricsFrame',
			frameborder: '0',
			marginheight: '0',
			marginwidth: '0',
			width: '422',
			height: '500'
		});
		this.dest.appendChild(this.iFrame);
	},
	move: function(){
		var tmpl = new Template(Em.TEMPLATES.iframe);
		var tmpObj = {css: this.options.css, js: this.options.js, lyrics: this.source.innerHTML};
		var iFDoc = this.iFrame.contentDocument;
		if(!iFDoc) iFDoc = this.iFrame.contentWindow.document;
		iFDoc.open();
		iFDoc.write(tmpl.evaluate(tmpObj));
		iFDoc.close();
		this.source.update();
	},
	reveal: function(){
		this.dest.show();
	}
};

if(Prototype.Browser.Gecko){
	Event.observe(document, 'DOMContentLoaded', init);
} else{
	Event.observe(window, 'load', init);
}

function init() {
	$L = new Em.lyricsPage('lyricsPage',{
		lyricsDest: 'lyricsContent',
		lyricsSource: 'lyrics',
		css: '/music/lyrics/styles/print.css',
		js: '/music/lyrics/js/lyricsProtect.js'
	});

    //page level
    /*
	try{
		Event.observe(document, 'mousedown', function(event){
			if (document.layers||(document.getElementById&&!document.all)) {
				if (event.which==2||event.which==3) return false;
			}
		}, true);

	} catch(err){}

	try{
		document.oncontextmenu=new Function("return false");
        document.onmousedown=ds;
		document.onclick=ra;
		document.onselectstart=new Function('return false');
        document.onselect=new Function('return false');
	} catch(err){}
    */
}


function ds(){
	return false;
}
function ra(){
	return true;
}

Em.TEMPLATES = {
	iframe: '<html><head><style>body { border: 0px;	font: 11px/15px verdana, sans-serif;}</style><script>function disableSelection(target){if (typeof target.onselectstart!="undefined"){target.onselectstart=function(){return false};} else if (typeof target.style.MozUserSelect!="undefined"){target.style.MozUserSelect="none";} else {target.onmousedown=function(){return false}} {target.style.cursor = "default"; } } function updateHeight(){parent.document.getElementById("lyricsFrame").style.height = (document.getElementById("oleg").offsetHeight + 40) + "px"; parent.document.getElementById("lyricsFrame").style.height = (document.getElementById("oleg").offsetHeight + 40) + "px"; } </script><script src="#{js}"></script><link href="#{css}" type="text/css" rel="stylesheet"></link></head><body oncontextmenu="return false;" onselectstart="return false;" ondrag="return false;" onclick="return false;"><div id="oleg">#{lyrics}</div><script>updateHeight(); disableSelection(document.getElementById("oleg"));</script></body></html>'
};
