

;

( function($) {
    
    /**
     * set class according to it's related input
     */
    var setState = function( elem, link ) {    
        if ( elem.isChecked() ) {        
            link.addClass('checked');            
        } else {  
            link.removeClass('checked');
        }        
    };
    
    /**
     * replace a single radiobutton with a prettier one
     */
    var replace = function( elem, options ) {
        
        var checked = elem.isChecked();
        
        var radioGroupName = elem.attr('name');
        
        var radioGroup = $( 'input[name=' + radioGroupName + ']' );
        
        var id = elem.attr('id');
        
        var label = $('label[for=' + id + ']');
        
        var link = $('<a href="#" />').addClass( options.radiobuttonClass ).text( elem.val() );
        
        var trigger = function(e) {
            change();
            e.preventDefault();
        };
        
        var change = function() {        	
        	radioGroup.show();
        	elem.check();
            radioGroup.trigger('change');
            radioGroup.hide();
        };
        
        link.click( trigger );
        
        label.click( trigger );
        
        elem.change( function(event) {
            setState( $(event.target), link );
        });
        
        link.insertAfter( elem );
        
        if ( checked ) {
            change();
        }
        
        elem.hide();
      
    };
    
    /**
     * default options for the pretty radiobuttones
     */
    var defaultOptions = {
        radiobuttonClass : 'radiobutton',
        onChange : function() {}
    };
 
    /**
     * replace radiobuttones with a pretty looking stylable html-only component
     */
    $.fn.radiobutton = function( options ) {
        
        options = options || {};
        
        var extendedOptions = $.extend( defaultOptions, options);
        
        return $(this).each( function(i) {
        
            //only replace once
            if ( $(this).data( '_radiobuttonReplaced' ) ) {
                return;
            }
            
            $(this).data( '_radiobuttonReplaced', true );
            
            // replace the baby
            replace( $(this), extendedOptions );
        });
    };
    
})(jQuery);




;

( function($) {

   var _elements = {};

   var replace = function( select, settings ) {
       
       
       /**
        * quick 'n dirty multiple
        */
       if ( select.attr('multiple') ) {
           return;
       }
       
       /**
        * private properties
        *
        */
       var select = select;
       var numChildren = select.children().length;
       var name = select.attr('name');
       var settings = settings;
       var currentIndex = 0;
       var previousIndex = 0;
       var cursor = 0;
     
       var callbacks = [];
       var selectedClass = 'selected';
       var openClass = 'open';
       var data = [];
       var isOpen = false;
       var max = 0;     
       var itemHeight = 0;
       var height = 0;
       var mouseInside = false;
       var disabled = false;
       var margin = 1;
       
       /**
        * set up the container view
        *
        */
       var hidden = $('<input type="hidden" name="' + name + '" />').val('');
       var dl = $("<dl></dl>").addClass('dropdown');
       
       disabled = select.attr('disabled') ? true : false;
       
       // add original classes to the dl
       var originalClassNames = select.attr('class').split(' ');       
       for (var x = 0; x < originalClassNames.length; x++) {
           dl.addClass(originalClassNames[x]);
       }
       
       if ( disabled || numChildren === 0 ) {
            dl.addClass('disabled');
       }

       var dt = $("<dt></dt>");
       
       if ( !disabled && numChildren > 0 ) {
           dt.mousedown( function(e) {
               if ( isOpen ) {
                   collapse();
               } else {
                   expand();
               }
               e.preventDefault();
           } );
       }
       
       var a = $('<a href="#"></a>').click( function(e) {
           e.preventDefault();
       });
       
       var current = $('<span class="current"></span>').text( settings.defaultText );
      
       a.append(current);
       dt.append($('<span class="icon" />'));
       
       var dropdownContainer = $("<div></div>").addClass('dropdown_container');
       
       $.each( settings.parents, function( i, parentClass ) {
            var inParent = select.parents( '.' + parentClass ).size() > 0;
            if ( inParent ) {
                dropdownContainer.addClass( 'in' + parentClass );
            }
       });
       
       var ul = $("<ul></ul>");
       
       dt.append( a );
       dl.append( dt );
       
      
       /**
        * detect if the mouse is within the dropdown area and store it in a flag
        * if the mouse leaves the area but doesn't return within 5 seconds close it
        */
       var timer = false;
       
       dl.mouseleave( function(e) {
           mouseInside = false;          
       });
       
       dl.mouseenter( function(e) {
           mouseInside = true;  
       });

       /**
        * close the dropdown
        */
       var collapse = function() {     
            isOpen = false;
            dl.removeClass( openClass );
            dropdownContainer.removeClass( openClass ).remove();
       };

       /**
        * open the dropdown
        */
       var expand = function() {
           
           isOpen = true;                   
           
           dropdownContainer.remove();
           // remove the container unbinds all eventhandlers so we attach them when we add the container
           // the live method won't work because it will trigger the event on all dropdowns at once
           
           dropdownContainer
           .mousedown( function(e) {
                e.stopImmediatePropagation();
           })
           .click( function(e) {
                e.stopImmediatePropagation();
           })
           .scroll( determinePosition )
           .find('a').each( function(i) {
               $(this).mousedown( function(e) {
                   moveToIndex(i);
                   pick();
                   e.preventDefault();
                   e.stopImmediatePropagation();                  
               } );
           });
           
           dl.addClass( openClass );
           
           $('body').append( dropdownContainer.addClass( openClass ) );
           
           determinePosition();
       };
          
       /**
        * convert the <select> to a <ul>
        */
       var convertToList = function() {
       
            max = numChildren - 1;
            
           // loop through options and create an unordered list from it's values
           select.children().each( function(i) {

               var value = $.trim( $(this).val() );
               var label = $.trim( $(this).text() );

               if ( $(this).attr('selected') ) {
                    currentIndex = i;
               }
               
               var li = $("<li></li>");
               var a = $('<a href="#"></a>').text( label );
               li.append( a );
               
               data.push( {
                   value : value,
                   label : label
               } );
               
               ul.append( li );
           } );
           
           // insert the list and hide the original select
           dl.insertAfter( select );
           
           select.hide();
           
           if ( numChildren > 0 ) {
           
               
               dl.append( dropdownContainer );
               
               dropdownContainer.append( ul );
               
               // calculate height of a single list item
               itemHeight = ul.children().eq(0).height();
               
               dropdownContainer.remove();    
               
               // calculate the height of the visible area
               height = numChildren * itemHeight;
               
               if ( numChildren > settings.maxItemsVisible ) {
                   height = settings.maxItemsVisible * itemHeight;
               }
               
               // set the height of the cropping area
               dropdownContainer.height( height );
               
               // set the width of the visible area
               var dlw = dl.outerWidth();
               dropdownContainer.width( dlw - 2 );
               
               // select the current value
               moveToIndex( currentIndex );
               
               // check if the dropdown should go up or down
               determinePosition();
                              
               // push the selected value to the hidden field
               setValue();
           }
       };
       
       /** 
        * detect if we have enough room below the trigger to open the dropdown
        * if not, open it above the trigger
        */
       var determinePosition = function() {           
           var offset = dl.offset();
           var top = offset.top - $(window).scrollTop();
           var wh = $(window).height();
           var diff = wh - height - itemHeight;

           if ( diff < top ) {
               dropdownContainer.css({
                   top: dl.offset().top - height - margin,
                   left : dl.offset().left
               });
           } else {
                dropdownContainer.css( {
                    top : dl.offset().top + dt.height() + margin,
                    left : dl.offset().left
               } );
           }
       };
       
       /** 
        * update position to show the selected item
        */
       var setScroll = function() {
           var max = settings.maxItemsVisible - 1;         
           var d = cursor - max;
           var y = d * itemHeight;
           dropdownContainer.scrollTop( 0 );
           if ( y >= 0 ) {     
               dropdownContainer.scrollTop( y );
           }
       };
      
       /**
        * move the cursor to a specified index
        */
       var moveToIndex = function( index ) {
           previousIndex = currentIndex;
           currentIndex = index;
           cursor = index;           
           setScroll();           
           ul.children().eq( previousIndex ).removeClass( selectedClass );
           ul.children().eq( currentIndex ).addClass( selectedClass );           
       };
       

       
       /**
        * store the selected value
        */
       var setValue = function() {
           var label = data[currentIndex].label;
           var value = data[currentIndex].value;
           current.text( label );
           select.show().val( value ).hide();
           collapse(); 
       };
       
       /**
        * triggered when the user selects a value
        * this will also trigger the change event
        */
       var pick = function() {
            setValue();
            select.trigger('change');
            if (typeof(settings.onChange) == 'function') {
                settings.onChange.apply($(select), [select.val()]);
            }
       };
       
       /**
        * move the cursor up or down
        */
       var move = function(dir) {
           cursor += dir;
           if ( cursor <= 0 ) {
               cursor = 0;
           }
           if ( cursor >= max ) {
               cursor = max;
           }
           moveToIndex(cursor);           
       };
       
       /**
        * find index of a value beginning with char c
        */
       var findIndex = function(c) {
           for( var i = 0; i < data.length; i++ ) {
               if ( data[i].label.charAt(0).toLowerCase() == c.toLowerCase() ) {
                   return i;
               }
           }
           return false;
       };
       
       /**
        * get a character from the pressed keycode and if a corresponding value is found move to that index
        */
       var find = function( keyCode ) {
           var c = String.fromCharCode( keyCode );
           var index = findIndex( c );
           if ( index !== false ) {
               moveToIndex(index);
           }
       };
       
       /**
        * monitor keystrokes and delegate actions
        */
       var onKeyUp = function(e) {
    
           if ( isOpen ) {
               switch( e.keyCode ) {
                   case 40: //down
                       move(1);
                       e.preventDefault();
                       break;                   
                   case 38: //up
                       move(-1);
                       e.preventDefault();
                       break;                
                   case 33: //page up
                       moveToIndex(0);
                       e.preventDefault();
                       break;
                   case 34: //page down
                       moveToIndex(max);
                       e.preventDefault();
                       break;                   
                   case 13:
                       pick();                       
                       e.preventDefault();                       
                       break;
                   case 27:
                       reset();
                       e.preventDefault();    
                       break;
                   default:
                       find( e.keyCode );
                       break;                       
               }               
           }
       };   
       
       /*
        * listen to keystrokes
        */
       $(document).keydown( onKeyUp );
       
       /*
        * detect if the mouse is clicked outside of the dropdown
        */
       var reset = function(e) {       
           if ( !mouseInside && isOpen ) {
               collapse();
           }              
       };
       
       var blur = function(e) {
            if ( $(e.target).parents('.dropdown_container').length == 0 ) {
                reset();
            }
       };
       
       $(document).click( blur );//.focus( blur );
       
       $(window).resize( reset );
        
       $( window ).scroll( determinePosition );
        
       
       convertToList();
        
   };

   var defaults = {
       defaultText : "Selecteer een waarde",
       animationSpeed : 0,
       maxItemsVisible : 10,
       onChange : function(value) {},
       parents : ['actions']
   };

   /**
    * dropdown plugin for pretty dropdowns
    */
   $.fn.dropdown = function(options) {
       
       //extend options with the defaults
       var extendedOptions = $.extend( defaults, options );
       
       return $(this).each( function(i) {
           //only replace once
           if ($(this).data('_dropdownReplaced')) {
               return;
           }
           $(this).data('_dropdownReplaced', true);
           
           replace( $(this), extendedOptions );
           
       } );
   };
  
})(jQuery);

;

( function($) {

    var setup = function( element, options ) {
    
        var tabs = element.find('.viewstack-tabs li:not(.print-guide)');
        
        var views = element.find('.view');
        
        views.find('.item:last').addClass('last');
        
        var activeIndex = 0;
        tabs.each( function(i) {
            if( $(this).is('.active') ) {
                activeIndex = i;
            }
        });

        var hide = function() {
            tabs.eq( activeIndex ).removeClass('active');            
            views.eq( activeIndex ).hide();
        };
        
        var show = function() {
            tabs.eq( activeIndex ).addClass('active');            
            views.eq( activeIndex ).show();    
        };
    
        if ( tabs.size() > 0 ) {
            
            tabs.removeClass('active');            
            tabs.eq( activeIndex ).addClass('active');            
            views.eq( activeIndex ).nextAll().hide();
            
            tabs.each( function( i ) {
                $(this).click( function(e) {
                    hide();
                    activeIndex = i;
                    show();
                    options.onChange( i );
                    e.preventDefault();                    
                } );                      
            } );                        
        }
        
        views.hide();
        
        show();
    };
    
    var defaultOptions = {
        onChange : function(index) {}
    };
    
    $.fn.viewstack = function( options ) {
        options = options || {};
        
        var extendedOptions = $.extend( defaultOptions, options );
        
        return $(this).each( function(i) {        
            setup( $(this), extendedOptions );
        });
    
    };
    
})(jQuery);

;

(function($) {
    
    /**
     * flip!
     */
    var setup = function( elem, options ) {
        var overlay = elem.find( options.overlaySelector );
        var title = overlay.find( options.headingSelector );
        
        var minH = title.height();
        var maxH = overlay.height();
        
        overlay.height( minH );  
        
        elem.hover(
            function() {
                overlay.stop(true).animate( { height : maxH } );
            },
            function() {
                overlay.stop(true).animate( { height : minH } );
            }
        );
    };
    
    /**
     * default options 
     */
    var defaultOptions = {        
        overlaySelector : ".info",
        headingSelector : 'h3'
    };
 
    /**
     * assign flipper as a jquery method
     */
    $.fn.flipper = function( options ) {        
        options = options || {};        
        var extendedOptions = $.extend( defaultOptions, options);        
        return $(this).each( function(i) {            
            setup( $(this), extendedOptions );
        });
    };
    
})(jQuery);

;

( function($) {
    /**
     * animate between states
     */
    var animate = function( views, index, options ) {  
        var x = 0; 
        
        views.each( function(i) {            
        
            var viewName = $(this).find('h2 strong');   
            
            $(this).stop(true).animate( { left : x } );
            
            if ( i == index ) {
                viewName.text( $(this).data('_title') );
                x += options.maxWidth;
            } else {
                viewName.text( $(this).data('_abbr') );
                x += options.minWidth;
            }
        } );
    };
    
    /**
     * create the accordion
     */
    var setup = function( elem, options ) {
        
        var views = elem.find( options.viewSelector );
        var numViews = views.size();
        var maxIndex = numViews - 1;
        var activeIndex = 0;
        var x = 0;
        
        if ( numViews > 0 ) {          
            
            // we need an extra element to show the red arrow when the last view is opened
            elem.append('<div class="closing-arrow" />');
            
            views.each( function(i) {
            
                var viewName = $(this).find('h2 strong');
                
                var title = viewName.attr('title');
                var abbr = viewName.text();
                
                // bind different dateformats as data to the element
                $(this).data( '_title', title );
                $(this).data( '_abbr', abbr );
                
                $(this).append('<div class="active-arrow" />');
                
                $(this).mouseover( function(e) {
                    
                    if ( ! $(e.target).is(".active-arrow") ) {

                        views.eq(activeIndex).removeClass( options.activeClass );
                        activeIndex = i;
                        
                        if ( activeIndex == maxIndex ) {                        
                            elem.addClass('last');
                        } else {
                            elem.removeClass('last');
                        }
                        
                        $(this).addClass( options.activeClass );    
                        
                        /*
                         * the view after the active view shouldn't get a border on the left side
                         * and it should hold an overlay with part of the red arrow
                         */
                        views.removeClass('next').eq( activeIndex ).next().addClass('next');
            
                        animate( views, activeIndex, options );
                    }
                    
                    e.stopPropagation();
                    
                }).css( {                    
                    left : x,
                    top : 0,
                    position : 'absolute'                   
                } );
                
                if ( $(this).hasClass( options.activeClass ) ) {
                    viewName.text( title );
                    activeIndex = i;
                    x += options.maxWidth;
                } else {
                    x += options.minWidth;
                }               
            } );   
            
            views.eq(activeIndex).next().addClass('next');
        }
    };
    
    /**
     * default options 
     */
    var defaultOptions = {
        minWidth : 80,
        maxWidth : 460,
        viewSelector : ".weekday",
        activeClass : 'active'
    };
 
    /**
     * assign accordion as a jquery method
     */
    $.fn.accordion = function( options ) {        
        options = options || {};        
        var extendedOptions = $.extend( defaultOptions, options);        
        return $(this).each( function(i) {            
            setup( $(this), extendedOptions );
        });
    };
    
})(jQuery);



;

(function($) {
    
    /**
     * set up
     */
    var setup = function( elem, options ) {
        
        var pages = elem.find( options.viewSelector );
        var numPages = pages.size();

        var ul = $("<ul></ul>");
        var active = 'active';
        
        var show = function(index) {
            pages.hide().eq(index).show();
            ul.children().removeClass(active).eq(index).addClass(active);
        };
        
        if ( numPages > 1 ) {

            var container = elem.find('.pageable-pager');
            
            var xstart = options.spacing * ( numPages - 1 );
            for( var i = 0; i < numPages; i++ ) {
                var li = $("<li></li>").text( i + 1 ).css({
                    right : xstart - ( i * options.spacing )
                });           
                
                (function(index) {
                    li.mouseover( function() {
                        show(index);
                    });
                })(i); 
                
                ul.append( li );
            }
            container.append( ul );
            
            show(0);
        }
        
    };
        
    /**
     * default options 
     */
    var defaultOptions = {      
        spacing : 17,
        viewSelector : ".view"
    };
 
    /**
     * assign pageable as a jquery method
     */
    $.fn.pageable = function( options ) {        
        options = options || {};        
        var extendedOptions = $.extend( defaultOptions, options);        
        return $(this).each( function(i) {            
            setup( $(this), extendedOptions );
        });
    };
    
})(jQuery);


;

/**
 * the basic namespace
 *
 */
var rtvNH = window.rtvNH || {};
var _sf_startpt = (new Date()).getTime();

/**
 * settings
 *
 */
rtvNH.settings = {
    baseUrl : ''
};

/**
 * utilities
 *
 */
rtvNH.util = {

    route : function() {
        var url = Array.prototype.slice.call( arguments );
        url.unshift( rtvNH.settings.baseUrl );
        return url.join('/');
    },
    
    redirect : function( route ) {
        document.location.href = rtvNH.settings.baseUrl + route;
    }   
};


/**
 * navigation
 *
 */
// elem is the topbutton which has an mouseover and out function
// do note that the submenus also have an mouseover and out function!
// those are defined in the topbutton mouseover function

rtvNH.navigation = {
    bodyClass: '',
    elements: Array(),
    leftOpen: false,
    init: function()
    {

var ta = document.createElement('textarea');
        ta.style.display = 'none';
ta.id = 'test_ta';
document.body.appendChild(ta);



        this.bodyClass = document.body.className;
        var navigation = document.getElementById('ul_navigation');
        
        var out = document.createElement('DIV');
        out.id = 'nav_out';

if (!navigation) {
 return;
}

if (document.getElementById('header'))
{
 document.getElementById('header').appendChild(out);
}
        
       if (typeof navigation.childNodes == 'undefined') {
 return;
}

        ta.value += navigation.childNodes.length + "\n";
        for (var i = 0; i < navigation.childNodes.length; i++)
        {

            for (var e = 0; e < navigation.childNodes[i].childNodes.length; e++)
            {
                var elem = navigation.childNodes[i].childNodes[e];
                if (typeof elem.className != 'undefined')
                {
                    if (elem.className == 'button')
                    {
                        this.elements.push(elem);
                        
                        elem._parent = this;
                        elem._object = elem;
                        elem.onmouseover = function()
                        {
                            var _id = this._object.parentNode.id.replace('nav_', '');
                            var _this = this;

                            if (this._parent.opened != false)
                            {
                                if (typeof closeWait != 'undefined') clearTimeout(closeWait);
                                this._parent.closeWait(_id, _this);
                                return;
                            }
                          
                            this._object.parentNode.className = 'active';
                            
                            document.getElementById('navigation').className = _id + '_active';
                            document.getElementById('header').className = _id + '_active';
                            
                            var f = function()
                            {
                                // one at a time;
                                if (_this._parent.opened != false) return;
                                
                                _this._parent.opened = _id;
            
                                $('#' + _id + '_menu').fadeIn('fast');
                                $('#cover_' + _id).fadeIn('fast');
                                
                                document.getElementById(_id + '_menu').onmouseover = function()
                                {
                                    if (typeof closeWait != 'undefined') {
                                        clearTimeout(closeWait);
                                    }
                                    // disable the waiting removal timer
                                    if (typeof menuWait != 'undefined') {
                                        clearTimeout(menuWait);
                                        mouseWait = null;
                                    }
                                }
                                document.getElementById(_id + '_menu').onmouseout = function()
                                {
                                    // nothing is opened, remove classes and stuff
                                    _this._parent.mouseWait(_id, _this, false);
                                }
                            }
                            
                            
                            // prevent multiple menu's from opening
                            if (typeof menuOpen != 'undefined') clearTimeout(menuOpen);
                           
                            if (document.getElementById(_id + '_menu') != null )
                            {
                                // open it
                                menuOpen = setTimeout(f, 800);
                            }

                        }
                        
                        elem.onmouseout = function()
                        {
                            var _id = this._object.parentNode.id.replace('nav_', '');
                            if (typeof mouseWait == 'undefined') mouseWait = null;
                                                    
                            if (this._parent.opened != false && mouseWait != null)
                            {
                                this._parent.mouseWait(_id, this, false);
                            }
                            
                            if (this._parent.opened != false)
                            {
                                this._parent.leftOpen = true;
                            }
                            
                            if (this._parent.opened == false)
                            {
                                this._object.parentNode.className = '';
                                document.getElementById('navigation').className = '';
                                document.getElementById('header').className =  '';
                                $('#cover_' + _id).fadeOut('fast');
                                if (typeof menuOpen != 'undefined') clearTimeout(menuOpen);
                                
                                this._parent.mouseLeaveNow(_id, this);
                            }
                    
                        }
                    }
                }
            }
        }
    },
    topWait: function(_id){
        var f = function()
        {
            
            // the one currently being open
            document.getElementById('navigation').className = '';
            if (document.getElementById('nav_' + _id) ) {
                document.getElementById('nav_' + _id).className = '';
            }
            $('#' + _id + '_menu').fadeOut('fast');
            $('#cover_' + _id).fadeOut('fast');
            rtvNH.navigation.opened = false;
            clearTimeout(topWait);
        }

        topWait = setTimeout(f, 500);
    },
    closeWait: function(_id, _this){
        var f = function()
        {
            // the one currently being open
            var _id = _this._parent.opened;
            document.getElementById('navigation').className = '';
            if (document.getElementById('nav_' + _id))
            {
                document.getElementById('nav_' + _id).className = '';
            }
            
            $('#' + _id + '_menu').fadeOut('fast');
            $('#cover_' + _id).fadeOut('fast');
            _this._parent.opened = false;
            
            // _this is the current hovered
            _this._object.onmouseover();
        }

        closeWait = setTimeout(f, 500);
    },
    mouseWait: function(_id, _this, hover, _time)
    {
        // called from the top button, give user one second to go to the submenu    
        var f = function()
        {
            document.getElementById('navigation').className = '';
            document.getElementById('nav_' + _id).className = '';
        
            $('#' + _id + '_menu').fadeOut('fast');
            $('#cover_' + _id).fadeOut('fast');
            _this._parent.opened = false;
            // _this is the current hovered
            if (hover)    _this._object.onmouseover();
        }

        menuWait = setTimeout(f, 300);
    },
    mouseLeave: function(_id, _this)
    {
        if (typeof menuOpen != 'undefined') clearTimeout(menuOpen);        
        var f = function()
        {
            //_this._object.parentNode.className = 'active';
            document.getElementById('navigation').className = '';
            _this._object.parentNode.className = '';
            $('#' + _id + '_menu').fadeOut('fast');
            $('#cover_' + _id).fadeOut('fast');
        }

        menuClose = setTimeout(f, 500);
    },
    mouseLeaveNow: function(_id, _this)
    {

        _this._object.parentNode.className = '';
        
        for(var i = 0; i < _this._parent.elements.length; i++)
        {
            
            var _id = _this._parent.elements[i].parentNode.id.replace('nav_', '');
            
            if (document.getElementById(_id + '_menu'))
            {
                document.getElementById('cover_' + _id).style.display = 'none';
                document.getElementById(_id + '_menu').style.display = 'none';
            }
        } 
    },
    current: false,
    opened: false,
    enter: false

};

/**
 * replace selectboxes, checkboxes and radiobuttons with stylable versions
 * give all input elements a classname describing the type
 */
rtvNH.form = {

    init : function( rootSelector ) {
        
        rootSelector = rootSelector || " ";
        
        if ( $().radiobutton ) {
            $( rootSelector + ' input[type=radio]' ).radiobutton();
        }
        
        if ( $().checkbox ) {
            $( rootSelector + ' input[type=checkbox]' ).checkbox();
        }
        
        if ( $().dropdown ) {
            $( rootSelector + ' select' ).dropdown();
        }
 
        if ( $().datetime ) {
            $( rootSelector + ' input.datetime' ).datetime();
        }
       
        $( rootSelector + " input" ).each( function() {
        
            $(this).addClass( $(this).attr('type') );
        
        });
        
        // $('input[type=submit]').wrap( $('<p class="submit"></p>') );
        
    }
    
};

/**
 * search
 *
 */
rtvNH.search = {

    init : function() {
        
        var keyword = $("#keyword");
        
        var defaultValue = keyword.val();
        
        keyword.focus( function() {
            if ( $(this).val() == defaultValue ) {
                $(this).val('');
            }
        }).blur( function() {
            if ( $(this).val() === '' ) {
                $(this).val( defaultValue );
            }
        });
        
        var doSearch = function(e) {
            var value = jQuery.stripTags( keyword.val() );
            if ( value.length > 1 && value != defaultValue ) {
                var route = rtvNH.util.route( "zoeken", value );
                rtvNH.util.redirect( route );
            }
            e.preventDefault();
        };
        
        var button = $('<a href="#" id="send">Zoek</a>').click( doSearch );
        
        $("#navigation #send").replaceWith( button );
        
        $("#navigation form").submit( doSearch );
        
        var expand = $("#navigation form .advanced-search").hide();
               
        $("#navigation form").hover( 
            function() {
                expand.show();
            }, 
            function() {
                expand.hide();
            } 
        );
    }
};


/**
 * fix detail page
 *
 */
rtvNH.detail = {
    
    /**
     * this fixes the article layout on the content-detail pages
     *
     */
    fixLayout : function() {
        var body = $(".content-detail-body"); 
        var insert = $(".content-detail .insert");
        var related = $(".content-detail .related");       
        var rightCol = $("#content .single-column");

        if (typeof body.exists == 'undefined') return;
        
        if ( body.exists() && related.exists() ) {
        
            var setPosition = function() {

                var t = body.position().top;
                var h = insert.exists() ? insert.fullHeight() : 0;
    
                var tweak = 5;
                var pos = h + t + tweak;
                
                related.css( {
                    position : 'absolute',
                    top : pos,
                    left : 10
                });        
                
                rightCol.css( {
                    marginTop : body.position().top - 55
                });
                
                body.css( {
                    minHeight : h + related.fullHeight() + 25
                });
                
            };
            
            setPosition();
            
           var img = insert.find('img').bind('load', setPosition );
        }
    },
    
    init : function() {
        
        /*
         * we have to wait for the images to load
         *
         */
        if ( $().slideshow ) {
            $(".slideshow").slideshow();
        }
    
        this.fixLayout();       
    }  
};

/**
 * check if component is loaded and trigger if so
 *
 */
rtvNH.components = {
    
    /*
     * we need the black overlay to show up at the bottom of the image whatever the height
     */
    fixFlexibleOverlays : function() {
        $(".overlay-aside").each( function() {
            var overlay = $(this).find('.overlay');
            var img = overlay.find('img');
            var h = img.height();
            overlay.height(h);
        });
    },

    initTicker : function() {        
        var items = $('.news-ticker li');
        var numItems = items.length;
        var max = numItems - 1;
        var index = 0;        
        if ( numItems > 1 ) {            
            items.eq(0).nextAll().hide();            
            var timer = setInterval( function() {            
                items.eq(index).fadeOut( 'fast', function() {
                    index++;
                    if ( index > max ) {
                        index = 0;
                    }
                    items.eq(index).fadeIn('slow');
                });                
            }, 3000 );            
        }
    },
    
    /*
     */   
    triggerPlugins : function() {
 
        if ( $().viewstack ) {
            $('.viewstack:not(.header-missed .double-column .viewstack)').viewstack();        
        }
        
        if ( $().accordion ) {
            $("#accordion").accordion();
        }
        
        if ( $().pageable ) {
        
            $(".pageable").pageable(); 
            
            $(".pageable-rows").pageable({
                viewSelector : ".row"
            }); 
        }
        
        if ( $().flipper ) {
            $(".flipper").flipper(); 
            
            $(".spread-overlay, .large-overlay").flipper( {
                headingSelector : "h2"
            } );            
        }  
        
        if ( $().expandable ) {
            $(".expandable").expandable();
        }
        
        if ( $().trimmable ) {
            $(".trimmable").trimmable();
        } 
        
        if ( $().fancyboxForm ) {
            $("a[rel=fancybox-form]").fancyboxForm();
        } 
        
        if(  $().newsticker ) { 
            $("#newsticker").newsticker();
        }
    
        $('.back a').click( function(e) {
            history.go(-1);
            e.preventDefault();
        } );
        
        $('.print-guide').click( function(e) {
            var activeTab = $('.viewstack-tabs li.active');
            var activeIndex = $('.viewstack-tabs li').index(activeTab);
            open_venster('/print/gids/' + activeIndex,'gids', 648, 600, 'yes', true);
            e.preventDefault();
            e.stopPropagation();
        });
    },
    
    /*
     * the list-items of the pager are floated right so we reverse them here
     */
    reversePagers : function() {        
        if ( $().reverse ) {
            $(".pager").each( function() {
                $(this).find("ul:last").reverse(); 
            }); 
        }
    },
    
    tweakMarkup : function() {     
    
        $("tbody tr:nth-child(even), .program-guide dl:nth-child(odd)").addClass('even');        
        $('a.video').append("<span />");    
        
               
        // make the floated images easy to target with css
        $(".content-detail-body *[style*='float'],.main-article *[style*='float']").each( function() {
            if ( $(this).width() < 460 ) {
                if ( $(this).css('float') == 'left' ) {
                    $(this).addClass("a-left");
                } else {
                    $(this).addClass("a-right");
                   }
            }
        } );
        
        // remove empty paragraphs from the article content
        $(".content-detail-body p").each( function() {
            //var html = $(this).html();
            //html = html.replace("/\s+/", "" );
            //html = html.split("&nbsp;").join("");
            //if ( "" == html ) {
                //$(this).remove();
            //}
        });
    },

    initAgenda : function() {    
        $('.agenda-results tr').click( function() {
            var href = $(this).find('h3 a').attr('href');
            rtvNH.util.redirect( href );
        });
    },
    
    initExternalLinks : function() {    
        var h = window.location.host.toLowerCase();
        $("a[href^='http']:not([href^='http://" + h + "']):not([href^='http://www." + h + "']), a[href$='.pdf'], a[rel='external']").attr("target","_blank");
    },

    initMailtoLinks : function() {
        $("a[rel='mail']").each( function() {
            var self = $(this);
            var needle = "[apenstaartje]";
            var href = self.attr('href');
            var content = self.html().split(needle).join("@")
            self.attr( 'href', "mailto:" + href.split(needle).join("@") );
            self.empty().html( content );
        });
    },
    
    loadDatePickers : function() {
       
        var pickers = $('.datepicker');
                if (typeof pickers.exists == 'undefined') return;
        if ( pickers.exists() ) {        
        
            var pretifyPicker = function() {
                if ( $().dropdown ) {
                    $("#ui-datepicker-div").find('select').dropdown();
                }
            };
            
            $.loadCss('/static/css/ui.datepick.css'); 
            
            $.getScript( '/static/js/datepicker.js', function() {
                
                pickers.datepicker( {
                    showOn : 'focus',
                    yearRange: '-10:+10',
                    duration: "",
                    changeFirstDay : false,                                    
                    onShow: pretifyPicker,                    
                    onChangeMonthYear : pretifyPicker                  
                });
            });
        }
    },
    
    init : function() {
        this.loadDatePickers();
        this.triggerPlugins();
        this.reversePagers();
        this.tweakMarkup();
        
        this.initTicker();
        this.initAgenda();
        this.initMailtoLinks();
        this.initExternalLinks();
    }
};

/**
 * trigger the various components
 *
 */
rtvNH.init = function() {
    rtvNH.form.init();
    rtvNH.components.init();
    
    rtvNH.search.init();
    
};


window.onload = function() {
    // we have to wait for all images to load
    rtvNH.detail.init();
    
    rtvNH.components.fixFlexibleOverlays();
$("#logo_link").click(function() {
             document.location = '/';   
        }); 
       
}
    
 
$(function() {
rtvNH.navigation.init();
});

;

/*
 * FancyBox - jQuery Plugin
 * Simple and fancy lightbox alternative
 *
 * Examples and documentation at: http://fancybox.net
 * 
 * Copyright (c) 2008 - 2010 Janis Skarnelis
 *
 * Version: 1.3.1 (05/03/2010)
 * Requires: jQuery v1.3+
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

(function($) {

    var tmp, loading, overlay, wrap, outer, inner, close, nav_left, nav_right,

        selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [],

        ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i,

        loadingTimer, loadingFrame = 1,

        start_pos, final_pos, busy = false, shadow = 20, fx = $.extend($('<div/>')[0], { prop: 0 }), titleh = 0, 

        isIE6 = !$.support.opacity && !window.XMLHttpRequest,

        /*
         * Private methods 
         */

        fancybox_abort = function() {
            loading.hide();

            imgPreloader.onerror = imgPreloader.onload = null;

            if (ajaxLoader) {
                ajaxLoader.abort();
            }

            tmp.empty();
        },

        fancybox_error = function() {
            $.fancybox('<p id="fancybox_error">The requested content cannot be loaded.<br />Please try again later.</p>', {
                'scrolling'        : 'no',
                'padding'        : 20,
                'transitionIn'    : 'none',
                'transitionOut'    : 'none'
            });
        },

        fancybox_get_viewport = function() {
            return [ $(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
        },

        fancybox_get_zoom_to = function () {
            var view    = fancybox_get_viewport(),
                to        = {},

                margin = currentOpts.margin,
                resize = currentOpts.autoScale,

                horizontal_space    = (shadow + margin) * 2,
                vertical_space        = (shadow + margin) * 2,
                double_padding        = (currentOpts.padding * 2),
                
                ratio;

            if (currentOpts.width.toString().indexOf('%') > -1) {
                to.width = ((view[0] * parseFloat(currentOpts.width)) / 100) - (shadow * 2) ;
                resize = false;

            } else {
                to.width = currentOpts.width + double_padding;
            }

            if (currentOpts.height.toString().indexOf('%') > -1) {
                to.height = ((view[1] * parseFloat(currentOpts.height)) / 100) - (shadow * 2);
                resize = false;

            } else {
                to.height = currentOpts.height + double_padding;
            }

            if (resize && (to.width > (view[0] - horizontal_space) || to.height > (view[1] - vertical_space))) {
                if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') {
                    horizontal_space    += double_padding;
                    vertical_space        += double_padding;

                    ratio = Math.min(Math.min( view[0] - horizontal_space, currentOpts.width) / currentOpts.width, Math.min( view[1] - vertical_space, currentOpts.height) / currentOpts.height);

                    to.width    = Math.round(ratio * (to.width    - double_padding)) + double_padding;
                    to.height    = Math.round(ratio * (to.height    - double_padding)) + double_padding;

                } else {
                    to.width    = Math.min(to.width,    (view[0] - horizontal_space));
                    to.height    = Math.min(to.height,    (view[1] - vertical_space));
                }
            }

            to.top    = view[3] + ((view[1] - (to.height    + (shadow * 2 ))) * 0.5);
            to.left    = view[2] + ((view[0] - (to.width    + (shadow * 2 ))) * 0.5);

            if (currentOpts.autoScale === false) {
                to.top    = Math.max(view[3] + margin, to.top);
                to.left    = Math.max(view[2] + margin, to.left);
            }

            return to;
        },

        fancybox_format_title = function(title) {
            if (title && title.length) {
                switch (currentOpts.titlePosition) {
                    case 'inside':
                        return title;
                    case 'over':
                        return '<span id="fancybox-title-over">' + title + '</span>';
                    default:
                        return '<span id="fancybox-title-wrap"><span id="fancybox-title-left"></span><span id="fancybox-title-main">' + title + '</span><span id="fancybox-title-right"></span></span>';
                }
            }

            return false;
        },

        fancybox_process_title = function() {
            var title    = currentOpts.title,
                width    = final_pos.width - (currentOpts.padding * 2),
                titlec    = 'fancybox-title-' + currentOpts.titlePosition;
                
            $('#fancybox-title').remove();

            titleh = 0;

            if (currentOpts.titleShow === false) {
                return;
            }

            title = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(title, currentArray, currentIndex, currentOpts) : fancybox_format_title(title);

            if (!title || title === '') {
                return;
            }

            $('<div id="fancybox-title" class="' + titlec + '" />').css({
                'width'            : width,
                'paddingLeft'    : currentOpts.padding,
                'paddingRight'    : currentOpts.padding
            }).html(title).appendTo('body');

            switch (currentOpts.titlePosition) {
                case 'inside':
                    titleh = $("#fancybox-title").outerHeight(true) - currentOpts.padding;
                    final_pos.height += titleh;
                break;

                case 'over':
                    $('#fancybox-title').css('bottom', currentOpts.padding);
                break;

                default:
                    $('#fancybox-title').css('bottom', $("#fancybox-title").outerHeight(true) * -1);
                break;
            }

            $('#fancybox-title').appendTo( outer ).hide();
        },

        fancybox_set_navigation = function() {
            $(document).unbind('keydown.fb').bind('keydown.fb', function(e) {
                if (e.keyCode == 27 && currentOpts.enableEscapeButton) {
                    e.preventDefault();
                    $.fancybox.close();

                } else if (e.keyCode == 37) {
                    if ( currentOpts.enableKeyboardNav ) {
                        e.preventDefault();
                        $.fancybox.prev();
                    }

                } else if (e.keyCode == 39) {
                    if ( currentOpts.enableKeyboardNav ) {
                        e.preventDefault();
                        $.fancybox.next();
                    }
                }
            });

            if ($.fn.mousewheel) {
                wrap.unbind('mousewheel.fb');

                if (currentArray.length > 1) {
                    wrap.bind('mousewheel.fb', function(e, delta) {
                        e.preventDefault();

                        if (busy || delta === 0) {
                            return;
                        }

                        if (delta > 0) {
                            $.fancybox.prev();
                        } else {
                            $.fancybox.next();
                        }
                    });
                }
            }

            if (!currentOpts.showNavArrows) { return; }

            if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) {
                nav_left.show();
            }

            if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) {
                nav_right.show();
            }
        },

        fancybox_preload_images = function() {
            var href, 
                objNext;
                
            if ((currentArray.length -1) > currentIndex) {
                href = currentArray[ currentIndex + 1 ].href;

                if (typeof href !== 'undefined' && href.match(imgRegExp)) {
                    objNext = new Image();
                    objNext.src = href;
                }
            }

            if (currentIndex > 0) {
                href = currentArray[ currentIndex - 1 ].href;

                if (typeof href !== 'undefined' && href.match(imgRegExp)) {
                    objNext = new Image();
                    objNext.src = href;
                }
            }
        },

        _finish = function () {
            inner.css('overflow', (currentOpts.scrolling == 'auto' ? (currentOpts.type == 'image' || currentOpts.type == 'iframe' || currentOpts.type == 'swf' ? 'hidden' : 'auto') : (currentOpts.scrolling == 'yes' ? 'auto' : 'visible')));

            if (!$.support.opacity) {
                inner.get(0).style.removeAttribute('filter');
                wrap.get(0).style.removeAttribute('filter');
            }

            $('#fancybox-title').show();

            if (currentOpts.hideOnContentClick)    {
                inner.one('click', $.fancybox.close);
            }
            if (currentOpts.hideOnOverlayClick)    {
                overlay.one('click', $.fancybox.close);
            }

            if (currentOpts.showCloseButton) {
                close.show();
            }

            fancybox_set_navigation();

            $(window).bind("resize.fb", $.fancybox.center);

            if (currentOpts.centerOnScroll) {
                $(window).bind("scroll.fb", $.fancybox.center);
            } else {
                $(window).unbind("scroll.fb");
            }

            if ($.isFunction(currentOpts.onComplete)) {
                currentOpts.onComplete(currentArray, currentIndex, currentOpts);
            }

            busy = false;

            fancybox_preload_images();
        },

        fancybox_draw = function(pos) {
            var width    = Math.round(start_pos.width    + (final_pos.width    - start_pos.width)    * pos),
                height    = Math.round(start_pos.height    + (final_pos.height    - start_pos.height)    * pos),

                top        = Math.round(start_pos.top    + (final_pos.top    - start_pos.top)    * pos),
                left    = Math.round(start_pos.left    + (final_pos.left    - start_pos.left)    * pos);

            wrap.css({
                'width'        : width        + 'px',
                'height'    : height    + 'px',
                'top'        : top        + 'px',
                'left'        : left        + 'px'
            });

            width    = Math.max(width - currentOpts.padding * 2, 0);
            height    = Math.max(height - (currentOpts.padding * 2 + (titleh * pos)), 0);

            inner.css({
                'width'        : width        + 'px',
                'height'    : height    + 'px'
            });

            if (typeof final_pos.opacity !== 'undefined') {
                wrap.css('opacity', (pos < 0.5 ? 0.5 : pos));
            }
        },

        fancybox_get_obj_pos = function(obj) {
            var pos        = obj.offset();

            pos.top        += parseFloat( obj.css('paddingTop') )    || 0;
            pos.left    += parseFloat( obj.css('paddingLeft') )    || 0;

            pos.top        += parseFloat( obj.css('border-top-width') )    || 0;
            pos.left    += parseFloat( obj.css('border-left-width') )    || 0;

            pos.width    = obj.width();
            pos.height    = obj.height();

            return pos;
        },

        fancybox_get_zoom_from = function() {
            var orig = selectedOpts.orig ? $(selectedOpts.orig) : false,
                from = {},
                pos,
                view;

            if (orig && orig.length) {
                pos = fancybox_get_obj_pos(orig);

                from = {
                    width    : (pos.width    + (currentOpts.padding * 2)),
                    height    : (pos.height    + (currentOpts.padding * 2)),
                    top        : (pos.top        - currentOpts.padding - shadow),
                    left    : (pos.left        - currentOpts.padding - shadow)
                };
                
            } else {
                view = fancybox_get_viewport();

                from = {
                    width    : 1,
                    height    : 1,
                    top        : view[3] + view[1] * 0.5,
                    left    : view[2] + view[0] * 0.5
                };
            }

            return from;
        },

        fancybox_show = function() {
            loading.hide();

            if (wrap.is(":visible") && $.isFunction(currentOpts.onCleanup)) {
                if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
                    $.event.trigger('fancybox-cancel');

                    busy = false;
                    return;
                }
            }

            currentArray    = selectedArray;
            currentIndex    = selectedIndex;
            currentOpts        = selectedOpts;

            inner.get(0).scrollTop    = 0;
            inner.get(0).scrollLeft    = 0;

            if (currentOpts.overlayShow) {
                if (isIE6) {
                    $('select:not(#fancybox-tmp select)').filter(function() {
                        return this.style.visibility !== 'hidden';
                    }).css({'visibility':'hidden'}).one('fancybox-cleanup', function() {
                        this.style.visibility = 'inherit';
                    });
                }

                overlay.css({
                    'background-color'    : currentOpts.overlayColor,
                    'opacity'            : currentOpts.overlayOpacity
                }).unbind().show();
            }

            final_pos = fancybox_get_zoom_to();

            fancybox_process_title();

            if (wrap.is(":visible")) {
                $( close.add( nav_left ).add( nav_right ) ).hide();

                var pos = wrap.position(),
                    equal;

                start_pos = {
                    top        :    pos.top ,
                    left    :    pos.left,
                    width    :    wrap.width(),
                    height    :    wrap.height()
                };

                equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height);

                inner.fadeOut(currentOpts.changeFade, function() {
                    var finish_resizing = function() {
                        inner.html( tmp.contents() ).fadeIn(currentOpts.changeFade, _finish);
                    };
                    
                    $.event.trigger('fancybox-change');

                    inner.empty().css('overflow', 'hidden');

                    if (equal) {
                        inner.css({
                            top            : currentOpts.padding,
                            left        : currentOpts.padding,
                            width        : Math.max(final_pos.width    - (currentOpts.padding * 2), 1),
                            height        : Math.max(final_pos.height    - (currentOpts.padding * 2) - titleh, 1)
                        });
                        
                        finish_resizing();

                    } else {
                        inner.css({
                            top            : currentOpts.padding,
                            left        : currentOpts.padding,
                            width        : Math.max(start_pos.width    - (currentOpts.padding * 2), 1),
                            height        : Math.max(start_pos.height    - (currentOpts.padding * 2), 1)
                        });
                        
                        fx.prop = 0;

                        $(fx).animate({ prop: 1 }, {
                             duration    : currentOpts.changeSpeed,
                             easing        : currentOpts.easingChange,
                             step        : fancybox_draw,
                             complete    : finish_resizing
                        });
                    }
                });

                return;
            }

            wrap.css('opacity', 1);

            if (currentOpts.transitionIn == 'elastic') {
                start_pos = fancybox_get_zoom_from();

                inner.css({
                        top            : currentOpts.padding,
                        left        : currentOpts.padding,
                        width        : Math.max(start_pos.width    - (currentOpts.padding * 2), 1),
                        height        : Math.max(start_pos.height    - (currentOpts.padding * 2), 1)
                    })
                    .html( tmp.contents() );

                wrap.css(start_pos).show();

                if (currentOpts.opacity) {
                    final_pos.opacity = 0;
                }

                fx.prop = 0;

                $(fx).animate({ prop: 1 }, {
                     duration    : currentOpts.speedIn,
                     easing        : currentOpts.easingIn,
                     step        : fancybox_draw,
                     complete    : _finish
                });

            } else {
                inner.css({
                        top            : currentOpts.padding,
                        left        : currentOpts.padding,
                        width        : Math.max(final_pos.width    - (currentOpts.padding * 2), 1),
                        height        : Math.max(final_pos.height    - (currentOpts.padding * 2) - titleh, 1)
                    })
                    .html( tmp.contents() );

                wrap.css( final_pos ).fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish );
            }
        },

        fancybox_process_inline = function() {
            tmp.width(    selectedOpts.width );
            tmp.height(    selectedOpts.height );

            if (selectedOpts.width    == 'auto') {
                selectedOpts.width = tmp.width();
            }
            if (selectedOpts.height    == 'auto') {
                selectedOpts.height    = tmp.height();
            }

            fancybox_show();
        },
        
        fancybox_process_image = function() {
            busy = true;

            selectedOpts.width    = imgPreloader.width;
            selectedOpts.height    = imgPreloader.height;

            $("<img />").attr({
                'id'    : 'fancybox-img',
                'src'    : imgPreloader.src,
                'alt'    : selectedOpts.title
            }).appendTo( tmp );

            fancybox_show();
        },

        fancybox_start = function() {
            fancybox_abort();

            var obj    = selectedArray[ selectedIndex ],
                href, 
                type, 
                title,
                str,
                emb,
                selector,
                data;

            selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox')));
            title = obj.title || $(obj).title || selectedOpts.title || '';
            
            if (obj.nodeName && !selectedOpts.orig) {
                selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj);
            }

            if (title === '' && selectedOpts.orig) {
                title = selectedOpts.orig.attr('alt');
            }

            if (obj.nodeName && (/^(?:javascript|#)/i).test(obj.href)) {
                href = selectedOpts.href || null;
            } else {
                href = selectedOpts.href || obj.href || null;
            }

            if (selectedOpts.type) {
                type = selectedOpts.type;

                if (!href) {
                    href = selectedOpts.content;
                }
                
            } else if (selectedOpts.content) {
                type    = 'html';

            } else if (href) {
                if (href.match(imgRegExp)) {
                    type = 'image';

                } else if (href.match(swfRegExp)) {
                    type = 'swf';

                } else if ($(obj).hasClass("iframe")) {
                    type = 'iframe';

                } else if (href.match(/#/)) {
                    obj = href.substr(href.indexOf("#"));

                    type = $(obj).length > 0 ? 'inline' : 'ajax';
                } else {
                    type = 'ajax';
                }
            } else {
                type = 'inline';
            }

            selectedOpts.type    = type;
            selectedOpts.href    = href;
            selectedOpts.title    = title;

            if (selectedOpts.autoDimensions && selectedOpts.type !== 'iframe' && selectedOpts.type !== 'swf') {
                selectedOpts.width        = 'auto';
                selectedOpts.height        = 'auto';
            }

            if (selectedOpts.modal) {
                selectedOpts.overlayShow        = true;
                selectedOpts.hideOnOverlayClick    = false;
                selectedOpts.hideOnContentClick    = false;
                selectedOpts.enableEscapeButton    = false;
                selectedOpts.showCloseButton    = false;
            }

            if ($.isFunction(selectedOpts.onStart)) {
                if (selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts) === false) {
                    busy = false;
                    return;
                }
            }

            tmp.css('padding', (shadow + selectedOpts.padding + selectedOpts.margin));

            $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() {
                $(this).replaceWith(inner.children());
            });

            switch (type) {
                case 'html' :
                    tmp.html( selectedOpts.content );
                    fancybox_process_inline();
                break;

                case 'inline' :
                    $('<div class="fancybox-inline-tmp" />').hide().insertBefore( $(obj) ).bind('fancybox-cleanup', function() {
                        $(this).replaceWith(inner.children());
                    }).bind('fancybox-cancel', function() {
                        $(this).replaceWith(tmp.children());
                    });

                    $(obj).appendTo(tmp);

                    fancybox_process_inline();
                break;

                case 'image':
                    busy = false;

                    $.fancybox.showActivity();

                    imgPreloader = new Image();

                    imgPreloader.onerror = function() {
                        fancybox_error();
                    };

                    imgPreloader.onload = function() {
                        imgPreloader.onerror = null;
                        imgPreloader.onload = null;
                        fancybox_process_image();
                    };

                    imgPreloader.src = href;
        
                break;

                case 'swf':
                    str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>';
                    emb = '';
                    
                    $.each(selectedOpts.swf, function(name, val) {
                        str += '<param name="' + name + '" value="' + val + '"></param>';
                        emb += ' ' + name + '="' + val + '"';
                    });

                    str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>';

                    tmp.html(str);

                    fancybox_process_inline();
                break;

                case 'ajax':
                    selector    = href.split('#', 2);
                    data        = selectedOpts.ajax.data || {};

                    if (selector.length > 1) {
                        href = selector[0];

                        if (typeof data == "string") {
                            data += '&selector=' + selector[1];
                        } else {
                            data.selector = selector[1];
                        }
                    }

                    busy = false;
                    $.fancybox.showActivity();

                    ajaxLoader = $.ajax($.extend(selectedOpts.ajax, {
                        url        : href,
                        data    : data,
                        error    : fancybox_error,
                        success : function(data, textStatus, XMLHttpRequest) {
                            if (ajaxLoader.status == 200) {
                                tmp.html( data );
                                fancybox_process_inline();
                            }
                        }
                    }));

                break;

                case 'iframe' :
                    $('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" scrolling="' + selectedOpts.scrolling + '" src="' + selectedOpts.href + '"></iframe>').appendTo(tmp);
                    fancybox_show();
                break;
            }
        },

        fancybox_animate_loading = function() {
            if (!loading.is(':visible')){
                clearInterval(loadingTimer);
                return;
            }

            $('div', loading).css('top', (loadingFrame * -40) + 'px');

            loadingFrame = (loadingFrame + 1) % 12;
        },

        fancybox_init = function() {
            if ($("#fancybox-wrap").length) {
                return;
            }

            $('body').append(
                tmp            = $('<div id="fancybox-tmp"></div>'),
                loading        = $('<div id="fancybox-loading"><div></div></div>'),
                overlay        = $('<div id="fancybox-overlay"></div>'),
                wrap        = $('<div id="fancybox-wrap"></div>')
            );

            if (!$.support.opacity) {
                wrap.addClass('fancybox-ie');
                loading.addClass('fancybox-ie');
            }

            outer = $('<div id="fancybox-outer"></div>')
                .append('<div class="fancy-bg" id="fancy-bg-n"></div><div class="fancy-bg" id="fancy-bg-ne"></div><div class="fancy-bg" id="fancy-bg-e"></div><div class="fancy-bg" id="fancy-bg-se"></div><div class="fancy-bg" id="fancy-bg-s"></div><div class="fancy-bg" id="fancy-bg-sw"></div><div class="fancy-bg" id="fancy-bg-w"></div><div class="fancy-bg" id="fancy-bg-nw"></div>')
                .appendTo( wrap );

            outer.append(
                inner        = $('<div id="fancybox-inner"></div>'),
                close        = $('<a id="fancybox-close"></a>'),

                nav_left    = $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),
                nav_right    = $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>')
            );

            close.click($.fancybox.close);
            loading.click($.fancybox.cancel);

            nav_left.click(function(e) {
                e.preventDefault();
                $.fancybox.prev();
            });

            nav_right.click(function(e) {
                e.preventDefault();
                $.fancybox.next();
            });

            if (isIE6) {
                overlay.get(0).style.setExpression('height',    "document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'");
                loading.get(0).style.setExpression('top',        "(-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'");

                outer.prepend('<iframe id="fancybox-hide-sel-frame" src="javascript:\'\';" scrolling="no" frameborder="0" ></iframe>');
            }
        };

    /*
     * Public methods 
     */

    $.fn.fancybox = function(options) {
        $(this)
            .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))
            .unbind('click.fb').bind('click.fb', function(e) {
                e.preventDefault();

                if (busy) {
                    return;
                }

                busy = true;

                $(this).blur();

                selectedArray    = [];
                selectedIndex    = 0;

                var rel = $(this).attr('rel') || '';

                if (!rel || rel == '' || rel === 'nofollow') {
                    selectedArray.push(this);

                } else {
                    selectedArray    = $("a[rel=" + rel + "], area[rel=" + rel + "]");
                    selectedIndex    = selectedArray.index( this );
                }

                fancybox_start();

                return false;
            });

        return this;
    };

    $.fancybox = function(obj) {
        if (busy) {
            return;
        }

        busy = true;

        var opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {};

        selectedArray    = [];
        selectedIndex    = opts.index || 0;

        if ($.isArray(obj)) {
            for (var i = 0, j = obj.length; i < j; i++) {
                if (typeof obj[i] == 'object') {
                    $(obj[i]).data('fancybox', $.extend({}, opts, obj[i]));
                } else {
                    obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts));
                }
            }

            selectedArray = jQuery.merge(selectedArray, obj);

        } else {
            if (typeof obj == 'object') {
                $(obj).data('fancybox', $.extend({}, opts, obj));
            } else {
                obj = $({}).data('fancybox', $.extend({content : obj}, opts));
            }

            selectedArray.push(obj);
        }

        if (selectedIndex > selectedArray.length || selectedIndex < 0) {
            selectedIndex = 0;
        }

        fancybox_start();
    };

    $.fancybox.showActivity = function() {
        clearInterval(loadingTimer);

        loading.show();
        loadingTimer = setInterval(fancybox_animate_loading, 66);
    };

    $.fancybox.hideActivity = function() {
        loading.hide();
    };

    $.fancybox.next = function() {
        return $.fancybox.pos( currentIndex + 1);
    };
    
    $.fancybox.prev = function() {
        return $.fancybox.pos( currentIndex - 1);
    };

    $.fancybox.pos = function(pos) {
        if (busy) {
            return;
        }

        pos = parseInt(pos, 10);

        if (pos > -1 && currentArray.length > pos) {
            selectedIndex = pos;
            fancybox_start();
        }

        if (currentOpts.cyclic && currentArray.length > 1 && pos < 0) {
            selectedIndex = currentArray.length - 1;
            fancybox_start();
        }

        if (currentOpts.cyclic && currentArray.length > 1 && pos >= currentArray.length) {
            selectedIndex = 0;
            fancybox_start();
        }

        return;
    };

    $.fancybox.cancel = function() {
        if (busy) {
            return;
        }

        busy = true;

        $.event.trigger('fancybox-cancel');

        fancybox_abort();

        if (selectedOpts && $.isFunction(selectedOpts.onCancel)) {
            selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts);
        }

        busy = false;
    };

    // Note: within an iframe use - parent.$.fancybox.close();
    $.fancybox.close = function() {
        if (busy || wrap.is(':hidden')) {
            return;
        }

        busy = true;

        if (currentOpts && $.isFunction(currentOpts.onCleanup)) {
            if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
                busy = false;
                return;
            }
        }

        fancybox_abort();

        $(close.add( nav_left ).add( nav_right )).hide();

        $('#fancybox-title').remove();

        wrap.add(inner).add(overlay).unbind();

        $(window).unbind("resize.fb scroll.fb");
        $(document).unbind('keydown.fb');

        function _cleanup() {
            overlay.fadeOut('fast');

            wrap.hide();

            $.event.trigger('fancybox-cleanup');

            inner.empty();

            if ($.isFunction(currentOpts.onClosed)) {
                currentOpts.onClosed(currentArray, currentIndex, currentOpts);
            }

            currentArray    = selectedOpts    = [];
            currentIndex    = selectedIndex    = 0;
            currentOpts        = selectedOpts    = {};

            busy = false;
        }

        inner.css('overflow', 'hidden');

        if (currentOpts.transitionOut == 'elastic') {
            start_pos = fancybox_get_zoom_from();

            var pos = wrap.position();

            final_pos = {
                top        :    pos.top ,
                left    :    pos.left,
                width    :    wrap.width(),
                height    :    wrap.height()
            };

            if (currentOpts.opacity) {
                final_pos.opacity = 1;
            }

            fx.prop = 1;

            $(fx).animate({ prop: 0 }, {
                 duration    : currentOpts.speedOut,
                 easing        : currentOpts.easingOut,
                 step        : fancybox_draw,
                 complete    : _cleanup
            });

        } else {
            wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup);
        }
    };

    $.fancybox.resize = function() {
        var c, h;
        
        if (busy || wrap.is(':hidden')) {
            return;
        }

        busy = true;

        c = inner.wrapInner("<div style='overflow:auto'></div>").children();
        h = c.height();

        wrap.css({height:    h + (currentOpts.padding * 2) + titleh});
        inner.css({height:    h});

        c.replaceWith(c.children());

        $.fancybox.center();
    };

    $.fancybox.center = function() {
        busy = true;

        var view    = fancybox_get_viewport(),
            margin    = currentOpts.margin,
            to        = {};

        to.top    = view[3] + ((view[1] - ((wrap.height() - titleh) + (shadow * 2 ))) * 0.5);
        to.left    = view[2] + ((view[0] - (wrap.width() + (shadow * 2 ))) * 0.5);

        to.top    = Math.max(view[3] + margin, to.top);
        to.left    = Math.max(view[2] + margin, to.left);

        wrap.css(to);

        busy = false;
    };

    $.fn.fancybox.defaults = {
        
        padding                :    10,
        margin                :    20,
        opacity                :    false,
        modal                :    false,
        cyclic                :    false,
        scrolling            :    'auto',    // 'auto', 'yes' or 'no'

        width                :    560,
        height                :    340,

        autoScale            :    true,
        autoDimensions        :    true,
        centerOnScroll        :    false,

        ajax                :    {},
        swf                    :    { wmode: 'transparent' },

        hideOnOverlayClick    :    true,
        hideOnContentClick    :    false,

        overlayShow            :    true,
        overlayOpacity        :    0.3,
        overlayColor        :    '#666',

        titleShow            :    true,
        titlePosition        :    'outside',    // 'outside', 'inside' or 'over'
        titleFormat            :    null,

        transitionIn        :    'fade',    // 'elastic', 'fade' or 'none'
        transitionOut        :    'fade',    // 'elastic', 'fade' or 'none'

        speedIn                :    300,
        speedOut            :    300,

        changeSpeed            :    300,
        changeFade            :    'fast',

        easingIn            :    'swing',
        easingOut            :    'swing',

        showCloseButton        :    true,
        showNavArrows        :    true,
        enableKeyboardNav      : true,
        enableEscapeButton    :    true,

        onStart                :    null,
        onCancel            :    null,
        onComplete            :    null,
        onCleanup            :    null,
        onClosed            :    null
    };

    $(document).ready(function() {
        fancybox_init();
    });

})(jQuery);

;

/*!
 * jQuery Form Plugin
 * version: 2.47 (04-SEP-2010)
 * @requires jQuery v1.3.2 or later
 *
 * Examples and documentation at: http://malsup.com/jquery/form/
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
;(function($) {

/*
    Usage Note:
    -----------
    Do not use both ajaxSubmit and ajaxForm on the same form.  These
    functions are intended to be exclusive.  Use ajaxSubmit if you want
    to bind your own submit handler to the form.  For example,

    $(document).ready(function() {
        $('#myForm').bind('submit', function() {
            $(this).ajaxSubmit({
                target: '#output'
            });
            return false; // <-- important!
        });
    });

    Use ajaxForm when you want the plugin to manage all the event binding
    for you.  For example,

    $(document).ready(function() {
        $('#myForm').ajaxForm({
            target: '#output'
        });
    });

    When using ajaxForm, the ajaxSubmit function will be invoked for you
    at the appropriate time.
*/

/**
 * ajaxSubmit() provides a mechanism for immediately submitting
 * an HTML form using AJAX.
 */
$.fn.ajaxSubmit = function(options) {
    // fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
    if (!this.length) {
        log('ajaxSubmit: skipping submit process - no element selected');
        return this;
    }

    if (typeof options == 'function') {
        options = { success: options };
    }

    var url = $.trim(this.attr('action'));
    if (url) {
        // clean url (don't include hash vaue)
        url = (url.match(/^([^#]+)/)||[])[1];
    }
    url = url || window.location.href || '';

    options = $.extend(true, {
        url:  url,
        type: this.attr('method') || 'GET',
        iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
    }, options);

    // hook for manipulating the form data before it is extracted;
    // convenient for use with rich editors like tinyMCE or FCKEditor
    var veto = {};
    this.trigger('form-pre-serialize', [this, options, veto]);
    if (veto.veto) {
        log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
        return this;
    }

    // provide opportunity to alter form data before it is serialized
    if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
        log('ajaxSubmit: submit aborted via beforeSerialize callback');
        return this;
    }

    var n,v,a = this.formToArray(options.semantic);
    if (options.data) {
        options.extraData = options.data;
        for (n in options.data) {
            if(options.data[n] instanceof Array) {
                for (var k in options.data[n]) {
                    a.push( { name: n, value: options.data[n][k] } );
                }
            }
            else {
                v = options.data[n];
                v = $.isFunction(v) ? v() : v; // if value is fn, invoke it
                a.push( { name: n, value: v } );
            }
        }
    }

    // give pre-submit callback an opportunity to abort the submit
    if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
        log('ajaxSubmit: submit aborted via beforeSubmit callback');
        return this;
    }

    // fire vetoable 'validate' event
    this.trigger('form-submit-validate', [a, this, options, veto]);
    if (veto.veto) {
        log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
        return this;
    }

    var q = $.param(a);

    if (options.type.toUpperCase() == 'GET') {
        options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
        options.data = null;  // data is null for 'get'
    }
    else {
        options.data = q; // data is the query string for 'post'
    }

    var $form = this, callbacks = [];
    if (options.resetForm) {
        callbacks.push(function() { $form.resetForm(); });
    }
    if (options.clearForm) {
        callbacks.push(function() { $form.clearForm(); });
    }

    // perform a load on the target only if dataType is not provided
    if (!options.dataType && options.target) {
        var oldSuccess = options.success || function(){};
        callbacks.push(function(data) {
            var fn = options.replaceTarget ? 'replaceWith' : 'html';
            $(options.target)[fn](data).each(oldSuccess, arguments);
        });
    }
    else if (options.success) {
        callbacks.push(options.success);
    }

    options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
        var context = options.context || options;   // jQuery 1.4+ supports scope context 
        for (var i=0, max=callbacks.length; i < max; i++) {
            callbacks[i].apply(context, [data, status, xhr || $form, $form]);
        }
    };

    // are there files to upload?
    var fileInputs = $('input:file', this).length > 0;
    var mp = 'multipart/form-data';
    var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);

    // options.iframe allows user to force iframe mode
    // 06-NOV-09: now defaulting to iframe mode if file input is detected
   if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
       // hack to fix Safari hang (thanks to Tim Molendijk for this)
       // see:  http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
       if (options.closeKeepAlive) {
           $.get(options.closeKeepAlive, fileUpload);
        }
       else {
           fileUpload();
        }
   }
   else {
       $.ajax(options);
   }

    // fire 'notify' event
    this.trigger('form-submit-notify', [this, options]);
    return this;


    // private function for handling file uploads (hat tip to YAHOO!)
    function fileUpload() {
        var form = $form[0];

        if ($(':input[name=submit],:input[id=submit]', form).length) {
            // if there is an input with a name or id of 'submit' then we won't be
            // able to invoke the submit fn on the form (at least not x-browser)
            alert('Error: Form elements must not have name or id of "submit".');
            return;
        }
        
        var s = $.extend(true, {}, $.ajaxSettings, options);
        s.context = s.context || s;
        var id = 'jqFormIO' + (new Date().getTime()), fn = '_'+id;
        window[fn] = function() {
            var f = $io.data('form-plugin-onload');
            if (f) {
                f();
                window[fn] = undefined;
                try { delete window[fn]; } catch(e){}
            }
        }
        var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ s.iframeSrc +'" onload="window[\'_\'+this.id]()" />');
        var io = $io[0];

        $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });

        var xhr = { // mock object
            aborted: 0,
            responseText: null,
            responseXML: null,
            status: 0,
            statusText: 'n/a',
            getAllResponseHeaders: function() {},
            getResponseHeader: function() {},
            setRequestHeader: function() {},
            abort: function() {
                this.aborted = 1;
                $io.attr('src', s.iframeSrc); // abort op in progress
            }
        };

        var g = s.global;
        // trigger ajax global events so that activity/block indicators work like normal
        if (g && ! $.active++) {
            $.event.trigger("ajaxStart");
        }
        if (g) {
            $.event.trigger("ajaxSend", [xhr, s]);
        }

        if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
            if (s.global) { 
                $.active--;
            }
            return;
        }
        if (xhr.aborted) {
            return;
        }

        var cbInvoked = false;
        var timedOut = 0;

        // add submitting element to data if we know it
        var sub = form.clk;
        if (sub) {
            var n = sub.name;
            if (n && !sub.disabled) {
                s.extraData = s.extraData || {};
                s.extraData[n] = sub.value;
                if (sub.type == "image") {
                    s.extraData[n+'.x'] = form.clk_x;
                    s.extraData[n+'.y'] = form.clk_y;
                }
            }
        }

        // take a breath so that pending repaints get some cpu time before the upload starts
        function doSubmit() {
            // make sure form attrs are set
            var t = $form.attr('target'), a = $form.attr('action');

            // update form attrs in IE friendly way
            form.setAttribute('target',id);
            if (form.getAttribute('method') != 'POST') {
                form.setAttribute('method', 'POST');
            }
            if (form.getAttribute('action') != s.url) {
                form.setAttribute('action', s.url);
            }

            // ie borks in some cases when setting encoding
            if (! s.skipEncodingOverride) {
                $form.attr({
                    encoding: 'multipart/form-data',
                    enctype:  'multipart/form-data'
                });
            }

            // support timout
            if (s.timeout) {
                setTimeout(function() { timedOut = true; cb(); }, s.timeout);
            }

            // add "extra" data to form if provided in options
            var extraInputs = [];
            try {
                if (s.extraData) {
                    for (var n in s.extraData) {
                        extraInputs.push(
                            $('<input type="hidden" name="'+n+'" value="'+s.extraData[n]+'" />')
                                .appendTo(form)[0]);
                    }
                }

                // add iframe to doc and submit the form
                $io.appendTo('body');
                $io.data('form-plugin-onload', cb);
                form.submit();
            }
            finally {
                // reset attrs and remove "extra" input elements
                form.setAttribute('action',a);
                if(t) {
                    form.setAttribute('target', t);
                } else {
                    $form.removeAttr('target');
                }
                $(extraInputs).remove();
            }
        }

        if (s.forceSync) {
            doSubmit();
        }
        else {
            setTimeout(doSubmit, 10); // this lets dom updates render
        }
    
        var data, doc, domCheckCount = 50;

        function cb() {
            if (cbInvoked) {
                return;
            }

            $io.removeData('form-plugin-onload');
            
            var ok = true;
            try {
                if (timedOut) {
                    throw 'timeout';
                }
                // extract the server response from the iframe
                doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
                
                var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
                log('isXml='+isXml);
                if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) {
                    if (--domCheckCount) {
                        // in some browsers (Opera) the iframe DOM is not always traversable when
                        // the onload callback fires, so we loop a bit to accommodate
                        log('requeing onLoad callback, DOM not available');
                        setTimeout(cb, 250);
                        return;
                    }
                    // let this fall through because server response could be an empty document
                    //log('Could not access iframe DOM after mutiple tries.');
                    //throw 'DOMException: not available';
                }

                //log('response detected');
                cbInvoked = true;
                xhr.responseText = doc.documentElement ? doc.documentElement.innerHTML : null; 
                xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
                xhr.getResponseHeader = function(header){
                    var headers = {'content-type': s.dataType};
                    return headers[header];
                };

                var scr = /(json|script)/.test(s.dataType);
                if (scr || s.textarea) {
                    // see if user embedded response in textarea
                    var ta = doc.getElementsByTagName('textarea')[0];
                    if (ta) {
                        xhr.responseText = ta.value;
                    }
                    else if (scr) {
                        // account for browsers injecting pre around json response
                        var pre = doc.getElementsByTagName('pre')[0];
                        if (pre) {
                            xhr.responseText = pre.innerHTML;
                        }
                    }              
                }
                else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
                    xhr.responseXML = toXml(xhr.responseText);
                }
                data = $.httpData(xhr, s.dataType);
            }
            catch(e){
                log('error caught:',e);
                ok = false;
                xhr.error = e;
                $.handleError(s, xhr, 'error', e);
            }

            // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
            if (ok) {
                s.success.call(s.context, data, 'success', xhr);
                if (g) {
                    $.event.trigger("ajaxSuccess", [xhr, s]);
                }
            }
            if (g) {
                $.event.trigger("ajaxComplete", [xhr, s]);
            }
            if (g && ! --$.active) {
                $.event.trigger("ajaxStop");
            }
            if (s.complete) {
                s.complete.call(s.context, xhr, ok ? 'success' : 'error');
            }

            // clean up
            setTimeout(function() {
                $io.removeData('form-plugin-onload');
                $io.remove();
                xhr.responseXML = null;
            }, 100);
        }

        function toXml(s, doc) {
            if (window.ActiveXObject) {
                doc = new ActiveXObject('Microsoft.XMLDOM');
                doc.async = 'false';
                doc.loadXML(s);
            }
            else {
                doc = (new DOMParser()).parseFromString(s, 'text/xml');
            }
            return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
        }
    }
};

/**
 * ajaxForm() provides a mechanism for fully automating form submission.
 *
 * The advantages of using this method instead of ajaxSubmit() are:
 *
 * 1: This method will include coordinates for <input type="image" /> elements (if the element
 *    is used to submit the form).
 * 2. This method will include the submit element's name/value data (for the element that was
 *    used to submit the form).
 * 3. This method binds the submit() method to the form for you.
 *
 * The options argument for ajaxForm works exactly as it does for ajaxSubmit.  ajaxForm merely
 * passes the options argument along after properly binding events for submit elements and
 * the form itself.
 */
$.fn.ajaxForm = function(options) {
    // in jQuery 1.3+ we can fix mistakes with the ready state
    if (this.length === 0) {
        var o = { s: this.selector, c: this.context };
        if (!$.isReady && o.s) {
            log('DOM not ready, queuing ajaxForm');
            $(function() {
                $(o.s,o.c).ajaxForm(options);
            });
            return this;
        }
        // is your DOM ready?  http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
        log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
        return this;
    }
    
    return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
        if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
            e.preventDefault();
            $(this).ajaxSubmit(options);
        }
    }).bind('click.form-plugin', function(e) {
        var target = e.target;
        var $el = $(target);
        if (!($el.is(":submit,input:image"))) {
            // is this a child element of the submit el?  (ex: a span within a button)
            var t = $el.closest(':submit');
            if (t.length == 0) {
                return;
            }
            target = t[0];
        }
        var form = this;
        form.clk = target;
        if (target.type == 'image') {
            if (e.offsetX != undefined) {
                form.clk_x = e.offsetX;
                form.clk_y = e.offsetY;
            } else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
                var offset = $el.offset();
                form.clk_x = e.pageX - offset.left;
                form.clk_y = e.pageY - offset.top;
            } else {
                form.clk_x = e.pageX - target.offsetLeft;
                form.clk_y = e.pageY - target.offsetTop;
            }
        }
        // clear form vars
        setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
    });
};

// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
$.fn.ajaxFormUnbind = function() {
    return this.unbind('submit.form-plugin click.form-plugin');
};

/**
 * formToArray() gathers form element data into an array of objects that can
 * be passed to any of the following ajax functions: $.get, $.post, or load.
 * Each object in the array has both a 'name' and 'value' property.  An example of
 * an array for a simple login form might be:
 *
 * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
 *
 * It is this array that is passed to pre-submit callback functions provided to the
 * ajaxSubmit() and ajaxForm() methods.
 */
$.fn.formToArray = function(semantic) {
    var a = [];
    if (this.length === 0) {
        return a;
    }

    var form = this[0];
    var els = semantic ? form.getElementsByTagName('*') : form.elements;
    if (!els) {
        return a;
    }
    
    var i,j,n,v,el;
    for(i=0, max=els.length; i < max; i++) {
        el = els[i];
        n = el.name;
        if (!n) {
            continue;
        }

        if (semantic && form.clk && el.type == "image") {
            // handle image inputs on the fly when semantic == true
            if(!el.disabled && form.clk == el) {
                a.push({name: n, value: $(el).val()});
                a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
            }
            continue;
        }

        v = $.fieldValue(el, true);
        if (v && v.constructor == Array) {
            for(j=0, jmax=v.length; j < jmax; j++) {
                a.push({name: n, value: v[j]});
            }
        }
        else if (v !== null && typeof v != 'undefined') {
            a.push({name: n, value: v});
        }
    }

    if (!semantic && form.clk) {
        // input type=='image' are not found in elements array! handle it here
        var $input = $(form.clk), input = $input[0];
        n = input.name;
        if (n && !input.disabled && input.type == 'image') {
            a.push({name: n, value: $input.val()});
            a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
        }
    }
    return a;
};

/**
 * Serializes form data into a 'submittable' string. This method will return a string
 * in the format: name1=value1&amp;name2=value2
 */
$.fn.formSerialize = function(semantic) {
    //hand off to jQuery.param for proper encoding
    return $.param(this.formToArray(semantic));
};

/**
 * Serializes all field elements in the jQuery object into a query string.
 * This method will return a string in the format: name1=value1&amp;name2=value2
 */
$.fn.fieldSerialize = function(successful) {
    var a = [];
    this.each(function() {
        var n = this.name;
        if (!n) {
            return;
        }
        var v = $.fieldValue(this, successful);
        if (v && v.constructor == Array) {
            for (var i=0,max=v.length; i < max; i++) {
                a.push({name: n, value: v[i]});
            }
        }
        else if (v !== null && typeof v != 'undefined') {
            a.push({name: this.name, value: v});
        }
    });
    //hand off to jQuery.param for proper encoding
    return $.param(a);
};

/**
 * Returns the value(s) of the element in the matched set.  For example, consider the following form:
 *
 *  <form><fieldset>
 *      <input name="A" type="text" />
 *      <input name="A" type="text" />
 *      <input name="B" type="checkbox" value="B1" />
 *      <input name="B" type="checkbox" value="B2"/>
 *      <input name="C" type="radio" value="C1" />
 *      <input name="C" type="radio" value="C2" />
 *  </fieldset></form>
 *
 *  var v = $(':text').fieldValue();
 *  // if no values are entered into the text inputs
 *  v == ['','']
 *  // if values entered into the text inputs are 'foo' and 'bar'
 *  v == ['foo','bar']
 *
 *  var v = $(':checkbox').fieldValue();
 *  // if neither checkbox is checked
 *  v === undefined
 *  // if both checkboxes are checked
 *  v == ['B1', 'B2']
 *
 *  var v = $(':radio').fieldValue();
 *  // if neither radio is checked
 *  v === undefined
 *  // if first radio is checked
 *  v == ['C1']
 *
 * The successful argument controls whether or not the field element must be 'successful'
 * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
 * The default value of the successful argument is true.  If this value is false the value(s)
 * for each element is returned.
 *
 * Note: This method *always* returns an array.  If no valid value can be determined the
 *       array will be empty, otherwise it will contain one or more values.
 */
$.fn.fieldValue = function(successful) {
    for (var val=[], i=0, max=this.length; i < max; i++) {
        var el = this[i];
        var v = $.fieldValue(el, successful);
        if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
            continue;
        }
        v.constructor == Array ? $.merge(val, v) : val.push(v);
    }
    return val;
};

/**
 * Returns the value of the field element.
 */
$.fieldValue = function(el, successful) {
    var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
    if (successful === undefined) {
        successful = true;
    }

    if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
        (t == 'checkbox' || t == 'radio') && !el.checked ||
        (t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
        tag == 'select' && el.selectedIndex == -1)) {
            return null;
    }

    if (tag == 'select') {
        var index = el.selectedIndex;
        if (index < 0) {
            return null;
        }
        var a = [], ops = el.options;
        var one = (t == 'select-one');
        var max = (one ? index+1 : ops.length);
        for(var i=(one ? index : 0); i < max; i++) {
            var op = ops[i];
            if (op.selected) {
                var v = op.value;
                if (!v) { // extra pain for IE...
                    v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
                }
                if (one) {
                    return v;
                }
                a.push(v);
            }
        }
        return a;
    }
    return $(el).val();
};

/**
 * Clears the form data.  Takes the following actions on the form's input fields:
 *  - input text fields will have their 'value' property set to the empty string
 *  - select elements will have their 'selectedIndex' property set to -1
 *  - checkbox and radio inputs will have their 'checked' property set to false
 *  - inputs of type submit, button, reset, and hidden will *not* be effected
 *  - button elements will *not* be effected
 */
$.fn.clearForm = function() {
    return this.each(function() {
        $('input,select,textarea', this).clearFields();
    });
};

/**
 * Clears the selected form elements.
 */
$.fn.clearFields = $.fn.clearInputs = function() {
    return this.each(function() {
        var t = this.type, tag = this.tagName.toLowerCase();
        if (t == 'text' || t == 'password' || tag == 'textarea') {
            this.value = '';
        }
        else if (t == 'checkbox' || t == 'radio') {
            this.checked = false;
        }
        else if (tag == 'select') {
            this.selectedIndex = -1;
        }
    });
};

/**
 * Resets the form data.  Causes all form elements to be reset to their original value.
 */
$.fn.resetForm = function() {
    return this.each(function() {
        // guard against an input with the name of 'reset'
        // note that IE reports the reset function as an 'object'
        if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
            this.reset();
        }
    });
};

/**
 * Enables or disables any matching elements.
 */
$.fn.enable = function(b) {
    if (b === undefined) {
        b = true;
    }
    return this.each(function() {
        this.disabled = !b;
    });
};

/**
 * Checks/unchecks any matching checkboxes or radio buttons and
 * selects/deselects and matching option elements.
 */
$.fn.selected = function(select) {
    if (select === undefined) {
        select = true;
    }
    return this.each(function() {
        var t = this.type;
        if (t == 'checkbox' || t == 'radio') {
            this.checked = select;
        }
        else if (this.tagName.toLowerCase() == 'option') {
            var $sel = $(this).parent('select');
            if (select && $sel[0] && $sel[0].type == 'select-one') {
                // deselect all other options
                $sel.find('option').selected(false);
            }
            this.selected = select;
        }
    });
};

// helper fn for console logging
// set $.fn.ajaxSubmit.debug to true to enable debug logging
function log() {
    if ($.fn.ajaxSubmit.debug) {
        var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
        if (window.console && window.console.log) {
            window.console.log(msg);
        }
        else if (window.opera && window.opera.postError) {
            window.opera.postError(msg);
        }
    }
};

})(jQuery);


(function($) {
 

    var closeFancyBox = function(e) {
            $.fancybox.close();
            e.preventDefault();
            e.stopPropagation();
    };    

    var setupFormHandler = function( link ) {        
        var formHandler = link.attr("href") + "/1";
        var formContainerSelector = "#fancybox-inner ";
        var loaderClass = "loader";

        var popup = $('<div class="fancy-popup clearfix"></div>');
        var popupContent = $('<div class="fancy-popup-content"></div>');
        var popupClose = $('<a href="#" class="close">sluiten</a>');
        popup.append(popupContent).append(popupClose);
        
        var refreshSection = function( resultsContainer, domContent ) {
            resultsContainer.removeClass( loaderClass ).empty().append( domContent );
            handlePageableContent();
            handleReports();
            $.fancybox.resize();
        };
        
        var requestPage = function( url, updateableSectionSelector ) {            
            var resultsContainer = $( formContainerSelector + updateableSectionSelector );    
            resultsContainer.addClass( loaderClass ).children().addClass("dimmed");              
            $.post( url, {}, function( html, textStatus, xmlHttpRequest ) { 
                var div = $('<div></div>').html( html );
                var domContent = div.find( updateableSectionSelector ).children();
                refreshSection( resultsContainer, domContent );            
            } );
        };
    
        var handlePageableContent = function() {
            $( formContainerSelector + ' .shadowbox-pager a').click( function(e) {
                var href = $(this).attr('href');
                requestPage( href, '.shadowbox-pageable-content' );
                e.preventDefault();
            });
        };
       
        var handleReports = function() {        
            $( formContainerSelector + ' a[rel=report]').click( function(e) {                
                var margin = 20;
                var top = $(this).offset().top - $(formContainerSelector).offset().top - 45;
                var left = $(this).offset().left - $(formContainerSelector).offset().left + 10;
                var outerWidth = 380;    
                var innerWidth = outerWidth - 20;
                var action = $(this).attr('href');
                var options = {
                    url : action,
                    success : function( data, status, xhr ) {
                        var div = $('<div></div>').html( data );                                        
                        popupContent
                            .html( div.find('#ajax-content') )
                            .find('.shadowbox')
                            .width( innerWidth )
                            .find( '#report_no' ).click( hidePopup );
                    }
                };
                
                popup.css( { 
                        left : left,
                        top: top, 
                        width : outerWidth
                    } );

                popupContent
                        .empty()
                        .load( action + ' #ajax-content', function() {                        
                            popupContent    
                                .find('form').ajaxForm( options )
                                .find( '#report_no' ).click( hidePopup );                                
                            popup.fadeIn().find('.shadowbox').width( innerWidth );                            
                        } );
                
                e.preventDefault();
            });
        };
        
        var hidePopup = function() {            
            popup.fadeOut('fast', function() {
                popupContent.empty();
            });
        };
        
        var initializePopupWindow = function() {
            popupContent.empty();
            $( formContainerSelector ).append( popup.hide() );
            popupClose.click( function(e) {
                hidePopup();
                e.preventDefault();
            });
        };
        
        var handleFancyboxLinks = function() {
            $( formContainerSelector + " a[rel='fancybox-form']").fancyboxForm();
        };
    
        var isNumeric = function(s) {
            return s.length > 0 && !isNaN(s);
        };
        
        var getPostCommentAction = function(oldAction) {            
            var parts = oldAction.split( '/' );
            var url = ['ajax','postcomment'];
            var start = false;                
            for( var i = 0; i < parts.length; i++) {
                var p = parts[i];
                if ( isNumeric(p) ) {
                    start = true;
                }
                if (start) {
                    url.push(p);
                }
            }            
            var action = '/' + url.join('/');
            return action;
        };
        
        var updatePageStatus = function() {
            var oldForm = $("#content .comment-form form");
            if ( oldForm.exists() ) { 
               var oldAction = oldForm.attr('action');           
               var action = getPostCommentAction(oldAction);  
               $.post( action, function( html, textStatus, xmlHttpRequest ) { 
                    var newContent = $('<div></div>').html( html ).children(); 
                    $( "#content .comment-form").remove();
                    $( "#content .comments").nextAll().andSelf().remove();
                    $("#content .double-column").append( newContent ); 
                    $( "#content .comment-form form").attr('action',oldAction);
                    $("#content a[rel='fancybox-form']").fancyboxForm();
                } );
            }
        };

        var hasLogin = false;
    
        var renderOverlay = function(content) {
            $( formContainerSelector ).empty().html(content).show();                        
            handleFancyboxLinks();                    
            if ( hasLogin ) {
                updatePageStatus();
            };            
            handleSubmit();                        
            $( formContainerSelector + ' #report_no').click( closeFancyBox );            
            // handle pageable content
            handlePageableContent();            
            initializePopupWindow();            
            handleReports();            
            rtvNH.form.init(formContainerSelector);            
            // resize the container
            $.fancybox.resize();
        };
                
        // handles the forms submit actions
        var handleSubmit = function() {        
            // get the form out of the overlay
            var form = $( formContainerSelector + " form");
            hasLogin = $(formContainerSelector).find("input[name='formaction'][value='loginuser']").exists();            
            var options = {
                url : formHandler,
                success : function( data, status, xhr ) {     
                    var div = $("<div></div>").html( data );                    
                    var content = div.find("#ajax-content").html();                    
                    renderOverlay( content ); 
                }
            };            
            form.ajaxForm( options );     
        };
        
        // check for fancybox availability
        if ( $().fancybox ) {
     
            link.fancybox( {            
                speedIn : 600,
                speedOut : 200,
                overlayOpacity: 0.7,
                overlayColor : '#000',
                padding : 10,
                centerOnScroll : false,
                scrolling : 'no',
                enableKeyboardNav : false,
                showNavArrows : false,
                onStart : function() {
                  $( formContainerSelector ).hide();
                },
                onComplete : function() {
                    // we don't want all the body content
                    
                    var content = $( formContainerSelector + " #ajax-content").html();            
                    renderOverlay( content );                    
                }
            } );        
        }
    };

    /**
     * default options
     */
    var defaultOptions = {        
    };
    
    /**
     * add form overlay trigger to the chosen elements
     */
    $.fn.fancyboxForm = function(options) {    
        // extend options with the defaults
        var extendedOptions = $.extend(defaultOptions, options);        
        return $(this).each( function(i) {       
           //only initialize once
           if ($(this).data('_fancyboxed')) {
               return;
           }           
           $(this).data('_fancyboxed', true );           
           setupFormHandler( $(this), extendedOptions );
       } );
    };
})(jQuery);



;

(function($) {
    
    /**
     * setup
     */
    var setup = function( elem, options ) {
        var name = options.name;
        var programs = elem.find('.' + name);
        var container = elem.find('.' + name + '-container');
        var menu = $('<div class="' + name + '-menu"></div>');
        var activeIndex = 0;
        var numPrograms = programs.size();        
        var thumbs = [];
        var timer = false;
        
        var animate = function(index) {
            thumbs.removeClass('active');
            activeIndex = index;
            programs.fadeOut('fast').eq(index).fadeIn('slow');
            thumbs.eq(index).addClass('active');
        };        
        
        programs.each( function(i) {
            
            $(this).css( {
                position : 'absolute',
                top : 0,
                left : 0
            });
            
            var img = $(this).find('img').clone().width(138).height(78).css( {
                display : 'block'
            });
            
            var a = $(this).find('a:eq(0)').clone().empty().css({
                position : 'absolute',
                top : 10,
                display : 'block',
                left : ( i * options.spacing )
            }).mouseover( function() {
                stop();
                if ( i !== activeIndex ) {                    
                    animate(i);                 
                }
            } ).mouseout( function() {
                start();
            }).append( img );
            
            menu.append( a ).css({ bottom: -100 });

        } );
        
        elem.append(menu).mouseover( function() {
            menu.stop().animate( { bottom : 0 } );                          
        }).mouseout( function() {
            menu.stop().animate( { bottom : -100 } );    
        });
        
        thumbs = menu.children();
        
        programs.hide().eq(activeIndex).show();
        
        var cycle = function() {
            activeIndex ++;
            if ( activeIndex >= numPrograms ) {
                activeIndex = 0;
            }
            animate(activeIndex);            
        };
        var start = function() {
            if(options.autostart){
                timer = setInterval( cycle, options.timeout );
            }
        };
        var stop = function() {
            if(options.autostart){
                clearInterval( timer );
                timer = false;
            }
        };
        
        thumbs.eq(0).addClass('active');
        if(options.autostart){
            start();
        }
    };
    
    /**
     * default options 
     */
    var defaultOptions = {       
        step : 350,
        spacing : 160,
        timeout : 10000,
        name : 'program',
        autoStart : 1
    };
 
    /**
     * assign carrousel as a jquery method
     */
    $.fn.carrousel = function( options ) {        
        options = options || {};        
        var extendedOptions = $.extend( defaultOptions, options);        
        return $(this).each( function(i) {            
            setup( $(this), extendedOptions );
        });
    };
    
})(jQuery);


(function(){  
    var autoStart = 1;  
    $(document).ready( function() {        
        if(window.carouselOptions){
            autoStart = carouselOptions.autoStart || 0;
        }
        $('#program-header').carrousel({
            name : 'program',
            autostart : autoStart
        });
    });
})();

;

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/

var Base64 = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = Base64._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

};


;

/*     
    Plugin: iframe autoheight jQuery Plugin 
    Author: original code by NATHAN SMITH; converted to plugin by Jesse House
    File: jquery.iframe-auto-height.plugin.js
    Description: when the page loads set the height of an iframe based on the height of its contents
    Remarks: original code from http://sonspring.com/journal/jquery-iframe-sizing    
    Version: 1.0.0 - see README: http://github.com/house9/jquery-iframe-auto-height
*/
(function ($) {
    $.fn.iframeAutoHeight = function (options) {
        // set default option values
        var options = $.extend({
            heightOffset: 0
        }, options);

        // iterate over the matched elements passed to the plugin
        $(this).each(function () {
            // Check if browser is Opera or Safari(Webkit so Chrome as well)
            if ($.browser.safari || $.browser.opera) {
                // Start timer when loaded.
                $(this).load(function () {
                    var iframe = this;
                    var delayedResize = function () {
                        resizeHeight(iframe);
                    };
                    setTimeout(delayedResize, 0);
                });

                // Safari and Opera need a kick-start.
                var source = $(this).attr('src');
                $(this).attr('src', '');
                $(this).attr('src', source);
            }
            else {
                // For other browsers.
                $(this).load(function () {
                    resizeHeight(this);
                });
            }

            // resizeHeight
            function resizeHeight(iframe) {
                // Set inline style to equal the body height of the iframed content plus a little
                var newHeight = iframe.contentWindow.document.body.offsetHeight + options.heightOffset;
                iframe.style.height = newHeight + 'px';
            }

        }); // end
    }
})(jQuery);

function hijacklinks(iframe){
  var as = iframe.contentDocument.getElementsByTagName('a');
  for(i=0;i<as.length;i++){
    as[i].setAttribute('target','_parent');
  }
}
