
/*
	New Hampshire Charitable Foundation
	Custom Javascript Functions
*/

BBI = {};

BBI.Core = 
{
	BBNC:
	{
		_version: 1.1,
		_updated: '04/17/2008 10:07:07 AM',

		isV5: !!window.Sys,
		isV4: !!(window.BBProcMsg && !window.Sys),
		isEditView: !!window.location.href.match('edit='),
		hasPRM: !this.isV5
	}
};


BBI.NHCF =
{
	pageLoad: function()
	{
		var _o = BBI.NHCF;
		
		// Background
		$('body').css('background','#eaeabf none no-repeat 0 0');

		// Positioning fix
		if(BBI.Core.BBNC.isEditView){
			$('div[id *= "_panelPopup"]').appendTo('body');
			$('div[id *= "_designPaneCloak"]').css({"top": "0px","left": "0px"});
			$('.DesignPane').css("position", "relative");
			$('#wrapNav').css('position', 'relative');
		}
		
		// Font resizer
		_o.initFontSize();
		
		//Login Labels
		$('*[id *= "_cbRememberLogin"]').css('display','none');
		$('*[for *= "_cbRememberLogin"]').css('display','none');
		$('table.LoginFormTable').css('visibility','visible');
		
		//Setting the initial value of the search box on quick search
		$('input.QuickSearchTextbox').val('Search Site');
		// Clearing the initial value only the first time the box is clicked
		var QuickSearchBoxCount = 0;
		$('input.QuickSearchTextbox').click( function() {
			if (QuickSearchBoxCount==0) {
				$('input.QuickSearchTextbox').val('');
				QuickSearchBoxCount = 1;
			};
		});
	},
	
	fontSize: 100,
	
	initFontSize: function()
	{
		var _o = BBI.NHCF;
		if ($.cookie('bbncFontSize')) {
			_o.fontSize = parseInt($.cookie('bbncFontSize'));
		}
	
		// Set font size
		_o.setFontSize(_o.fontSize);
		
		// Bind increase font size
		$('#increaseFontSize').bind('click',function(){BBI.NHCF.setFontSize(_o.fontSize + 25);});
		
		// Bind decrease font size
		$('#decreaseFontSize').bind('click',function(){BBI.NHCF.setFontSize(_o.fontSize - 25);});
	},
	
	setFontSize: function(_s)
	{
		var _o = BBI.NHCF;

		// Out of bounds
		if (_s<100 || _s>150)
			return;

		_o.fontSize = _s;
		
		$.cookie('bbncFontSize',_o.fontSize);
		$('#cres_content').css({'font-size':_o.fontSize + '%','line-height':'normal'});
	},
	
	bbinit_initFlickrGallery: function(_in)
	{
		var _o = BBI.NHCF;
		var _msg = '';
		var _err = 0;
		
		// Default type
		if (!_in.type)
			_in.type = 'single';
		
		
		//Find errors (like a boss)
		if ((_in.type == 'single' || _in.type == 'inline') && !_in.photoSet)
		{
			_err = 1;
			_msg = 'No Flickr photoset defined.';
		}
		else if (_in.type == 'multiple' && !_in.setListingWrapper)
		{
			_err = 1;
			_msg = 'No Flickr listing wrapper element defined.';
		}
		else if (_in.type != 'single' && _in.type != 'inline' && _in.type != 'multiple' && _in.type != 'multipleInline' && _in.type != 'multipleSingle')
		{
			_err = 1;
			_msg = 'Unknown error.';
		}


		// Write banner
		if (BBI.Core.BBNC.isEditView)
			document.write('<h2>Flickr Integration: Initialize Gallery');
	

		// Write admin error banner (if needed?)
		if (_err && BBI.Core.BBNC.isEditView)
			document.write('<h2>ERROR: ' + _msg + '</h2>');


		// Kill if error exists
		if (_err)
			return;


		// Add to pageLoaded (MS Ajax library)
		Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function()
		{
			$('#contentPrimary').bbncFlickr(
			{
				// Variables
				max_galleries:		25, // Maximum number of galleries to list in sidebar
				api_key:			'2d5a606b72c94dd49eaad5962b5c43f1', // Flickr API key
				user_id:			'40059212@N08', // Flickr user id; get from http://idgettr.com
				cssPrefix:			'flickr', // Prefix to begin CSS IDs and classes with
				
				lightbox:
				{
					// Lightbox images
					imageBlank:			'view.image?id=502',
					imageBtnClose:		'view.image?id=503',
					imageBtnNext:		'view.image?id=504',
					imageBtnPrev:		'view.image?id=505',
					imageLoading:		'view.image?id=506',
					
					
					// Lightbox options
					// Reference: http://leandrovieira.com/projects/jquery/lightbox/
					overlayBgColor:			'#000',
					overlayOpacity:			0.8,
					fixedNavigation:		true,
								
					containerBorderSize:	10,
					containerResizeSpeed:	400,
								
					txtImage:				'Image',
					txtOf:					'of',
						
					keyToClose:				'c',
					keyToPrev:				'p',
					keyToNext:				'n'
				},
				
				// Don't touch!
				doAction:			_in.type + 'Set',
				photoSet:			_in.photoSet,
				setListingWrapper:	_in.setListingWrapper
			});
		});
	}
};

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};

// On page load
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(BBI.NHCF.pageLoad);

