$(document).ready(function()
{
	// Details popup boxes
	$('[id^="detailbox"]').click(function() 
	{
		var buttonId = $(this).attr("id");
		var detail_type = buttonId.substr(10, (buttonId.length-10));
			
		$('#details_dialog').dialog({ autoOpen:false, resizable:false, modal:true,  width:450, close:function() {
            $('#details_dialog').dialog('destroy');	
        }});
			
	   $('#details_dialog').dialog('open');
			
	   loadVideoDemo("/frm/includes/product_tools_info.php?pd_lvl={/literal}{$level}{literal} #"+detail_type);
    });
		
    $('#showTopics').click(function() 
    {
    	var dialogId = $(this).attr("boxName");
    			
    	$("[id='"+dialogId+"']").dialog({ autoOpen:false, resizable:true, modal:true, width:450 }).dialog("open");
    
    	return false;
    });
		
    $('#cycle_images').cycle({
    	fx:'fade',
    	timeout:8000
    });
		
    // Additional Tools popups
    $('[id^="detshow"]').click(function() 
    {
        var pid = $(this).attr('id').substr(8);
        var lvl = $(this).attr('lev');
        var year = $(this).attr('yr');
        var addButton = '';
                
        $('#packDescHolder').dialog(
        {
            autoOpen:false,
            resizable:true,
            modal:true,
            width:712,
            height:355,
            close:function()
            {
    			$('#packDescHolder').dialog('destroy');
    		}
        });
                
        document.getElementById("packDescHolderInner").innerHTML = '<p>Loading...<br /></p>';
               
        $('#packDescHolder').dialog('open');
        $("#packDescHolderInner p").load("/frm/includes/package_details.php?p="+pid+"&l="+lvl+"&y="+year+" #packDesc");
    
        document.getElementById("packDescHolderButtons").innerHTML = addButton;
                
        $("#packDescHolder").dialog('option', 'position', "center");	
        
        return false;
    });	
});

function loadVideoDemo(page) 
{
    document.getElementById("details_dialog").innerHTML = '<p>Loading...<br /><img src=\"/images/buttons/loading.gif\" alt=\"Loading...\" /></p>';
		
    $("#details_dialog p").load(page, null, function() 
    {
        // Destroy and recreate the box incase we have any video boxes open
		$('#details_dialog').dialog({ autoOpen:false, resizable:false, modal:true,  width: 450, close:function(ev, ui) {
            $('#details_dialog').dialog('destroy'); // Removes the Audio from IE on Close - whether pressing ESC or clicking Close :)
        }});	
			
        $('#details_dialog').dialog('open');
		$("#details_dialog").dialog('option', 'position', "center");	
		    
		// When weekly online demo link is clicked
		$('#demo_link_weeklyonline1').click(function() 
		{
            $('#weekly_online_program_info').fadeOut('fast');
			$('div.ui-dialog').animate(
			{
				height:550, 
				width:624, 
				"marginLeft": ($(window).width()/(-22)) + 'px',
				"marginTop": (($(window).height()/(-5))-($(this).height()/2)) + 'px'
			},function()
			{
				document.getElementById("details_dialog").innerHTML = '<p align="center" style="padding-top:15px;">Loading...<br /><img src=\"/images/buttons/loading.gif\" alt=\"Loading...\" /></p>';
					
				$("#details_dialog").load("/frm/info/weekly_online_demo.php?new_level=frm_2m", null, function() 
				{
					$('#weekly_online_program_info').click(function() 
					{
						$('#weekly_online_program_info').fadeIn('fast');
							
						var returnId = $(this).attr("id");
						var buttonId = $(this).attr("id");
						var detail_type = buttonId.substr(0, (buttonId.length-0));
							
						loadVideoDemo("/frm/includes/product_tools_info.php?pd_lvl={/literal}{$level}{literal} #"+detail_type);
							
						$('div.ui-dialog').animate(
						{
							height:160, 
							width:450, 
							"marginLeft": ($(window).width()/(-200)) + 'px',
							"marginTop": (($(window).height()/16)-($(this).height()/2)) + 'px'
						});
							
						return false;
					});
				});
					
				return false;
			});
				
			$("#details_dialog").dialog('option', 'position', "center");
				
			return false;
	   	});

        // When schweserpro qbank is clicked
        $('#demo_link_schweserproQbank').click(function()
        {
            $('#schweserproQbank_program_info').fadeOut('fast');
			$('div.ui-dialog').animate(
			{
				height:550, 
				width:624, 
				"marginLeft": ($(window).width()/(-22)) + 'px',
				"marginTop": (($(window).height()/(-5))-($(this).height()/2)) + 'px'
			},function()
			{
				document.getElementById("details_dialog").innerHTML = '<p align="center" style="padding-top:15px;">Loading...<br /><img src=\"/images/buttons/loading.gif\" alt=\"Loading...\" /></p>';
					
				$("#details_dialog").load("/frm/info/schweserproQbank_demo.php?new_level=frm_2m", null, function() 
				{
					$('#schweserproQbank_program_info').click(function() 
					{
						$('#schweserproQbank_program_info').fadeIn('fast');
							
						var returnId = $(this).attr("id");
						var buttonId = $(this).attr("id");
						var detail_type = buttonId.substr(0, (buttonId.length-0));
							
						loadVideoDemo("/frm/includes/product_tools_info.php?pd_lvl={/literal}{$level}{literal} #"+detail_type);
							
						$('div.ui-dialog').animate(
						{
							height:360, 
							width:450, 
							"marginLeft": ($(window).width()/(-200)) + 'px',
							"marginTop": (($(window).height()/16)-($(this).height()/2)) + 'px'
						});
							
						return false;
					});
				});
					
				return false;
			});
				
			$("#details_dialog").dialog('option', 'position', "center");
				
			return false;
	   	});


        // When InstructorLink is clicked
	$('#demo_link_instructorLink').click(function()
        {
            $('#instructorLink_program_info').fadeOut('fast');

            $('div.ui-dialog').animate(
            {
                height:550,
                width:624,
                "marginLeft": ($(window).width()/(-22)) + 'px',
                "marginTop": (($(window).height()/(-5))-($(this).height()/2)) + 'px'
            },function()
            {
                document.getElementById("details_dialog").innerHTML = '<p>Loading...<br /><img src=\"/images/buttons/loading.gif\" alt=\"Loading...\" /></p>';

                $("#details_dialog").load("/frm/info/instructorLink_demo.php?new_level=frm_1m", null, function()
                {
                    $('#instructorLink_program_info').click(function()
                    {
                        $('#instructorLink_program_info').fadeIn('fast');

                        var returnId = $(this).attr("id");
                        var buttonId = $(this).attr("id");
                        var detail_type = buttonId.substr(0, (buttonId.length-0));

                        loadVideoDemo("/frm/includes/product_tools_info.php?pd_lvl={/literal}{$level}{literal} #"+detail_type);

                        $('div.ui-dialog').animate(
                        {
    						height:160,
    						width:450,
                            "marginLeft": ($(window).width()/(-200)) + 'px',
                            "marginTop": (($(window).height()/16)-($(this).height()/2)) + 'px'
                        });

                        return false;
                    });
                });

                return false;
            });

            $("#details_dialog").dialog('option', 'position', "center");

            return false;
        });


    });
		
	return false;
}

function closeMe()
{
    $('#packDescHolder').dialog('close');
}

