/*** Copy Right Information ***
  * Please do not remove following information.
  * Author: Nguyen Thanh Duong, Ikkosha co., Osaka, Japan
  * Email: duong@ikkosha.co.jp
  * 
  * You are welcome to modify the codes as long as you include this copyright information.
 *****************************/
 
var popupWidth = 600;
var popupWidthEx = 728;
var popupHeight = 380;
var orgVideoLeft, orgVideoTop;

var soVideo;
var soVideoEx;
var timeDelay = 500;

$(document).ready(function(){

	soVideo = new SWFObject("js/mediaplayer.swf","flvplayer","400","320","8.0", "#FFFFFF");
	soVideo.addParam("allowfullscreen","true");
	soVideo.addParam("quality", "high");
	soVideo.addParam("menu", "false");
	soVideo.addVariable("showstop","true");
	soVideo.addVariable("autostart","true");
	soVideo.addVariable('width', '400');
	soVideo.addVariable('height', '320');
	soVideo.addVariable('displayheight', '300');
	createVideo();

	soVideoEx = new SWFObject("js/mediaplayer.swf","flvplayer","528","320","8.0", "#FFFFFF");
	soVideoEx.addParam("allowfullscreen","true");
	soVideoEx.addParam("quality", "high");
	soVideoEx.addParam("menu", "false");
	soVideoEx.addVariable("showstop","true");
	soVideoEx.addVariable("autostart","true");
	soVideoEx.addVariable('width', '528');
	soVideoEx.addVariable('height', '320');
	soVideoEx.addVariable('displayheight', '300');
	createVideoEx();

	if (document.layers) { // Netscape
		document.captureEvents(Event.MOUSEMOVE);
	    document.onmousemove = captureMousePosition;
	} else if (document.all) { // Internet Explorer
		document.onmousemove = captureMousePosition;
	} else if (document.getElementById) { // Netcsape 6
		document.onmousemove = captureMousePosition;
	}
});

function showVideoPopup(videoIdx) {
	if (!videoIdx) return;

	if (!videoData[videoIdx]) {
		alert('Video not found !');
		return;
	}
	ModalPopup(videoData[videoIdx], 
		{AddLeft:100, AddTop:-50, BackgroundColor:999999, 
		 Title: videoTitle[videoIdx], 
		 Profile:'<span class=\'videotitle\'>MBA <br>Video Message</span><hr/>' + videoInfo[videoIdx]});
}

var movingVideo = false;
var moveMode = false;
var offsetX, offsetY;
var newTop, newLeft;

function createVideo() {
	$('body').append('<div id="video" style="position:absolute;display:none;overflow:none">' +
					 '<table cellspacing="0" cellpadding="0"><tr>' + 
					 '<td width="' + popupWidth + '" height="' + popupHeight + '" background="http://gmba.doshisha.ac.jp/img/video.gif" valign="top">' +
					 '<table width="100%" cellspacing="0" cellpadding="0">' +
					 '<tr>' +
					 '	<td width="20"></td>' +
					 '	<td id="vtitle" align="left" width="410" height="40" class="videotitle" valign="middle">Video Title</td>' +
					 '	<td align="right" width="170" class="videotitle">' +
					 '    <img id="closevideo" src="http://gmba.doshisha.ac.jp/img/close.gif" border="0" alt="Close"></td>' +
					 '</tr>' +
					 '<tr>' +
					 '	<td width="20"></td>' +
					 '	<td align="left" valign="top" width="410" height="320">' +
					 '    <div id="playerContainer" style="width:400px;height:320px;overflow:none" align="left">' +
					 '      <a href="http://www.macromedia.com/go/getflashplayer" target="_blank">' +
					 '      Get the Flash Player</a> to see this player.' +
					 '    </div></td>' +
					 '	<td id="vinfo" valign="top" align="left" width="150"></td>' +
					 '</tr>' +
					 '</table>' +
					 '</td></tr></table>' +
					 '</div>');
					 
	$('#video').bind('selectstart', function() {
		return false;
	}).mouseout(function(){
		movingVideo = false;
		$(this).css("cursor", "arrow");
	}).mousedown(function(){
		movingVideo = true;
		offsetX = xMousePos - newLeft;
		offsetY = yMousePos - newTop;
	}).mouseup(function(){
		movingVideo = false;
	}).mousemove(function(){
		$(this).css("cursor", "move");
		if (movingVideo) {
			newLeft = xMousePos - offsetX;
			newTop = yMousePos - offsetY;
			$('#video').css("left", newLeft + "px");
			$('#video').css("top", newTop + "px");
		}
	});
	
	$('#closevideo').click(function() {
		ModalPopup.Close();
	}).mousemove(function(){
		$(this).css("cursor", "pointer");
		$(this).attr("src", "http://gmba.doshisha.ac.jp/img/close2.gif");
	}).mouseout(function(){
		$(this).css("cursor", "arrow");
		$(this).attr("src", "http://gmba.doshisha.ac.jp/img/close.gif");
	});
}

/*** Copy Right Information ***
  * Please do not remove following information.
  * Modal Popup v1.0
  * Author: John J Kim
  * Email: john@frontendframework.com
  * URL: www.FrontEndFramework.com
  * 
  * You are welcome to modify the codes as long as you include this copyright information.
 *****************************/
 
// With the window size & the element size functions built-in

ModalPopup = function (videofile, options) {
	//option default settings
	options = options || {};
	var HasBackground = (options.HasBackground!=null)?options.HasBackground:true;
	var BackgroundColor = options.BackgroundColor || '000000';
	var BackgroundOpacity = options.BackgroundOpacity || 60; // 1-100
	BackgroundOpacity = (BackgroundOpacity > 0) ? BackgroundOpacity : 1;
	var BackgroundOnClick = options.BackgroundOnClick || function(){};
	var BackgroundCursorStyle = options.BackgroundCursorStyle || "default";
	var Zindex = options.Zindex || 300; // 90000;
	var AddLeft = options.AddLeft || 0;
	var AddTop = options.AddTop || 0;
	var Profile = options.Profile || '';
	var Title = options.Title || '';

	var winW = (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
	var winH = window.innerHeight ? window.innerHeight :(document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));

	var popup = document.getElementById('video');
	if (!popup) {return;}

	newTop = (winH -  popupHeight) / 2 + AddTop + $(document).scrollTop();
	newLeft = (winW - popupWidth) / 2 + AddLeft + $(document).scrollLeft();

	orgVideoLeft = xMousePos - 30;
	orgVideoTop = yMousePos - 20;

	popup.style.left = orgVideoLeft + "px";
	popup.style.top = orgVideoTop + "px";
	popup.style.width = "60px";
	popup.style.height = "40px";

	popup.style.zIndex = Zindex + 1;
	popup.style.display = "block";

	if (HasBackground) {		
		if (!ModalPopup._BackgroundDiv) {
			ModalPopup._BackgroundDiv = document.createElement('div');
			ModalPopup._BackgroundDiv.id = "div_background";
			ModalPopup._BackgroundDiv.style.display = "none";
			ModalPopup._BackgroundDiv.style.width = winW;
			ModalPopup._BackgroundDiv.style.position = "absolute";
			ModalPopup._BackgroundDiv.style.top = "0px";
			ModalPopup._BackgroundDiv.style.left = "0px";
			document.body.appendChild(ModalPopup._BackgroundDiv);
		}
		ModalPopup._BackgroundDiv.onclick =  BackgroundOnClick;
		ModalPopup._BackgroundDiv.style.background = BackgroundColor;	
		ModalPopup._BackgroundDiv.style.height = document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0)) + "px";
		ModalPopup._BackgroundDiv.style.zIndex = Zindex;
		ModalPopup._BackgroundDiv.style.cursor = BackgroundCursorStyle;

		ModalPopup._BackgroundDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + BackgroundOpacity +")";
		ModalPopup._BackgroundDiv.style.opacity =  BackgroundOpacity / 100;
		ModalPopup._BackgroundDiv.style.MozOpacity = BackgroundOpacity / 100;

	}

	$('#vtitle').html(Title);
	$('#vinfo').html(Profile);

	$(popup).animate({
		left: newLeft + "px",
		top: newTop + "px",
		width: popupWidth + "px",
		height: popupHeight + "px"
	    }, timeDelay, function() {
			soVideo.addVariable("file", videofile);
			soVideo.write("playerContainer");
	});

	$('#div_background').fadeIn("slow");
}

ModalPopup.Close = function() {
	var popup = document.getElementById("video");
	if (!popup) {return;}
	
	soVideo.addVariable("file", "");
	soVideo.write("playerContainer");

	$(popup).animate({
		left: orgVideoLeft + "px",
		top: orgVideoTop + "px",
		width: "60px",
		height: "40px"
		}, timeDelay, function() {
			var vsource = document.getElementById("playerContainer");
			if (!vsource) {return;}
			vsource.src = '<a href="http://www.macromedia.com/go/getflashplayer" target="_blank">' +
						  'Get the Flash Player</a> to see this player.';
			popup.style.display = "none";
	});

	if  (ModalPopup._BackgroundDiv) {
		$('#div_background').fadeOut("slow");
	}
}

xMousePos = 0;		// Horizontal position of the mouse on the screen
yMousePos = 0;		// Vertical position of the mouse on the screen
xMousePosMax = 0;	// Width of the page
yMousePosMax = 0;	// Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

/**********************
  VideoEx (528 x 300)
 **********************/

function showVideoPopupEx(videoIdx) {
	if (!videoIdx) return;

	if (!videoData[videoIdx]) {
		alert('Video not found !');
		return;
	}
	ModalPopupEx(videoData[videoIdx], 
		{AddLeft:30, AddTop:-50, BackgroundColor:999999, 
		 Title: videoTitle[videoIdx], 
		 Profile:'<span class=\'videotitle\'>MBA <br>Video Message</span><hr/>' + videoInfo[videoIdx]});
}

function createVideoEx() {
	$('body').append('<div id="videox" style="position:absolute;display:none;overflow:none">' +
					 '<table cellspacing="0" cellpadding="0"><tr>' + 
					 '<td width="' + popupWidthEx + '" height="' + popupHeight + '" background="http://gmba.doshisha.ac.jp/img/videox.gif" valign="top">' +
					 '<table width="100%" cellspacing="0" cellpadding="0">' +
					 '<tr>' +
					 '	<td width="20"></td>' +
					 '	<td id="vtitlex" align="left" width="538" height="40" class="videotitle" valign="middle">Video Title</td>' +
					 '	<td align="right" width="170" class="videotitle">' +
					 '    <img id="closevideox" src="http://gmba.doshisha.ac.jp/img/close.gif" border="0" alt="Close"></td>' +
					 '</tr>' +
					 '<tr>' +
					 '	<td width="20"></td>' +
					 '	<td align="left" valign="top" width="538" height="320">' +
					 '    <div id="playerContainerx" style="width:528px;height:320px;overflow:none" align="left">' +
					 '      <a href="http://www.macromedia.com/go/getflashplayer" target="_blank">' +
					 '      Get the Flash Player</a> to see this player.' +
					 '    </div></td>' +
					 '	<td id="vinfox" valign="top" align="left" width="150"></td>' +
					 '</tr>' +
					 '</table>' +
					 '</td></tr></table>' +
					 '</div>');
					 
	$('#videox').bind('selectstart', function() {
		return false;
	}).mouseout(function(){
		movingVideo = false;
		$(this).css("cursor", "arrow");
	}).mousedown(function(){
		movingVideo = true;
		offsetX = xMousePos - newLeft;
		offsetY = yMousePos - newTop;
	}).mouseup(function(){
		movingVideo = false;
	}).mousemove(function(){
		$(this).css("cursor", "move");
		if (movingVideo) {
			newLeft = xMousePos - offsetX;
			newTop = yMousePos - offsetY;
			$('#videox').css("left", newLeft + "px");
			$('#videox').css("top", newTop + "px");
		}
	});

	$('#closevideox').click(function() {
		ModalPopupEx.Close();
	}).mousemove(function(){
		$(this).css("cursor", "pointer");
		$(this).attr("src", "http://gmba.doshisha.ac.jp/img/close2.gif");
	}).mouseout(function(){
		$(this).css("cursor", "arrow");
		$(this).attr("src", "http://gmba.doshisha.ac.jp/img/close.gif");
	});
}

ModalPopupEx = function (videofile, options) {
	//option default settings
	options = options || {};
	var HasBackground = (options.HasBackground!=null)?options.HasBackground:true;
	var BackgroundColor = options.BackgroundColor || '000000';
	var BackgroundOpacity = options.BackgroundOpacity || 60; // 1-100
	BackgroundOpacity = (BackgroundOpacity > 0) ? BackgroundOpacity : 1;
	var BackgroundOnClick = options.BackgroundOnClick || function(){};
	var BackgroundCursorStyle = options.BackgroundCursorStyle || "default";
	var Zindex = options.Zindex || 300; // 90000;
	var AddLeft = options.AddLeft || 0;
	var AddTop = options.AddTop || 0;
	var Profile = options.Profile || '';
	var Title = options.Title || '';

	var winW = (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
	var winH = window.innerHeight ? window.innerHeight :(document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));

	var popup = document.getElementById('videox');
	if (!popup) {return;}

	newTop = (winH -  popupHeight) / 2 + AddTop + $(document).scrollTop();
	newLeft = (winW - popupWidth) / 2 + AddLeft + $(document).scrollLeft();

	orgVideoLeft = xMousePos - 30;
	orgVideoTop = yMousePos - 20;

	popup.style.left = orgVideoLeft + "px";
	popup.style.top = orgVideoTop + "px";
	popup.style.width = "60px";
	popup.style.height = "40px";

	popup.style.zIndex = Zindex + 1;
	popup.style.display = "block";

	if (HasBackground) {		
		if (!ModalPopup._BackgroundDiv) {
			ModalPopup._BackgroundDiv = document.createElement('div');
			ModalPopup._BackgroundDiv.id = "div_background";
			ModalPopup._BackgroundDiv.style.display = "none";
			ModalPopup._BackgroundDiv.style.width = winW;
			ModalPopup._BackgroundDiv.style.position = "absolute";
			ModalPopup._BackgroundDiv.style.top = "0px";
			ModalPopup._BackgroundDiv.style.left = "0px";
			document.body.appendChild(ModalPopup._BackgroundDiv);
		}
		ModalPopup._BackgroundDiv.onclick =  BackgroundOnClick;
		ModalPopup._BackgroundDiv.style.background = BackgroundColor;	
		ModalPopup._BackgroundDiv.style.height = document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0)) + "px";
		ModalPopup._BackgroundDiv.style.zIndex = Zindex;
		ModalPopup._BackgroundDiv.style.cursor = BackgroundCursorStyle;

		ModalPopup._BackgroundDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + BackgroundOpacity +")";
		ModalPopup._BackgroundDiv.style.opacity =  BackgroundOpacity / 100;
		ModalPopup._BackgroundDiv.style.MozOpacity = BackgroundOpacity / 100;

	}

	$('#vtitlex').html(Title);
	$('#vinfox').html(Profile);

	$(popup).animate({
		left: newLeft + "px",
		top: newTop + "px",
		width: popupWidthEx + "px",
		height: popupHeight + "px"
	    }, timeDelay, function() {
			soVideoEx.addVariable("file", videofile);
			soVideoEx.write("playerContainerx");
	});

	$('#div_background').fadeIn("slow");
}

ModalPopupEx.Close = function() {
	var popup = document.getElementById("videox");
	if (!popup) {return;}
	
	soVideoEx.addVariable("file", "");
	soVideoEx.write("playerContainerx");

	$(popup).animate({
		left: orgVideoLeft + "px",
		top: orgVideoTop + "px",
		width: "60px",
		height: "40px"
		}, timeDelay, function() {
			var vsource = document.getElementById("playerContainerx");
			if (!vsource) {return;}
			vsource.src = '<a href="http://www.macromedia.com/go/getflashplayer" target="_blank">' +
						  'Get the Flash Player</a> to see this player.';
			popup.style.display = "none";
	});

	if  (ModalPopup._BackgroundDiv) {
		$('#div_background').fadeOut("slow");
	}
}
