function sortProducts(productArray) {
    for (i = 0; i < productArray.length; i++) {
        if (jQuery('#' + productArray[i]).html() !== null) {
            productString += '<div id="' + productArray[i] + '">' + jQuery('#' + productArray[i]).html() + '</div>';
        }
    }
    productArray = [];

    jQuery('#productsSorted').html(productString);

    jQuery('#productsSorted').hide().show();

    productString = "";
}
var productString = "";
jQuery(document).ready(function() {
jQuery('#sortBox').change(function (event) { // Detect if they changed options
    if (jQuery('#sortBox').val() == 'rank') { //Detect which thing they selected
        event.preventDefault();
        sortProducts([1, 5, 3, 2, 4, 6, 8, 9, 10, 7]); //Sort the products
    }
    if (jQuery('#sortBox').val() == 'weightlosspower') {
        event.preventDefault();
        sortProducts([2, 1, 3, 5, 4, 6, 10, 8, 7]);

    }
    if (jQuery('#sortBox').val() == 'appetitesuppression') {
        event.preventDefault();
        sortProducts([5, 2, 3, 1, 9, 4, 6, 10, 8, 7]);

    }
    if (jQuery('#sortBox').val() == 'longterm') {
        event.preventDefault();
        sortProducts([5, 1, 3, 4, 6, 10, 2, 8, 7, 9]);

    }
    if (jQuery('#sortBox').val() == 'customer') {
        event.preventDefault();
        sortProducts([2, 1, 3, 7, 5, 4, 6, 10, 9, 8]);

    }
    if (jQuery('#sortBox').val() == 'safety') {
        event.preventDefault();
        sortProducts([9, 7, 3, 1, 8, 4, 6, 10, 5, 2]);

    }
    if (jQuery('#sortBox').val() == 'costperpound') {
        event.preventDefault();
        sortProducts([8, 6, 3, 2, 1, 10, 5, 7, 4, 9]);

    }
    if (jQuery('#sortBox').val() == 'price') {
        event.preventDefault();
        sortProducts([8, 9, 3, 4, 1, 5, 10, 7, 2, 6]);

    }
});
});
this.vtip = function() {    
    this.xOffset = -10; // x distance from mouse
    this.yOffset = 10; // y distance from mouse       
    
    jQuery(".vtip").unbind().hover(    
        function(e) {
            this.t = this.title;
            this.title = ''; 
            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
            
            jQuery('body').append( '<p id="vtip"><img id="vtipArrow" />' + this.t + '</p>' );
                        
            jQuery('p#vtip #vtipArrow').attr("src", '../images/vtip_arrow.png');
            jQuery('p#vtip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
            
        },
        function() {
            this.title = this.t;
            jQuery("p#vtip").fadeOut("slow").remove();
        }
    ).mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);
                         
            jQuery("p#vtip").css("top", this.top+"px").css("left", this.left+"px");
        }
    );            
    
};

jQuery(document).ready(function(jQuery){vtip();}) 
