// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name library.js
// ==/ClosureCompiler==

/* Clues for http://jshint.com/ */
/*jshint curly: true, eqeqeq: true, onevar: true, undef: true, white:true */
/*global jQuery: true */

/*
    IMG RESIZER
    Image scaling in IE6 and 7 is bobbins. This uses their proprietary filter gubbins to make it better.
    Original by Ethan Marcotte, at http://unstoppablerobotninja.com/entry/fluid-images/
    Rejigged by Olly Hodgson.
*/
function imgresizer() {
    $(".ie6 .profiles img:not(.clone),.ie7 .profiles img:not(.clone)").each(function (i) {
        var currentImg, currentClone, currentCloneId, currentWidth, currentHeight;
        currentImg = $(this);

        /* Wrap a span around the original image to help with positioning */
        if (!$(currentImg).parent().hasClass("imgWrapper")) {
            $(currentImg).wrap("<span class='imgWrapper'></span>");
        }
        $(currentImg).attr("id", "original" + i);

        /* Figure out if this image has a clone, and if not, clone it. */
        currentCloneId = "#clone" + $(currentImg).attr("id").substring(8);

        if ($(currentCloneId).length === 0) {
            $(currentImg).clone().insertAfter(currentImg).addClass("clone").css({"position" : "absolute", "top" : "0", "left" : "0", "opacity" : "0" }).attr("id", "clone" + i);
            /* Remove these so screenr reader users don't get them twice */
            $(currentImg).attr("alt", "");
            $(currentImg).attr("title", "");                
        }

        currentClone = $(currentCloneId);

        /* Set the original img src to that of the clone */
        if ($(currentImg).attr("src") !== $(currentClone).attr("src")) {
            $(currentImg).attr("src", $(currentClone).attr("src"));
        }

        /* Resize it accordingly */
        $(currentImg).width("100%");      
        $(currentImg).height("auto");        

        currentWidth = currentImg[0].clientWidth;
        currentHeight = currentImg[0].clientHeight;

        /* Now apply the filter and put the transparent gif back */
        currentImg[0].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + currentImg[0].src + "', sizingMethod='scale')";
        currentImg[0].src = "media/images/x.gif"; 

        /* Now set the height on both the original and it's clone */
        $(currentImg).width(currentWidth);
        $(currentImg).height(currentHeight);
        $(currentClone).width(currentWidth);
        $(currentClone).height(currentHeight);

    });
}

/*
	CSS FIXES
	This adds classes to work around shortcomings in older browsers (*cough* Internet Explorer *cough*)
*/
function cssfixes() {

	/* This helps when attribute selector support is lacking (*cough* IE6) */
	$("#content input[type='text']").addClass("text");
	$("#content input[type='radio']").addClass("radio");
	$("#content input[type='checkbox']").addClass("checkbox");
	$("#content input[type='password']").addClass("password");
	$("#content input[type='submit']").addClass("submit");

	/* This helps when :last-child support is lacking */
	$("#content :last-child").addClass("last-child");

    /* Fix the IE6 backgound image caching problem */
    try { 
        document.execCommand("BackgroundImageCache", false, true); 
    } catch (err) {}

    /* Fluid images fix for IE6 and 7 */
    if ($(".ie6 img, .ie7 img").length > 0) {
        imgresizer();
        $(window).resize(function () {
            imgresizer();
        });    
    }    

}

/*
	ONLOAD FUNCTION
	These functions are fired as soon as the DOM is ready
*/
$(document).ready(function () {
	cssfixes();
});
