﻿$(document).ready(function() {
    var title;
    var element;
    $(".dialogbox").click(function(){
        //alert(title + " and " + element);
        $("div.ui-dialog, div#dialogContainer").remove();
        if(element != null){
            element.html(title);
        }
        var relval = $(this).attr("rel").toLowerCase();
        var doctorVideoTitle = $(this).attr("title");
        var width = 10;
        var height = 200;
        if(relval != null && relval.indexOf('x') > 0)
        {
            var wnh = relval.split("x");
            width = parseInt(wnh[0]);
            height = parseInt(wnh[1]);
        }
        element=$(this);
         if (doctorVideoTitle == null )
         {
           title = $(this).html();
           
        }
        else
        {
            title = doctorVideoTitle  ;
           }
        
        var source = $(this).attr("href");
                
        createMyDivContainer(element, 'dialogContainer', title);
        var iframew = width - 40;
        var iframeh = height - 65;
	    generateMyIFrame('#dialogContainer', 'myModalContact', source, iframew, iframeh);
	    showMyDialog('#dialogContainer', width, height);
        return false;
    });
    
    $(".closeDialogbox").click(function(){
         title = $(this).html();
        parent.closedialog();
        return false;
    });
    
    $(".closeNgo").click(function(){
        if($(this).attr("href") != null)
        {
            closeNgo($(this).attr("href"));
        }
    });
    
});

function closeNgo(targetUrl)
{
    parent.location.href = targetUrl;
}

function showMyDialog(identifier, modalWidth, modalHeight) {
	$(identifier).dialog('destroy');
	$(identifier).dialog({			  
		modal: true,
		height: modalHeight,
		width: modalWidth
	});
}
function createMyDivContainer(trigger, divId, title) {
	trigger.append('<div id="' + divId +  '" title="' + title + '"></div>');
	$('#' + divId).hide();
}
function generateMyIFrame(containerID, iframeID, srcPath, width, height) {
	// Create basic container
	$(containerID).append('<iframe id="' + iframeID + '" marginwidth="0" marginheight="0" scrolling="no" frameborder="0">Your browser does not support iframes</iframe>');
	
	// Add attributes
	$('#' + iframeID).attr('src', srcPath);
	$('#' + iframeID).attr('width', width);
	$('#' + iframeID).attr('height', height);
}

function closedialog()
{
    $("#dialogContainer").dialog('close');
}
