
// this function called from the flash for each page view
function flashCall_pageView(pageName,siteSection,property) {
	//alert("pageview="+pageName+" siteSection="+siteSection+" property="+property);
	if (window["cto"]) {
		omni_log("pageView pageName="+pageName+" siteSection="+siteSection+" property="+property);
		cto.initFlashPV(); // Let the DIMG analytics layer know that we are going to send a flash PV
		if (siteSection != "") 
		{
			siteSection=":"+siteSection;
		}
		cto.siteSection = "video"+siteSection;
		//Set new values for CTO variables
		cto.pageName=pageName;
		cto.trackFlashPV(); // Submit the PV data along with updated values for the properties.
	} else {
		omni_error("flashCall_pageView::Error with analytics cto object is not defined on the page");
	}
}

function flashCall_mediaOpen(name,mediaLength) {
	if (window["cto"]) {
		omni_log("1 flashCall_mediaOpen name="+name+" mediaLength="+mediaLength);
		cto.MediaOpen(buildMediaName(name),mediaLength,"dcbb_dreamsocket");
	} else {
		omni_error("flashCall_mediaOpen::Error with analytics cto object is not defined on the page");
	}
}

function flashCall_mediaPlay(name,mediaOffset,propertyName) {
	omni_log("1 flashCall_mediaPlay name="+name+" mediaOffset="+mediaOffset+" propertyName="+propertyName);
	if (window["cto"]) {
		cto.MediaPlay(buildMediaName(name),mediaOffset, "video_asset",propertyName);
	} else {
		omni_error("flashCall_mediaPlay::Error with analytics cto object is not defined on the page");
	}
}

function flashCall_mediaStop(name,mediaOffset) {
	omni_log("1 flashCall_mediaStop name="+name+" mediaOffset="+mediaOffset);
	if (window["cto"]) {
		cto.MediaStop(buildMediaName(name),mediaOffset, "video_asset")
	} else {
		omni_error("flashCall_mediaStop::Error with analytics cto object is not defined on the page");
	}
}

function flashCall_mediaClose(name) {
	if (window["cto"]) {
		omni_log("1 flashCall_mediaClose name="+pageName);
		cto.MediaClose(buildMediaName(name));
	} else {
		omni_error("flashCall_mediaClose::Error with analytics cto object is not defined on the page");
	}
}

function buildMediaName(name) {
	return "vid:"+name;
}

function getConsole(){
	//need to check for console this way, testing console==null throws a reference error if it's not defined - and that stops the script running
	if (window["console"] == null){
		window["console"] = {log:function(value){}, error:function(value){}};
	}
	return window["console"];
}
 
function showLogging() {
	//should the firebug log be visible?
	var hasDebugParam = window.location.href.indexOf("debug")>0;
	var isDevPlatform = (host.indexOf("dev.")>=0)||(host.indexOf("localhost.")>=0);
	return (hasDebugParam||isDevPlatform);
}

function omni_log(msg) {	
	if (showLogging()) {
		getConsole().log("Omniture JS:"+msg);	
	}
}
function omni_error(msg) {
	getConsole().error("Omniture JS:"+msg);
}

function flashCall_log(msg) {
	if (showLogging()) {
		getConsole().log("Omniture SWF:"+msg);
	}
}
function flashCall_error(msg) {
	getConsole().error("Omniture SWF:"+msg);
}

omni_log("EMEA Omniture code loaded ok javascript version");