/*
Dancefoundation's YouTube player embed
WordPress Plugin by Dancefoundation, http://www.dancefoundation.com
*/

//check for ie
ie = false;
if (document.all) {
	var ie = true;
}

//a function to choose another youtube-video without reloading the page
function dfYoutubePlaylist_cy(ytSrc,containerId,type) {
	if (type == null || type == '') {
		type = 'v';
	}
	document.getElementById(containerId).innerHTML = eval("dfYoutubePlaylist_cf('',ytSrc,900,525,type)");
	
	var so = new SWFObject('/wp-content/themes/dancefoundation-v3-theme/swf/player.swf','mpl','900','525','9');
		  so.addParam('allowfullscreen','true');
		  so.addParam('allowscriptaccess','always');
		  so.addParam('wmode','opaque');
		  so.addVariable('file','http://www.youtube.com/watch?v='+ ytSrc +'');
		  so.addVariable('image','http://img.youtube.com/vi/'+ ytSrc +'/0.jpg');
		  so.addVariable('controlbar','over');
		  so.addVariable('dock','false');
		  so.addVariable('icons','false');
		  so.write('mediaspace');
}

//a function to load flashmovies. it also prevents ie from adding the ugly border
function dfYoutubePlaylist_cf(FlashVars,movie,width,height,type) {
	dfYoutubePlaylist_cfStr = '<div id="mediaspace"><obj' + 'ect width="' + width + '" height="' + height + '" data="' + 'http://www.youtube.com/'+ type +'/'+ movie +'&rel=0&hl=en&fs=1&hd=1&iv_load_policy=3&showinfo=0&showsearch=0' + '" type="application/x-shockwave-flash">';
	dfYoutubePlaylist_cfStr += '<param name="movie" value="http://www.youtube.com/'+ type +'/'+ movie +'&rel=0&hl=en&fs=1&hd=1&iv_load_policy=3&showinfo=0&showsearch=0"/>';
	dfYoutubePlaylist_cfStr += '<param name="allowFullScreen" value="true"/>';
	dfYoutubePlaylist_cfStr += '<param name="allowscriptaccess" value="always"/>';
	//dfYoutubePlaylist_cfStr += '<param name="FlashVars" value="'+ FlashVars +'">';
	dfYoutubePlaylist_cfStr += '<embed src="http://www.youtube.com/'+ type +'/'+ movie +'&rel=0&hl=en&fs=1&hd=1&iv_load_policy=3&showinfo=0&showsearch=0" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" allowscriptaccess="always" allowfullscreen="true"/>';
	dfYoutubePlaylist_cfStr += '<' + '/object></div>';
		
	return dfYoutubePlaylist_cfStr;
	
}

//a function to load all movies with thumbs to a list
function dfYoutubePlaylist_dl(allVideos,containerId,targetContainerId) {
	allVideosArr = allVideos.split(', ');
	if (allVideosArr.length > 1) {
		allVideosLi = '<ul class="dfYoutubePlaylist_Ul" >';	
		for (var i=0; i < allVideosArr.length; i++) {
			thisLink = 'javascript:dfYoutubePlaylist_cy(\''+allVideosArr[i]+'\',\''+targetContainerId+'\');'
			allVideosLi += '<li>' + '<a href="'+thisLink+'">' + '<img class="dfYoutubePlaylist_Img"  alt="" src="http://img.youtube.com/vi/'+allVideosArr[i]+'/0.jpg" width="100" height="75" />' + '</'+'a></'+'li>';
		}
		allVideosLi += '</ul>';
		document.getElementById(containerId).innerHTML = allVideosLi;
	} else {
		document.getElementById(containerId).style.display = 'none';
	}
}