﻿function hoverShow(myObj, selector, targetContent) {
    /*
    Purpose:	    Toggle content based on hover; for instances when content is OUTside of hover element
    Parameters:	    myObj           | selector object (usu -this-)
                    selector 	    | common selector, for resetting active value
                    targetContent   |	element to be toggled
		
    Reqs:		    CSS		| 	.active class for setting style of current event handler
                    HTML 	| 	*name* attribute on selector that corresponds w/*id* attribute on target content
    */

    var contentID = $(myObj).attr("name");

    // Hide all content areas, reset hover style... 
    $(selector).parent().removeClass('active');
    $(targetContent).css('display', 'none');

    // Show the requested area
    $('#' + contentID).fadeIn();
    $(myObj).parent().addClass('active');
};

/* Clear place holder content on focus/restore on blur. Requires input fields to have placeholder attribute */

function clearInputDefaultOnFocus(myObj, inputValue, eventType) {
    var txtInput = myObj.value;
    var idInput = myObj.id;

    if (eventType == 'focus') {
        if (myObj.value == txtInput && $(myObj).attr("placeholder") == txtInput) {
            myObj.value = '';

            $(myObj).css('text-transform', 'none');
            return;
        }
    }

    if (eventType == 'blur') {
        if (myObj.value == '') {
            if (idInput != 'txtHeaderSearch') {
                $(myObj).css('text-transform', 'uppercase');
            }
            myObj.value = inputValue;
        }
    }
}

//jQuery(function () {
//    // Borrowed from Chris Coyier // www.css-tricks.com
//    $.fn.placeholder = function () {

//        if (this[0] && 'placeholder' in document.createElement('input') ) {return this;};

//        function setPlaceholder($elem) {
//            if (
//                $elem.val() === '' || $elem.val() === $elem.attr('placeholder')) {
//                $elem.addClass('placeholder').val($elem.attr('placeholder'));
//            } 
//            else {$elem.removeClass('placeholder');};
//        };

//        $('form:has([placeholder])').submit(function () {
//            $('.placeholder', this).val('');
//        });

//        $(window).unload(function () {
//            $('.placeholder').val('');
//        });

//        return this.each(function () {
//            var $input = $(this);

//            if ($input.is(':password')) {
//                return;
//            };

//            setPlaceholder($input);

//            $input.focus(function () {
//                if ($input.val() === $input.attr('placeholder')) {
//                    $input.val('').removeClass('placeholder');
//                };
//            }).blur(function () {
//                setPlaceholder($input);
//            });
//        });
//    };

//    $("input").placeholder();
//    $("textarea").placeholder();
//});

jQuery(function () {

    var timeout = 600;
    var queue = [];

    var queueFlush = function () {
        while (queue.length) {
            clearTimeout(queue[0][0]);
            queueTimeout();
        }
    }

    var queueTimeout = function () {
        if (queue.length) {
            jQuery(queue.shift()[1]).removeClass("sfhover");
        }
    }

    // Check to determine whether the browser is ie7
    var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;

    // Any LI elments in either the international drop down or main navigation will get the "sfHover" class
    // added to it on mouseover
    jQuery("#mainnav li").mouseover(
        function () {
            queueFlush();
            jQuery(this).addClass("sfhover");
        }
    );

    // focus and blur handlers for keyboard based navigation.
    jQuery("#mainnav li").focus(
        function () {
            queueFlush();
            jQuery(this).addClass("sfhover");
        }
    );

    jQuery("#mainnav li").blur(
        function () {
            queue.push([setTimeout(queueTimeout, timeout), jQuery(this)]);
        }
    );

    // For some reason ie7 doesn't like onmouseleave.  It does like onmouseout though.
    if (ie7) {
        // onmouseout, remove the sfhover class
        jQuery("#mainnav li").mouseout(
        function () {
            queue.push([setTimeout(queueTimeout, timeout), jQuery(this)]);
            }
        );
    }
    else {
        // All other browsers, even ie6, can deal with onmouseleave
        // onmouseout, remove the sfhover class
        jQuery("#mainnav li").mouseleave(
            function () {
                queue.push([setTimeout(queueTimeout, timeout), jQuery(this)]);
            }
        );
    }
});
