PopupVideo = Class.create();

PopupVideo.prototype = {
	controller: null,
 	initialize: function() {
		this.onWindowResize=this.setPopPositionXOnly.bindAsEventListener(this);
		this.closeOnPageClick=this.close.bindAsEventListener(this);
		this.closeButtonHandler=this.close.bindAsEventListener(this);
		this.createPopup();
		this.setDefaults();
	},
	
 	createPopup: function() {
 		if(!PopupVideo.popup) {
			PopupVideo.popup={};
			PopupVideo.popup.closeBtn = Builder.node('a', {href:'#close', 'class':'close'}, 'Close');
			PopupVideo.popup.popupimgnode = Builder.node('td');
			PopupVideo.popup.popuptitle = Builder.node('th', {});
			PopupVideo.popup.videocode = Builder.node('tbody', [
					Builder.node('tr')
				]);				
			PopupVideo.popup.popupcontents = Builder.node('table', {'class':'popupcontents' }, [ 
				Builder.node('thead', [
					Builder.node('tr', PopupVideo.popup.popuptitle),
				]),
				PopupVideo.popup.videocode
			]);
			PopupVideo.popup.popup = Builder.node('div', {'id':'gallery', 'class':'gallery'}, [
				PopupVideo.popup.closeBtn,
				PopupVideo.popup.popupcontents,
			]);
			
			PopupVideo.popup.popupshadow = Builder.node('div', {id:'gallery-shadow', 'class':'gallery-shadow'}, [
				Builder.node('img', {src:Browser.SiteRoot()+'/images/video_back.png', alt:'', border:0, 'class':'pngfix'})
			]);
			Event.observe(PopupVideo.popup.popup, 'click', this.eatEvent.bindAsEventListener(this));
			document.body.appendChild(PopupVideo.popup.popupshadow);
			document.body.appendChild(PopupVideo.popup.popup);
		}
		this.closeBtn = PopupVideo.popup.closeBtn;
		this.popuptitle = PopupVideo.popup.popuptitle;
		this.popupcontents = PopupVideo.popup.popupcontents;
		this.popup = PopupVideo.popup.popup;
 		this.popupshadow = PopupVideo.popup.popupshadow;
 		this.videocode = PopupVideo.popup.videocode;
 	},
 	
 	setDefaults: function() {
		this.defaultWidth = this.popup.offsetWidth;
		this.padleft = parseInt(Element.getStyle(this.popup, 'marginLeft').replace(/px/i,''));
		this.padright = parseInt(Element.getStyle(this.popup, 'marginRight').replace(/px/i,''));
		PopupVideo.ispopped = false;
		this.defaultHeight = this.popup.offsetHeight;
		this.padtop = parseInt(Element.getStyle(this.popup, 'marginTop').replace(/px/,''));
		this.padbottom = parseInt(Element.getStyle(this.popup, 'marginBottom').replace(/px/,''));
 	},


 	eatEvent: function(evt) {
		// stop the default event
 		Event.stop(evt);
	},
 	
	windowSize: function() {
		var width = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
		var height = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
		var x = window.pageXOffset || (window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
		var y = window.pageYOffset || (window.document.documentElement.scrollTop || window.document.body.scrollTop);
		if(Browser.IsiPhone()) {
			width = parseInt(980);
			height = parseInt(1212);
		}
		return {'width':width, 'height':height, 'x':x, 'y':y}
	},

 	setPopPosition: function() {
		var left, top = null;
		left = this.windowSize().x+(this.windowSize().width-this.defaultWidth-this.padleft-this.padright)/2;
		if (this.windowSize().width<this.defaultWidth+this.padleft+this.padright) left = this.windowSize().x-(this.padtop-this.closeBtn.offsetWidth);
		top = this.windowSize().y+(this.windowSize().height-this.defaultHeight-this.padtop-this.padbottom)/2;
		if (this.windowSize().height<this.defaultHeight+this.padtop+this.padbottom) top = this.windowSize().y-(this.padtop-this.closeBtn.offsetHeight);
		this.popup.style.left = left+'px';
		this.popupshadow.style.left = left+'px';
		this.popup.style.top = top+'px';
		this.popupshadow.style.top = top+'px';
 	},

 	setPopPositionXOnly: function() {
		var left = null;
		left = this.windowSize().x+(this.windowSize().width-this.defaultWidth-this.padleft-this.padright)/2;
		if (this.windowSize().width<this.defaultWidth+this.padleft+this.padright) left = this.windowSize().x-(this.padtop-this.closeBtn.offsetWidth);
		this.popup.style.left = left+'px';
		this.popupshadow.style.left = left+'px';
 	},

 	beforePop: function() {
		

Element.addClassName(this.popup, 'isanim');
		
Element.addClassName(this.popupshadow, 'isanim');
 	},
 	
 	removeVideo: function(){
 		while (this.videocode.firstChild){
 			this.videocode.removeChild(this.videocode.firstChild);
 		}
 	},
	
	setVideo: function(videoPage) {
		this.removeVideo();
		newVideo = Builder.node('tr', [
			Builder.node('td', [
				Builder.node('br'),
				Builder.node('iframe', {'src':videoPage, 'width':'720', 'height':'480', 'scrolling': 'no'})
			])	
		]);
		this.videocode.appendChild(newVideo);
	},
	
 	

pop: function(title,videoPage) {
 		this.popuptitle.innerHTML=title;
 		this.setVideo(videoPage);
 		this.setPopPosition();
		Event.observe(window, 'resize', this.onWindowResize);
		Event.observe(this.closeBtn, 'click', this.closeButtonHandler, false);
		Element.setOpacity(this.popup, 0);
		Element.setOpacity(this.popupshadow, 0);
		this.beforePop();
		this.afterPop();	
	},

 	afterPop: function(item, i) {
		Element.removeClassName(this.popup, 'isanim');
		Element.removeClassName(this.popupshadow, 'isanim');
		Element.addClassName(this.popup, 'popped');
		Element.addClassName(this.popupshadow, 'popped');
		this.popup.style.width = '';
		this.popupshadow.style.width = '';
		this.popup.style.height = '';
		this.popupshadow.style.height = '';
		Element.setOpacity(this.popup, '');
		Element.setOpacity(this.popupshadow, '');
 	},

 	beforeClose: function() {
		Element.addClassName(this.popup, 'isanim');
		Element.addClassName(this.popupshadow, 'isanim');
 		Element.removeClassName(this.popup, 'popped');
 		Element.removeClassName(this.popupshadow, 'popped');
 	},

 	close: function(evt) {
 		if (evt) Event.stop(evt);
		Event.stopObserving(window, 'resize', this.onWindowResize);
		Event.stopObserving(window, 'click', this.closeOnPageClick);
		Event.stopObserving(this.closeBtn, 'click', this.closeButtonHandler);
		this.beforeClose();
		this.afterClose();
	},

 	afterClose: function() {
 		this.removeVideo();
		Element.removeClassName(this.popup, 'isanim');
		Element.removeClassName(this.popupshadow, 'isanim');
		this.popup.style.width = '';
		this.popupshadow.style.width = '';
		this.popup.style.height = '';
		this.popupshadow.style.height = '';
		this.popup.style.left = '';
		this.popupshadow.style.left = '';
		this.popup.style.top = '';
		this.popupshadow.style.top = '';
		this.popup.style.display = '';
		this.popupshadow.style.display = '';
		if (Browser.IsWebKit()) this.fixSafarisScrollBars();
 	},

 	fixSafarisScrollBars: function() {
		_scrollTo = 1;
		window.scroll(this.windowSize().x+_scrollTo, this.windowSize().y+_scrollTo);
		_scrollTo = -_scrollTo;
		window.scroll(this.windowSize().x+_scrollTo, this.windowSize().y+_scrollTo);
 	}
};



Event.observe(window, 'load', function() {
	window.PopupVideoPlayer = new PopupVideo();
}, false);

PopupVideo = Class.create();

PopupVideo.prototype = {
	controller: null,
 	initialize: function() {
		this.onWindowResize=this.setPopPositionXOnly.bindAsEventListener(this);
		this.closeOnPageClick=this.close.bindAsEventListener(this);
		this.closeButtonHandler=this.close.bindAsEventListener(this);
		this.createPopup();
		this.setDefaults();
	},
	
 	createPopup: function() {
 		if(!PopupVideo.popup) {
			PopupVideo.popup={};
			PopupVideo.popup.closeBtn = Builder.node('a', {href:'#close', 'class':'close'}, 'Close');
			PopupVideo.popup.popupimgnode = Builder.node('td');
			PopupVideo.popup.popuptitle = Builder.node('th', {});
			PopupVideo.popup.videocode = Builder.node('tbody', [
					Builder.node('tr')
				]);				
			PopupVideo.popup.popupcontents = Builder.node('table', {'class':'popupcontents' }, [ 
				Builder.node('thead', [
					Builder.node('tr', PopupVideo.popup.popuptitle),
				]),
				PopupVideo.popup.videocode
			]);
			PopupVideo.popup.popup = Builder.node('div', {'id':'gallery', 'class':'gallery'}, [
				PopupVideo.popup.closeBtn,
				PopupVideo.popup.popupcontents,
			]);
			
			PopupVideo.popup.popupshadow = Builder.node('div', {id:'gallery-shadow', 'class':'gallery-shadow'}, [
				Builder.node('img', {src:Browser.SiteRoot()+'/images/video_back.png', alt:'', border:0, 'class':'pngfix'})
			]);
			Event.observe(PopupVideo.popup.popup, 'click', this.eatEvent.bindAsEventListener(this));
			document.body.appendChild(PopupVideo.popup.popupshadow);
			document.body.appendChild(PopupVideo.popup.popup);
		}
		this.closeBtn = PopupVideo.popup.closeBtn;
		this.popuptitle = PopupVideo.popup.popuptitle;
		this.popupcontents = PopupVideo.popup.popupcontents;
		this.popup = PopupVideo.popup.popup;
 		this.popupshadow = PopupVideo.popup.popupshadow;
 		this.videocode = PopupVideo.popup.videocode;
 	},
 	
 	setDefaults: function() {
		this.defaultWidth = this.popup.offsetWidth;
		this.padleft = parseInt(Element.getStyle(this.popup, 'marginLeft').replace(/px/i,''));
		this.padright = parseInt(Element.getStyle(this.popup, 'marginRight').replace(/px/i,''));
		PopupVideo.ispopped = false;
		this.defaultHeight = this.popup.offsetHeight;
		this.padtop = parseInt(Element.getStyle(this.popup, 'marginTop').replace(/px/,''));
		this.padbottom = parseInt(Element.getStyle(this.popup, 'marginBottom').replace(/px/,''));
 	},


 	eatEvent: function(evt) {
		// stop the default event
 		Event.stop(evt);
	},
 	
	windowSize: function() {
		var width = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
		var height = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
		var x = window.pageXOffset || (window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
		var y = window.pageYOffset || (window.document.documentElement.scrollTop || window.document.body.scrollTop);
		if(Browser.IsiPhone()) {
			width = parseInt(980);
			height = parseInt(1212);
		}
		return {'width':width, 'height':height, 'x':x, 'y':y}
	},

 	setPopPosition: function() {
		var left, top = null;
		left = this.windowSize().x+(this.windowSize().width-this.defaultWidth-this.padleft-this.padright)/2;
		if (this.windowSize().width<this.defaultWidth+this.padleft+this.padright) left = this.windowSize().x-(this.padtop-this.closeBtn.offsetWidth);
		top = this.windowSize().y+(this.windowSize().height-this.defaultHeight-this.padtop-this.padbottom)/2;
		if (this.windowSize().height<this.defaultHeight+this.padtop+this.padbottom) top = this.windowSize().y-(this.padtop-this.closeBtn.offsetHeight);
		this.popup.style.left = left+'px';
		this.popupshadow.style.left = left+'px';
		this.popup.style.top = top+'px';
		this.popupshadow.style.top = top+'px';
 	},

 	setPopPositionXOnly: function() {
		var left = null;
		left = this.windowSize().x+(this.windowSize().width-this.defaultWidth-this.padleft-this.padright)/2;
		if (this.windowSize().width<this.defaultWidth+this.padleft+this.padright) left = this.windowSize().x-(this.padtop-this.closeBtn.offsetWidth);
		this.popup.style.left = left+'px';
		this.popupshadow.style.left = left+'px';
 	},

 	beforePop: function() {
		

Element.addClassName(this.popup, 'isanim');
		
Element.addClassName(this.popupshadow, 'isanim');
 	},
 	
 	removeVideo: function(){
 		while (this.videocode.firstChild){
 			this.videocode.removeChild(this.videocode.firstChild);
 		}
 	},
	
	setVideo: function(videoPage) {
		this.removeVideo();
		newVideo = Builder.node('tr', [
			Builder.node('td', [
				Builder.node('br'),
				Builder.node('iframe', {'src':videoPage, 'width':'720', 'height':'480', 'scrolling': 'no'})
			])	
		]);
		this.videocode.appendChild(newVideo);
	},
	
 	

pop: function(title,videoPage) {
 		this.popuptitle.innerHTML=title;
 		this.setVideo(videoPage);
 		this.setPopPosition();
		Event.observe(window, 'resize', this.onWindowResize);
		Event.observe(this.closeBtn, 'click', this.closeButtonHandler, false);
		Element.setOpacity(this.popup, 0);
		Element.setOpacity(this.popupshadow, 0);
		this.beforePop();
		this.afterPop();	
	},

 	afterPop: function(item, i) {
		Element.removeClassName(this.popup, 'isanim');
		Element.removeClassName(this.popupshadow, 'isanim');
		Element.addClassName(this.popup, 'popped');
		Element.addClassName(this.popupshadow, 'popped');
		this.popup.style.width = '';
		this.popupshadow.style.width = '';
		this.popup.style.height = '';
		this.popupshadow.style.height = '';
		Element.setOpacity(this.popup, '');
		Element.setOpacity(this.popupshadow, '');
 	},

 	beforeClose: function() {
		Element.addClassName(this.popup, 'isanim');
		Element.addClassName(this.popupshadow, 'isanim');
 		Element.removeClassName(this.popup, 'popped');
 		Element.removeClassName(this.popupshadow, 'popped');
 	},

 	close: function(evt) {
 		if (evt) Event.stop(evt);
		Event.stopObserving(window, 'resize', this.onWindowResize);
		Event.stopObserving(window, 'click', this.closeOnPageClick);
		Event.stopObserving(this.closeBtn, 'click', this.closeButtonHandler);
		this.beforeClose();
		this.afterClose();
	},

 	afterClose: function() {
 		this.removeVideo();
		Element.removeClassName(this.popup, 'isanim');
		Element.removeClassName(this.popupshadow, 'isanim');
		this.popup.style.width = '';
		this.popupshadow.style.width = '';
		this.popup.style.height = '';
		this.popupshadow.style.height = '';
		this.popup.style.left = '';
		this.popupshadow.style.left = '';
		this.popup.style.top = '';
		this.popupshadow.style.top = '';
		this.popup.style.display = '';
		this.popupshadow.style.display = '';
		if (Browser.IsWebKit()) this.fixSafarisScrollBars();
 	},

 	fixSafarisScrollBars: function() {
		_scrollTo = 1;
		window.scroll(this.windowSize().x+_scrollTo, this.windowSize().y+_scrollTo);
		_scrollTo = -_scrollTo;
		window.scroll(this.windowSize().x+_scrollTo, this.windowSize().y+_scrollTo);
 	}
};



Event.observe(window, 'load', function() {
	window.PopupVideoPlayer = new PopupVideo();
}, false);

