
jQuery(document).ready(function() {

    var sID            = '';
    var sClass         = '';
    var bSubMnuActive  = false;

    var bDoSlide       = true;

    var iHeightPatch   = 180;
    var iOldHeight     = ( document.getElementById("page").offsetHeight - iHeightPatch);
    var iPageHeight    = 0;
    var iRestoreHeight = 0;

 // --------------------

    // Product-Details::Height-Fix
    if( document.getElementById("torso_left_contentproducts_footer") )
    {
        document.getElementById("torso_left_contentproducts_footer").style.minHeight = (document.getElementById("page").offsetHeight - 545) + 'px';
    }

 // --------------------

    if( sID ) sClass = jQuery( "#" + sID ).css("color");

    if( jQuery('#bCheck').val() == 'true' ) {
        sID = jQuery('#sID').val();
        jQuery('#bCheck').val('false');
    }

    jQuery("li.mnu a").mouseover(function(event) {

        if( bDoSlide ) 
        {
            bDoSlide = false;

            if ( sID ) {
                jQuery( "#" + sID + "s" ).css({"display": "none", "width": "0px"});

                if( jQuery(".selectedSubMenu").length ) jQuery( 'a[class$="selectedSubMenu"]' ).removeClass("selectedSubMenu").css({"color": sClass});
                if( jQuery(".selectedMainMenu").length ) jQuery( "#" + sID ).removeClass("selectedMainMenu").css({"color": sClass});
            }

            sID = jQuery(event.target).attr("id");

            jQuery( "#" + sID + "s" ).animate(
                {"opacity":"toggle", "width":"164px"}, 
                { duration: 50, 
                    complete: function() {
                        bDoSlide = true;
                    }
                }
            );
        }
    });

    jQuery("#head").mouseover(function() {

        if( sID ) jQuery( "#" + sID ).addClass("selectedMainMenu").css({"color":"#fff"});
    });

 // --------------------

    function doQSTBLLinks()
    {
        jQuery( ".QSResult tr[link]" ).css("cursor", "pointer");

        jQuery( ".QSResult tr[link]" ).bind("click", function() {
            var link = jQuery(this).attr("link");
            window.location.href = link;
        });

        jQuery( '.QSResult tr[class!="Head"]' ).hover(function() {
            jQuery(this).css({"text-decoration":"underline"});
        }, function() {
            jQuery(this).css({"text-decoration":"none"});
        });
    }

    // ---

    doQSTBLLinks();

 // --------------------

    jQuery( '#ShowMoreProducts' ).click(function() {
        jQuery( '#MoreProducts' ).slideToggle(
            "slow", 
            function() {
                iPageHeight = ( document.getElementById("page").offsetHeight - iHeightPatch );

                if( iRestoreHeight == 0 ) iRestoreHeight = iPageHeight; 
                else iRestoreHeight = iOldHeight;

                document.getElementById("torso_right_quicksearch").style.minHeight = iRestoreHeight + 'px';
                document.getElementById("torso_left_contentproducts_footer").style.minHeight = (iRestoreHeight - 353) + 'px';

                if( (iRestoreHeight - iHeightPatch) == (iOldHeight - iHeightPatch) ) iRestoreHeight = 0;
        });
    });

 // --------------------

    jQuery( '#qsresult a.QSSort' ).live("click", function() 
    {
        oEle = this;

        var LoaderPos = jQuery( '#' + oEle.id ).parents('div[id*="QSTBL"]').offset().top;
        LoaderPos = parseInt(LoaderPos);

        if( LoaderPos < 1000 ) LoaderPos = 100;
        else if( LoaderPos > 1000 ) LoaderPos -= 250;

        jQuery('#qsloader-wrapper').css({ 'margin-top': LoaderPos + 'px' });

        jQuery( '#qsresult' ).fadeOut( "slow", function()
        {
            jQuery( '#qsloader-wrapper' ).show();

            jQuery( '#qsresult' ).load( '/api/qs-result.html?QS=' + oEle.id , function() 
            {
                doQSTBLLinks();
                jQuery( '#qsloader-wrapper' ).hide();
                jQuery( '#qsresult' ).fadeIn("slow");
            });
        });
    });

});

