var initialized	= false;
var theTime		= 0;

Event.observe(window, 'load', function() { init(); });
Event.observe(window, 'load', function() { refreshAd(); });

function init() {
	var flashvars = {
		configURL: swf_config,
		JSEventListener:"handleMosaicEvent",
		OMNITURE_ACCOUNT: omni_account,
		OMNITURE_MOVIEID: omni_movieid,
		OMNITURE_VISITORNAMESPACE: omni_vistornamespace,
		OMNITURE_TRACKINGSERVER: omni_trackingserver,
		OMNITURE_TRACKCLICKMAP: omni_trackclickmap,
		OMNITURE_TRACKLOCAL: omni_tracklocal,
		OMNITURE_TESTSUPPORT: omni_testsupport
	};
	var params = {
		bgcolor: "#ffffff",
		allowscriptaccess: "always",
		allowFullScreen:"true"
	};
	var attributes = {
		id:"mosaicModule",
		name:"mosaicModule"
	};

	swfobject.embedSWF(swf_player, "moduleDiv", "832", "468","9", "expressinstall.swf",  flashvars, params, attributes);
}

function selectStream(p_ID) {
	if (initialized) {	// only let calls go through after the module is initialized
		var module = (navigator.appName.indexOf("Microsoft") != -1) ? window["mosaicModule"] : document["mosaicModule"];

		module.selectStream(p_ID);
	}
}

function mute(p_v) {
	if (initialized) {	// only let calls go through after the module is initialized
		var module = (navigator.appName.indexOf("Microsoft") != -1) ? window["mosaicModule"] : document["mosaicModule"];

		module.mute(p_v);
	}
}
/**
function handleMosaicEvent(p_evt) {
	switch (p_evt.type) {
		case "initialized":
			initialized = true;
			break;
		case "feedSelected":
			break;
		case "feedRequested":
			break;
		case "prerollAdRequested":
		// 	perform ad banner swap
		//	window.frames["ad_frame_234"].location.replace("http://www.dreamsocket.com");
			ad_url_234 += p_evt.tileID;
			ad_url_728 += p_evt.tileID;

			document.getElementById('ad_frame_234').src = ad_url_234;
			document.getElementById('ad_frame_728').src = ad_url_728;
			ad_url_234 += p_evt.tileID;
			break;
	}
}
**/
// Timer for ad refreshing
function refreshAd () {
    theTime = setInterval ( "cnnad_refreshAds()", ad_refresh_length );
}

function adtimer () {
//	var adURL = "http://ads.tnt.tv/html.ng/site=pga&pga_pagetype=live1&pga_pos=728x90_sync&pga_rollup=majors&pga_section=pga&pga_subsection=video&page.allowcompete=yes";
	var html = '<iframe hspace="0" vspace="0" marginHeight="0" marginWidth="0" src="' + ad_url + '" border="0" frameborder="0" width="728" height="90" scrolling="no"  id="banner_ad_frame"></iframe>';

	document.getElementById("ad_728").innerHTML = html;
}

function handleMosaicEvent(p_evt)	{
	switch (p_evt.type)	
	{
	case "initialized":
		initialized = true;
		break;
	case "feedSelected":
		break;
	case "feedRequested":
		break;
	case "prerollAdRequested":
	// perform ad banner swap
		doSyncAd(p_evt);
		break;
	}
}

	var frame_synch1URL = "";
	var frame_synch2URL = "";

function doSyncAd(p_evt) {

	synch1URL = "http://ads.pga.com/html.ng/site=pga&pga_pos=234x60_spon&pga_rollup=majors&pga_section=british_open&pga_subsection=live&params.styles=fs&tile=";
	synch2URL = "http://ads.pga.com/html.ng/site=pga&pga_pos=728x90_sync&pga_rollup=majors&pga_section=british_open&pga_subsection=live&params.styles=fs&tile=";

// cnn_tileID is what the adproxy will use to deterimine the tile ID instead of having a unique page request each time cnnad_tileID = p_evt.tileID;

		if(synch1URL != null) 	{
			document.getElementById('ad_frame_234').src = synch1URL + p_evt.tileID; //"weather.html";
		}
		if(synch2URL != null)	{
			document.getElementById('ad_frame_728').src = synch2URL + p_evt.tileID; //"weather.html";
		}
		
		frame_synch1URL = synch1URL;
		frame_synch2URL = synch2URL;
}

