﻿//Class: Pop-out inline window for external (local) content
var PopOutWindow = new Class({
	Implements: [Options, Events],
	Binds: ['goForIt', 'closeIt'],
	options: {
		content: null,
		overlayId: 'POWoverlay',
		overOberlayId: 'POWinnerlay',
		innerOverlayId: 'POWdiv',
		stylesForOuterInner: {'width':'650px','height':'500px','margin':'0 0 0 -325px'},
		stylesForInnerInner: {'width':'640px','height':'480px','overflow-y':'scroll','overflow-x':'hidden'}
	},
	initialize: function(options){
		this.setOptions(options);
		this.newOverlay = new Element('div', {'id':this.options.overlayId}).inject(document.body);
		this.newOverlay.addEvent('click', function(){ this.closeIt();return false;}.bind(this));
		this.newOverlay.fade('hide');
		this.newOverlay.fade(0.6);
		this.newInnerlay = new Element('div', {'id':this.options.overOberlayId, 'styles': this.options.stylesForOuterInner}).inject(this.newOverlay, 'after');
		this.getScrollLength=window.getScroll().y;
		this.getWinSize=window.getSize().y;
		this.calcTopMargin=(this.getWinSize-($(this.options.overOberlayId).getStyle('height').toInt()))/2;
		this.newInnerlay.setStyles({'top':this.getScrollLength+'px', 'margin-top':this.calcTopMargin+'px'});
		this.newDiv = new Element('div', {'id':this.options.innerOverlayId, 'class':'backgroundLoading', 'styles':this.options.stylesForInnerInner}).inject(this.newInnerlay);
		this.newDivAfter = new Element('div', {'styles':{'position':'absolute','bottom':'0','right':'5px'}, 'html':'<div style="text-align:right;float:right;height:19px;width:110px;min-height:19px;min-width:110px;"><a href="#" style="color:white;font-size:10px">CLOSE THIS BOX</a></div><div class="clear"></div>'}).inject(this.newDiv, 'after');
		this.newDivAfter.addEvent('click', function(){ this.closeIt();return false;}.bind(this));
		this.goForIt();
	},
	goForIt: function(){
		this.requ=new Request.HTML({
			noCache: true,
			evalScripts: true,
			evalResponse: true,
			url: this.options.content,
			onSuccess: function(html) {
				$(this.options.innerOverlayId).removeClass('backgroundLoading');
				$(this.options.innerOverlayId).set('html', this.requ.response.text);
			}.bind(this),
			onCancel: function() {
				alert('There was an error while processing your request. You, your browser or your ISP cancelled the connection to our server. Try again.');
			},
			onException: function() {
				alert('There was an error while processing your request. We are working on this issue and it should be resolved soon.');
			},
			onFailure: function() {
				alert('There was an error while processing your request. We are working on this issue and it should be resolved soon.');
			}
		}).post();
	},
	closeIt: function(){
		$(this.options.innerOverlayId).destroy();
		$(this.options.overOberlayId).destroy();
		$(this.options.overlayId).fade(0);
		(function(){$(this.options.overlayId).destroy()}.bind(this)).delay(600);
	}
});
function periAJXCall(url,id){
	var requ=new Request.HTML({
		noCache: true,
		evalScripts: true,
		evalResponse: true,
		url: url,
		onSuccess: function(html) {
			$(id).set('html', requ.response.text);
		}
	}).post();	
}
//DomReady Events/Functions
var allValid = false;
window.addEvent('domready',function(){if($('ktsdloadcountloader')){periAJXCall.periodical(10000, this, ['ktsdloadcount.php','ktsdloadcountloader']);}if($('homepage')){$('home').addClass('active');}
else if($('portfoliopage')){$('portfolio').addClass('active');}
else if($('innovationpage')||$('ktspage')||$('pepiospage')||$('simadminpag')||$('dynalogpage')||$('jfmp3page')){$('innovation').addClass('active');}
else if($('radpage')){$('rad').addClass('active');}
else if($('teampage')){$('team').addClass('active');}
else if($('contactpage')){$('contact').addClass('active');new FormCheck('contactus',{submitByAjax:true,onAjaxRequest:function(){$('submitp').set('html','<img src="assets/loading.gif" alt="Sending now..." style="position:absolute;right:10px;bottom:-8px;"/>');}});}});