$(document).ready(function() {

//$(function() {		$( "#contentText" ).tooltip();	});
// stylesheet switching
	$("#ssSwitch a").click(function() { 	
		$('body').append('<div id="overlay" />');
		$('body').css({height:'100%'});
		$('#overlay')
			.css({
				display: 'none',
				position: 'absolute',
				top:0,
				left: 0,
				width: '100%',
				height: '100%',
				zIndex: 1000,
				background: '#e8e8e8 url("img/elements/loader.gif") no-repeat center'
			})
			.fadeIn(500,function(){
					$('#stylesheet').attr("href",$(this).attr('rel'));
						$('#overlay').fadeOut(500,function(){
							$(this).remove();
				});
			});
	
	$("link").attr("href",$(this).attr('rel'));
	 $('head').append('<link rel="stylesheet" href="css/swadeStylesPrint.css" type="text/css" media="print" />');
		return false;
	});



// control of content loads

jQuery.get('main.txt', function (response) {
    $('#contentText').html(response);
    $('#contentText').fadeIn(300); // ? whatever
});
// menu control of content loads
$("#lselect li a").each(function(){ // Where the function must work on
var href = $(this).attr("href");
$(this).click(function(){


$("#contentText").hide().load(href).fadeIn("slow"); //A Nice Fadein Effect
$(this).attr({ href: "#"}); //#show is the Div who loads the content
});
});

// skip nav links  controls
	$("#showSkip").click(function(){
		$("#skipLinks").attr("class", "visible");
		});
// accessibility info array handling 
var acc_array = Array(); // iterate through all links and find those with accessibility features
	$('#swadeworx a').each(function() {
		if($(this).attr('accesskey') != null){
		// push to my array
		acc_array.push("</td></tr><tr><td class='accDesc'>" + $(this).attr('title')+"</td><td class='accKey'>" + $(this).attr('accesskey') +"</td><td class='accTabIn'>" +$(this).attr('tabindex'));

				}
	});
		var $dialog = $('<div></div>') // dynamic dialog
			.html("<table><tr><th>Description</th><th>Key</th><th>Tab Index</th></tr>" + acc_array + "</table>")
			.dialog({
				autoOpen: false,
				width:'auto',
				id : 'assistDialog',
				title: 'Assistive Information'
			});

		$('.accessKeyLink').click(function() { // call on click of two links with class of accessKeyLink, top of page and in footer
 			$dialog.dialog('open');
			return false; // prevent link follow
		});


//gallery from galleriffic-2.0 - modified here and in the supporting script to accomodate the needs of swadeworx.com

				// We only want these styles applied when javascript is enabled
				$('div.content').css('display', 'block');
// $("#contentText").load("portfolio.txt")
				// 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({

					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 screenshots index display
						this.$captionContainer.find('div.screenshots')
							.html('Screenshot '+ (nextIndex+1) +' of '+ this.data.length);
					},
					onPageTransitionOut:       function(callback) {
						this.fadeTo('fast', 0.0, callback);
					},
					onPageTransitionIn:        function() {
						var prevPageLink = this.find('a.prev').css('visibility', 'hidden');
						var nextPageLink = this.find('a.next').css('visibility', 'hidden');
						
						// Show appropriate next / prev page links
						if (this.displayedPage > 0)
							prevPageLink.css('visibility', 'visible');

						var lastPage = this.getNumPages() - 1;
						if (this.displayedPage < lastPage)
							nextPageLink.css('visibility', 'visible');

						this.fadeTo('fast', 1.0);
					}
				});

				/**************** 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;
				});
				


// jquery onload end
});



function doMenu(){
var menuTxt = '<div id="menuList"><div id="menuList2"><div id="lselect"><h3 class="select"><span>explore</span></h3><ul>' +
'<li class="active"><a id="indexLink" href="main.txt" url="http://www.swadeworx.com/index.html" title="View Overview" accesskey="i" tabindex="10">main</a></li>' +
'<li><a id="resLink" href="resume.txt" url="http://www.swadeworx.com/resume.html" title="View Resume" accesskey="r" tabindex="11">resume</a></li>' +
'<li><a id="portLink" href="portfolio.txt" url="http://www.swadeworx.com/portfolio.html" title="View Portfolio" accesskey="p" tabindex="12">portfolio</a></li>' +
'<li><a id="skillsLink" href="skills.txt" url="http://www.swadeworx.com/skills.html" title="View Skills" accesskey="s" tabindex="13">skills</a></li>' +
'<li><a id="rolesLink" href="roles.txt" url="http://www.swadeworx.com/roles.html" title="View Roles" accesskey="l" tabindex="14">roles</a></li>' +
'<li><a id="othLink" href="versions.txt" url="http://www.swadeworx.com/versions.html" title="Other Versions" accesskey="v" tabindex="15">other versions</a></li>' +
'<li><a id="contactLink" href="contact.txt" url="http://www.swadeworx.com/contact.html" title="Contact Me" accesskey="c"  tabindex="16">contact me</a></li>' +
'<li><a id="faqLink" href="siteInfo.txt" url="http://www.swadeworx.com/siteInfo.html" title="Site Info" accesskey="q" tabindex="19">site info</a></li></ul></div></div></div>';
document.write(menuTxt);	
}
