$(function(){
	
	// this part of the code deals with modal msg window.
	$("#modalmsg").showModalBox();
	
	$("#modal_ok").click(function(){
		$("#modalmsg").removeModalBox();
	});
	
	$('a.lightbox_youtube').livequery(function(){
		$(this).addClass('various iframe');
	});
	
	// enabling the lightbox
	$('a.show_lightbox, a.lightbox_youtube').livequery(function(){
		$(this).fancybox();
	});
});


function EnableDisable(chk_id){
	/* RULE: for making this work a checkbox needs to have a onclick handler set to EnableDisable("checkbox_id") and a class named 'enable_disable'. 
	 * then it will be able to activate or deactive the immediate follwing table. this could be achieved by adding a parameter 'enable_disable'=>1 
	 * upon the creation of the checkbox. and the whole table needs to
	 * be under a div which should have a class called "fade_area".
	 */
	div = $("#" + chk_id).parent().parent().find("div.fade_area");
	
	chkbox = $("#" + chk_id);
	
	if( !chkbox.is(':checked')){
		div.ghostBox(true);
	}else{
		div.ghostBox(false);
	}
}



jQuery.fn.ghostBox = function (fade_visible){

	if(fade_visible){
		$(this).css("position", "relative").css("opacity", 0.3);
		var winW 	= $(this).width();
		var winH 	= $(this).height();
		
		var fade = $("<div class='fade'></div>");
		fade.css("position", "absolute").css("top",0).css("left", 0).css("height", winH).css("width", winW ).css("z-index", 9999).css("opacity", 0.5);
		$(this).append(fade);
	}else{
		$(this).css("opacity", "1");
		$(this).find(".fade").remove();
	}
}

if (typeof jQuery.fromEvent == 'undefined')
{
    jQuery.fromEvent = function(e){
        if (e.target)
        {
            return $(e.target);
        }
        else if (e.srcElement)
        {
            return $(e.srcElement);
        }
        else
        {
            return $();
        }
    };
}

if (typeof jQuery.fn.clickLink == 'undefined')
{
    // Special event binding method that is aware of events
    jQuery.fn.clickLink = function(fn) {
        $(this).click(function(e){
            return handleLink(this, e, fn);
        });
    };
}

if (typeof handleLink == 'undefined')
{
    function handleLink(elem, event, fn)
    {
        if ( event && !event.originalEvent ) {
            event = jQuery.event.fix(event);
        }
        
        // If any modifier key is down, let the browser decide how to handle the click
        if (event.ctrlKey || event.altKey || event.shiftKey)
        {
            return; // returning undefined will let the browser continue as normal
        }
        
        // Regular click. Use the function
        try
        {
            return fn.apply(elem, [event]);
        }
        catch (err)
        {
            console.error(err);
            return false;
        }
    }
}

/**
 * Extend the implementation of val() so we can offer widget specific behaviors
 */
var rawVal = jQuery.fn.rawVal = jQuery.fn.val;
jQuery.fn.val = function(value) {
    
    // trigger an event
    var event = jQuery.Event("widgetval", { valarguments: arguments });
    event.stopPropagation(); // this event doesn't bubble to parents
    this.trigger(event);
    var ret = event.result;
    
    // If the event didn't do anything, 
    if (typeof ret == 'undefined')
    {
        // ret = this.__val_before_event_extension(value);
        ret = rawVal.apply(this, arguments);
    }
    
    return ret;
};

/**
 * Method for registering a widget specific val implementation.
 * 
 * @param fn - function(value, e){...}
 * 
 * if fn()'s arguments.length is 0, fn should return the value, otherwise it should
 * set the value.
 * 
 * TODO: Allow get/set object, like internal jQuery valHooks object
 */
jQuery.fn.widgetVal = jQuery.fn.valHook = function(fn) {
    this.bind('widgetval', function(e){
        return fn.apply(this, e.valarguments);
    });
};


jQuery.maxZIndex = function() {
    return $(window.document).maxZIndex();
};

/**
 * Contextual deferral until document ready
 */
jQuery.fn.documentReady = function (fn, args){
    if (typeof args == 'undefined')
    {
        args = [];
    }

    var self = this;
    $(function(){
        return fn.apply(self, args);
    });
    
    return this;
};

/**
 * eval from a context
 */
jQuery.fn.eval = function (s){
    var self = this;
    return eval.apply(this, [s]);
};

/**
 * If no inc is given, Returns the max zIndex of the set
 * 
 * if inc is nonzero, it is a relative increment to use to
 * set the zIndex.
 * 
 * group is an optional selector to use to filter the set
 * when searching for zIndex
 */
jQuery.fn.maxZIndex = function(inc, group) {
    if (typeof group == 'undefined')
    {
        group = '*';
    }

    var zmax = 0;
    $(this).find(group).each(function() {
        if ($(this).is(':visible')) // only consider visible stuff
        {
            var cur = parseInt($(this).css('z-index'));
            zmax = cur > zmax ? cur : zmax;
        }
    });

    // if no increment was given, just return
    if (typeof inc == 'undefined' || !inc)
    {
        return zmax;
    }

    // Parameter was given. Set the zIndex
    return this.each(function() {
        zmax += inc;
        $(this).css("z-index", zmax);
    });
};

/**
 * Basic shim for the "input" event. Emulates support in all browsers.
 * 
 * Original code from http://whattheheadsaid.com/projects/input-special-event
 */
(function($) {    
    // Handler for propertychange events only
    function propHandler () {
        var $this = $(this);
        if (window.event.propertyName == "value" && !$this.data("triggering.inputEvent")) {
            $this.data("triggering.inputEvent", true).trigger("input");
            window.setTimeout(function () {
                $this.data("triggering.inputEvent", false);
            }, 0);
        }
    }
    
    $.event.special.input = {
        setup: function(data, namespaces) {
            var timer,
                // Get a reference to the element
                elem  = this,
                // Store the current state of the element
                state = elem.value,
                // Create a dummy element that we can use for testing event support
                tester = document.createElement(this.tagName),
                // Check for native oninput
                oninput = "oninput" in tester || checkEvent(tester),
                // Check for onpropertychange
                onprop = "onpropertychange" in tester,
                // Generate a random namespace for event bindings
                ns = "inputEventNS" + ~~(Math.random() * 10000000),
                // Last resort event names
                evts = ["focus", "blur", "paste", "cut", "keydown", "drop", ""].join("."+ns+" ");

            function checkState () {
                var $this = $(elem);
                if (elem.value != state && !$this.data("triggering.inputEvent")) {
                    state = elem.value;

                    $this.data("triggering.inputEvent", true).trigger("input");
                    window.setTimeout(function () {
                        $this.data("triggering.inputEvent", false);
                    }, 0);
                }
            }
            
            // Set up a function to handle the different events that may fire
            function handler (e) {
                // When focusing, set a timer that polls for changes to the value
                if (e.type == "focus") {
                    checkState();
                    clearInterval(timer),
                    timer = window.setInterval(checkState, 250);
                }
                
                // When blurring, cancel the aforeset timer
                else if (e.type == "blur")
                    window.clearInterval(timer);
                
                // For all other events, queue a timer to check state ASAP
                else
                    window.setTimeout(checkState, 0);
            }
            
            // Bind to native event if available
            if (oninput)
                return false;
            
            // Else fall back to propertychange if available
            else if (onprop)
                $(this).find("input, textarea").andSelf().filter("input, textarea").bind("propertychange."+ns, propHandler);
            
            // Else clutch at straws!
            else
                $(this).find("input, textarea").andSelf().filter("input, textarea").bind(evts, handler);
            
            $(this).data("inputEventHandlerNS", ns);
        },
        teardown: function () {
            var elem = $(this);
            elem.find("input, textarea").unbind(elem.data("inputEventHandlerNS"));
            elem.data("inputEventHandlerNS", "");
        }
    };

    // Setup our jQuery shorthand method
    $.fn.input = function (handler) {
        return handler ? this.bind("input", handler) : this.trigger("input");
    };
    
    /*
       The following function tests the element for oninput support in Firefox.  Many thanks to
       http://blog.danielfriesen.name/2010/02/16/html5-browser-maze-oninput-support/
    */
    function checkEvent(el) {
        // First check, for if Firefox fixes its issue with el.oninput = function
        el.setAttribute("oninput", "return");
        if (typeof el.oninput == "function")
            return true;
        
        // Second check, because Firefox doesn't map oninput attribute to oninput property
        try {
            var e  = document.createEvent("KeyboardEvent"),
                ok = false,
                tester = function(e) {
                    ok = true;
                    e.preventDefault();
                    e.stopPropagation();
                };
            e.initKeyEvent("keypress", true, true, window, false, false, false, false, 0, "e".charCodeAt(0));
            document.body.appendChild(el);
            el.addEventListener("input", tester, false);
            el.focus();
            el.dispatchEvent(e);
            el.removeEventListener("input", tester, false);
            document.body.removeChild(el);
            return ok;
        } catch(e) {}
    }
})(jQuery);



////////////////////////////////// Modal Box Function ///////////////////////////////////////////////////////
jQuery.fn.showModalBox = function() {
	// Making the MaskBox for the modal box//////////
   if($(this).size() == 0){
		return false;	// no object has been found so nothing is done.
	}
	var mask    = $("<div id='mask'></div>");
	var winW 	= $(window).width();
	var winH 	= $(window).height();
    var scrollW = Math.max($('body').width(), $('html').width());
    var scrollH = Math.max(
        Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
        Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
        Math.max(document.body.clientHeight, document.documentElement.clientHeight)
    );
    var scrollT = $('body').scrollTop() + $('html').scrollTop();
    var scrollL = $('body').scrollLeft() + $('html').scrollLeft();
	mask.css("position", "absolute").css("background-color", "#000").css("top",0).css("left", 0).css("height", scrollH).css("width", scrollW ).css("z-index", 9999).css("opacity", 0.4).css("display", "none");
	
	
	

	//cloning the THIS Object and then removing it.......
	$(this).addClass("jquery_modal");
	var div_id = $(this).attr("id");
	var div_modal = $(this).clone();
	// we need a placeholder for putting the div back to where it originally belonged
	$(this).wrap('<div id="holder_of_' + div_id + '"></div>');
	$(this).remove();
	
	w = div_modal.css("width") == "" || div_modal.css("width") == "0px" ? "auto" : div_modal.css("width");
	h = div_modal.css("height") == "" || div_modal.css("height") == "0px"  ? "auto" : div_modal.css("height");
	

	
	div_modal.css("width", w).css("height", h).css("background", "url(images/new/modal_background.png) repeat-x top center").css("background-color", "#FFFFFF").css("display", "none").css("position", "absolute").css("z-index", 9999).css("padding","0 10px").css("border", "4px solid #D8D8D8").css({"-moz-border-radius": "15px", "-webkit-border-radius": "15px", "border-radius": "15px", "-moz-box-shadow": "5px 5px 5px #333333", "-webkit-box-shadow": "5px 5px 5px #333333", "box-shadow": "5px 5px 5px #333333"});
	var modalL 	= winW / 2;
	var modalT 	= winH / 2;

	
	
	
	
	//appending and showing all the divs...
	$("body").append(mask);
	$("body").append(div_modal);
	$("#mask").fadeIn(500);
	div_modal.fadeIn(500);
	
	//putting the div in the middle
	var modalW	= div_modal.width();
	var modalH	= div_modal.height();
	modalL		= parseInt(modalL - (modalW / 2)) + scrollL + "px";
	modalT		= parseInt(modalT - (modalH / 2)) + scrollT + "px";
	div_modal.css("top", modalT).css("left", modalL);
	dojo.parser.parse(dojo.byId(div_id));
	div_modal.move();
}



///// Removing Any Modal Box ////////////////////
jQuery.fn.removeModalBox = function( callback_function ){
	$(this).fadeOut(500, function(){
		// after the div fades out, we need to put it back to where it originally was
		var holder_id = 'holder_of_' + $(this).attr('id');
		var clone_box = $(this).clone();
		$(this).remove();
		$('#' + holder_id).replaceWith(clone_box);
	});
	$("#mask").fadeOut(500, function(){
		$("#mask").remove();
		if( typeof(callback_function) != 'undefined' ){
			callback_function();
		}
	});
}







////////// Some Other Common Function /////////



// this function is to select a value for a SELECT TAG.
jQuery.fn.valSelect = function( select ){
	
	this_id = $(this).attr("id");
	
	$("#" + this_id + " option").removeAttr("selected");
	//$("#" + this_id + 'option[value=" + training_type + "]').attr("selected", "selected"); this is supposed to work.. but somereason this doesnt.. so i changed to the following way....
	$("#" + this_id + " option[value=" + select + "]").attr("current","selected");

	var list_html 	= $("#" + this_id).html();
	list_html 		= list_html.replace(new RegExp( "current", "g" ), "selected");
	$("#" + this_id).html(list_html);
}








///////////// This Function Makes Any Window Move /////////////////////////

jQuery.fn.move = function(){

	//getting id, height, width and src....
	var this_id		= $(this).attr("id");	



	//setting all the variables....
	mouseState = "up";
	mouseX		= 0;
	mouseY		= 0;
	startX		= 0;
	startY		= 0;
	sTop		= 0;
	sLeft		= 0;
	

	$("#" + this_id).mousedown(function(e){	
		mouseState 	= (mouseState == 'up') ? "down" : mouseState;
		startX 		= e.pageX;
		startY 		= e.pageY;
		sTop		= parseInt($("#" + this_id).css("top"));
		sLeft		= parseInt($("#" + this_id).css("left"))

		$(document).css("cursor", "move");		
				
	});
	
	
	// put nodragg class on object which should not be dragble
	$("#" + this_id + " input, #" + this_id + " textarea, #" + this_id + " button, .nodrag").mousedown(function(e){
		mouseState = "ontextbox";
	});
	
	$(document).mousemove(function(e){
		
		if(mouseState == "down"){
			
			//rettriving values.....
			mouseX 	= e.pageX;
			mouseY 	= e.pageY;
			
			
			//calculating values....
			disX	= mouseX - startX;
			disY	= mouseY - startY;
			
			currX 	= sLeft + disX;
			currY 	= sTop + disY;
			
			$("#" + this_id).css("top", parseInt(currY) + "px").css("left", parseInt(currX) + "px");

			
		}
	});

	$(document).mouseup(function(){
		mouseState	= "up";
		$("#" + this_id).css("cursor", "default");
	});

};

  jQuery.print = function(){
      // TODO: Fire beforeprint event if there is no native browser support
      window.print();
      // TODO: Fire afterprint event if there is no native browser support
  };

  jQuery.fn.print = function(){
      $('body').addClass('printspecific');
      $(this).addClass('printtarget');
      // TODO: Fire beforeprint event if there is no native browser support
      window.print();
      // TODO: Fire afterprint event if there is no native browser support
      $('body').removeClass('printspecific');
      $(this).removeClass('printtarget');
      
  };

// Measure the dimensions of all images in the current jQuery array of elements:
// Optional: Specify deep=true to also measure dimensions of all images within the array of elements.
// Required: Provide a callback to receive the measurements. (This is necessary because images are loaded asynchronously)
// The callback will be triggered for every IMG in the jQuery array that has a "src" attribute.
// The callback is passed 2 params:
// - The first param is an object of {width,height,fileSize}.
// - The second param is the temporary IMG element that was used for measuring. (It gets destroyed after callback)
// Inside the callback you can use "this" to refer to the IMG element that was in the original jQuery array. 
// Note that fileSize can only be measured in IE. This value will be 0 in browsers that doe not support IMG.fileSize.
jQuery.fn.imgSize = function(deep,callback){

 callback = callback || deep;
 var $images = this.filter("IMG[src]");
 if(deep) $images.add( this.find("IMG[src]") );

 $images.each(function(){

  var origImg = this;
  var url = $(origImg).attr("src");

  $("<img>").load(function(){
   var $dummy = $(this), size = { width:$dummy.width(), height:$dummy.height(), fileSize:0 };
   try{ size.fileSize = parseInt($dummy.attr("fileSize")) || 0 }catch(e){};
   jQuery.isFunction(callback) && callback.apply( origImg, [size,this] );
   $dummy.remove();
  })
  // To be on the safe side, apply inline styles to prevent any css styles affecting our measurements:
  // (We use a try-catch workaround for IE7 because it raises errors when we try to set maxWidth/maxHeight)
  .css({ display:"none", width:"auto", height:"auto", minWidth:"auto", minHeight:"auto" })
  .each(function(){ try{ $(this).css({ maxWidth:"auto", maxHeight:"auto" }) }catch(e){}; })
  .addClass("imgSize-temp-img")
  .appendTo(document.body)    // The width/height would be zero if img is not added to DOM.
  .attr({ src:url });

 });

 return this;
};

// Cleans any Dojo widgets from the content (to prevent it from exploding)
$.fn.clearDojo = function()
{
    var $this = $(this);
    // It's very hard to destroy without leaving orphans. This code will take care
    // of any orphans at the same time as it destroys any widgets. This has various
    // other advantages in terms of stability.
    dijit.registry.forEach(function(widget, index, hash){
       // if we can find an element with the given ID, or if the element doesn't exist at all, destroy the widget
       if ($this.find('#'+widget.id).length || !$('#'+widget.id).length)
       {
           widget.destroy();
       }
    });
    return this;
}

// forces Dojo parsing of the element(s)
$.fn.parseDojo = function()
{
    $(this).each(function(idx, e){
        dojo.parser.parse(e);
    });
    return this;
}

$.fn.troonlineContentView = function()
{
    var $this = $(this);

    $this.parseDojo();

    $this.jargonize();
    
    $this.find('.box').each(function(){
    	if(!$(this).hasClass('timerequiredbox'))
    	{
	        if ($(this).find('.box-pointer-box').length == 0)
	        {
	            $(this).append($('<div class="box-pointer-box">'));
	        }
	        if ($(this).find('.bg-box').length == 0)
	        {
	            $(this).wrapInner('<div class="bg-box"/>');
	        }
	        $(this).find('img:not(.box-pointer-box)').imgSize(function(size){
	            var $this = $(this);
	            if ($this.width() < size.width)
	            {
	                // Image was scaled down. Add a lightbox effect when clicked.
	                $a_tag = $('<a href="' + $this.attr('src') + '" class="show_lightbox" />');
                	$this.wrap($a_tag);
	                
	                // Also add a class to indicate clickability
	                $this.addClass('img-lightbox');
	            }
	        });
    	}
    });

    // this part of the code deals with the Ghost Boxes seen on the dashboard..
    $(".ghost").each(function(index){
        
        $(this).ghostBox(true);
    });

    // this part is for enabling or disabling table of input field via checkbox.
    $(".enable_disable").each(function(){
        
        if($.browser.msie){
            chk_id = this.id;           
        }else{
            chk_id = $(this).find("input:first-child").attr("id");          
        }
        EnableDisable(chk_id);      
    });
};

$(function(){
    $('#centercontentpane .chapter').troonlineContentView();
});

$.fn.troonlineLeftNav = function()
{
    var $this = $(this);
    $this.find('.nav_sectiongroup .groupname a.custom').click(function(){
        var $section_group = $(this).closest('.nav_sectiongroup');
        var $sections = $section_group.find('.nav_sectiongroup_sections');
        $sections.toggle(300);
        return false;
    });
}

$(function(){
    $('#leftnavpane').troonlineLeftNav();
});

// https://gist.github.com/854622
(function(window,undefined){
    
    // Prepare our Variables
    var
        History = window.History,
        $ = window.jQuery,
        document = window.document;

    // Check to see if History.js is enabled for our Browser
    if ( !History.enabled ) {
        return false;
    }

    // Wait for Document
    $(function(){
        // Prepare Variables
        var
            /* Application Specific Variables */
            contentSelector = '#right-widget',
            /* Application Generic Variables */
            $body = $(document.body),
            rootUrl = History.getRootUrl(),
            State = History.getState(),
            stackIdx = State.data.stackIdx,
            stackTop = State.data.stackIdx,
            scrollOptions = {
                duration: 800,
                easing:'swing'
            };
        
        // Internal Helper
        $.expr[':'].internal = function(obj, index, meta, stack){
            // Prepare
            var
                $this = $(obj),
                url = $this.attr('href')||'',
                isInternalLink;
            
            // Check link
            isInternalLink = url.substring(0,rootUrl.length) === rootUrl || url.indexOf(':') === -1;
            
            // Ignore or Keep
            return isInternalLink;
        };
        
        // HTML Helper
        var documentHtml = function(html){
            // Prepare
            var result = String(html)
                .replace(/<\!DOCTYPE[^>]*>/i, '')
                .replace(/<(html|head|body|title|meta|script)([\s\>])/gi,'<div class="document-$1"$2')
                .replace(/<\/(html|head|body|title|meta|script)\>/gi,'</div>')
            ;
            
            // Return
            return result;
        };
        
        // Ajaxify Helper
        $.fn.ajaxify = function(){
            // Prepare
            var $this = $(this);
            
            // Ajaxify
            $this.find('a:internal:not(.no-ajaxy):not([href=#])').click(function(event){
                // Prepare
                var
                    $this = $(this),
                    url = $this.attr('href'),
                    title = $this.attr('title')||null;
                
                // Continue as normal for cmd clicks etc
                if ( event.which == 2 || event.metaKey ) { return true; }
                
                // Ajaxify this link
                stackTop = stackIdx; // pushState will truncate the stack
                History.pushState({stackIdx:stackIdx+1},title,url);
                event.preventDefault();
                return false;
            });
            
            // Chain
            return $this;
        };
        
        // Ajaxify our Internal Links
        $body.find('#leftnavpane').ajaxify();
        $body.find('#navigation-wrap').ajaxify();

        // Hook into State Changes
        $(window).bind('statechange',function(){
            // Prepare Variables
            var
                State = History.getState(),
                url = State.url,
                relativeUrl = url.replace(rootUrl,'');

            DoAjaxNavigateTo(State.data.stackIdx, url, State.data.params, State.data.options);
        }); // end onStateChange

        // Function to use for navigating
        window.AjaxNavigateTo = function (url, params, options){
            stackTop = stackIdx; // pushState will truncate the stack
            History.pushState({stackIdx: stackIdx+1, params: params, options: options},null,url);
        };

        // Function used to fulfil navigation
        function DoAjaxNavigateTo(idx, url, params, options){
            
            var $contentpane = $('#centercontentpane');

            // Parameter normalization and manipulation
            if (typeof params == 'undefined') {params = {}};
            if (typeof options == 'undefined') {options = {};}
            if (!jQuery.isArray(params))
            {
                if (typeof(params) != 'object') {params = {};}
                $.extend(params, {_x_ajax_navigate: true});
            }
            else
            {
                // the array method uses a series of objects instead. We have to extend it differently.
                params.push({name:"_x_ajax_navigate", value: true});
            }
    
            // Set Loading on the body
            $body.addClass('loading');
            
            // Determine what type of maneuver this is
            var navType = 'new';
            var navDirection = 1;
            var forceAnimation = undefined;
            idx = idx != undefined ? idx : 0; // treat undefined as 0 
            if (idx > stackTop)
            {
                // Inserting to the top of the stack
                navType = 'new';
                navDirection = 1;
            }
            else if (idx == stackIdx)
            {
                // Replacing the current index
                navType = 'replace';
                navDirection = 1;
            }
            else if (idx == stackIdx - 1)
            {
                // moving back
                navType = 'back';
                navDirection = -1;
                forceAnimation = 'slide-right';
            }
            else if (idx == stackIdx + 1)
            {
                // moving forward
                navType = 'forward';
                navDirection = 1;
                forceAnimation = 'slide-left';
            }
            
            // Update the stack information so that we can track this later as needed
            stackIdx = idx;
            if (navType == 'new')
            {
                stackTop = idx;
            }

            // Hide, with optional animation
            var animation = forceAnimation != undefined ? forceAnimation : options['animate'];
            if (animation == 'slide-left')
            {
                $contentpane.hide('slide', { direction: "left" }, 300);
            }
            else if (animation == 'slide-right')
            {
                $contentpane.hide('slide', { direction: "right" }, 300);
            }
            else if (animation == false)
            {
                $contentpane.hide();
            }
            else
            {
                $contentpane.fadeOut(800);
            }
            
            // Scroll to the top to better simulate a typical navigation experience
            $contentpane.parents().animate({ scrollTop: 0 }, 'slow');
    
            // Ajax Request the Traditional Page
            $.php(jQuery.extend({
                url: url,
                data: params,
                loading: false,
                success: function(data, textStatus, php){
                },
                error: function(xmlEr, typeEr, except, php){
                },
                complete: function (XMLHttpRequest, textStatus, php) {
                    // Remove the loading class
                    $body.removeClass('loading');
    
                    // Restore the content visibility with optional animation
                    var animation = forceAnimation != undefined ? forceAnimation : options['animate'];
                    if (animation == 'slide-left')
                    {
                        $contentpane.show('slide', { direction: "right" }, 300);
                    }
                    else if (animation == 'slide-right')
                    {
                        $contentpane.show('slide', { direction: "left" }, 300);
                    }
                    else if (animation == false)
                    {
                        $contentpane.show();
                    }
                    else
                    {
                        $contentpane.fadeIn(300);
                    }

                    // process the view as needed
                    $contentpane.find('.chapter').troonlineContentView();
                }
            }, options));
            
            /*
            // Ajax Request the Traditional Page
            $.ajax({
                url: url,
                success: function(data, textStatus, jqXHR){
                    // Prepare
                    var
                        $data = $(documentHtml(data)),
                        $dataBody = $data.find('.document-body:first'),
                        $dataContent = $dataBody.find(contentSelector).filter(':first'),
                        $menuChildren, contentHtml, $scripts;
                    
                    // Fetch the scripts
                    $scripts = $dataContent.find('.document-script');
                    if ( $scripts.length ) {
                        $scripts.detach();
                    }
    
                    // Fetch the content
                    contentHtml = $dataContent.html()||$data.html();
                    if ( !contentHtml ) {
                        document.location.href = url;
                        return false;
                    }
                    
                    // Update the menu
                    $menuChildren = $menu.find(menuChildrenSelector);
                    $menuChildren.filter(activeSelector).removeClass(activeClass);
                    $menuChildren = $menuChildren.has('a[href^="'+relativeUrl+'"],a[href^="/'+relativeUrl+'"],a[href^="'+url+'"]');
                    if ( $menuChildren.length === 1 ) { $menuChildren.addClass(activeClass); }
    
                    // Update the content
                    $content.stop(true,true);
                    $content.html(contentHtml).ajaxify().css('opacity',100).show(); // you could fade in here if you'd like
    
                    // Update the title
                    document.title = $data.find('.document-title:first').text();
                    try {
                        document.getElementsByTagName('title')[0].innerHTML = document.title.replace('<','&lt;').replace('>','&gt;').replace(' & ',' &amp; ');
                    }
                    catch ( Exception ) { }
                    
                    // Add the scripts
                    $scripts.each(function(){
                        var $script = $(this), scriptText = $script.html(), scriptNode = document.createElement('script');
                        scriptNode.appendChild(document.createTextNode(scriptText));
                        contentNode.appendChild(scriptNode);
                    });
    
                    // Complete the change
                    if ( $body.ScrollTo||false ) { $body.ScrollTo(scrollOptions); } // http://balupton.com/projects/jquery-scrollto
                    $body.removeClass('loading');
    
                    // Inform Google Analytics of the change
                    if ( typeof window.pageTracker !== 'undefined' ) {
                        window.pageTracker._trackPageview(relativeUrl);
                    }
    
                    // Inform ReInvigorate of a state change
                    if ( typeof window.reinvigorate !== 'undefined' && typeof window.reinvigorate.ajax_track !== 'undefined' ) {
                        reinvigorate.ajax_track(url);
                        // ^ we use the full url here as that is what reinvigorate supports
                    }
                },
                error: function(jqXHR, textStatus, errorThrown){
                    document.location.href = url;
                    return false;
                }
            }); // end ajax
            */
        };
    }); // end onDomLoad

})(window); // end closure
