var videoID = '';
var popUpDiv = null;
var bgDiv;
var boxDiv;
var closeDiv;
function ShowPopUp (vidID) {
	videoID = vidID;
	
	
	
	if (popUpDiv == null) {
		popUpDiv = document.createElement('div');
		popUpDiv.setAttribute('id','PopUp');	
	

		bgDiv = document.createElement('div');
		bgDiv.setAttribute('id','PopUpBG');	
		bgDiv.onclick = HidePopUp;
		popUpDiv.appendChild(bgDiv);
	
		boxDiv = document.createElement('div');
		boxDiv.setAttribute('id','PopUpBox');
		popUpDiv.appendChild(boxDiv);
		
		closeDiv = document.createElement('div');
		closeDiv.className = 'close';
		closeDiv.innerHTML = '<a href="#" onClick="HandleClose();"><span>close</span></a>';
		
		
	}
	
	document.body.appendChild(popUpDiv);
	
	boxDiv.innerHTML = '<iframe src="http://player.vimeo.com/video/' + videoID + '?title=0&amp;byline=0&amp;portrait=0" width="640" height="360" frameborder="0"></iframe>';
	
	boxDiv.appendChild(closeDiv);
}

function HidePopUp () {
	videoID = '';
	boxDiv.innerHTML = '';
	document.body.removeChild(popUpDiv);
}

function HandleClick (e) {	
 	
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
	{
		return true;
	}

	//var vidID = this.href.split('/').pop();
	var vidID = this.getAttribute('rev');
	ShowPopUp(vidID);
	return false;
}

function HandleClose (e) {
	HidePopUp();
	return false;
}


function SetupPopUp () {	

	var links = document.getElementsByTagName('a');//.concat(document.getElementsByTagName('area'));
	
    for(var i = 0; i < links.length; i++){
        var rel = links[i].getAttribute('rel');
		
        if (rel == 'PopUp') {
			links[i].onclick = HandleClick;
		}
	}
	
	
	var areas = document.getElementsByTagName('area');
	
	for(var i = 0; i < areas.length; i++){
        var rel = areas[i].getAttribute('rel');
		
        if (rel == 'PopUp') {
			areas[i].onclick = HandleClick;
		}
	}
	
	
}
