var PopupVideo = {
	
	linkClass : 'video_link',
	windowUrl : 'popupVideo.php',
	windowWidth : 350,
	windowHeight : 300,

	errorReporting : true,
	
	init : function() {
		var links = document.getElementsByTagName('A');
		var regEx = new RegExp('(^| )'+PopupVideo.linkClass+'( |$)', 'i');
		for(var i=0; i<links.length; i++) {
			if( (links[i].className+'').match(regEx) ) links[i].onclick = PopupVideo.show;
		}
	},
	
	show : function() {
		var wUrl = new PopupVideo.urlObject( this.windowUrl ? this.windowUrl : PopupVideo.windowUrl );

		wUrl.addParam('video', this.href);
		wUrl.addParam('title', this.title ? this.title : PopupVideo.getInnerText(this));
		if(this.player_width) wUrl.addParam('player_width', this.player_width);
		if(this.player_height) wUrl.addParam('player_height', this.player_height);

		var wWidth = this.windowWidth ? this.windowWidth : PopupVideo.windowWidth;
		var wHeight = this.windowHeight ? this.windowHeight : PopupVideo.windowHeight;
		var wLeft = (screen.width/2) - (wWidth/2);
		var wTop  = (screen.height/2) - (wHeight/2);
		
		window.open(wUrl.href(), '', 'width='+wWidth+',height='+wHeight+',left='+wLeft+',top='+wTop);
		return false;
	},
	
	urlObject : function(url) {
		this.url = url;
		this.params = new Object();
		this.addParam = function(key,value) { this.params[key] = value; };
		this.href = function() {
			var rStr = this.url + '?';
			var pStr = '';
			for(key in this.params) { pStr += (pStr ? '&':'') + key + '=' + this.params[key]; }
			return rStr + pStr;
		};
	},
	
	getInnerText : function(el) {
		var tmp = el.innerHTML.replace(/<br>/gi,"\n");
		return tmp.replace(/<[^>]+>/g,"");
	},

	addLoadEvent : function(fn) {
		var old_onload = window.onload;
		window.onload = (typeof old_onload == 'function') ? function() { old_onload(); fn(); } : fn;
	}

/*
	///////////////////////////////////////////
	///////////////// OLD WAY /////////////////
	///////////////////////////////////////////

	el_slideshow : '',
	el_PopupVideo : '',
	
	init : function() {
		try {
			el_slideshow = document.getElementById('slideshow');
			el_PopupVideo = document.getElementById('PopupVideoeo');
			var el_show  = document.getElementById('PopupVideoeo_show');
			var el_hide  = document.getElementById('PopupVideoeo_hide');
			el_show.onclick = PopupVideo.show;
			el_hide.onclick = PopupVideo.hide;
		} catch(err) {}
	},
	
	show : function() {
		try {
			el_slideshow.style.display = 'none';
			el_PopupVideo.style.display = 'block';
			stopSlides();
		} catch(err) { return false; }
		return false;
	},
	
	hide : function() {
		try {
			el_slideshow.style.display = 'block';
			el_PopupVideo.style.display = 'none';
			if(el_PopupVideo.getElementsByTagName('OBJECT')) {
				el_PopupVideo.getElementsByTagName('OBJECT')[0].stop();
			}
			startSlides();
		} catch(err) { return false; }
		return false;
	},
*/
	
};

PopupVideo.addLoadEvent(PopupVideo.init);
