﻿$(document).ready(function() {
	if (swfobject.hasFlashPlayerVersion("8.0.0")) {
		
		/* Get the Name from the ID of the video div */
		function getVideo(panel) {
			var arrVideoPnl = panel.attr('id').split('pnl');
			divVideoPnl = arrVideoPnl[1];
			return divVideoPnl;
		}
		
		/* Replace "No Flash/Javascript" error message with correct link/image to show full-size video */
		$('div.noFlash').remove();
		$("div.video.portrait").each(function() {
			getVideo($(this));
			
			switch (divVideoPnl) {
				case 'CarolineHCP':
					strImgAlt = 'Watch Dr. Allen\'s Video';
					break;
				case 'MaryHusband':
					strImgAlt = 'Watch Dan\'s Story';
					break;
				case 'PatrickHCP':
					strImgAlt = 'Watch Dr. Allen\'s Video';
					break;
				case 'PatrickWife':
					strImgAlt = 'Watch Amy\'s Story';
					break;
				default:
					strImgAlt = 'Watch '+divVideoPnl+'\'s Story';
			}
			
			var strVideoPnl = '<img src="/images/video/'+ divVideoPnl.toLowerCase() +'.jpg" alt="'+strImgAlt+'"/>';
			$(this).append(strVideoPnl);
			
		});
		
		/* onclick: set function to open full-size video */
		$('div.video.portrait img').click(function() {
			getVideo($(this).parent());
			passXMLToLargeSwf('/swf/xml/'+divVideoPnl+'.xml', 'single');
		});
		
		/* Video thumbnail rollover state */
		$('div.video.portrait img').hover(
			function() {
				this.src = this.src.replace(".jpg","-hover.jpg");
			},
			function() {
				this.src = this.src.replace("-hover.jpg",".jpg");
			}
		);
		
	}
});



//Video In Page Constants

var MOVIE_WRAPPER_DIV = 'large-player-wrapper';
var VIDEO_LIBRARY_PATH = '/tools-support/bipolar-disorder-depression-videos.aspx';

var MOVIE_EMBED_DIV_LARGE = 'flash-player-large';
var MOVIE_NAME_LARGE = 'SQC114_inPagePlayer';
var MOVIE_PATH_LARGE = '/swf/video-in-page/SQC114_inPagePlayer.swf';


var SINGLE_MOVIE_PATH_LARGE = '/swf/SQC202C-full.swf';
var FULL_MOVIE_PATH_LARGE = '/swf/SQC202C-single2.swf';

var MOVIE_EMBED_DIV_SMALL = 'flash-player-small';
var MOVIE_NAME_SMALL = 'SQC114_inPage';
var MOVIE_PATH_SMALL = '/swf/video-in-page/SQC114_inPage.swf';

var currentType= "";
//Set an interval before we call the externalInterface method.
//This allows the XML to load.
var MOV_ID = '';
var t;


//Called by the small swf
function passIDToLargeSwf(id, path, divId) { 
    
    var newMovieName = MOVIE_NAME_LARGE + id + "-video";
    
    
    //Ensure movie is visible
	toggleFlashDiv(id,1);
	
}




function resetSwf() {
	$(".large-player-wrapper").html('<div id="large-video" class="player"></div>');
}








//Called by the small swf
function passXMLToLargeSwf(path, type) { 
    
    divId = "large-video";
    swf = document.getElementById(SINGLE_MOVIE_PATH_LARGE);
    resetSwf();
    
    embedSwf(path, divId ,type);
    //Ensure movie is visible
    toggleFlashDiv(divId,1);
	
}


//This function is called by Flash to show or hide the large flash div.
function toggleFlashDiv(id,n) {
	if (n == 0) {
		$(".large-player-wrapper").hide();
	}else{
	    $(".large-player-wrapper").show().center();
	}
}


function flashCallClose(){
    $(".large-player-wrapper").hide();
}

// EMBED SWFs


function setXmlPath(xml){
    resetSwf();
    embedSwf(xml,"large-video");
}

function embedSwf(path, divId, type){
	var params =  { wmode: "transparent", allowScriptAccess: "always", scale: "showall"}
	//var params =  { allowScriptAccess: "sameDomain" }
	var attributes = { };
	var flashvars = { 
		configPath: path,
		largeFlashDivID: divId,
		vidLib: VIDEO_LIBRARY_PATH
	};
    if(type=="" || type == null){
	    type=currentType;
    }else{
        currentType = type;
    }
	//Embed large video
	var newMovieName = MOVIE_NAME_LARGE ;
	attributes = { id: MOVIE_NAME_LARGE, name: MOVIE_NAME_LARGE};
	if(type == "single"){
	    $(".large-player-wrapper").css("height", 688);
	    $(".large-player-wrapper").css("width", 714);
	    swfobject.embedSWF(SINGLE_MOVIE_PATH_LARGE, divId, "714", "688", "8.0.0", "", flashvars, params, attributes);
	} else if(type=='full') {
		$(".large-player-wrapper").css("height", 688);
	    $(".large-player-wrapper").css("width", 714);
	    swfobject.embedSWF(FULL_MOVIE_PATH_LARGE, divId, "714", "688", "8.0.0", "", flashvars, params, attributes);
	} else {
	    swfobject.embedSWF(MOVIE_PATH_LARGE, divId, "716", "356", "8.0.0", "", flashvars, params, attributes);
	}
	
	

	
	
	var currentId = document.getElementById(newMovieName); //Reassociate for IE6.		
}
	
