app.config = {
	runOnload: false,
	defaultController: 'home',
	googleAnalyticsKey: false,
	autoloadModels: true,
	useHistory: false
};

app.colors = {
	menuItem: '#b2b2b2'
};

app.paths.iscroll = 'js/appjs/libs/iscroll-lite.js';
app.paths.dragscroll = 'js/appjs/libs/dragscroll.js';

app.utils.loadScript([app.paths.jQuery, app.paths.builderjs], function(url, result, key){
	if(!_.isUndefined(window.jQuery) && !_.isUndefined(window.Div)){
		jQuery.fn.center = function(){
		    this.css("position","absolute");
		    this.css("top", (($(window).height() - $(this).height()) / 2) + $(window).scrollTop() + "px");
			this.css('left', (($(window).width() - $(this).width()) / 2) + $(window).scrollLeft() + "px");
		    return this;
		};
		jQuery.fn.toj = function(){
			return this;
		}
		$.getJSON('/PressHandler.ashx', function(data){
			app.data.pressItems.add(data);
		});
		app.utils.ready();
		if(app.env.mobile){
			app.utils.loadScript(app.paths.iscroll);
		}else{
			app.utils.loadScript(app.paths.dragscroll);
		}
	}
});

app.utils.ready = function(){
	app.utils.loadAppjs();
	app.session.write('currentView', 'panels');
	app.session.write('tooltip.shows', 0);
	app.session.write('disableNav', false);
	app.run('page/render', {'hidePanels':true});
//	app.run('view/panels');
//	app.run('view/aoy');
	app.utils.checkUrlForAction('view/aoy');
	app.utils.centerPage(true);
	$(window).resize(function(){ app.utils.centerPage(false); });
	app.runIn('page/loadPanels', 3000);
};

app.utils.centerPage = function(initial){
	if(initial){
		var menuLeft = $('#menu-container').offset().left;
		var contentLeft = $('#content-container').offset().left;
		var bottomLeft = $('#bottom-content-container').offset().left;
		$('#menu-container').css({'margin':'0', 'left':menuLeft});
		$('#content-container').css({'margin':'0 0 30px 0', 'left':contentLeft});
		$('#bottom-content-container').css({'margin':'0', 'left':bottomLeft});
		app.session.write('menu.width', $('#menu-container').width());
		app.session.write('content.width', $('#content-container').width());
		app.session.write('bottom.width', $('#bottom-content-container').width());
	}else{
		$('#menu-container').css('left', ($(window).width()/2 - app.session.menu.width/2));
		$('#content-container').css('left', ($(window).width()/2 - app.session.content.width/2));
		$('#bottom-content-container').css('left', ($(window).width()/2 - app.session.bottom.width/2));
	}
};

app.utils.checkUrlForAction = function(defaultAction){
	//get "action" from appropriate place in url
	if(window.location.hash){
		var page = false;
		var panel = false;
		page = app.utils.parameter('page', '#!');
		panel = app.utils.parameter('panel', '#!');
	}
	var action = page ? page : (panel ? panel : null);
	if(action){
		if(action === 'work'){
			action = 'panels';
		}
		app.run('view/'+action);
		window.location.hash = '#!';
	}else{
		app.run(defaultAction);
	}
};

app.utils.loadImage = function(src, cb){
	var img = new Image();
	if(cb){
		img.onload = function(){
			cb.call(img);
		}
	}
	img.src = src;
};

app.utils.friendlyId = function(id){
	return id.replace(' ', '-').toLowerCase();
};
String.prototype.friendly = function(){
	return this.replace(' ', '-').toLowerCase();
};

app.utils.loading = function(which){
	if($('#loading-dimmer').length < 1){
		$('<div />').attr('id', 'loading-dimmer').css({'position':'absolute', 'left':'0', 'top':'0', 'background-color':'#000000'}).hide().appendTo('body').fadeTo(1, 0.7);
	}
	if(which === 'hide'){
		$('#loading-dimmer, #loading').fadeOut(300);
	}else{
		$('#loading').center();
		$('#loading-dimmer').width($(window).width()).height($(document).height());
		$('#loading, #loading-dimmer').fadeIn(300);
	}
};

/* controllers */
app.myController = app.libs.controller.extend({
	init: function(){
		this._super();
	}
});

app.controllers.page = app.libs.controller.extend({
	init: function(){
		this._super();
	},
	
	render: function(){
		$('body').append(new app.views.menu().render());
		var items = this.contentItem.find(function(item){ return (!item.bottom); });
		var contentContainer = new app.views.contentContainer(items, (this.data.hidePanels || false));
		$('body').append(contentContainer.render());
		var bottomItems = this.contentItem.find({'bottom':true});
		$('body').append(new app.views.bottomContentContainer(bottomItems, (this.data.hideBottomContainer || false)).render()).append(new app.views.panelContainer().render()).append(new app.views.panelCloser().render()).append(new app.views.loading().render()).append(new app.views.scrollBarCover().render()).append(new app.views.scrollTooltip().render()).click(function(event){ app.session.write('mouse.position', {'x':event.pageX, 'y':event.pageY}); });
		$(window).resize(function(){
			$('.js-center').each(function(){
				$(this).css('left', ($(window).width() / 2 - $(this).width() / 2));
			});
		});
	},
	
	renderAOY: function(){
		
	},
	
	loadPanels: function(){
		var items = this.contentItem.find(function(item){ return (!item.bottom); });
		for(var i = 0; i < items.length; i++){
			if(!items[i].href){ 
				app.utils.loadImage('images/content/panels/'+items[i].id+'.jpg', (function(){
					var id = items[i].id
					return function(){
						var width = this.width;
						var contentItem = new app.models.contentItem();
						contentItem.update({'panelWidth':width}, id);
					}
				})());
			}
		}
		setTimeout(function(){
			_.each(app.views.pages, function(object, page){
				app.utils.loadImage('images/content/pages/'+page+'.png');
			});
		}, 5000);
	}
});

app.controllers.view = app.libs.controller.extend({
	init: function(){
		this._super();
	},
	
	panels: function(skipCheck){
		if(app.session.disableNav) return;
		if(app.session.currentView === 'panel'){
			$('#panel-closer, #panel-container, #scroll-tooltip').fadeOut(250, function(){
				$('#panel-container').html(' ').css({'overflow-x':'hidden'});
			});
			$('#panel-container').dragscrollable('disable').unbind('scroll.tooltip');
			$('#scroll-bar-cover').stop().fadeOut(300, function(){
				$(this).stop().hide();
				setTimeout(function(){
					$('#scroll-bar-cover').hide();
				}, 50);
				app.session.currentView = 'panels';
			});
			app.runIn('view/panels/true', 500);
			return;
		}else{
			app.session.currentView = 'panels';
			$('#pages-container').fadeOut(350, function(){
				$('.page').remove();
				$('#panels-container, #bottom-content-container').fadeIn(350, function(){
					app.session.currentPage = null;
				});
			});
		}
	},
	
	panel: function(id){
		var item = this.contentItem.find('key', id);
		if(item.href){
			window.open(item.href);
			return;
		}
		if(!item.panelWidth){
			app.utils.when(function(){ app.utils.loading(); return item.panelWidth; }, function(){ app.utils.loading('hide'); app.run('view/'+id); });
			return;
		}		
		
		if(app.session.tooltip.shows < 2){
			$('body').bind('mousemove.tooltip', function(event){
				app.session.write('mouse.position', {'x':event.pageX, 'y':event.pageY});
				$('#scroll-tooltip').css({'left':app.session.mouse.position.x - 80, 'top':app.session.mouse.position.y - 67});
			});
		}

		app.session.disableNav = true;
		var $thumb = $('#content-thumb-'+id.friendly());
		var offset = $thumb.offset();
		var width = $thumb.width();
		var height = $thumb.height();
		$('#panel-container').width(width - 8).height(height - 10).css({'left':offset.left + 4, 'top':offset.top + 5, 'background-color':"#ffffff"}).fadeIn(400, function(){
			$('#panels-container, #bottom-content-container').fadeOut(650);
			var panel = !_.isUndefined(app.views.panels[id]) ? new app.views.panels[id](item) : new app.views.panel(item);
			$(this).append(panel.render()).scrollLeft(0).animate({'left':0, 'top':'137px', 'width':$(window).width() + 15, 'height':'450px'}, 750, function(){
				var i = 0;
				setTimeout(function(){
					$('#panel-container').scrollLeft(0);	
				}, 150);
				$('#panel-closer, #panel-'+id.friendly()).fadeIn(1250, function(){
					if(i++ > 0) return;
					app.session.currentView = 'panel';
					if(app.env.mobile){
						var iscroll = new iScroll('panel-container', {'hscroll':true, 'vscroll':false, 'lockDirection':true, 'bounce':false})
						app.session.write('iscroll', iscroll);
					}else{
						if(app.session.tooltip.shows < 2){
							$('#panel-container').bind('scroll.tooltip', function(){
								if($('#panel-container').scrollLeft() > 150){
									$('#scroll-tooltip').fadeOut(550, function(){
										$('body').unbind('mousemove.tooltip');
									});
									$('#panel-container').unbind('scroll.tooltip');
								}
							});
							$('#scroll-tooltip').css({'left':app.session.mouse.position.x - 80, 'top':app.session.mouse.position.y - 67}).fadeIn(350, function(){
								app.session.tooltip.shows++;
							});
						}
						setTimeout(function(){
							if(app.session.currentView === 'panel'){
								app.session.disableNav = false;
								$('#scroll-bar-cover').show();
								$('#panel-container').css({'height':'465px', 'overflow-x':'auto', 'width':'100%'}).dragscrollable({'axis':'x'});
							}
						}, 250);
					}
				});
			});
		});
	},
	
	closePanel: function(){
		app.session.currentView = 'panels';
		if(app.env.mobile){
			app.session.iscroll.destroy();
		}
		$('#panels-container, #bottom-content-container').fadeIn(250);
		$('#panel-closer, #panel-container, #scroll-tooltip').fadeOut(250, function(){
			$('#panel-container').html(' ').css({'overflow-x':'hidden'});
		});
		$('#panel-container').dragscrollable('disable').unbind('scroll.tooltip');
		$('#scroll-bar-cover').stop().fadeOut(300, function(){
			$(this).stop().hide();
			setTimeout(function(){
				$('#scroll-bar-cover').hide();
			}, 50);
		});
	},
	
	page: function(id){
		if(app.session.disableNav) return;
		if(app.session.currentView === 'panel'){
			$('#panel-closer, #panel-container, #scroll-tooltip').fadeOut(250, function(){
				$('#panel-container').html(' ').css({'overflow-x':'hidden'});
			});
			$('#panel-container').dragscrollable('disable').unbind('scroll.tooltip');
			$('#scroll-bar-cover').stop().fadeOut(300, function(){
				$(this).stop().hide();
				setTimeout(function(){
					$('#scroll-bar-cover').hide();
				}, 50);
				app.session.currentView = 'page';
			});
			app.runIn('view/'+id, 500);
			return;
		}
		
		if(app.session.currentPage === id) return;
		var $container = (app.session.currentView === 'page') ? $('#pages-container') : $('#panels-container');
		if(id !== 'aoy'){
			$('#bottom-content-container').fadeOut(350);
		}else{
			setTimeout(function(){
				$('#bottom-content-container').fadeIn(350);	
			}, 300);
		}
		app.session.currentView = 'page';
		$container.fadeOut(350, function(){
			$('.page').remove();
			$('#pages-container').html(' ').append(new app.views.pages[id]().render()).fadeIn(350, function(){
				app.session.currentPage = id;
			});
		});
	},
	
	close: function(){
		$('#panel-container').html(' ');
	}
});

app.controllers.services = app.libs.controller.extend({
	init: function(){
		this._super();
	},
	
	index: function(){
		
	}
});

app.controllers.people = app.libs.controller.extend({
	init: function(){
		this._super();
	},
	
	view: function(name){
		var person = this.person.find('key', name);
		var overlay = new app.views.personOverlay(person);
		overlay.render().appendTo('body').fadeTo(250, 0.9);

		setTimeout(function(){
			$('html').bind('click.personOverlay', function(){
				$(this).unbind('click.personOverlay');
				$('#person-overlay').fadeOut(250, function(){
					$(this).remove();
				});
			});
		}, 560);
	}
});

/* views */
app.views.menu = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new AbsDiv().width('100%').height(82).bg('images/menu/background.png').top(0);
		this.itemContainer = new RelDiv({'margin':'0 auto', 'zoom':'1', 'z-index':'24'}).id('menu-container').width(960).height(82);
		var leftItems = ['People', 'Services', 'Work'];
		var rightItems = ['Press', 'QLabs', 'Contact Us'];
		this.renderItems(leftItems, 'left');
		this.renderItems(rightItems, 'right');
		this.element.toj().append(this.itemContainer.toj());
		this.itemContainer.toj().append( new RelDiv({'margin':'0 auto'}).top(-3).width(182).height(133).pointer().bg('images/menu/questus.png').toj().append(new AbsDiv().left(31).top(0).width(120).height(100).pointer().toj().click(function(){ app.run('view/aoy')})) );
	},
	
	renderItems: function(items, side){
		var css = (side === 'left') ? {'left':'0'} : {'right':'0'};
		var sideContainer = new AbsDiv(css).css({'zoom':'1'}).width(960/2 - 122/2).height(82);
		for(var i = 0; i < items.length; i++){
			sideContainer.toj().append(new app.views.menuItem(items[i], side).render());
			if(i + 1 < items.length){
				sideContainer.toj().append(new FloatDiv({'float':(side === 'left' ? 'right' : 'left')}).width(2).height(82).bg('images/menu/separator.png').toj());
			}
		}
		this.itemContainer.toj().append(sideContainer.toj());
	}
});

app.views.menuItem = app.libs.view.extend({
	init: function(text, side){
		this._super();
		this.element = new FloatDiv({'cursor':'pointer', 'padding':'32px 18px','font-size':'18px', 'color':app.colors.menuItem}).height(18).html(' ').id('menu-item-'+text.friendly());
		if(side === 'left'){
			this.element.right();
		}
		if(text === 'QLabs'){
			var width = 45;
		}else if(text === 'Contact Us'){
			var width = 76;
		}else if(text === 'People'){
			var width = 48;
		}else{
			var width = 55;
		}
		this.element.width(width);
		if(text === 'QLabs'){
			this.element.toj().click(function(){ window.location = 'http://questusblog.com/'; });
		}else if(text === 'Work'){
			this.element.toj().click(function(){ app.go('view/panels'); });
		}else{
			this.element.toj().click(function(){ app.go('view/'+text.friendly()); });
		}
		this.element.bg('images/menu/'+text.replace(' ', '-').toLowerCase()+'.png').css({'background-position':'center center', 'background-repeat':'no-repeat'});
	}
});

app.views.contentContainer = app.libs.view.extend({
	init: function(contentItems, hidePanels){
		this._super();
		this.element = new AbsDiv({'margin':'0 auto 30px'}).addClass('js-center').top(137).id('content-container').width(970).left(($(window).width()/2 - 970/2));
		var panelsContainer = new Div().id('panels-container').width(970).left(0).top(0).height('auto').toj();
		if(hidePanels){
			panelsContainer.hide();
		}
		this.element.toj().append(panelsContainer).append(new AbsDiv().id('pages-container').width(960).left(0).top(0).height('auto').hide().toj());
		for(var i = 0; i < contentItems.length; i++){
			panelsContainer.append(new app.views.contentThumb(contentItems[i]).render());
		}
	}
});

app.views.contentThumb = app.libs.view.extend({
	init: function(item){
		this._super();
		this.element = new FloatDiv().id('content-thumb-'+item.id.friendly()).addClass('content-thumb').pointer().bg('images/content/thumbs/'+item.id+'.png').width(323).height(160);
		this.element.toj().click(function(){ app.run('view/'+item.id) });
	}
});

app.views.bottomContentContainer = app.libs.view.extend({
	init: function(items, hide){
		this._super();
		this.element = new AbsDiv({'clear':'both', 'margin':'0 auto'}).addClass('js-center').top(655).id('bottom-content-container').width(900).left(($(window).width()/2 - 900/2));
		for(var i = 0; i < items.length; i++){
			this.element.toj().append(new app.views.bottomContentItem(items[i], (i + 1 === items.length)).render());
		}
		this.element.toj().append(new Div({'clear':'both'}).height(60).toj());
		if(hide){
			this.element.hide();
		}
	}
});

app.views.bottomContentItem = app.libs.view.extend({
	init: function(item, isLast){
		this._super();
		var click = function(){ window.open(item.href); };
		this.element = new FloatDiv({'margin-right':'87px'}).width(239).height(200);
		this.element.toj().append(new RelDiv({'margin-bottom':'13px'}).pointer().left(5).color('#8fb7ff').html(item.title).toj().click(click)).append(new Div({'margin-bottom':'13px'}).pointer().width(239).height(54).bg('images/bottom-content/thumbs/'+item.id+'.png').toj().click(click));
		this.element.toj().append(new RelDiv({'margin-bottom':'13px'}).color('#ffffff').width(231).left(5).size(13).lh('16px').html(item.content).toj());
		this.element.toj().append(new A({'position':'relative'}).underline('hover').left(5).color('#ffcc00').size(13).href(item.href).target('_blank').html(item.linkText).toj());
		if(isLast){
			this.element.css({'margin-right':'0'});
		}
	}
});

app.views.panelContainer = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new AbsDiv({'overflow':'hidden'}).id('panel-container').width(320).height(159).hide();
	}
});

app.views.panel = app.libs.view.extend({
	init: function(item){
		this._super();
		this.element = new AbsDiv().id('panel-'+item.id.friendly()).bg('images/content/panels/'+item.id+'.jpg').hide().width(item.panelWidth).height(450).left(0).top(0);
	}
});
app.views.panels = {};
app.views.panels.peel = app.views.panel.extend({
	init: function(item){
		this._super(item);
		this.element.toj().append(new app.views.visitSiteLink(2693, 49, 'http://www.facebook.com/yoplaitsmoothie').render()).append(new app.views.visitSiteLink(3067, 49, 'http://yoplait.com/products/smoothies.aspx').render());
		this.element.toj().append('<iframe style="z-index:1;position:absolute;left:1609px;top:98px;width:472px;height:265px;" width="472" height="265" src="http://www.youtube.com/embed/CwGoiINB-DQ?controls=0&rel=0&fs=1" frameborder="0" allowfullscreen></iframe>');
		this.element.toj().append(new AbsDiv({'z-index':'2'}).width(107).height(110).left(2015).top(330).bg('images/content/panel-layers/peel/strawberries.png').toj());
	}
});
app.views.panels.autodesk = app.views.panel.extend({
	init: function(item){
		this._super(item);
		this.element.toj().append(new app.views.visitSiteLink(1436, 117, 'http://demo.questus.com/AutoDesk/').render());
	}
});
app.views.panels.capone = app.views.panel.extend({
	init: function(item){
		this._super(item);
		this.element.toj().append(new app.views.visitSiteLink(1373, 297, 'http://www.youtube.com/CapitalOne').render()).append(new AbsA().left(1907).top(342).href('http://demo.pointroll.com/PointRoll/AdDemo/CreativeManager/CapitalOne/1486350/CapOne_CrabGame_300x250_Exp_DERIVE0.18385084997862577.asp').width(75).height(13).toj().attr('target', '_blank'));
	}
});
app.views.panels.indiana = app.views.panel.extend({
	init: function(item){
		this._super(item);
		this.element.toj().append(new app.views.visitSiteLink(1390, 60, 'http://demo.questus.com/IJTE/').render());
	}
});
app.views.panels.nfl = app.views.panel.extend({
	init: function(item){
		this._super(item);
		this.element.toj().append(new app.views.visitSiteLink(1404, 97, 'http://nfl.dev.questus.com/').render()).append(new app.views.visitSiteLink(2470, 97, 'http://nfl.dev.questus.com/').render());
	}
});
app.views.panels.salesforce = app.views.panel.extend({
	init: function(item){
		this._super(item);
		this.element.toj().append(new app.views.visitSiteLink(1478, 37, 'http://yourservicecloud.com/').render());
	}
});
app.views.panels.busa = app.views.panel.extend({
	init: function(item){
		this._super(item);
		this.element.toj().append().append(this.video()).append(this.guy()).append(new AbsA().target('_blank').right(837).top(130).width(98).height(12).href('http://suzukicycles.com').toj());
	},
	
	video: function(){
		return '<iframe style="z-index:2;width:438px;height:245px;position:absolute;left:1558px;top:119px;" width="438" height="245" src="http://www.youtube.com/embed/UH6sJDN7KKs?rel=0&autohide=1&modestbranding=1" frameborder="0" allowfullscreen></iframe>'
	},
	
	guy: function(){
		return new AbsDiv({'z-index':'9'}).width(303).height(450).left(1890).top(0).bg('images/content/panel-layers/busa/guy.png').toj();
	}
});
app.views.panels.suzuki = app.views.panel.extend({
	init: function(item){
		this._super(item);
		this.element.toj().append(new app.views.visitSiteLink(850, 337, 'http://suzukicycles.com').render());
		this.element.toj().append(new AbsDiv({'z-index':'7'}).bg('images/content/panel-layers/suzuki/bike.png').width(455).height(245).right(477).top(202).toj());
		this.element.toj().append(new AbsDiv({'z-index':'7'}).bg('images/content/panel-layers/suzuki/rocks.png').width(104).height(39).right(129).top(334).toj());
	}
});

app.views.pages = {};
app.views.pages.aoy = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new RelDiv().id('pages-aoy').addClass('page').left(-30).width(952).height(437).top(-34).bg('images/content/pages/aoy.png');
		this.element.toj().append(new AbsA().right(0).bottom(65).width(191).height(35).target('_blank').href('http://www.imediaconnection.com/awards/agency2011/').toj());
	}
});

app.views.pages.people = app.libs.view.extend({
	init: function(){
		this._super();
		var people = new app.models.person().find('all');
		this.element = new RelDiv().id('pages-people').addClass('page').left(28).width(913).height(446).bg('images/content/pages/people.png');
		_.each(people, function(person){
			var size = person.size === 'large' ? [104, 152] : [77, 115];
			this.element.toj().append(new AbsA().left(person.position[0]).top(person.position[1]).width(size[0]).height(size[1]).pointer().toj().click(function(){ app.run('people/'+person.name) }));
		}, this);
	}
});

app.views.pages.services = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new RelDiv().id('pages-services').addClass('page').left(16).width(942).height(576).bg('images/content/pages/services.png?v1');
	}
});

app.views.pages['contact-us'] = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new RelDiv().id('pages-contact-us').addClass('page').left(32).width(550).height(240).bg('images/content/pages/contact-us.png');
		this.element.toj().append(new AbsA().href('mailto:sales@questus.com').width(140).height(17).left(0).top(73).toj().attr('target','_blank')).append(new AbsA().href('http://maps.google.com/maps?q=675+Davis+Street,+San+Francisco,+CA+94111&hl=en&sll=24.126702,-95.712891&sspn=59.640375,74.619141&vpsrc=0&hnear=675+Davis+St,+San+Francisco,+California+94111&t=h&z=17').width(38).height(16).left(0).bottom(0).toj().attr('target','_blank')).append(new AbsA().href('http://maps.google.com/maps?q=250+Hudson+Street,+8th+Floor+NY,+NY+10013&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&um=1&ie=UTF-8&hq=&hnear=0x89c259f343030b69:0xcfd0b49bcfdc0591,250+Hudson+St,+New+York,+NY+10013&gl=us&ei=AHVyTvy7N-rdiAKMuf2GCQ&sa=X&oi=geocode_result&ct=title&resnum=1&ved=0CBgQ8gEwAA').width(38).height(16).left(344).bottom(0).toj().attr('target','_blank'));
	}
});

app.views.pages.imedia = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new RelDiv().id('pages-imedia').addClass('page').left(223).top(50).width(517).height(186).bg('images/content/pages/imedia.png');
		this.element.toj().append(new AbsA().href('imedia/Questus-Social-Editorial-Process.xlsx').width(108).height(17).left(0).top(145).toj().attr('target','_blank'));
	}
});

app.views.pages.press = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new RelDiv({'min-height':'500px', 'background-position':'22px top', 'background-repeat':'no-repeat'}).id('pages-press').addClass('page').left(16).width(941).height('auto').bg('images/content/pages/press.png');		
		var $container = new AbsDiv().left(0).top(137).width(941).height('auto').id('press-items-container').toj();
		this.element.toj().append($container);
		var $element = this.element.toj();
		app.utils.when(function(){ 
			if(app.data.pressItems.count() > 0){
				$element.append(new app.views.pressFilter().render())
				return true;
			}else{
				app.utils.loading();
				return false;
			}
		}, function(){
			app.utils.showPressItems('all', 0, $container);
			app.utils.loading('hide');
		});
	}
});

app.utils.showPressItems = function(category, start, $container){	
	$('.press-filter').css({'color':'#00ffff'});
	$('#press-filter-'+category).css({'color':'#ffffff'});
	var numItems = 5;
	var items = new app.models.pressItem().findByCategory(category).splice(start, numItems);
	_.each(items, function(item){
		$container.append(new app.views.pressItem(item).render());
	});
	
	app.session.write('press.items', {'category':category, 'last':(start + numItems) });
	$(window).unbind('scroll.pressItems');
	if(items.length > 0){
		$(window).bind('scroll.pressItems', _.throttle(function(){
			if($(window).scrollTop() >= $(document).height() - $(window).height() - 10){
				$(window).unbind('scroll.pressItems');
				app.utils.showPressItems(app.session.press.items.category, app.session.press.items.last, $container);
		    }
		}, 250));
	}
};

app.views.pressFilter = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new AbsDiv({'font-size':'11px', 'font-weight':'bold', 'color':'#00ffff'}).left(32).top(112).width(528).height(12).html('<span style="color:#ffffff;">Sort by:</a>');
		this.element.toj().append(new app.views.spacer(16, 12).render()).append(this.filter('all', true));
		var $element = this.element.toj();
		var _this = this;
		_.each(['press', 'awards', 'speaking engagements'], function(category){
			if(new app.models.pressItem().findByCategory(category.split(' ')[0]).length > 0){
				$element.append(new app.views.spacer(16, 12).render()).append('|').append(new app.views.spacer(16, 12).render()).append(_this.filter(category))
			}
			
		});
	},
	
	filter: function(text){
		var filter = text.split(' ')[0];
		return new Span({'cursor':'pointer'}).id('press-filter-'+filter).attr({'rel':filter}).addClass('press-filter').html(text.toUpperCase()).toj().click(function(){
			$('.press-item').fadeOut(250).remove();
			app.utils.showPressItems(filter, 0, $('#press-items-container'));
		});
	}
});

app.views.personOverlay = app.libs.view.extend({
	init: function(person){
		this._super();
		this.element = new AbsDiv().id('person-overlay').width(700).height(440).bg('#000000').toj().fadeTo(1, 0.0).center().css({'top':'150px'});
		this.element.toj().append(new Div({'font-size':'15px', 'line-height':'20px', 'padding':'20px', 'width':'650px'}).color("#ffffff").html(person.content).toj()).append(new AbsDiv().size('75%').color('#ffffff').pointer().right(5).top(5).html('X').toj());
	}
});

app.views.panelCloser = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new FixedDiv({'z-index':'99'}).id('panel-closer').hide().right(350).top(124).width(62).height(62).pointer().bg('images/controls/close.png');
		this.element.toj().click(function(){
			app.run('view/closePanel');
		});
	}
});

app.views.scrollBarCover = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new AbsDiv({'z-index':'99', 'background-position':'center center'}).id('scroll-bar-cover').hide().height(15).left(0).top(587).width('100%').bg('images/graphics/scroll-bar-cover.png');
	}
});

app.views.loading = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new AbsDiv({'z-index':'100'}).id('loading').width(68).height(68).bg('images/graphics/q-loading.png').hide();
	}
});

app.views.visitSiteLink = app.libs.view.extend({
	init: function(left, top, href){
		this._super();
		this.element = new AbsA().left(left).top(top).width(83).height(13).href(href).toj().attr({'target':'_blank'});
	}
});

app.views.scrollTooltip = app.libs.view.extend({
	init: function(){
		this._super();
		this.element = new AbsDiv().id('scroll-tooltip').z(98).right(40).top(165).width(166).height(64).hide().bg('images/graphics/scroll-tooltip.png');
	}
});

app.views.pressItem = app.libs.view.extend({
	init: function(data){
		this._super();
		this.element = new RelDiv({'margin-bottom':'8px'}).addClass('press-item').width(941).height(182).bg('images/backgrounds/press-item.png');
		this.element.toj().append(new AbsDiv({'font-size':'20px', 'font-weight':'bold', 'color':'#ffffff'}).left(31).top(29).width(835).height(22).html(data.Title).toj())
						.append(new AbsDiv().left(28).top(64).width(161).height(92).bg('images/press/'+data.ImagePath).toj())
						.append(new AbsDiv({'font-size':'14px', 'color':'#ffffff'}).left(200).top(68).width(96).height(14).html(data.Date.replace(/\//g, '.')).toj())
						.append(new AbsDiv({'font-size':'14px', 'line-height':'17px', 'color':'#00ffff'}).left(200).top(84).width(692).height(46).html(data.Description).toj())
						.append(new AbsA({'font-weight':'bold', 'text-decoration':'none', 'font-size':'14px', 'color':'#ffcc00'}).attr({'target': '_blank'}).href(data.Link).left(200).top(138).width('auto').height(14).html('Read More').toj());
	}
});

app.views.spacer = app.libs.view.extend({
	init: function(w, h){
		this._super();
		this.element = new Img().src('images/spacer.png').width(w).height(h).attr({'width':w, 'height':h});
	}
});

/* libs */
app.libs.requests = app.libs.Class.extend({
	init: function(){
		
	}
});

app.router = app.libs.router.extend({
	init: function(action){
		//simple router
		if(!action || action === '/'){
			action = app.config.defaultController;
		}
		var parts = action.split('/');
		this.controller = parts[0];
		if(this.controller === 'view'){
			if(parts[1] === 'panels'){
				this.method = 'panels';
				this.params = [];
				return;
			}else if(parts[1] === 'closePanel'){
				this.method = 'closePanel';
				this.params = [];
				return;
			}
			var contentItem = new app.models.contentItem();
			if(contentItem.find(function(item){ return (item.id === parts[1]); }).length > 0){
				this.method = 'panel';
			}else{
				this.method = 'page';
			}
			this.params = [parts[1]];
		}else if(this.controller === 'people'){
			this.method = 'view';
			this.params = [parts[1]];
		}else{
			this.method = parts.length > 1 ? parts[1] : 'index';
			this.params = parts.length > 2 ? parts.slice(2) : [];
		}
	}
});

app.libs.interval = app.libs.Class.extend({
	init: function(settings){
		this.settings = _.extend({'interval': 50}, settings || {});
		this.intervalObject = null;
		this.functions = {};
	},
	
	start: function(){
		this.intervalObject = setInterval(_.bind(function(){
			_.each(this.functions, function(func){
				func.call();
			});
		}, this), this.settings.interval);
	},
	
	stop: function(){
		clearInterval(this.intervalObject);
		this.intervalObject = null;
	},	
	
	addFunction: function(id, func){
		if(_.isFunction(id)){
			var func = id;
			var id = _.uniqueId('intervalFunc');
		}
		this.functions[id] = func;
		return id;
	},
	
	removeFunction: function(id){
		delete(this.functions[id]);
	}
});

/* data */
app.data.contentItems = new app.libs.dataStore();
app.data.contentItems.add([
	{'id':'busa'},
	{'id':'autodesk'},
	{'id':'peel'},
	{'id':'salesforce'},
	{'id':'nfl'},
	{'id':'capone'},
	{'id':'hope', 'href':'http://hopebeyondthehype.com'},
	{'id':'suzuki'},
	{'id':'indiana'},
	{'id':'qlabs', 'href':'http://questusblog.com/', 'linkText':'Check it out', 'title':'QLabs', 'content':'Ever wanted to know what goes on in our heads or what we find cool and engaging? This is the place where we get to share with you all the cool and exciting stuff we do, find and love.', 'bottom':true},
	{'id':'davey', 'href':'http://www.daveyawards.com/awards/', 'linkText':'Learn about the Davey Awards', 'title':'Gold at Davey Awards', 'content':'Questus picked up two Golds at the Davey Awards for our work with Suzuki and Yoplait.', 'bottom':true},
	{'id':'naked-brand', 'href':'http://thenakedbrandfilm.com', 'linkText':'See the trailer', 'title':'The Naked Brand', 'content':'What’s the future of advertising? How will brands respond in the age of transparency?  We explore these issues in a Questus produced and directed documentary <b>The Naked Brand</b>.', 'bottom':true}
]);

app.data.people = new app.libs.dataStore({'key':'name'});
app.data.people.add([
	{'name':'jordan', 'position':[5, 101], 'size':'large', 'content':'<h1>Jordan Berg | Co-Founder</h1><p>Jordan Berg brings over a decade of advertising experience to Questus. Recognized for his dynamic brand-building innovation and thinking across multi-disciplined teams and marketing channels, Jordan has recently completed projects for world-class brands such as Verizon, Suzuki, Reuters, Capital One, Disney and ESPN.</p><p>Jordan has received many of the industries top honors from leading organizations including The Webby’s, Web Marketing Association and Communication Arts. Jordan is a regular contributor to Fox Business, iMedia Connection, Media Magazine and speaks at national conferences—including ad:tech and SHOP.ORG.</p><p>Jordan makes his home in San Francisco and holds a Bachelor of Fine Arts degree from the University of Vermont and Masters Studies from the San Francisco Academy of Art.</p>'},
	{'name':'jr', 'position':[234, 101], 'size':'large', 'content':'<h1>Jeff Rosenblum | Co-Founder</h1><p>Jeff Rosenblum is a pioneer, a disruptor, an innovator and a pain in the ass.  He is widely regarded as one of the leading innovators in the field of digital marketing and has worked on teams that have helped revolutionize market research, magazine publishing, sports broadcasting as well as advertising.</p><p>As a Founding Partner of Questus, Jeff focuses on developing processes that break down the boundaries that exist between research, strategy and creative. He has brought this multi-disciplinary philosophy to help the Questus team produce industry-changing results for leading brands such as Capital One, General Mills, The NFL and Suzuki Motorcycles.</p><p>Every few years, Jeff likes to take on an insane challenge which has culminated in him getting repeatedly punched in the face in the “Vermont Toughman Competition,” jumping in the frozen Atlantic Ocean in the middle of winter to raise money for the Make a Wish Foundation, running an Olympic distance triathlon with no training, and making a documentary despite never actually watching one in its entirety.</p><p>Jeff is on the Advisory Board for the New York Chapter of the Make a Wish Foundation and lives in New York City with his wife and two kids.  He is currently soliciting ideas for his next insane challenge on Twitter:  <a target="_blank" href="http://twitter.com/jrquestus">@jrquestus</a>.</p>'},
	{'name':'joey', 'position':[465, 101], 'size':'large', 'content':'<h1>Joseph Dumont | Partner</h1><p>As Partner of Questus, Joseph’s primary responsibilities are to pursue and grow key client  and partner relationships at Questus while elevating awareness about the agency.  With his deep understanding of management, technology, and business methodology Joseph plays a critical role in helping to realize the overall vision and growth of Questus.</p><p>Joseph is currently working with many industry-leading-brands such as Verizon, Disney, ABC, and Suzuki.  He sits on the advisory board of iMedia and is a frequent guest speaker at industry events including iMedia, Adtech, Mediapost, and Hollywood Digital.</p><p>Prior to joining Questus, Joseph was the Managing Partner and Corporate Vice President of Birdsall Interactive, a California based interactive Marketing Agency.  While there Joseph led new business development and management of clients like Hitachi, Peoplesoft, Palm, Cisco and Sony Electronics.</p>'},
	{'name':'jw', 'position':[6, 313], 'size':'small', 'content':'<h1>Jeff Wagener | VP, Creative Director</h1><p>As Questus’ Creative Director, Jeff believes in a strategic, multidisciplinary, and experiential approach to interactive projects. Over the past three years, he has built an open, idea-driven environment that fosters a collaborative atmosphere for the Agency’s creative team.</p><p>Jeff has provided more than ten years of creative direction on major brands like Verizon, Suzuki, Disney, mlb.com, Discovery Channel, Visa, Apple, and Wells Fargo. In that time, he’s brought brands to life across a variety of media — from print and outdoor advertising to direct mail, and fully integrated online/offline campaigns. Jeff brings all of that to bear for Questus clients, leading his team with passionate, highly crafted creative work at the heart of the user’s interactive experience. </p><p>Previously, Jeff worked at Euro RSCG Worldwide, where he focused on brand hierarchy projects for eVisa, establishing the sub-brand and to-market materials for their innovative Visa Contactless technology, as well as the development of co-branded Verified by Visa marketing tools. Both of these projects were instrumental in furthering eVisa’s internal growth while supporting the overall Visa brand. </p><p>Jeff has a Bachelor of Fine Arts Degree in Printmaking and Digital Media from the San Francisco Art Institute.</p>'},
	{'name':'kris', 'position':[209, 313], 'size':'small', 'content':'<h1>Kris Rohman | Director of Project Management</h1><p>As Director of Project Management, Kris oversees the production and flow of deliverables with focus on project goals, budgets and timelines.</p><p>With nearly 10 years of project management experience, Kris has a proven track record of successfully managing digital initiatives. He has managed a variety of design and development projects for many clients, including Verizon, Disney, Suzuki, Revlon, Capital One and the Golden State Warriors.</p><p>Prior to joining Questus, Kris held positions as a project manager at Carat Fusion, and as a marketing manager at the Exploratorium. Kris holds an M.A. in Sport Management, and a B.A. in Communications.</p>'},
	{'name':'debbie', 'position':[414, 313], 'size':'small', 'content':'<h1>Debbie Tung | Sr. Account Director</h1><p>Debbie brings over eight years of experience in the marketing, advertising, and interactive media space. With her background in both project and account management, she continues to lead successful creative and media campaigns for clients within the consumer product, tech and financial service industries.</p><p>Since joining the Questus team, Debbie has led development efforts in web, community, mobile, video, 3D, live streaming and viral programs for brands such as Verizon, Disney, Expedia, Autodesk, Autograph Collection and salesforce.com.</p><p>Prior to Questus, Debbie worked at Carat Fusion where she managed Eastman Kodak’s media and creative campaigns in the US, Europe and Asia as Account Supervisor. In addition, she led digital brand and direct-response creative development for Progressive Direct.</p><p>Upon earning a BBA in Marketing from the University of Texas, Debbie traveled through Southern Africa and Europe as an international media consultant for print and televised media organizations.  She caught the travel bug, and is now always looking for that next exciting place to visit.</p>'},
	{'name':'will', 'position':[615, 313], 'size':'small', 'content':'<h1>Will Chamberlin | VP, Director of Technology</h1><p> Will bring over thirteen years of experience to Questus in areas such as enterprise development, design patterns and SOA in both .Net and Java. One of Will’s recently completed efforts includes architecting OncorMeterData.com, a meter data portal, and he is currently re-architecting SuzukiCycles.com for 2008. </p><p>Previously, Will was the development manager for 729 Solutions, a custom software shop that wrote business focused websites such as VentureDeal.com. </p><p>His earlier technical projects include the design and development of an electronic patient chart application for Philips Medical Systems’ patient monitoring systems group, the launch of eBidEnergy.com, development of a commercial shopping cart application for an upstate NY regional hardware chain, and processing terabytes of clickstream data for the internet market research site Compete.com. His experience also includes working for Lockheed Martin where he wrote a terrain database compiler and designed vehicle simulators.</p><p>A product of upstate New York, Will graduated from Syracuse University with a BS in Computer Science in 1995.</p>'},
	{'name':'scott', 'position':[829, 313], 'size':'small', 'content':'<h1>Scott Fiaschetti | Director of Insights</h1><p>As Director of Research for Questus, Scott truly believes that research is everywhere.  We do it every day, without even thinking about it.  It is in the conversations we have with friends, it is in what we subtly observe when we go shopping, and in the opinions we express and form online. Throughout his career, Scott has been inspired by finding ways to combine the best of traditional research techniques with what’s new and innovative. He enjoys the challenge of helping clients gain deeper insights into their consumers by translating findings into concise actionable recommendations – because without actionable results, research is just an academic exercise.</p><p>Scott brings a breadth of qualitative and quantitative research experience to Questus. He has worked with numerous brands from large Fortune 500 companies like Viacom, Citibank and PepsiCo to smaller well-known niche firms like Tumi, Cannondale and Stoneyfield Farm.  His experience working with these clients on brand positioning, new product development and product innovation allows him to leverage key insights from a variety of industries and help clients apply them in new ways to a quickly changing marketplace.</p><p>Scott holds an MBA from Syracuse University, and a B.S. in Engineering from Clarkson University.  He is also a Visiting Associate Professor of Management at the Pratt Institute in New York City since 2001.</p>'}	
]);

app.data.pressItems = new app.libs.dataStore({'key':'Title'});

/* models */
app.models.contentItem = app.libs.model.extend({
	init: function(){
		this._super();
		this.data = app.data.contentItems;
	},
	
	topItems: function(){
		return this.find(function(item){ return (!item.bottom); });
	}
});

app.models.person = app.libs.model.extend({
	init: function(){
		this._super();
		this.data = app.data.people;
	}
});

app.models.pressItem = app.libs.model.extend({
	init: function(){
		this._super();
		this.data = app.data.pressItems;
		this.sortByDate = function(a, b){
			var a = a.Date.split('/');
			var b = b.Date.split('/');
			if(a[2] !== b[2]){
				return parseInt(b[2], 10) - parseInt(a[2], 10);
			}else if(a[0] !== b[0]){
				return parseInt(b[0], 10) - parseInt(a[0], 10);
			}else{
				return parseInt(b[1], 10) - parseInt(a[1], 10);
			}
		}
	},
	
	findByCategory: function(category){
		if(category === 'all'){
			return this.find('all').sort(this.sortByDate);
		}else{
			return this.find({'Category':category}).sort(this.sortByDate);
		}
	},
	
	findAllCategories: function(){
		var categories = [];
		_.each(this.find('all'), function(item){
			if(categories.indexOf(item.Category) === -1){
				categories.push(item.Category);
			}
		});
		return categories;
	}
});
