        

$(document).ready(function() {
  
        hideParagraphs();        
        hideWRCimages();
  
        // Hide "Other Links" etc
        $("#otherlinks").hide();
        $("#magazines").hide();
        $("#pursuitforce").hide();
  
        // Add view link onto links
        $("ul#links").append("<li>Magazines - <a href=\"magazinestop\" id=\"viewmags\">view link</a></li>");
        $("ul#links").append("<li>Pursuit Force - <a href=\"pursuitforcetop\" id=\"viewpursuit\">view link</a></li>");
        $("ul#links").append("<li>Other Links - <a href=\"otherlinkstop\" id=\"viewotherlinks\">view link</a></li>");
          
        // Attach event to "viewmags" we jsut created above
        $("#viewmags").click(function(){
                if ($("#magazines").css("display") == "none") { showPanel("mags"); } else { hidePanel("mags"); }
                return false;    
        });  
        
        // Attach event to "viewpursuit" we jsut created above
        $("#viewpursuit").click(function(){
                
                if ($("#pursuitforce").css("display") == "none") { showPanel("pursuit"); } else { hidePanel("pursuit"); }
                return false;    
        });  
        
        // Attach event to "viewotherlinks" we jsut created above
        $("#viewotherlinks").click(function(){                        

                if ($("#otherlinks").css("display") == "none") { showPanel("otherlinks"); } else { hidePanel("otherlinks"); }
                return false;    
        });                  
});

function showPanel(whichPanel) {

        switch (whichPanel) {
        
                case "mags":
                
                        $("#pursuitforce").hide();            
                        $("#otherlinks").hide();                        
                        $("#magazines").show(); 
                        $("a[@name='magazinestop']").ScrollTo("fast");                                
                        break;
                case "pursuit":
                        
                        $("#magazines").hide();
                        $("#otherlinks").hide();                                        
                        $("#pursuitforce").show();         
                        $("a[@name='pursuitforcetop']").ScrollTo("fast");                
                        break;
                default:
                
                        $("#magazines").hide();             
                        $("#pursuitforce").hide();                                        
                        $("#otherlinks").show();         
                        $("a[@name='otherlinkstop']").ScrollTo("fast");                
                        break;
        }
}

function hidePanel(whichPanel) {

        switch (whichPanel) {
        
                case "mags":                        
                        $("#magazines").hide();                               
                        break;
                case "pursuit":                                      
                        $("#pursuitforce").hide();                      
                        break;
                default:                                      
                        $("#otherlinks").hide();                         
                        break;
        }
}

function hideWRCimages() {

        var start = 0;
        var imageperpage = 2;
        var totalimages = $("#wrcright img").length;
        var images = $("#wrcright img");
  
        // Hide all bar first 2
        $("#wrcright img:gt(1)").hide();
  
        var next = "<a href=\"#\" id=\"nextwrcimage\">Next &gt;</a>";
        var previous = "<a href=\"#\" id=\"previouswrcimage\">&lt; Previous</a>";
  
        // Attach links      
        $("#wrcimagecontrols").append(previous)
        $("#previouswrcimage").click(function() {
                
                images.hide();
                $(images.get(start - 2)).show();
                $(images.get(start - 1)).show();
      
                start -= imageperpage;
      
                if (start < totalimages) {
                        $("#nextwrcimage").show();
                }
      
                if (start <= 0 ) {
                        $("#previouswrcimage").hide();
                }
                
                return false;
        });
          
        // Initial state for previous button is "off"
        if (start <= 0 ) {
                $("#previouswrcimage").hide();
        }
            
        $("#wrcimagecontrols").append(next)
        $("#nextwrcimage").click(function() {
      
                images.hide();
                $(images.get(start + 2)).show();
                $(images.get(start + 3)).show();
      
                start += imageperpage;
       
                if (start >= (totalimages - imageperpage)) {
                        $("#nextwrcimage").hide();
                }
      
                if (start > 0 ) {
                        $("#previouswrcimage").show();
                }
     
                return false;
        });
}


function hideParagraphs() {

        // Hide the first paragraph in each block
  
        // Home page
        $("#content_right div.newscontent").each(function(i) {
                $("p:gt(0)", this).hide();      
                $("p:eq(0)", this).append("<span class=\"latestnewslink\">&gt; <a href=\"/news-and-jobs/index.aspx\" class=\"seelatestnews\">See Latest News</a></span>")
        });
  
        /* -------------------------------------------------------------- */
  
        // About us        
        $("#aboutus_right div.aboutuscontent").each(function(i){
                $("p:gt(0)", this).hide();      
                // Gotta show the "readmore link"
                $("p.readmore").show();
        });
          
        /* -------------------------------------------------------------- */
  
        // About us main content
        $("#aboutuscontent .separator").hide();
        $("#aboutuscontent div.leftpage:gt(0)").hide();
        $("#Biog").hide(); 
        $("#aboutuscontent div.rightpage)").hide(); 
  
        var amore = '+ <a href=\"#\" class=\"aboutcontentreadmore\">Read more</a>';
        var aless = '- <a href=\"#\" class=\"aboutcontentreadmore\">Read less</a>';
          
        $("#aboutuscontent div.leftpage:eq(0)")
                .append("<span class=\"aboutusmorelink\">" + amore + "</span>")
                .toggle(function(){
          
                        // Show all hidden paragraphs
                        $("#aboutuscontent .separator").show();
                        $("#aboutuscontent div.leftpage:gt(0)").show();
                        $("#Biog").show();
                        $("#aboutuscontent div.rightpage)").show(); 
                        // Change link message
                        $("span.aboutusmorelink", this).html(aless);
    
                        return false;              
                }, function(){
          
                        // Hide all shown paragraphs
                        $("#aboutuscontent .separator").hide();
                        $("#aboutuscontent div.leftpage:gt(0)").hide();
                        $("#Biog").hide();
                        $("#aboutuscontent div.rightpage)").hide(); 
                        // Change link message
                        $("span.aboutusmorelink", this).html(amore);
    
                        return false;
                });  
          
        /* -------------------------------------------------------------- */
  
        // News
        $("#news_left div.newscontent").each(function(i) {
                $("p:gt(0)", this).hide();

                var more = '+ <a href=\"#\" class=\"readmore\">Read more</a>';
                var less = '- <a href=\"#\" class=\"readmore\">Read less</a>';
      
                $("p:eq(0)", this)
                        .append("<span class=\"newsmorelink\">" + more + "</span>")
                        .toggle(function(){
          
                                // Show all hidden paragraphs
                                $("p:gt(0)", $("div.newscontent", $(this).parent()).get(i)).show();
                                // Change link message
                                $("span.newsmorelink", this).html(less);
    
                                return false;              
                        }, function(){
          
                                // Hide all shown paragraphs
                                $("p:gt(0)", $("div.newscontent", $(this).parent()).get(i)).hide();
                                // Change link message
                                $("span.newsmorelink", this).html(more);
    
                                return false;
                        });
                });
        
        /* -------------------------------------------------------------- */
  
        // Events
        $("#news_right div.eventcontent").each(function(i) {
                
                $("p:gt(6)", this).hide();
    
                var more = '+ <a href=\"#\" class=\"eventsreadmore\">Read more</a>';
                var less = '- <a href=\"#\" class=\"eventsreadmore\">Read less</a>';
          
                $("p:eq(6)", this)
                        .append("<span class=\"eventsmorelink\">" + more + "</span>")
                        .toggle(function(){
          
                                // Show all hidden paragraphs
                                $("p:gt(6)", $("div.eventcontent", $(this).parent()).get(i)).show();
                                // Change link message
                                $("span.eventsmorelink", this).html(less);
    
                                return false;              
                        }, function(){
          
                                // Hide all shown paragraphs
                                $("p:gt(6)", $("div.eventcontent", $(this).parent()).get(i)).hide();
                                // Change link message
                                $("span.eventsmorelink", this).html(more);
    
                                return false;
                        });
                });
        
        /* -------------------------------------------------------------- */
        
        // Application form
        $("#benefits p:gt(0)").hide();
        $("#benefits ul").hide();
        
        var bmore = '+ <a href=\"#\" class=\"benefitsreadmore\">Read more</a>';
        var bless = '- <a href=\"#\" class=\"benefitsreadmore\">Read less</a>';
          
        $("#benefits p:eq(0)")
                .append("<span class=\"benfitsmorelink\">" + bmore + "</span>")
                .toggle(function(){
          
                        // Show all hidden paragraphs
                        $("#benefits p:gt(0)").show();
                        $("#benefits ul").show();
                        // Change link message
                        $("span.benfitsmorelink", this).html(bless);
    
                        return false;              
                }, function(){
          
                        // Hide all shown paragraphs
                        $("#benefits p:gt(0)").hide();
                        $("#benefits ul").hide();
                        // Change link message
                        $("span.benfitsmorelink", this).html(bmore);
    
                        return false;
                }); 
          
     /* -------------------------------------------------------------- */ 
}
