var imgPath = "/Portals/0/Skins/Chartwell/images/";

// Preload images function
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}


// Preload nav hover image
jQuery.preloadImages(imgPath + "nav-on.gif", imgPath + "chartwell-logo2.jpg", imgPath + "chartwell-logo3.jpg", imgPath + "chartwell-logo4.jpg", imgPath + "add-tag-on.png", imgPath + "search-button-large-on.png", imgPath + "search-button-on.png");


jQuery(document).ready(function () {
    // Extra span for accessible navigation. Span is a holder for a background image
    jQuery("ul.nav a, ul.footnav a").prepend("<span></span>");

    // Highlight nav menu on hover, except for already highlighted.
    jQuery("ul.nav li:not(ul.nav li.on), ul.footnav li:not(ul.footnav li.on)").hover(
		function () {
		    jQuery(this).addClass("on");
		},
		 function () {
		     jQuery(this).removeClass("on");
		 }
		);


    // Load a random logo image
    var randomLogoClass = "img" + (Math.floor(Math.random() * 4) + 1);
    jQuery("#logo").addClass(randomLogoClass);

    // Hover state for img buttons
    var imgName = '';
    jQuery("input.searchbutton, input.addtagsbutton").hover(
        function () {
            imgName = jQuery(this).attr('src').replace('.png', ''); // save image name to a var
            jQuery(this).attr('src', imgName + '-on.png');
        },
        function () {
            jQuery(this).attr('src', imgName + '.png');
            imgName = '';
        });




    // Expand/collapse long content
    var longcontent = jQuery(".longcontent");
    // If height is longer a certain number of px then restrict the height and add an expand/collapse link
    // The size of restricted area is defined in skin.css, the value below is just a trigger for the restriction
    if (longcontent.height() > 420) { // This value should be greater then the .maxheight height in skin.css.
        longcontent.addClass("maxheight"); // Add class that restricts content height
        longcontent.after("<p><a href=\"#expand\" id=\"expandlink\">Read full story</a></p>"); // Add a link that expands the content

        var expandlink = jQuery("#expandlink");

        expandlink.click(
            function () {
                // On click add/remove the class to collapse/expand the content
                (longcontent.hasClass("maxheight")) ? longcontent.removeClass("maxheight") : longcontent.addClass("maxheight");
                // Change link icon
                (expandlink.hasClass("expanded")) ? expandlink.removeClass("expanded") : expandlink.addClass("expanded");
            }
        );
    }


});	
	
	
	
function getPrintButton() {
    document.write('<a href="#print" title="Print page" onclick="window.print()"><img src="' + imgPath + 'icon_print.gif" width="22" height="21" alt="Print" border="0" /></a>');
}
