$(document).ready(function () {
    //
		// SORT IMG FLOTATION IN CASE OF CMS EDITING ERRORS
		$(".bodyCopy p img").each(function () {
       if($(this).hasClass('imgright')) {
				$(this).removeClass('imgright');
				$(this).parent().addClass('imgright');
				}
				if($(this).hasClass('imgleft')) {
				$(this).removeClass('imgleft');
				$(this).parent().addClass('imgleft');
				}
				if($(this).hasClass('imgfull')) {
				$(this).removeClass('imgfull');
				$(this).parent().addClass('imgfull');
				}
    });
		//
    // Add captions to images where needed, using the title attr
    $(".bodyCopy p img").each(function () {
        // check if the image has a caption to add
        getTitle = $(this).attr("title");
        if (getTitle != '') {
            // add a class to containing para
            $(this).parent().addClass('imgPara');
            // check if the containing para is floated right
            if ($(this).parent().hasClass("imgright")) {
                // create an appropriate class for the caption to follow
                capAddClass = "captionRight";
            } else {
                // create an alternative appropriate class for the caption to follow
                capAddClass = "captionNorm";
                // check if the image is not full width
                if ($(this).parent().width() <= 460) {
                    // adjust the class created for the caption
                    capAddClass = "captionNormMargRight";
                }
            }
            // finally, add the caption
            $('<div class="imageCaption ' + capAddClass + '" style="width:' + $(this).width() + 'px"><p>' + getTitle + '</p></div>').insertAfter($(this).parent());
        }
    });
		//
		// SORT PDF LISTS LINKS IN CASE OF CMS EDITING ERRORS
    $(".bodyCopy .pdflink").each(function () {
        gettag = $(this).get(0).tagName.toUpperCase();
        getparenttag = $(this).parent().get(0).tagName.toUpperCase();
				// if its a link do this
        if (gettag == 'A' && getparenttag == 'LI'||gettag == 'SPAN' && getparenttag == 'LI') {
            $(this).parent().addClass('pdflinkList');
						$(this).removeClass('pdflink');

        }
				// if its a list
				else if (gettag == 'LI') {
            $(this).addClass('pdflinkList');
						$(this).removeClass('pdflink');
        }
    });
		//
		// SORT WORD LISTS LINKS IN CASE OF CMS EDITING ERRORS
    $(".bodyCopy .wordlink").each(function () {
        gettag = $(this).get(0).tagName.toUpperCase();
        getparenttag = $(this).parent().get(0).tagName.toUpperCase();
				// if its a link do this
        if (gettag == 'A' && getparenttag == 'LI'||gettag == 'SPAN' && getparenttag == 'LI') {
            $(this).parent().addClass('wordlinkList');
						$(this).removeClass('wordlink');
        }
				// if its a list
				else if (gettag == 'LI') {
            $(this).addClass('wordlinkList');
						$(this).removeClass('wordlink');
        }
    });
    //
    // SEARCH FORM remove value text on click
    $(".searchBox").click(function () {
        this.value = "";
    });
    // --------------------------------------------------------
});
