var embedFlowVideoContainer = null;
var embedFlowVideoConfig = null;
var embedFlowVideoApiObject = null;
var embedFlowVideoEnabled = false;
function embedFlowVideo(source){
    popVid("<div id='flowVideoClip'/>","flashVideo_popWin",source);    
}
function popVid(content,id,source){
    if (embedFlowVideoEnabled == false) {
		$('.popVid').remove();
        embedFlowVideoConfig = getFlowVideoConfig(source);
        if (source == "farmerscalcom.f4v") {
            embedFlowVideoContainer = getPopVidWide(id, content);
            vidMaskOver();
            centerToWindow(embedFlowVideoContainer);
            $('body').append(embedFlowVideoContainer);
            embedFlowVideoApiObject = flashembed("flowVideoClip",{src:'/modules/lifeVideos/FlowPlayerDark.swf',width:550,height:310,bgcolor:'#ffffff'},embedFlowVideoConfig);
        } else {
            embedFlowVideoContainer = getPopVid(id, content);
            vidMaskOver();
            centerToWindow(embedFlowVideoContainer);
            $('body').append(embedFlowVideoContainer);
            embedFlowVideoApiObject = flashembed("flowVideoClip",{src:'/modules/lifeVideos/FlowPlayerDark.swf',width:352,height:270,bgcolor:'#ffffff'},embedFlowVideoConfig);
        }
        embedFlowVideoEnabled = true;
	    $('.popVidCtrl').click(function(){
	        if(embedFlowVideoApiObject != null)
	        {
	            embedFlowVideoApiObject.Pause();
	        }
		    vidKillMaskOver();
			killPopVid();
	    })
    } else {
        vidMaskOver();
	    centerToWindow(embedFlowVideoContainer);
	    embedFlowVideoConfig.videoFile = checkExtension(source); 
        //embedFlowVideoConfig.streamingServer='fms';
        //embedFlowVideoConfig.streamingServerURL='rtmp://adv22kov7ihg.rtmphost.com/farmersprogram/_definst_/';
        embedFlowVideoConfig.baseURL = 'http://wds.mp.advection.net/mp/vmi/_dld/farmersprogram/agent/';
        embedFlowVideoApiObject.setConfig(embedFlowVideoConfig);
        
    }	
	$('.popVid').css("display", "");
}
function killPopVid() {
    if (embedFlowVideoEnabled == true)
    {
        //if(embedFlowVideoContainer) embedFlowVideoContainer = null;
        //if(embedFlowVideoConfig) embedFlowVideoConfig = null;
        //if(embedFlowVideoApiObject != null) embedFlowVideoApiObject = null;
        embedFlowVideoEnabled = false;
		
        $('.popVid').css("display", "none");
        if(!document.all) {
            $('.popVid').remove();   
            embedFlowVideoContainer = null;
            embedFlowVideoConfig = null;
            embedFlowVideoApiObject = null;
        }
    }
}
function getFlowVideoConfig(source){
return {config: {   
    videoFile: checkExtension(source),     
    initialScale: 'scale', 
    useNativeFullScreen: true,
    showVolumeSlider: false,
    controlsOverVideo: 'ease',
    controlBarBackgroundColor: -1,
    controlBarGloss: 'low',
    bufferLength: '1',
    startingBufferLength: '1',
    //streamingServer: 'fms',
    //streamingServerURL: 'rtmp://adv22kov7ihg.rtmphost.com/farmersprogram/_definst_/'
    baseURL: 'http://wds.mp.advection.net/mp/vmi/_dld/farmersprogram/agent/'
    }};
}
function checkExtension(source) {   
    if (source.indexOf('.flv') > 0 || source.indexOf('.f4v') > 0) {
        return source;
    }
    else {
        return source + ".flv";
    }
}
function getPopVid(id,content){
return $('<div class="popWinContainer">'+
'<div class="popVid" id="'+id+'Pop">'+
'<div class="popWinTopRight"><div class="popWinTopLeft">'+
'<div class="popWinTopCenter"><div class="popWinCtrls"><span class="popVidCtrl">close <img src="/skins/themes/saphire/images/popWin/closeWindow.gif" width="13" height="12" /></span></div></div>'+
'</div></div>'+
'<div class="popWinMiddleRight"><div class="popWinMiddleLeft">'+
'<div class="popWinMiddleContent">'+$(content).outerHtml()+'</div>'+
'</div></div>'+
'<div class="popWinBottomRight"><div class="popWinBottomLeft">'+
'<div class="popWinBottomCenter"></div>'+
'</div></div>'+
'</div></div>');
}
function getPopVidWide(id, content) {
    return $('<div class="popWinContainer">' +
'<div class="popVid" id="' + id + 'Pop" style="width:618px;">' +
'<div class="popWinTopRight"><div class="popWinTopLeft">' +
'<div class="popWinTopCenter"><div class="popWinCtrls"><span class="popVidCtrl">close <img src="/skins/themes/saphire/images/popWin/closeWindow.gif" width="13" height="12" /></span></div></div>' +
'</div></div>' +
'<div class="popWinMiddleRight"><div class="popWinMiddleLeft">' +
'<div class="popWinMiddleContent">' + $(content).outerHtml() + '</div>' +
'</div></div>' +
'<div class="popWinBottomRight"><div class="popWinBottomLeft">' +
'<div class="popWinBottomCenter"></div>' +
'</div></div>' +
'</div></div>');
}
function vidMaskOver(){
		var mask = $('<div class="maskOver">&nbsp;<div>');
		$(mask).css('height', $(document).height());
		$('body').append(mask);
		if(getFlashMovie("areYouCoverredSWF") != null) {
		    getFlashMovie("areYouCoverredSWF").VM_Standby();
		}
		eval("pauseSlideShow()");
}
function vidKillMaskOver(){
	if(getFlashMovie("areYouCoverredSWF") != null) {
	    getFlashMovie("areYouCoverredSWF").VM_Resume();
	}
	$('.maskOver').remove();
	eval("unpauseSlideShow()");
}

// ----- START RUCOVRD ----- //
function initializeAreYouCovered(){
    $('#areYouCoveredWidgetLink').click(function(){
		var html = $('<div id="RUCOVRD_container"></div>');
		popWin(html, 'RUCOVRD');
		$('#RUCOVRDPop').css('width', '760px');
		var so = new SWFObject("/modules/areYouCovered/RUCovered.swf", "areYouCoverredSWF", "700", "237", "8", "#FFFFFF", true);
		so.addVariable("getAQuoteFunction", "javascript:SWFCallGetAQuote_LPPage()");
		so.addVariable("dataXML", "/xml/RUCovered.xml");
		so.addParam("wmode", "transparent");
		so.write('RUCOVRD_container');
		return false;
	});
}

$(document).ready(function() {
    initializeAreYouCovered();

    $("#lnk80Years").click(function() {
        start80YearsVideo();
    });
});

function SWFCallGetAQuote_LPPage(){
	$('.popWinContainer').remove();
	$.getScript('/skins/themes/saphire/scripts/getAQuoteFq.js');
}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

// --- START 80 YEARS SCRIPTS
function start80YearsVideo()
{	
	if(getFlashMovie("areYouCoverredSWF") != null) {
		getFlashMovie("areYouCoverredSWF").VM_Standby();
	}
	$("#flashEmbed80YearsVideo").css({opacity: 0, display: "inline"});
	$("#close80YearsDiv").css("display", "none");
	$("#flashEmbed80YearsVideo").animate({opacity: 1, left: "-600px", top: "-130px", width: "600px", height: "300px"}, 1200, null, show80YearsVideo);
}

var videoShown = false;
function show80YearsVideo()
{
	ignoreFirstClipDone = true;
	videoShown = true;
	flashembed("flashEmbed80YearsVideo",{src:'/modules/lifeVideos/FlowPlayerDark.swf',width:600,height:300,bgcolor:'#ffffff',wmode:'transparent'}, get80YearsFlowVideoConfig("80YearsAudio"));
	$("#close80YearsDiv").css("display", "block");
	$("#flashEmbed80YearsVideo").hover(function(){
		if(videoShown){
			$("#close80YearsDiv").show();
		}
	},
	function(){
		$("#close80YearsDiv").hide();
	});
	
	$("#close80YearsDiv").hover(function(){
		if(videoShown){
			$("#close80YearsDiv").show();
		}
	},
	function(){
		$("#close80YearsDiv").hide();
	});
}

function get80YearsFlowVideoConfig(source){
	return {config: { 
		    videoFile: source,
		    initialScale: 'scale', 
		    useNativeFullScreen: true,
		    controlsOverVideo: 'ease',
		    controlBarBackgroundColor: -1,
		    controlBarGloss: 'low',
		    bufferLength: '3',
		    startingBufferLength: '3',
		    streamingServer: 'fms',
		    streamingServerURL: 'rtmp://adv22kov7ihg.rtmphost.com/farmersprogram/_definst_/',
			autoPlay: false,
			autoBuffering: true,
			scaleSplash: false,
			splashImageFile: '/modules/lifeVideos/80-Years-Composition.jpg'
		}};
}

var ignoreFirstClipDone = true;
// flowplayer video end event
function onClipDone(clip)
{
	if(!ignoreFirstClipDone){
		hide80YearsVideo();
	}
	ignoreFirstClipDone = false;
}
function onPlay(clip)
{
	videoIsPlaying = true;
}

function hide80YearsVideo()
{
	videoShown = false;
	$("#close80YearsDiv").hide();
	$("#flashEmbed80YearsVideo").html("");
	$("#flashEmbed80YearsVideo").animate({opacity: 0, left: "0px", top: "0px", width: "200px", height: "200px"}, 1200, null, remove80YearsDiv);
}

function remove80YearsDiv()
{
	$("#flashEmbed80YearsVideo").css("display", "none");
}

// --- END 80 YEARS SCRIPTS 

