/**
 * Default Fancybox parameters
 */
var defaultFancyboxParams = {
	'opacity': false,
	'overlayShow': true,
	'transitionIn'	: 'none',
	'transitionOut': 'none',
	'overlayColor': '#000',
	'centerOnScroll': true,
	'padding': 0,
	'margin': 0,
	'autoDimensions': false,
	'autoScale': false,
	'width'	: 500,
	'height': 300,
	'scrolling': false
};

/**
 * Checks video box container id and hash of href
 * @param name id of video box container
 * @returns string
 */
function checkHrefHash(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regex = new RegExp("[\\#]"+name+"([^&#]*)");
	return regex.exec(window.location.href);
}

function videoPopup(el){
	var a = $(el);
	a.click(function(e){
		e.preventDefault();
		var params = {
			watch: a.attr('data-tkn-watch'),
			m4v: a.attr('data-tkn-m4v'),
			webm: a.attr('data-tkn-webm'),
			poster: a.attr('data-tkn-poster'),
			rewind: true,
			width: a.attr('data-tkn-width'),
			height: a.attr('data-tkn-height'),
			onEnd: function(){ if(iosmode()){ $.fancybox.close(); } },
			afterPoster: a.attr('data-tkn-after-poster'),
			autoActivateKeyControl: false
		};
		var currentFancyboxParams;
		currentFancyboxParams = defaultFancyboxParams;
		currentFancyboxParams.width = params.width;
		currentFancyboxParams.height = params.height;
		$.fancybox('<div id="video-popup"></div>', currentFancyboxParams);
		var player = new uberPlayer('video-popup', params);
	});
	if(checkHrefHash(a.attr('href').substring(1))){
		a.trigger('click');
	}
}
