var utils = 
{
	check_location : function()
	{
		var address = window.location.toString().slice(7); // get rid of the "http://"
		var currentLoc = address.slice(address.indexOf("/",0)+1); // search for the address after the ".com/"
				
		switch (currentLoc)
		{
			case 'faq.php':
				toggle_view.init();
				break;
			case 'tour-de-bulb.php':
			case 'news.php':
				$.getScript('http://newideassc.com/js/shadowbox.js', utils.load_shadowbox);
				break;
			default: 
				break;
		}
	},
	
	load_shadowbox : function()
	{
		var options =
		{
			displayNav		: true,
			displayCounter	: true,
			viewportPadding : 0,
			hadnleLgImages	: "resize",
			loadingImage	: "/img/loading.gif",
			overlayBgImage	: "/img/overlay-85.png"
		}
		
		Shadowbox.init(options);
	}	
};

var toggle_view = 
{
	init : function()
	{
		$('h3', '.toggle-view').wrapInner("<a href='' class='t-link'></a>").css({ margin:".5em 0 0 0"});
		$('.toggle').hide();
		this.set_nav();
		this.add_view_all();
	},
	
	add_view_all : function()
	{
		$('.toggle-view').prepend("<a id='view-all' href=''>view all</a>");
		$('#view-all').click().toggle(
			function(e){
				e.preventDefault();
				$('.active', '.toggle-view').removeClass('active');
				$('.toggle').slideDown('fast');
				$('.t-link')
					.addClass('active')
					.unbind('click')
					.bind('click', function(e){e.preventDefault();});
				$(this).text("collapse all");
			},
			function(e){
				e.preventDefault();
				$('.active', '.toggle-view').unbind('click').removeClass('active');				
				$('.toggle').slideUp('fast');
				$(this).text("view all");
				toggle_view.set_nav();
			}
		);
	},
	
	set_nav : function()
	{
		$('.t-link').click(function(e){
			e.preventDefault();
			$('a.active', '.toggle-view').removeClass('active');
			$('.active', '.toggle-view').slideUp('fast').removeClass('active');
			$(this).parent().next().slideDown('fast').addClass('active');
			$(this).addClass('active');
		});
	}
};

utils.check_location();	
