function isAppleDevice() {
	return (/iPhone|iPod|iPad/i).test(navigator.userAgent);
}
function popUpWindow(url, width, height, left, top) {
	window.open(url, "popUp", "width=" + width + ", height=" + height + ", left=" + left + ", top=" + top + ", location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no");
}
function centeredPopUpWindow(url, width, height) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	popUpWindow(url, width, height, left, top);
}
function createVideoLink(theLink, mobileVideoPath, videoPagePath, videoPageWidth, videoPageHeight) {
	if( isAppleDevice() ) {
		theLink.click(function() {
			$(this).attr("href", mobileVideoPath);
			$(this).attr("target", "_blank");
		});
	} else {
		theLink.click(function() {
			centeredPopUpWindow(videoPagePath, videoPageWidth, videoPageHeight);
		});
	}
}

// Brightcove video player in Fancybox modal window
function playBrightCoveVideo(videoID, width, height, playerID, playerKey) {
	playerID = (typeof playerID == "undefined") ? '1197837031001' : playerID;
	playerKey = (typeof playerKey == "undefined") ? 'AQ~~,AAABFqPzsMk~,rOBoq7_7Mzksl4IbRxQ-OQkUykWzCMf0' : playerKey;
	
	var fbContent = $('\
		<object id="brightcoveExperience" class="BrightcoveExperience"> \
			<param name="bgcolor" value="#FFFFFF" /> \
			<param name="width" value="' + width + '" /> \
			<param name="height" value="' + height + '" /> \
			<param name="playerID" value="' + playerID + '" /> \
			<param name="playerKey" value="' + playerKey + '" /> \
			<param name="isVid" value="true" /> \
			<param name="isUI" value="true" /> \
			<param name="dynamicStreaming" value="true" /> \
			<param name="@videoPlayer" value="' + videoID + '" /> \
			<param name="wmode" value="transparent" /> \
		</object>');
	
	$.fancybox({
		'content' : fbContent, 
		'padding' : 0, 
		'autoScale' : false, 
		'autoDimensions' : false, 
		'width': width,
		'height': height,
		'transitionIn' : 'none', 
		'transitionOut' : 'none', 
		'title' : '', 
		'swf' : {
			'wmode'	: 'transparent', 
			'allowfullscreen' : 'true'
		}, 
		'overlayOpacity': 0.5, 
		'overlayColor': '#000', 
		'scrolling': 'no', 
		'onComplete' : function() {
			brightcove.createExperiences();
		}
	});
}

$(document).ready(function() {
	$(document).scroll(function() {
		$.fancybox.center();
	});
});
