SWFAddress.addEventListener(SWFAddressEvent.CHANGE, swfAddressSwap);

var sectionName= new Array;
sectionName[1] = "what-i-am-doing"
sectionName[2] = "latest-photos"
sectionName[3] = "about"
sectionName[4] = "contact";
sectionName[5] = "miscellany";

var sectionTitle= new Array;
sectionTitle[1] = "What I am Doing - dbox.us"
sectionTitle[2] = "Latest Photos - dbox.us"
sectionTitle[3] = "About - dbox.us"
sectionTitle[4] = "Contact - dbox.us";
sectionTitle[5] = "Miscellany - dbox.us";

$(document).ready(function() {  
	

	// instead of using Javascript: on the "onclick" tag
	$('.hotLink').click(function(){
		var spot = $('.hotLink').index(this);
		showContent(spot+1);
		return false;
	});
	// fix link focus
	if (document.getElementsByTagName) {
        var a = document.getElementsByTagName('a');
        for (var i = 0; i < a.length;  i++) {
        	a[i].onfocus = function(){this.blur()};
    	}
	}
	// Try to fix backgroundimagecache for IE6...
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {
	}  
	
	// Project Hover                                
	$('.project').live('mouseover', function() {
		$(this).addClass('active');					  
	});
	$('.project').live('mouseout',function(){				  
		$(this).removeClass('active');
	});

	// Project Linkout
	$('.project').live('click',function(){
	window.location = $(this).find('a').attr('href');
		return false; 
	});
	
});

function showContent(spot) {
	SWFAddress.setValue('/'+sectionName[spot]+'/');
	SWFAddress.setTitle(sectionTitle[spot]);
}

function moveContent(spot) {
	var targ = '#block'+spot;
	var thetarg = $(targ).css('display');
	if (thetarg == "block") {
		//closeContent(spot);
	}
	else {
		openContent(spot);
	}
}

function closeContent(spot) {
	var targ = '#block'+spot;
	$(targ).slideUp(300);
}

function openContent(spot) {
	var targ = '#block'+spot;
	$open = $('.activate:visible:not("'+targ+'")');
	if ($open.size() != 0) {
		$open.slideUp(300);
	}
	$(targ).slideDown(300);
}

function swfAddressSwap(event) {
	// replaces '/' from seo tags to '' ... RegEx is so 1337
	var location = event.value.replace(/\//g,'');
	// if no location open first tab by default (makes sure if you return to first history entry with no /#/ it still opens right tab
	if(location == '') {
		openContent(1);
		SWFAddress.setTitle('dbox.us - The personal webpage of Daniel Box');
	}
	// cycles through sections looking for matching name and returns array index {1,2,3,4}
	else {
		var index = 0;
		for (x in sectionName) {
			if(sectionName[x] == location) {
				var spot = x;
			}
		}
	}
	if(typeof spot != 'undefined') {
		SWFAddress.setTitle(sectionTitle[spot]);
		moveContent(spot);
	}
}  



/* legacy code */
function showProjectContent (targ) {
	var activeProjectDiv ="#project1";
	$(activeProjectDiv).toggle();
	activeProjectDiv = targ;
	$(activeProjectDiv).toggle();
}
function showContactContent (targ) {
	if(targ == '#contact2')
		var activeContactDiv ="#contact1";
	if(targ == '#contact1')
		var activeContactDiv ="#contact2";
	$(activeContactDiv).hide();
	$(targ).show();
}
function projectSlide(num){
	$("#project-wrapper").animate({
	  left: num
	}, 400);
}
function linkActivate(targ) {
var link = '#'+targ;
$(link).addClass('linkVisted');
$(link).siblings().removeClass('linkVisted');
}   


