
var IDEOSelects = {
		init: function()
		{
			this.panels = new Array('whoisideo');
			this.selected_lens = "";
			
			$('#whoisideo').click(IDEOSelects.lenses.whoisideo.reveal);
			
			$('#whoisideo_collapse').click(IDEOSelects.lenses.whoisideo.collapse);
			
			
			
		},
		lenses: {
			inspiration: {
				reveal: function()
				{
					IDEOSelects.show_panel('inspiration');
				},
				collapse: function()
				{
					IDEOSelects.hide_panel('inspiration');
					IDEOSelects.hide_panel('empathy');
					IDEOSelects.hide_panel('intuition');
				}
			},
			empathy: {
				reveal: function()
				{
					IDEOSelects.show_panel('inspiration');
					IDEOSelects.show_panel('empathy');
				},
				collapse: function()
				{
					IDEOSelects.hide_panel('empathy');
					IDEOSelects.hide_panel('intuition');
				}
			},
			intuition: {
				reveal: function()
				{
					IDEOSelects.show_panel('inspiration');
					IDEOSelects.show_panel('empathy');
					IDEOSelects.show_panel('intuition');
				},
				collapse: function()
				{
					IDEOSelects.hide_panel('intuition');
				}
			},
			whoisideo: {
				reveal: function()
				{
					IDEOSelects.show_panel('whoisideo');
				},
				collapse: function()
				{
					IDEOSelects.hide_panel('whoisideo');
				}
			}
		},
		show_panel: function(panel){
			for(var i=0; i<this.panels.length; i++){
				e = this.panels[i];
				if (e == panel){
					$("#panel_"+e+":hidden").fadeIn("slow");
				} else {
					//$("#panel_"+e+":visible").fadeOut(0);
				}
			}
			
			
		},
		hide_panel: function(panel) {
			$("#panel_"+panel+":visible").animate(
				{ opacity: 'hide' },
				500);
		},
		hide_panels: function(){
			for(var i=0; i<this.panels.length; i++){
				e = this.panels[i];
				$("#panel_"+e).animate(
						{ opacity: 'hide' },
						500);
			}
		}
}

jQuery(document).ready(function() {
	IDEOSelects.init();
});


/**
 * Lens Panels 
 */
 
$(document).ready(function() {
	$('#lenses > div.panel').click(function(){
		if ($(this).width() == 45){
			//Panel is not extended
			$(this).addClass("selected");
			var w = $('img',this).width();
			$(this).animate({ width: w },"slow");
			for (var i = this.previousSibling; i; i = i.previousSibling){
				if ( i.nodeType != 1 ) continue;
				$(i).animate({ width: w },"slow");
			}
		} else {
			//Panel is extended
			/** 
			 * Check if there are other extended panels to our right. If so, we need
			 * to hide those, and show this one. Otherwise, hide this one and all next siblings.
			 */
			var siblings_stack = new Array();
			for( var i = this.nextSibling; i; i = i.nextSibling ) {
				if ( i.nodeType != 1 ) continue;
				if ($(i).width() > 45){
					siblings_stack.push(i);
				}
			}
			if (siblings_stack.length > 0){
				$.each(siblings_stack,function(i,n){
					$(n).animate({ width: 45 },"slow");
					});
			} else {
				$(this).removeClass("selected");
				var w = 45;
				$(this).animate({ width: w },"slow");
				for( var i = this.nextSibling; i; i = i.nextSibling ) {
					 if ( i.nodeType != 1 ) continue;
					 $(i).animate({ width: w },"slow");
				}
			}
		}
		});
	});

