//JQ functions for populating DOM. 

//This function adds a SPAN tag to the carousel image items. It uses the image's ALT tag as the hover tip.
jQuery.fn.addImageCaptions = function (e) {
    $(this).each(function () {
        alt = $(this).find('img').attr('alt');
        if (!alt) {
        }
        else {
            $(this).append(e);
            $(this).find('span').html(alt);
        }
    });
};

//This function adds a IMG element tag to all top-level navigation sub LI's. This is used for the image flyouts from the navigation.
//This image is populated from the parent item (the A)'s REL tag.
jQuery.fn.addNavImages = function (e) {

    $(this).each(function () {
        var src = $(this).find('a').attr('rel');

        if (!src) {
            $(this).find('img').remove();
        }
        else {

            //preload the image
            $.preloadImgPath(src);

            $(this).append(e);
            $(this).find('img').attr('src', src);

            //1.22.2011 - nav image dropshadow fix
            $(this).find('img').wrap('<div class="ds_navimg_outterwrap ima_pic_div"><div class="ds_outer1_topright ima_pic_div"><div class="ds_outer2_bottomleft ima_pic_div"><div class="ds_inner1_shadow ima_pic_div"><div class="ds_navimg_inner ima_pic_div">');

        }
    });
};

/*
* sticky nav functions
* used for the click-and-stay functionality for the nav tabs
*/

//global function to detect if there is any nav elements with a sticky state
$.areAnySticky = function () {

    var ret = false;

    $("#mainNavigation ul li.photog, #mainNavigation ul li.motion, #mainNavigation ul li.category, #mainNavigation ul li.hair").each(function () {

        if ($(this).getStickyState()) {
            ret = true;
        }
    });
    return ret;

};

//returns the sticky'd element if there is any
$.getStickyElement = function () {

    var ret = null;

    $("#mainNavigation ul li.photog, #mainNavigation ul li.motion, #mainNavigation ul li.category, #mainNavigation ul li.hair").each(function () {

        if ($(this).getStickyState()) {
            ret = $(this);
        }
    });
    return ret;

};



//returns the sticky-state of an element
jQuery.fn.getStickyState = function () {

    if ($(this).data("nav_sticky") == null) { return false; }
    return $(this).data("nav_sticky");

};

//sets the sticky state to 'on' and does all necessary css maintainence
jQuery.fn.setStickyOn = function () {

    //set sticky state on
    $(this).setStickyState(true);

    //show it	
    //1.22.2011 - nav image dropshadow fix
    //$(this).find("div").css("display","block");
    $(this).find("div.ima_nav_div").css("display", "block");
    //END

    //apply hover class
    var cl = $(this).attr("class");
    if (cl) {
        $(this).addClass(cl + "Hover");
        $(this).find("a").addClass("over");
    }


};

//sets the sticky state to 'off' and does all necessary css maintainence
jQuery.fn.setStickyOff = function () {

    //set sticky state off
    $(this).setStickyState(false);

    //hide it
    //1.22.2011 - nav image dropshadow fix
    //$(this).find("div").css("display","none");
    $(this).find("div.ima_nav_div").css("display", "none");
    //END

    //remove the class we added
    var tmp_s = $(this).attr("class").split(" ", 2);
    if (tmp_s.length == 2) {

        $(this).removeClass(tmp_s[1]);
        //needed for the text hover
        $(this).find("a").removeClass("over");


    }
};

//helper method to set the stickystate data on element 
jQuery.fn.setStickyState = function (s) {

    $(this).data("nav_sticky", s);
};




