﻿/********************
*					*
*  Solution Popup	*
*					*
********************/
var movieWidth = 480;
var movieHeight = 270;

function LoadPopupImage(url) {
	LoadMoviePopup();
	var html = '<img src=\"' + url + '\" alt=\"\" />';

	$('div.MoviePopupContentDiv').html(html);
};

function LoadMovie(url) {
	LoadMoviePopup();
	var html = '<object id=\"player\" name=\"player\" width=\"' + movieWidth + '\" height=\"' + movieHeight + '\"><param name=\"movie\" value=\"flashs/mediaplayer.swf\" /><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"flashvars\" value=\"file=' + url + '&stretching=fill\" /><embed type=\"application/x-shockwave-flash\" id=\"player2\" name=\"player2\" src=\"flashs/mediaplayer.swf\" width=\"' + movieWidth + '\" height=\"' + movieHeight + '\" allowscriptaccess=\"always\" allowfullscreen=\"true\" flashvars=\"file=' + url + '&stretching=fill\" /></object>';

	$('div.MoviePopupContentDiv').html(html);
};

function LoadYoutubeMovie(vclId, videoKey) {
	LoadChannelVideoHtml(vclId, videoKey, function (data) {
		LoadMoviePopup();
		var response = eval(data);
		$('div.MoviePopupContentDiv').html(response.d);
	});
};

function LoadChannelVideoHtml(vclId, videoKey, callback) {
	$.ajax({
		type: "POST",
		contentType: "application/json; charset=utf-8",
		url: 'Index.aspx/GetChannelVideoHTML',
		data: "{'vclId':'" + vclId + "', 'videoKey':'" + videoKey + "', 'width':'" + movieWidth + "', 'height':'" + movieHeight + "'}",
		success: function (data) {
			if (typeof (callback) === "function") {
				callback(data);
			}
		}
	});
};

function LoadDetailImagePopup(htmlLeft, htmlRight) {
	$('.DetailImagePopupImageTd').html(htmlLeft);
	$('.DetailImagePopupContentTd').html(htmlRight);

	LoadPopup('.DetailImagePopupDiv');
	$(".CloseDetailImagePopupImage").click(function () {
		DisablePopup('.DetailImagePopupDiv');
	});
};

function LoadMoviePopup() {
	LoadPopup('.MoviePopupDiv');

	$(".CloseMoviePopupImage").click(function () {
		DisablePopup('.MoviePopupDiv');
	});
};

function LoadPopup(popupSelector) {
	//loads popup only if it is disabled
	if ($("#backgroundPopup:visible").size() <= 0) {
		if ($(popupSelector).size() > 0) {
			var $popupDiv = $(popupSelector);
			//Click out event!
			$("#backgroundPopup").click(function () {
				DisablePopup(popupSelector);
			});
			//Press Escape event!
			$(document).keypress(function (e) {
				if (e.keyCode == 27 && $("#backgroundPopup:visible").size() > 0) {
					DisablePopup(popupSelector);
				}
			});


			if (IE6) {
				var top = $("#backgroundPopup").parent().offset().top;
				top = top > 0 ? top * -1 : 0;
				var left = $("#backgroundPopup").parent().offset().left;
				left = left > 0 ? left * -1 : 0;

				$("#backgroundPopup").css({
					//'z-index': 1,
					'width': ($(window).width() - 2) + 'px',
					'height': ($(window).height() - 2) + 'px',
					'top': top + 'px',
					'left': left + 'px'
				});

				$popupDiv.css({
					'top': ($(window).height() / 2) + 'px'
				});
			}

			$("#backgroundPopup").css({
				"opacity": "0.8"
			});

			CenterPopup(popupSelector);
			$("#backgroundPopup").fadeIn("fast");
			$popupDiv.fadeIn('slow');
		}
	}
};

//centering popup
function CenterPopup(popupSelector) {
	if ($(popupSelector).size() > 0) {
		var $popupDiv = $(popupSelector);
		//request data for centering
		var windowWidth = $('#innerDiv').width();
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $popupDiv.innerHeight();
		var popupWidth = $popupDiv.innerWidth();

		var marginTestVert = ($popupDiv.innerHeight()) / 2;
		var marginTestHor = ($popupDiv.innerWidth()) / 2;

		//centering
		$popupDiv.css({
			"top": ($(window).scrollTop() + 75) + 'px',
			"margin-left": -marginTestHor
		});
		//only need force for IE6

		$("#backgroundPopup").css({
			"height": "100%"
		});
	}
};

function DisablePopup(popupSelector) {
	if ($(popupSelector).size() > 0) {
		var $popupDiv = $(popupSelector);
		//disables popup only if it is enabled
		if ($("#backgroundPopup:visible").size() > 0) {
			$popupDiv.fadeOut('fast');
			$("#backgroundPopup").fadeOut("slow");
		}
	}
};
