/**************************************/
$(document).ready(function () {
        checkVideoTrigger();
});

function checkVideoTrigger() {
        
        urlHash = getUrlParam();  // Parse URL params into a hash
        if(urlHash['config'] && urlHash['config'].length > 0 ) {
                embedPlayer(urlHash['config'], urlHash['chapter']);
        }
        return false;
}

/* 
utlity function to get the parameters from querystring 
returns an array : hash[0] is the param name; hash[1] is the param value
*/
function getUrlParam()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = escape(hash[1]);
    }
    return vars;
}


/** End of video send to a friend handling **/


if ($('#p25_content').hasClass('p25_pdp')) $("#player_container").addClass("player_pdp");


// Modified on 3/26 
function embedPlayer(xml, chapter) {
	// Example: embedPlayer('/us_non_production_assets/flash/player/xml/player_config.xml','picturequality')
	var flashvars = {};
	flashvars.config_file = xml;
    flashvars.share = "/ae/p25/flash/player/xml/player_share.xml";	
    flashvars.main_file = "/ae/p25/flash/player/videoplayer.swf";
	flashvars.css_file = "/ae/p25/flash/player/css/flash.css";
	flashvars.fonts_xml = "/ae/p25/flash/player/xml/player_styles.xml";
	//flashvars.tracking = "/us/flash/player/xml/player_tracking.xml";
	if (chapter!=undefined && chapter!="") flashvars.video_id = chapter;
    flashvars.debug = "false";
    // possible values are: verbose, warning, error
    flashvars.log_level = "";
	
	// Make player
	makePlayer(flashvars);
}

// Old function 
/*
function embedPlayer(xml, chapter) {
	// Example: embedPlayer('/us_non_production_assets/flash/player/xml/player_config.xml','picturequality')
	var flashvars = {};
	flashvars.config_file = xml;
    flashvars.share = "/public/p25/flash/player/xml/player_share.xml";	
    flashvars.main_file = "/public/p25/flash/player/videoplayer.swf";
	flashvars.css_file = "/public/p25/flash/player/css/flash.css";
    //flashvars.tracking = "/ae/demotest/xml/player_tracking.xml";
	if (chapter!=undefined && chapter!="") flashvars.video_id = chapter;
    flashvars.debug = "false";
    // possible values are: verbose, warning, error
    flashvars.log_level = "";
	
	// Make player
	makePlayer(flashvars);
}*/


/*
function embedVideo(video_file, video_title, widescreen, share_img) {
	var flashvars = {};
	// Standard Flash params
    flashvars.share = "/public/p25/flash/player/xml/player_share.xml";	
    flashvars.main_file = "/public/p25/flash/player/videoplayer.swf";
	flashvars.css_file = "/public/p25/flash/player/css/flash.css";
    //flashvars.tracking = "/ae/demotest/xml/player_tracking.xml";
    flashvars.debug = "false";
	// possible values are: verbose, warning, error
    flashvars.log_level = "";

	//parameters for single video without a config file
	// Example: embedVideo("/public/p25_non_production_assets/flash/player/video/Music_VO/1200/LED_7000_innovation.flv","Innovation",true)
	flashvars.flv_path = video_file;
	flashvars.video_title = video_title;
	// Get the URL of this page
	flashvars.share_link = location.href;
	// Get the title of this page
	flashvars.share_title = video_title;
	//flashvars.share_title = document.title;
	// Widescreen? (true or false)
	flashvars.widescreen = ((widescreen!=undefined) && ((widescreen == "false") || !widescreen))?"false":"true";
	// If an image was passed, use that, otherwise, use a default 120x120 image
	// This is for the email that gets sent
	if (share_img!=undefined && share_img!="") flashvars.share_image = share_img;
	else flashvars.share_image = "http://www.samsung.com/us/p2images/common/logo.png";

     // Localized "close demo" copy
     flashvars.close_copy = "close demo";
     flashvars.buffer_copy = "Buffering";
     flashvars.default_buffer_time = "5";
     flashvars.enable_tracking = "false";
	
	// Make player
	makePlayer(flashvars);
}*/

function makePlayer(flashvars) {
	var params = {};
	params.allowScriptAccess = "always"
	params.wmode = "opaque"
	params.allowFullScreen = "true"
	
	var attributes = {};
	attributes.id = "playerWrap";
	attributes.name = "player";
	
	// Embed player
	$("#player_container").prepend("<div id='player'></div>");
	swfobject.embedSWF("/ae/p25/flash/player/videoplayer_preloader.swf", "player", "896", "504", "9.0.115", "js/expressInstall.swf", flashvars, params, attributes);
	// Unhide the Flash and grey out the rest of the page
	$("#player_embedlayer").removeClass("player_hide");
	windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	pgHeight = Math.max(Math.max(document.body.scrollHeight, 630), windowHeight);
	$("#player_overlay").css("height",pgHeight+"px");
	$("#player_overlay").removeClass("player_hide");
	
}

function closePlayer() {
	// Display the page again and close the Flash layer
	$("#player_overlay").addClass("player_hide");
	$("#player_embedlayer").addClass("player_hide");
	// Destroy the Flash
	$("#playerWrap").remove();
}


$('#player_overlay').click(function(){
	closePlayer();
})


