//set from flash
function setAdvertising(src, href, syncID, auditSrc){
	setBanner(syncID);
	if (document.location.href.indexOf('n090213_crash')==-1){
		setVideo(src, href, auditSrc);
	}
}


function setBanner(syncID) {
	if (typeof frames['oasShow'] != "undefined") {	
		if (syncID){
			frames['oasShow'].location.href = getAdUrl(syncID);
		}else {
			frames['oasShow'].location.href = getAdUrl("");
		}
	}
}

function getAdUrl(syncId){
	//http://gannett.gcion.com/adiframe/3.0/5111.1/778079/0/-1/ADTECH;size=728x90;
//	var url = "http://gannett.gcion.com/adiframe/3.0/5111.1/778079/0/0/ADTECH;header=yes;cc=2;alias=www.usatoday.com/video/photogallery_Top728x90;cookie=info;";

	var url = "http://gannett.gcion.com/adiframe/3.0/5111.1/778079/0/-1/ADTECH;size=728x90;header=yes;cc=2;alias=www.usatoday.com/video/photogallery_Top728x90;cookie=info;";
	var key = "key=" + syncId;
	var misc = ";adct=204;grp=12345;misc=" + new Date().valueOf();

	return url + key + misc;
}


function setVideo(src, href, auditSrc) {
	if (src) {

		$('#videoModal').modal({
									overlay: 70,
									persist: true,
									onOpen: function(dialog) 
									{
										openModal(dialog);
										embedPreRoll(src, href, auditSrc);
									}
								});
		$('#prerollModal').css({position: "absolute"});
		$('#modalOverlay').height(570);
	}
}


function closeVideo() {
	$.modal.close();
}


function createSWF(attributes, flashvars, params, swf) {

	swfobject.embedSWF(
						swf.movie, swf.id, 
						swf.width, swf.height, 
						swf.version, 
						"http://i.usatoday.net/_common/_scripts/_swfObject/expressInstall.swf", 
						flashvars, params, attributes
					  );
}

function embedPreRoll(src, href, auditSrc) {

	var attributes = {};
	var flashvars = {};
	var params = {};

	flashvars.video = src;
	flashvars.href = href;
	flashvars.audit = auditSrc;
	flashvars.message = "Advertisement will end in # seconds.";

	params.scale = "noScale";
	params.align = "middle";
	params.allowScriptAccess = "always";
	

	var movie = "http://i.usatoday.net/_common/_flash/_video-preroll/video.swf";
	var swf = {
				movie: movie,
				id: "prerollModal",
				width: "100%",
				height: "100%",
				version: "9"
			  };

	createSWF(attributes, flashvars, params, swf);
}

function openModal(dialog) {
	dialog.overlay.fadeIn('slow', function(){
		openModalContainer(dialog);
		}
	);
}

function openModalContainer(dialog){
	dialog.container.fadeIn('slow', 
		function () {
			dialog.data.fadeIn('slow'); 
		}
	)
}

function resizeVideo(width, height){
	$("#movie").width(width);
	$("#movie").height(height);
	
	var left = (width / 2) * -1;
		
	$("#modalContainer").width(width);
	$("#modalContainer").height( height );

	$("#modalContainer").css({ marginLeft: left });
}
