$(document).ready(function () {


    /*START-Social Media - Share Window*/

    $(function () {
        var bar = $('#headerSlideContainer');
        var top = bar.css('top');
        $(window).scroll(function () {
            if ($(this).scrollTop() > 222) {
                bar.stop().animate({ 'top': '0px' }, 500);
            } else {
                bar.stop().animate({ 'top': top }, 500);
            }
        });
    });

//    $('.sharingBar2').hover(function () {
//        $('#ProductBodyContainer').css({ "position": "relative", "z-index": "100000", "opacity": ".1" });
//        $('.sharingBar2').css({ "position": "relative", "z-index": "200000", "opacity": "1" });
//    });

    /*END-Social Media - Share Window*/


    //Hide Left Column Sort Boxes on page-ready event...
    $('.SortBoxBottom').hide();
    //fire Colorbox function and set focus appropriately...
    $('#signIn').colorbox({ inline: true, iframe: true, initialWidth: 450, initialHeight: 250, opacity: .66, innerWidth: 450, innerHeight: 250, onClosed: function () { location.reload(true); } });
    $('.Logo').colorbox({ inline: true, iframe: true, initialWidth: '50%', initialHeight: '70%', opacity: .66, innerWidth: '50%', innerHeight: '70%' });
    $('.Logo2').colorbox({ inline: true, iframe: false, initialWidth: '50%', initialHeight: '70%', opacity: .66, innerWidth: '50%', innerHeight: '70%' });
    $('.colorbox').colorbox({ inline: true, iframe: true, initialWidth: '50%', initialHeight: '70%', opacity: .66, innerWidth: '50%', innerHeight: '70%' });
    $(".cbVideo").colorbox({ width: "540px", height: "425px", iframe: true });
    $("#colorbox").appendTo('form');
    //Ready slide-down FAQ list on page-ready event...
    //Another iteration created 10/4/2010 to keep Lists (Both Ordered and Unordered) from BREAKING sections...
    //Added "Find Absolute Path" scripting for Aaron 10/08/2010...
    $('ul.RESme li.clicker').each(function (index) {
        $(this).find('a.clik').click(function () {

            //$('.subSet').hide();
            if ($('.subSetRES').eq(index).is(":visible")) {
                $('.subSetRES').eq(index).slideUp('slow', function () { });
                // Begin "Find Absolute Path" to images folder...
                var strImageUrl = "Arrow-Right.gif";
                var strDocumentUri = $('.openItRES').eq(index).attr("src");
                strDocumentUri = strDocumentUri.substring(0, strDocumentUri.lastIndexOf("/"));
                strImageUrl = strDocumentUri + "/" + strImageUrl;
                //End "Find absolute path" to images folder
                $('.openItRES').eq(index).attr("src", strImageUrl);
                return false;
            }
            else {
                $('.subSetRES').eq(index).slideDown('slow', function () { });
                // Begin "Find Absolute Path" to images folder...
                var strImageUrl = "Arrow-Down.gif";
                var strDocumentUri = $('.openItRES').eq(index).attr("src");
                strDocumentUri = strDocumentUri.substring(0, strDocumentUri.lastIndexOf("/"));
                strImageUrl = strDocumentUri + "/" + strImageUrl;
                //End "Find absolute path" to images folder
                $('.openItRES').eq(index).attr("src", strImageUrl);
                return false;
            }
        });
    });
    $('ul.FAQme li.clicker').each(function (index) {
        $(this).find('a.clik').click(function () {
            //$('.subSet').hide();
            if ($('.subSetFAQ').eq(index).is(":visible")) {
                $('.subSetFAQ').eq(index).slideUp('slow', function () { });
                // Begin "Find Absolute Path" to images folder...
                var strImageUrl = "Arrow-Right.gif";
                var strDocumentUri = $('.openItFAQ').eq(index).attr("src");
                strDocumentUri = strDocumentUri.substring(0, strDocumentUri.lastIndexOf("/"));
                strImageUrl = strDocumentUri + "/" + strImageUrl;
                //End "Find absolute path" to images folder
                $('.openItFAQ').eq(index).attr("src", strImageUrl);
                return false;
            }
            else {
                $('.subSetFAQ').eq(index).slideDown('slow', function () { });
                // Begin "Find Absolute Path" to images folder...
                var strImageUrl = "Arrow-Down.gif";
                var strDocumentUri = $('.openItFAQ').eq(index).attr("src");
                strDocumentUri = strDocumentUri.substring(0, strDocumentUri.lastIndexOf("/"));
                strImageUrl = strDocumentUri + "/" + strImageUrl;
                //End "Find absolute path" to images folder
                $('.openItFAQ').eq(index).attr("src", strImageUrl);
                return false;
            }
        });
    });
    //"Check for cookie" script should be inserted here...
    if ($.cookie('SBOpen0')) {
        //alert('Cookie SBOpen0 found! Nom Nom Nom...');
        $('.SortBoxBottom').eq($.cookie('SBOpen0')).slideDown('fast', function () { });
    }
    if ($.cookie('SBOpen1')) {
        //alert('Cookie SBOpen1 found! Nom Nom Nom...');
        $('.SortBoxBottom').eq($.cookie('SBOpen1')).slideDown('fast', function () { });
    }
    //Left Column: SortBox - slide up/slide down function
    $('.SortBox').each(function (index) {
        $(this).find('h3').click(function () {
            //$('.subSet').hide();
            if ($('.SortBoxBottom').eq(index).is(":visible")) {
                $('.SortBoxBottom').eq(index).slideUp('slow', function () { });
                //destroy the currently indexed cookie object
                $.cookie("SBOpen" + index, null);
                //alert($.cookie("SBOpen"));								
            }
            else {
                $('.SortBoxBottom').eq(index).slideDown('slow', function () { });
                //create the currently indexed cookie object
                $.cookie("SBOpen" + index, index, { expires: 7 });
                //alert($.cookie("SBOpen"));
                // If one accordion is to close when the other opens, uncomment these lines
                //if(index == '0')
                //{
                //	$('.SortBoxBottom').eq(1).slideUp('slow',function(){});
                //	$.cookie("SBOpen"+index, index, {expires:7});
                //	$.cookie("SBOpen"+1, null);
                //}
                //if(index =='1')
                //{
                //	$('.SortBoxBottom').eq(0).slideUp('slow',function(){});
                //	$.cookie("SBOpen"+index, index, {expires:7});
                //	$.cookie("SBOpen"+0, null);
                //}
            }
        });
    });
    $('#PLabelA').click(function () {
        $('#productLabel').removeClass('hide');
    });
    $.urlParam = function (name) {
        var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
        if (!results) {
            return 0;
        }
        return results[1] || 0;
    }
    //Begin Open Colorbox from URL Script...
    var myPassedValue = $.urlParam('openCB');
    if (myPassedValue != '') {
        var isLoaded = ($.cookie('cbLoad' + myPassedValue));
        var myPassedID;
        var inIFrame;
        if (isLoaded != '1' || isLoaded == null) {
            if (myPassedValue.indexOf('.') == -1) {
                myPassedID = "#" + myPassedValue;
                inIFrame = false;
            }
            else {
                myPassedID = myPassedValue;
                inIFrame = true;
            }
            $.fn.colorbox({ href: myPassedID, inline: true, iframe: inIFrame, opacity: .66, innerWidth: '50%', innerHeight: '70%' });
            $.cookie('cbLoad' + myPassedValue, 1);
        }
    }
    //End Open Colorbox from URL Script...
});


setTimeout('timeOut()', 1000);
function timeOut() {
    if ($('.ProductDetailContainer').length != 0) {
        $('.ProductDetailContainer').each(function (index) {
            $(this).addClass('hide')
        });
        $('.ProductDetailContainer').eq(0).removeClass('hide');
    }
    //$('#productLabel').addClass('hide');
}

