﻿function pageLoad()
{
	$("a.zoom").fancybox
	({
		'autoDimensions': true,
		'autoScale': true
	});

	$("a.htmlzoom").fancybox
	({
		'width': 1000,
		'height': 580,
		'type': 'iframe',
		'hideOnOverlayClick': true,
		'hideOnContentClick': true
		
	});

	if (document.getElementById('images'))
	{
		document.getElementById('images').style.visibility = 'visible';
		document.getElementById('pleasewait').style.display = 'none';
	}
	if (document.URL.indexOf('Scripts.aspx', 0) == -1)
	{
		tinyMCE.init({
			// General options
			mode: "textareas",
			theme: "advanced",
			plugins: "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",

			// Theme options
			theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
			theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
			theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
			theme_advanced_toolbar_location: "top",
			theme_advanced_toolbar_align: "left",
			theme_advanced_statusbar_location: "bottom",
			theme_advanced_resizing: true,

			// Example word content CSS (should be your site CSS) this one removes paragraph margins
			content_css: "css/word.css",

			// Drop lists for link/image/media/template dialogs
			template_external_list_url: "lists/template_list.js",
			external_link_list_url: "lists/link_list.js",
			external_image_list_url: "lists/image_list.js",
			media_external_list_url: "lists/media_list.js",

			// Replace values for the template plugin
			template_replace_values: {
				username: "Some User",
				staffid: "991234"
			}
		});
	}


	//-- GALLERIFFIC
	if ($('#thumbs').length>0)
	{
		// We only want these styles applied when javascript is enabled
		$('div.content').css('display', 'block');



		// Initially set opacity on thumbs and add
		// additional styling for hover effect on thumbs
		var onMouseOutOpacity = 0.67;
		$('#thumbs ul.thumbs li, div.navigation a.pageLink').opacityrollover({
			mouseOutOpacity: onMouseOutOpacity,
			mouseOverOpacity: 1.0,
			fadeSpeed: 'fast',
			exemptionSelector: '.selected'
		});

		// Initialize Advanced Galleriffic Gallery
		var gallery = $('#thumbs').galleriffic({
			delay: 3000,
			numThumbs: 6,
			preloadAhead: 3,
			enableTopPager: false,
			enableBottomPager: true,
			maxPagesToShow: 1,
			imageContainerSel: '#slideshow',
			controlsContainerSel: '#controls',
			captionContainerSel: '#caption',
			loadingContainerSel: '#loading',
			renderSSControls: true,
			renderNavControls: true,
			playLinkText: 'Play Slideshow',
			pauseLinkText: 'Pause Slideshow',
			prevLinkText: '&lsaquo; Previous Photo',
			nextLinkText: 'Next Photo &rsaquo;',
			nextPageLinkText: '<img src="/images/arrow-right.png" border="0" />',
			prevPageLinkText: '<img src="/images/arrow-left.png" border="0" />',
			enableHistory: true,
			autoStart: false,
			syncTransitions: true,
			defaultTransitionDuration: 900,
			onSlideChange: function(prevIndex, nextIndex)
			{
				// 'this' refers to the gallery, which is an extension of $('#thumbs')
				this.find('ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('fast', 1.0);

				// Update the photo index display
				$('div.photo-index')
							.html('Image ' + (nextIndex + 1) + ' of ' + this.data.length);
			},
			onPageTransitionOut: function(callback)
			{
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn: function()
			{
				var prevPageLink = this.find('a.prev').css('display', 'none');
				var nextPageLink = this.find('a.next').css('display', 'none');

				// Show appropriate next / prev page links
				if (this.displayedPage > 0)
					prevPageLink.css('display', '');

				var lastPage = this.getNumPages() - 1;
				if (this.displayedPage < lastPage)
					nextPageLink.css('display', '');

				this.fadeTo('fast', 1.0);
			}

		});

		//-- Get filename
		var url = document.URL;
		var lastSlash = url.lastIndexOf("/");
		var firstQuestionMark = url.indexOf("?");
		if (firstQuestionMark == -1) firstQuestionMark = url.length;
		var fileName = url.substring(lastSlash + 1, firstQuestionMark);

		//-- only apply slideshow is it is the home page.
		if (fileName.toLowerCase() == 'default.aspx' || fileName == '') gallery.play();

		/**************** Event handlers for custom next / prev page links **********************/

		gallery.find('a.prev').click(function(e)
		{
			gallery.previousPage();
			e.preventDefault();
		});

		gallery.find('a.next').click(function(e)
		{
			gallery.nextPage();
			e.preventDefault();
		});

		/****************************************************************************************/

		/**** Functions to support integration of galleriffic with the jquery.history plugin ****/

		// PageLoad function
		// This function is called when:
		// 1. after calling $.historyInit();
		// 2. after calling $.historyLoad();
		// 3. after pushing "Go Back" button of a browser
		function pageload(hash)
		{
			// alert("pageload: " + hash);
			// hash doesn't contain the first # character.
			if (hash)
			{
				$.galleriffic.gotoImage(hash);
			} else
			{
				gallery.gotoIndex(0);
			}
		}

		// Initialize history plugin.
		// The callback is called at once by present location.hash. 
		$.historyInit(pageload, "advanced.html");

		// set onlick event for buttons using the jQuery 1.3 live method
		$("a[rel='history']").live('click', function(e)
		{
			if (e.button != 0) return true;

			var hash = this.href;
			hash = hash.replace(/^.*#/, '');

			// moves to a new page. 
			// pageload is called at once. 
			// hash don't contain "#", "?"
			$.historyLoad(hash);

			return false;
		});
	}
}
