$(function() {
			$('.create-user').click(function() {
			$('#dialog').dialog('destroy');
			$('#dialog').load("/forms/register_modal.php", function() {
			$('#dialog').dialog('open');
		});
		});
		
			$('.logon').click(function() {
			$('#dialog').dialog('destroy');
			$('#dialog').load("/forms/logon_modal.php", function() {
			$('#dialog').dialog('open');
		});
		});
		
			$('#edit-details').click(function() {
			$('#dialog').dialog('destroy');
			$('#dialog').load("/forms/change_details_modal.php", function() {
			$('#dialog').dialog('open');
		});
		});
		
			$('#change-password').click(function() {
			$('#dialog').dialog('destroy');
			$('#dialog').load("/forms/change_password_modal.php", function() {
			$('#dialog').dialog('open');
		});
		});

			$('#contact_us').click(function() {
			$('#dialog').dialog('destroy');
			$('#dialog').load("/dynamic_contact_us.php", function() {
			$('#dialog').dialog('open');
		});
		return false;
		});

			$('.add_comment').live('click', function() {
			var id=$(this).attr('rel');
			$('#dialog').dialog('destroy');
			$('#dialog').load("/dynamic_add_comment.php?id="+id, function() {
			$('#dialog').dialog('open');
		});
		return false;
		});

			$('.add_reply').live('click', function() {
			var id=$(this).attr('rel');
			$('#dialog').dialog('destroy');
			$('#dialog').load("/dynamic_add_reply.php?comments_id="+id, function() {
			$('#dialog').dialog('open');
		});
		return false;
		});

		$("a[href='/#contact_us']").attr('href', '#');
		$("a[href='/my_account.htm?action=change_password']").attr('href', '#');
	$("a[href='/my_account.htm?action=Register']").attr('href', '#');
	});
	
		var http_request = false;
	var duplicate_email=false;
	
	   function makeRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
     // http_request.onreadystatechange = alertContents;
      http_request.open('POST', url,true);
	  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

      
	  http_request.onreadystatechange = function() {//Call a function when the state changes.
	if(http_request.readyState == 4 && http_request.status == 200) {
		duplicate_email = http_request.responseText;
	}
}
http_request.send(parameters);
}

//   function alertContents() {
 //     if (http_request.readyState == 4) {
 //        if (http_request.status == 200) {
  //          //alert(http_request.responseText);
   //         duplicate_email = http_request.responseText;
    //     }
     // }
  // }
   
   function get(obj) {
      var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         
      }
     // makeRequest('get.php', getstr);
   }
   
   	function getRequest(url,parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
     // http_request.onreadystatechange = alertContents;
      http_request.open('GET', url + parameters, false);
      http_request.send(null);
	  
	  if (http_request.status == 200) {
            //alert(http_request.responseText);
           return http_request.responseText;
         }
	}
	


 (function($){
    var origContent = "";
    function loadContent(hash) {
	$.compassSessionUrl = '/session.php';
	var prev_section = $.sessionGet('prev_section');
        if(hash != "") {
            if(origContent == "") {
                origContent = $('#content').html();
            }
            window.scrollTo(0,0);
 $('#wait').show();

 	pWidth=$(".col1").width();
 				$(".col1").fadeOut("slow", function() {
				$('.col1').load('/dynamic_page.php?page='+hash+'&w='+pWidth, function() {
				
				$('h1').addClass('ui-state-active');
				$('h1').addClass('ui-widget-header');
				$('h1').addClass('ui-corner-top');
				$(".col1").fadeIn("slow");    
				
				var parts  = hash.split('/');

				if ((hash.indexOf( "courses" ) == -1) || (prev_section==""))
				{
					if ((hash.indexOf( "references" ) == -1) || (prev_section==""))
					{
				$(".col3").fadeOut("slow", function() {
				$(".col3").load('/dynamic_right_box.php?page='+hash, function()  {
					  $('h3').addClass('ui-state-active');
					  $('h3').addClass('ui-widget-header');
					  $('h3').addClass('ui-corner-top');
					  
					  $("#accordion").accordion({ 
	header: "h3",
	autoHeight: false,
	collapsible: true,
	active: false 
	});
	// Tabs
	$('#tabs').tabs();
					  $(".col3").fadeIn("slow", function() { $('#wait').hide(); });   
					  });
					});
				}
				$('#wait').hide();
				}
				
				else if ((hash.indexOf( "courses" ) != -1) && (prev_section != "courses"))
				{
				$(".col3").fadeOut("slow", function() {
				$(".col3").load('/dynamic_right_box.php?page='+hash, function()  {
					  $('h3').addClass('ui-state-active');
					  $('h3').addClass('ui-widget-header');
					  $('h3').addClass('ui-corner-top');
					  
					  $("#accordion").accordion({ 
	header: "h3",
	autoHeight: false,
	collapsible: true,
	active: false 
	});
	// Tabs
	$('#tabs').tabs();
					  $(".col3").fadeIn("slow", function() { $('#wait').hide(); });   
					  });
					});

				$('#wait').hide();
				}
				
				else if ((hash.indexOf( "references" ) != -1) && (prev_section != "references"))
				{
				$(".col3").fadeOut("slow", function() {
				$(".col3").load('/dynamic_right_box.php?page='+hash, function()  {
					  $('h3').addClass('ui-state-active');
					  $('h3').addClass('ui-widget-header');
					  $('h3').addClass('ui-corner-top');
					  
					  $("#accordion").accordion({ 
	header: "h3",
	autoHeight: false,
	collapsible: true,
	active: false 
	});
	// Tabs
	$('#tabs').tabs();
					  $(".col3").fadeIn("slow", function() { $('#wait').hide(); });   
					  });
					});

				$('#wait').hide();
				}
				
				else
				{
				$('#wait').hide();
				}
				
				});  
			});

return false		
        } else if(origContent != "") {
            $('#content').html(origContent);
        }

		}
	
    $(document).ready(function() {
            $.history.init(loadContent,{ unescape: "/" } );
			       			
			$(".fg-menu > li a").click(function(e){
				$.compassSessionUrl = '/session.php';
				var prev_section = $.sessionSet('prev_section','');
                    var url = $(this).attr('href');
                    url = url.replace(/^.*#/, '');
                    $.history.load(url);
                    return false;
                });
				
					$(".fg-menu-course-main > li a").live('click',function(e){ 
					$.compassSessionUrl = '/session.php';
					var prev_section = $.sessionSet('prev_section','');
                    var url = $(this).attr('href');
                    url = url.replace(/^.*#/, '');
                    $.history.load(url);
                    return false;
                });			
				
					$(".fg-menu-course > li a").live('click',function(e){  
                    var url = $(this).attr('href');
                    url = url.replace(/^.*#/, '');
                    $.history.load(url);
                    return false;
                });	

				$(".fg-menu-reference-main > li a").live('click',function(e){
				$.compassSessionUrl = '/session.php';
				var prev_section = $.sessionSet('prev_section','');				
                    var url = $(this).attr('href');
                    url = url.replace(/^.*#/, '');
                    $.history.load(url);
                    return false;
                });			
				
					$(".fg-menu-reference > li a").live('click',function(e){  
                    var url = $(this).attr('href');
                    url = url.replace(/^.*#/, '');
                    $.history.load(url);
                    return false;
                });	
				
					$(".course_nav").live('click',function(e){  
                    var url = $(this).attr('href');
                    url = url.replace(/^.*#/, '');
                    $.history.load(url);
                    return false;
                });	
				
					$("#portfolio").live('click',function(e){  
                    var url = $(this).attr('href');
					url=url+'.htm';
                    url = url.replace(/^.*#/, '');
                    $.history.load(url);
                    return false;
                });	
				
        $('.answer_div').hide();
	});
})(jQuery);

(function ($) {
	$.sessionGet = function(name) {	
		var ret;
		
		$.ajax({
			type: 'POST',
			async: false,
			url: $.compassSessionUrl,
			data: 'name='+name,
			dataType: 'text',
			success: function(msg) {
				ret = msg;
			}
		});
		
		return ret;
	}
	
	$.sessionSet = function(name, val) {
		$.ajax({
			type: 'POST',
			async: false,
			url: $.compassSessionUrl,
			data: 'name='+name+'&val='+val,
			dataType: 'text'
		});
	}

	$.compassSessionUrl = '';
})(jQuery);

// -----------------------------------------------------------------------
// Eros Fratini - eros@recoding.it
// jqprint 0.3
//
// - 19/06/2009 - some new implementations, added Opera support
// - 11/05/2009 - first sketch
//
// Printing plug-in for jQuery, evolution of jPrintArea: http://plugins.jquery.com/project/jPrintArea
// requires jQuery 1.3.x
//
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
//------------------------------------------------------------------------

(function($) {
    var opt;

    $.fn.jqprint = function (options) {
        opt = $.extend({}, $.fn.jqprint.defaults, options);

        var $element = (this instanceof jQuery) ? this : $(this);
        
        if (opt.operaSupport && $.browser.opera) 
        { 
            var tab = window.open("","jqPrint-preview");
            tab.document.open();

            var doc = tab.document;
        }
        else 
        {
            var $iframe = $("<iframe  />");
        
            if (!opt.debug) { $iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-600px", top: "-600px" }); }

            $iframe.appendTo("body");
            var doc = $iframe[0].contentWindow.document;
        }
        
        if (opt.importCSS)
        {
            if ($("link[media=print]").length > 0) 
            {
                $("link[media=print]").each( function() {
                    doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' media='print' />");
                });
            }
            else 
            {
                $("link").each( function() {
                    doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' />");
                });
            }
        }
        
        if (opt.printContainer) { doc.write($element.outer()); }
        else { $element.each( function() { doc.write($(this).html()); }); }
        
        doc.close();
        
        (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).focus();
        setTimeout( function() { (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).print(); if (tab) { tab.close(); } }, 1000);
    }
    
    $.fn.jqprint.defaults = {
		debug: false,
		importCSS: true, 
		printContainer: true,
		operaSupport: true
	};

    // Thanks to 9__, found at http://users.livejournal.com/9__/380664.html
    jQuery.fn.outer = function() {
      return $($('<div></div>').html(this.clone())).html();
    } 
})(jQuery);


