// JavaScript Document

// Suckerfish JavaScript
sfHover = function() {
	var sfEls = document.getElementById('nav').getElementsByTagName('LI');
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=' sfhover';
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(' sfhover\\b'), '');
		}
	}
}
if (window.attachEvent) window.attachEvent('onload', sfHover);

// Custom functions for the home page image cycler
function onBefore() { 
    var newCopy = $(this).attr('title');
	$('div#home-copy p').empty().append(newCopy);
}

function pagerClick() {
	$('div#feature-slideshow').cycle('pause');	
}

$(document).ready(function () {

// Add dots behind most footer links
$('a.footer-link').not('a.last-link').after(' &bull;');

// Home page image cycle
$('div#feature-slideshow').cycle({
	activePagerClass	:	'current',
	fx					:	'fade',
	speed				:	800,
	timeout				:	7000,
	pager				:	'#feature-nav',
	before				:	onBefore,
	onPagerEvent		:	pagerClick
});

// Home page feature navigation tweak
// $("ul#feature-nav li:first-child a").addClass("current");

// Home page feature image navigation functionality
//$("ul#feature-nav li a").click(function() {
//	$('div#feature-slideshow').cycle(1);
//	var newCopy = $(this).find("span").html();
//	$("a.current").removeClass("current");
//	$(this).addClass("current");
//	$("div#feature-slideshow").find("img").animate({opacity:0},400,function() {
//		$("div#feature-slideshow").find("img").attr("src",newImage).animate({opacity:1},400);
//	});
//	$("div#home-copy").find("p").empty().append(newCopy);
//	return false;
//});

// About page image swap
$('a.image-swap').click(function() {
	var bgImagePath = $(this).attr('href');
	var bgImage = 'url(' + bgImagePath + ')';
	$('div#image-frame').css('background-image', bgImage);
	return false
});

// custom scrollbars
$('section#project-gallery').jScrollPane({
	'showArrows'	:	true
});

// convert all <audio> and labeled <video> tags
$('video.convert, audio').mediaelementplayer({
	features	:	['playpause','progress','volume','fullscreen']
});

// hide player-wrap
$('div#player-wrap').css('visibility','hidden');

// create player for later
var player = new MediaElementPlayer('#project-player',{features: ['playpause', 'progress', 'current', 'duration', 'volume', 'fullscreen']});
player.pause();
player.setSrc('http://www.altny.com/assets/video/blank.mp4');
$('div#player-wrap, div[class^=mejs-]').css('visibility','hidden');

// portfolio image/video swap
$('div.gallery-thumb a.gallery-swap').click(function() {
	var newDesc = $(this).attr('title');
	var newSource = $(this).attr('href');
	if ($(this).attr('rel') == 'image') {
		var newImage = 'url(' + newSource + ')';
		$('div#player-wrap, div[class^=mejs-]').css('visibility','hidden');
		$('section#project-image').css('background-image',newImage);
		$('section#project-image p').text(newDesc);
	} else if ($(this).attr('rel') == 'video') {
		$('section#project-image').css('background-image','none');
		// video handling
		$('div#player-wrap, div[class^=mejs-]').css('visibility','visible');
		player.pause();
		player.setSrc(newSource);
		player.play();
		$('section#project-image p').text(newDesc);
	}
	return false;
});

});
