$(function() {
	$('ul.nav a').bind('click',navigatePage);
	$('.team a').bind('click',navigatePage);
	$('a.backtoteam').bind('click',navigatePage);
});

function navigatePage(event){
	var $anchor = $(this);
	var $ahref = $anchor.attr('href');
	$returnstring = $ahref.slice(1,2).toUpperCase()+$ahref.slice(2,$ahref.length);
	if($returnstring.slice(0,11)=="Showandtell"){
		$returnstring = "Show & Tell: "+$returnstring.slice(11,12).toUpperCase()+$returnstring.slice(12,$returnstring.length);
	}
	
	document.title = "Onesum Agency | "+$returnstring;
	
	$('html, body').stop().animate({
		scrollTop: $($anchor.attr('href')).offset().top
	}, 1000,'easeInOutExpo',completed);
	
	function completed(){
		window.location.hash = String($ahref.slice(1,$ahref.length));
	}
	event.preventDefault();
	pauseJSVideos();
}

//var flashVideos = new Array("osa_demoreel","osa_bodogheroreel","osa_ikeafamilyman");
var flashVideos = new Array();
var jsVideos = new Array();

function embedVideo(videofile,videoid){
	var flashvars = { theVideo:videofile };
	var params = { allowScriptAccess:"always" };
	var attributes = { id:videoid, name:videoid };
	swfobject.embedSWF("vid/osa_videoplayer.swf", videoid, "640", "420", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
	flashVideos.push(videoid);
}

function pauseFlash() {
	for(var i = 0; i<flashVideos.length; i++){
		var obj = document.getElementById(flashVideos[i]);
		obj.pauseVideo();
	}
}

function pauseJSVideos(){
	//alert("js videos paused");
	for(var i = 0; i<jsVideos.length; i++){
		var obj = document.getElementById(jsVideos[i]);
		obj.pause();
	}
}

function writeJSVideo(videoName){
	jsVideos.push(videoName);
	var videoObject='<div class="video-js-box vim-css">\r<video id="'+videoName+'" class="video-js" width="640" height="360" controls="controls" preload="auto" poster="vid/'+videoName+'.jpg">\r<source src="vid/'+videoName+'.mp4" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\' />\r<object id="'+videoName+'Fallback" class="vjs-flash-fallback" width="640" height="360" type="application/x-shockwave-flash" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf">\r<param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" />\r<param name="allowfullscreen" value="true" />\r<param name="flashvars" value=\'config={"playlist":["http://onesum.ca/vid/'+videoName+'.jpg", {"url": "http://onesum.ca/vid/'+videoName+'.mp4","autoPlay":false,"autoBuffering":true}]}\' />\r<img src="vid/'+videoName+'.jpg" width="640" height="264" alt="Poster Image" title="No video playback capabilities." />\r</object>\r</video>\r<p class="vjs-no-video"><strong>Download Video:</strong>\r<a href="vid/'+videoName+'.mp4">MP4</a>\r</p>\r</div>'
	document.write(videoObject);
}
