﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var popupHeight;
var popupWidth;
//loading popup with jQuery magic!
function loadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
    	
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");
        
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
    loadPlayer('0','true');
        $("#backgroundPopup").fadeOut("fast");
        $("#popupContact").fadeOut("fast");
        popupStatus = 0;
    }
}
var popupTop;
var popupLeft;
//centering popup
function centerPopup(obj1) {
    
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    popupHeight = obj1.offsetHeight;
    popupWidth = obj1.clientWidth;
    //var videoId = $("img[class$=image]")[0].attr('alt'); 
   //alert("1- "+videoId);  
   var videotag = $(obj1).html();
   var video = $(videotag).attr('vid');  
    loadPlayer(video,'true');
    //centering
    $("#popupContact").css({
        "top": windowHeight/4  - popupHeight/4 ,
        "left": windowWidth/4  - popupWidth/4 
    });
    //$("#popupContact")[0].innerHTML = obj1.innerHTML;
    //only need force for IE6

    $("#backgroundPopup").css({
        "height": windowHeight
    });

}


//CONTROLLING EVENTS IN jQuery
	function BindEvents(){

    //LOADING POPUP
    //Click the button event!
    //	$("#button").click(function(){
    //		//centering with css
    //		centerPopup();
    //		//load popup
    //		loadPopup();
    //	});

    //CLOSING POPUP
    //Click the x event!
    $("#popupContactClose").click(function () {
        disablePopup();
    });
    //Click out event!
    $("#backgroundPopup").click(function () {
        disablePopup();
    });
    //Press Escape event!
    $(document).keypress(function (e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });
}
//loadPlayer(737434254001,true);
function loadPlayer(videoID, videoAutoStart) {
	var bc_params = {};
	bc_params["id"] = "myExperience";
	bc_params["bgcolor"] = "#FFFFFF";
	bc_params["wmode"] = "transparent";
	bc_params["width"] = 610;
	bc_params["height"] = 399;
	//bc_params["playerId"] = 100684735001;
	bc_params["playerId"] = 89779177001;
	bc_params["publisherID"] = 82070934001;
	bc_params["@videoPlayer"] = videoID; 

	var pHtmlx = "<iframe allowtransparency=true frameborder=0 scrolling=no src=http://www.facebook.com/plugins/like.php?href=http://www.amdocs.com/video/pages/index.aspx?vid=" + videoID + "&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;style=border:none; overflow:hidden;></iframe>";

	//document.getElementById("bcPlayerx").innerHTML = pHtmlx;
	var pHtml = "\n\n<!-- Start Brightcove Player -->";
	pHtml += "<div id='popupContactClose'><img alt='Close' src='/PublishingImages/Re-Brand/close-button.png' /></div><div>"
	pHtml += "\n<object id=\"myExperience\" class=\"BrightcoveExperience\">";
	pHtml += "\n<param name=\"wmode\" value=\"" + bc_params["wmode"] + "\" />";
	pHtml += "\n<param name=\"bgcolor\" value=\"" + bc_params["bgcolor"] + "\" />";
	pHtml += "\n<param name=\"width\" value=\"" + bc_params["width"] + "\" />";
	pHtml += "\n<param name=\"height\" value=\"" + bc_params["height"] + "\" />";
	pHtml += "\n<param name=\"playerID\" value=\"" + bc_params["playerId"] + "\" />";

	// Start Assigning Programming
	if(bc_params["@videoPlayer"] != null) {
		pHtml += "\n<param name=\"@videoPlayer\" value=\"" + bc_params["@videoPlayer"] + "\" />";
	} else if(bc_params["@playlistTabs"] != null) {
		pHtml += "\n<param name=\"@playlistTabs\" value=\"" + bc_params["@playlistTabs"] + "\" />";
		if(bc_params["@playlistTabs.featured"] != null) { pHtml += "\n<param name=\"@playlistTabs.featured\" value=\"" + bc_params["@playlistTabs.featured"] + "\" />"; }
		if(bc_params["@videoList.featured"] != null) { pHtml += "\n<param name=\"@videoList.featured\" value=\"" + bc_params["@videoList.featured"] + "\" />"; }
	}
	// End Assigning Programming


	pHtml += "\n<param name=\"linkBaseURL\" value=\"" + buildVideoLink(videoID) + "\" />";
	pHtml += "\n<param name=\"autoStart\" value=\""+videoAutoStart+"\" />";
	pHtml += "\n<param name=\"isVid\" value=\"true\" />";
	pHtml += "\n<param name=\"isUI\" value=\"true\" />";
	pHtml += "\n</object></div>";
	pHtml += "\n<!-- End Brightcove Player -->\n\n";
	
//	document.getElementById("bcPlayer").innerHTML = pHtml;
$("#popupContact")[0].innerHTML=pHtml;

	brightcove.createExperiences('0', 'myExperience');
	
}

/////// building video link for linkBaseURL //////
function buildVideoLink(videoID) {
	var vidUrl;
	var currentLink = window.location.href;
 	// Get the current URL and remove any existing URL parameter
	if(currentLink.indexOf("?") != -1) {
		currentLink = currentLink.substring(0,currentLink.indexOf("?"));
	}
	
	 vidUrl = currentLink + "?vid=" + videoID;
	//vidUrl = currentLink;
	return vidUrl;
}

/*
function onTemplateLoaded(experienceID) {
    //alert("EVENT: TEMPLATE_LOAD");

    bcExp = brightcove.getExperience(experienceID);

    modVP = bcExp.getModule(APIModules.VIDEO_PLAYER);
    modExp = bcExp.getModule(APIModules.EXPERIENCE);
    modCon = bcExp.getModule(APIModules.CONTENT);
    modMenu = bcExp.getModule(APIModules.MENU);


    modExp.addEventListener(BCExperienceEvent.TEMPLATE_READY, onTemplateReady);
    modExp.addEventListener(BCExperienceEvent.CONTENT_LOAD, onContentLoad);
    modCon.addEventListener(BCContentEvent.VIDEO_LOAD, onVideoLoad);
    modMenu.addEventListener(BCMenuEvent.VIDEO_REQUEST, onMenuContentLoad);
    modVP.addEventListener(BCMediaEvent.BEGIN, onMediaBegin);

}
function onTemplateReady(evt) {

    }
function onContentLoad(evt) {


    var currentVideo = modVP.getCurrentVideo();


    var currentMedia = modCon.getMedia(currentVideo.id);


    document.getElementById("bcPlayer-VideoTitle").innerHTML = currentMedia.displayName;
    document.getElementById("bcPlayer-VideoShortDescription").innerHTML = currentMedia.shortDescription;
    document.getElementById("bcPlayer-VideoID").innerHTML = currentVideo.id;
 
    var adKeys = readAdKeys(currentMedia.adKeys);
    var adChannel = adKeys["chan"];
    var adShow = adKeys["show"];


    modCon.getMediaAsynch(currentVideo.id);
}
function onMenuContentLoad(evt) {

    
    var currentMedia = evt["args"];

    document.getElementById("bcPlayer-VideoTitle").innerHTML = currentMedia.displayName;
    document.getElementById("bcPlayer-VideoShortDescription").innerHTML = currentMedia.shortDescription;
    document.getElementById("bcPlayer-VideoID").innerHTML = currentMedia.id;
    
    //function LoadAds(adposID", adSite, adZone, adOrd, adChannel, adCategories, adMiscTag)
    var adKeys = readAdKeys(currentMedia.adKeys); // adKeys=;aspect=16_9;chan=business;show=pbt
    var adChannel = adKeys["chan"];
    var adShow = adKeys["show"];



}

function onMediaBegin(evt) {

	for(prop in evt["media"]["tags"]) {
		var myTag = evt["media"]["tags"][prop]["name"];
		if (myTag==findTag) {
			if (chkSubscription(findCookie)==false) {
				//document.location = redirectUrl + "&vid=" + evt["media"]["id"];
				window.location.href = redirectUrl + "&vid=" + evt["media"]["id"];
			}
		}
	}
}

function chkSubscription(coo) {
	var subKey = readCookie(coo);
	if ( (subKey==null) || (subKey=='') ) {
		return (false);
	} else {
		return (true);
	}
} 

function onVideoLoad(evt) {

    modVP.loadVideo(evt.video.id);
}

*/
