$(function() {

	$('a.modal-link').colorbox({
		speed:200,
		initialWidth:512,
		initialHeight:490,
		scrolling:false,
		close:'',
		onOpen:modalFix,
		onComplete:modalOpen,
		onCleanup:modalCleanup
	});

	$('a.modal-map').colorbox({
		speed:200,
		initialWidth:640,
		initialHeight:520,
		innerWidth:640,
		innerHeight:520,
		scrolling:false,
		close:'',
		onOpen:modalFix,
		onComplete:modalMapOpen,
		onCleanup:modalCleanup
	});

	$('a.modal-video').colorbox({
		speed:200,
		initialWidth:512,
		initialHeight:430,
		innerWidth:512,
		innerHeight:430,
		scrolling:false,
		close:'',
		onOpen:modalFix,
		onComplete:modalVideoOpen,
		onCleanup:modalVideoClose
	});

	$('a.modal-video').click(function() {
		var url = $(this).attr('href');
		cId = getUrlParam('cId',url);
		vId = getUrlParam('vId',url);
		vHeight = getUrlParam('vHeight',url);
	});

});

function modalFix()
{
	$('#cboxWrapper').css('visibility', 'hidden');
	if ($('#cboxClose > #cboxMiddleRight').length > 0)
	{
		return;
	}
	var closebtn = $('#cboxClose');
	closebtn.appendTo($('#cboxMiddleRight'));
	closebtn.attr('display:block');
}

function modalOpen()
{
	$('#cboxWrapper').css('visibility', 'visible');
	if (typeof(DD_belatedPNG) == 'object')
	{
		DD_belatedPNG.fix('#cboxTopLeft, #cboxTopCenter, #cboxTopRight, #cboxBottomLeft, #cboxBottomCenter, #cboxBottomRight, #cboxMiddleLeft, #cboxMiddleRight');
	}
}

function modalCleanup()
{
	$('#cboxWrapper').css('visibility', 'hidden');
}

function modalMapOpen()
{
	modalOpen();
	var flashvars_modal = {}; 
	var params_modal = {};
	params_modal.play = "true";
	params_modal.loop = "false";
	params_modal.quality = "high";
	params_modal.bgcolor = "#ffffff";
	params_modal.allowscriptaccess = "sameDomain";
	params_modal.allowfullscreen = "false";
	var attributes_modal = {};
	swfobject.embedSWF("/group/map/map5.swf", "map-container", "640", "447", "9.0.45", "/map/expressInstall.swf", flashvars_modal, params_modal, attributes_modal);
}

function modalVideoOpen()
{
	modalOpen();
	var flashvars_modal = {}; 
	flashvars_modal.catalogId = cId;
	flashvars_modal.videoId = vId;    
	flashvars_modal.autoPlay = "false";
	flashvars_modal.autoRewind = "false";
	flashvars_modal.showPreview = "true";
	flashvars_modal.localeChain = "en_US";
	flashvars_modal.remoteUrl = "http://www.goodmoodtv.com/internettv/application/itella";
	var params_modal = {};
	params_modal.play = "true";
	params_modal.loop = "false";
	params_modal.quality = "high";
	params_modal.bgcolor = "#000000";
	params_modal.allowscriptaccess = "always";
	params_modal.allowfullscreen = "true";
	params_modal.wmode = "transparent";
	params_modal.base = "http://www.goodmoodtv.com/internettv/application/itella/system/";    
	var attributes_modal = {};
	attributes_modal.id = "InternetTV";
	attributes_modal.name = "InternetTV";
	flashHeight = 430;
	if (vHeight != '')
	{
		flashHeight = vHeight;
	}
	// swfobject.embedSWF("http://www.goodmoodtv.com/internettv/application/itella/system/SingleVideoPlayer.swf", "InternetTVDiv", "512", "490", "9.0.45", "http://www.goodmoodtv.com/internettv/application/itella/system/playerProductInstall.swf", flashvars_modal, params_modal, attributes_modal);
	swfobject.embedSWF("http://www.goodmoodtv.com/internettv/application/itella/system/SingleVideoPlayer.swf", "InternetTVDiv", "512", flashHeight, "9.0.45", "http://www.goodmoodtv.com/internettv/application/itella/system/playerProductInstall.swf", flashvars_modal, params_modal, attributes_modal);
	$("#modal-video").width(512).height(flashHeight);
	$.fn.colorbox.resize();
}

function modalVideoClose()
{
	modalCleanup();
	var itv = document.getElementById("InternetTV");
	if (itv && typeof(itv.closePlayer) == 'function')
	{
//		itv.closePlayer();
	}
}

function removePlayer()
{
	swfobject.removeSWF("InternetTV");
	$.fn.colorbox.close();
}

function getUrlParam(name, url)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( url );
	if (url == '')
	{
		var url = window.location.href;
	}
	if (results == null)
	{
		return "";
	}
	return results[1];
}

