/**
 * BillyReid.com - Home JS.
 * 
 * @author Randy Little
 * @created 11/17/2011
 * @updated 11/17/2011
 * @version 1
 * @copyright Billy Reid, Inc.
 */
jQuery(function(){
    jQuery("img", "#home-content").mouseover(function(){
        if ( jQuery(this).attr("data-highlight") == "true" )
        {
            jQuery(this).after(getHighlightHtml());

            jQuery(".highlight").bind("mouseleave",function(){
                destroyHighlight();
            });

            if ( jQuery(this).parent("a").parent("div").css("position") == "relative" )
            {
                jQuery(".highlight").css({
                        "top" : ( jQuery(this).position().top ) + "px",
                        "left" : ( jQuery(this).position().left ) + "px",
                        "width" : ( jQuery(this).width() ) + "px",
                        "height" : ( jQuery(this).height() ) + "px"
                });
            } else {
                jQuery(".highlight").css({
                        "top" : ( jQuery(this).offset().top - jQuery("#home-content").offset().top ) + "px",
                        "left" : ( jQuery(this).offset().left - jQuery("#home-content").offset().left ) + "px",
                        "width" : ( jQuery(this).width() ) + "px",
                        "height" : ( jQuery(this).height() ) + "px"
                });
            }
            //jQuery("#product-link", ".highlight").attr("href", jQuery(this).parent("a").attr("href"));

            jQuery("#caption", ".highlight").html(
                    jQuery(this).attr("data-caption")/* +
                    "<br/><span class=\"price\">"+ 
                    jQuery(".high-res[data-id="+jQuery(this).attr("data-id")+"]").attr("data-price") +
                    "</span>"*/
            );
                
            jQuery("#product-link", ".highlight").attr("href", jQuery(this).parent("a").attr("href"));

            /*if ( jQuery(".high-res[data-id="+jQuery(this).attr("data-id")+"]").attr("data-special-price") )
            {
                    jQuery(".price","#caption").css("text-decoration","line-through");
                    jQuery("#caption").append(
                            " <span class=\"special-price\">" + jQuery(".high-res[data-id="+jQuery(this).attr("data-id")+"]").attr("data-special-price") + "</span>"
                    );
            } else {
                    jQuery(".price","#caption").css("text-decoration","none");
            }*/
        }
    });
    /**
     * Hide highlight under following conditions:
     * * Window Resize
     * * Mouse leaves Window
     * * Mouse enters Side Links
     * * Mouse enters Top Menu
     */
    jQuery("#top-menu").mouseover(function(){
            destroyHighlight();
    });
    jQuery("#side-links").mouseover(function(){
            destroyHighlight();
    });
    jQuery('body').mouseleave(function(){
            destroyHighlight();
    });
    jQuery(window).resize(function(){
            destroyHighlight();
    });
    function destroyHighlight()
    {
        jQuery(".highlight").each(function(){
            jQuery(this).unbind();
            jQuery(this).remove();
        });
    }
    function getHighlightHtml()
    {
        if ( jQuery('.highlight').length )
            jQuery('.highlight').remove();
        
        return "<div class=\"highlight\"><div id=\"wrapper\"><a href=\"\" id=\"product-link\"><div id=\"fade\"></div><div id=\"caption\" class=\"tk-trajan-pro\"></div></a></div>";
    }
});
