$(document).ready(function(){
	
	initMenu();
	sortOutScrollWrap();
	initGallery();
	SwapImage.rollover.init();
	sortOutLinks();
});

/***** Menu ****************************************************************************************/

function initMenu(){
	
	cPageURL = window.location.pathname.split('/', 2)[1];
	if(cPageURL != '')
	{
		cPageURL = cPageURL + '/'
	}
	//window.console.log(cPageURL)
	$('div#nav').flash(
	{
		src: '/assets/site/swf/menu.swf',
		width: 200,
		height: 200,
		scale: 'noscale',
		menu: 'false',
		wmode: 'transparent',
		flashvars: {
			cPageURL: cPageURL
		}
	})
	
}

/***** ScrollWrap ****************************************************************************************/

function sortOutScrollWrap(){
	
	if($('#scrollWrap').get(0).scrollHeight == $('#scrollWrap').get(0).clientHeight)
	{
		$('.scrollSurround img').hide();
		var border = "1px solid #FFFFFF";
		$('.scrollSurround.top').css('border-top', border);
		$('.scrollSurround.bottom').css('border-bottom', border);
		$('#scrollWrap').width(480)
	}
}

/***** ImageRollovers ****************************************************************************************/

SwapImage = {};

SwapImage.rollover =
{
   init: function()
   {
      this.preload();
      
      $("#main a img").hover(
         function () { $(this).attr( 'src', SwapImage.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', SwapImage.rollover.oldimage($(this).attr('src')) ); }
      );
   },
   
   preload: function()
   {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', SwapImage.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src ) { return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_over' + src.match(/(\.[a-z]+)/)[0]; },
   oldimage: function( src ){ return src.replace(/_over/, ''); }
};

/***** Gallery ****************************************************************************************/

function initGallery(){

	$('.gallery a').mouseover(function(){$(this).addClass('over')})
	.mouseout(function(){$(this).removeClass('over')})
	
	var lineLengths = [6, 4, 2, 4, 2, 1, 5, 3, 4, 1];
	var cLineLength = 0;
	var cLineLengthIndex = 0;
	
	$('.gallery a').each(function()
	{
		cLineLength ++;
		if(cLineLength > lineLengths[cLineLengthIndex])
		{
			$(this).addClass('newLine');
			cLineLengthIndex ++;
			cLineLength = 0;
		}
	})
		
	$('.gallery a').lightBox({
		imageLoading: '/assets/library/images/jquery_lightbox/loading.gif',
		imageBtnPrev:			'/assets/library/images/jquery_lightbox/btn-prev.gif',
		imageBtnNext:			'/assets/library/images/jquery_lightbox/btn-next.gif',
		imageBtnClose:			'/assets/library/images/jquery_lightbox/btn-close.gif',
		imageBlank:				'/assets/library/images/blank.gif',
		containerBorderSize:	10,		
		containerResizeSpeed:	400,
		txtImage:				'Image',
		txtOf:					'of',
		keyToClose:				'down',
		keyToPrev:				'left',
		keyToNext:				'right'
	});
}

/***** Links ****************************************************************************************/

function sortOutLinks()
{
    /* make any links in body text links open in a new window */
    
    $('#main a').attr('target', '_blank')
}

/***** SIFF ****************************************************************************************/

	/*
	 sifr 3 example:
	var vagRoundedBold = { src: '/assets/site/swf/vag_rounded_bold.swf' };

	sIFR.activate(vagRoundedBold);
	
	sIFR.replace(vagRoundedBold, {
	  selector: '#nav li',
	  css: '.sIFR-root { color: #FFDE00; leading: 50} .sIFR-root a { color: #FFFFFF; text-decoration: none} .sIFR-root a:hover { color: #FFB300; text-decoration: none}',
	  wmode: 'transparent'
	});
	*/
	
	/*jQuery.fn.extend(
	{
		flashGallery: function()
		{
			return this.each(function()
			{	
				//var attrs = $.getAttributes($(this));
				//for(var attr in attrs){
				//	window.console.log('flashGallery(): '+attr + ' = '+ attrs[attr])
				//};
				$(this).flash(
				{
					swf: '/assets/site/swf/tabernacle_nav.swf',
					width: 400,
					height: 400,
					params: {
						scale: 'noscale',
						menu: 'false'
					},
					flashVars: $.getAttributes($(this))
				});
				return $(this)
			});
		}
	});
	
	
	$('.flashGallery').flashGallery();*/
