var QC = { };
QC.ActivateTab = function(id) {
	if(id != null || id.length != 0) {
		if($(id)) {
			$(id).className = 'nav_item_active';
		}
	}
}
QC.Window = Class.create({ 
	initialize: function() {
		this.focusElementId = 'window_focus_element';
		//this._createFocusElement();
	},
	_createFocusElement: function() {
		if(!$(this.focusElementId)) {
			document.body.appendChild(
				new Element('div', { id:this.focusElementId })
			);
			$(this.focusElementId).setStyle({
  				display: 'none',
  				width: '0px',
				height: '0px',
				position: 'absolute',
				zIndex: 'auto',
				top: '0px',
				left: '0px'
			});
		}
	},
	blur: function(c,o) {
		
		c = (c) ? c : '#000';
		o = (o) ? o : 1.0;
		
		if(this.isFocused()) {
			$(this.focusElementId).setStyle({
				width: QC.Window.pageSize()[0] + "px",
				height: QC.Window.pageSize()[1] + "px",
				backgroundColor: c,
				opacity: o
			});
			$(this.focusElementId).show();	
		}
	},
	focus: function() {
		if(!this.isFocused()) {
			$(this.focusElementId).setStyle({
				width: "0px",
				height: "0px",
				opacity: 0
			});
			$(this.focusElementId).hide();
		}
	},
	isFocused: function() {
		return !$(this.focusElementId).visible();
	}
});
/*
 * Static Window class method
 * @return Array [width,height]
 */
QC.Window.pageSize = function() {
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
		
	var windowWidth, windowHeight;
		
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
		
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
};
QC.Content = Class.create(QC.Window, { 
	initialize: function($super) {
		$super();
	}
});
/*
 * Static Content class method
 * @var String url
 * @return Boolean isVideo
 */
QC.Content.isVideo = function(url) {
	var regexp = /\.(mov|mpg)/ig;
	return regexp.test(url);
}
/*
 * Static Content class method
 * @var String url
 * @return Boolean isImage
 */
QC.Content.isImage = function(url) {
	var regexp = /\.(jpg|gif|png)/ig;
	return regexp.test(url);
}
/*
 * Static Content class method
 * @var String url
 * @return Boolean isFlash
 */
QC.Content.isFlash = function(url) {
	/**
	var regexp = /\.(swf|flv|f4v)/ig;
	return regexp.test(url);
	*/
	return (url.indexOf('swf') > -1);
}
QC.SlideSolo = Class.create({
	initialize: function() {
		this.activeId = null;	
	},
	toggle: function(id) {
		if(id) {
			if(id != this.activeId) {
				if(this.activeId) {
					Effect.toggle(this.activeId, 'slide', { duration: 0.5 });
				}
				this.activeId = id;
			} else {
				this.activeId = null;
			}
			Effect.toggle(id, 'slide', { duration: 0.5 });
		}
	}
});
QC.TeamContent = Class.create(QC.Content, { 
	initialize: function($super) { 
		$super();
		this.contentElementId = 'team_content_element';
		this.closeElementId = 'team_content_close_box';
		this.mediaElementId = 'team_content_media';
		this.insertElementId = 'team_content_insert';
		this.nameElementId = 'team_content_name';
		this.quoteElementId = 'team_content_quote';
		this.width = 640;
		this.height = 525;
		this.topMargin = 25;
		//this._createContentElement();
	},
	_createContentElement: function() {
		if(!$(this.contentElementId)) {
			document.body.appendChild(
				new Element('div', { id:this.contentElementId })
			);
			$(this.contentElementId).setStyle({
  				display: 'none',
  				width: '0px',
				height: '0px',
				position: 'absolute',
				zIndex: 'auto',
				top: '0px',
				left: '0px'
			});
		}
		$(this.contentElementId).appendChild(
			new Element('div', { id:this.closeElementId })				 
		);
		$(this.closeElementId).appendChild(
			new Element('a', { onclick:"QC.ContentMgr.unload();",href:"Javascript:;" }).update('x')				 
		);
		$(this.contentElementId).appendChild(
			new Element('div', { id:this.mediaElementId })				 
		);
		$(this.mediaElementId).appendChild(
			new Element('div', { id:this.insertElementId })				 
		);
		$(this.contentElementId).appendChild(
			new Element('div', { id:this.nameElementId })				 
		);
		$(this.contentElementId).appendChild(
			new Element('div', { id:this.quoteElementId })				 
		);
	},
	load: function(m,n,q) {
		if(this.isFocused()) {
			this.blur(null,0.5);	
		}
		$(this.contentElementId).setStyle({
			width: this.width + "px",
			height: this.height + "px",
			top: (document.viewport.getScrollOffsets()[1] + this.topMargin) + "px",
			left: Math.floor((document.viewport.getWidth()-this.width)/2) + "px"
		});
		$(this.contentElementId).show();
		
		if(QC.Content.isFlash(m)) {
			swfobject.embedSWF(m,this.insertElementId, 640, 360, "9.0.0","/assets/swf/expressInstall.swf");
		} else {
			$(this.insertElementId).update('<img src="'+m+'" />');
		}
		
		$(this.nameElementId).update('<img src="'+n+'" />');
		
		$(this.quoteElementId).update(q);
	},
	loadURL: function(url) {
		if(url.length > 1) {
			new Ajax.Request(url,
			{
				method:'get',
				onSuccess: function(transport) {
					var response = transport.responseText || "no response text";
					$('team_content_element').update(response);
    			},
    			onFailure: function() { 
					$('team_content_element').update( "There was an error loading this information..." );		
				}
			});
			if(this.isFocused()) {
				this.blur(null,0.5);	
			}
			$(this.contentElementId).setStyle({
				width: this.width + "px",
				height: this.height + "px",
				top: (document.viewport.getScrollOffsets()[1] + this.topMargin) + "px",
				left: Math.floor((document.viewport.getWidth()-this.width)/2) + "px"
			});
			$(this.contentElementId).show();
		}
	},
	unload: function() {
		if(!this.isFocused()) {
			this.focus();	
		}
		$(this.contentElementId).hide();
		// reset content
		$(this.mediaElementId).update("");
		$(this.mediaElementId).appendChild(
			new Element('div', { id:this.insertElementId })				 
		);
		$(this.nameElementId).update("");
		$(this.quoteElementId).update("");
	}
});
QC.Gallery = Class.create({
	initialize: function() {
		this.lastVisibleId = 'galleryImage_0';
	},
	show: function(id) {
		if(this.lastVisibleId && $(this.lastVisibleId)) {
			$(this.lastVisibleId).hide();
		}
		$(id).show();
		this.lastVisibleId = id;
	}
});
QC.GalleryMgr = new QC.Gallery();
