﻿$(document).ready(function () {
    //Select all anchor tag with rel set to tooltip
    $('img[rel=tooltip]').mouseover(function (e) {
        //Grab the title attribute's value and assign it to a variable
        var tip = $(this).attr('alt');

        //Remove the title attribute's to avoid the native tooltip from the browser
        $(this).attr('alt', '');

        //Append the tooltip template and its value
        $('body').append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + unescape(tip) + '</div><div class="tipFooter"></div></div>');

        //Show the tooltip with faceIn effect
        $('#tooltip').fadeIn('500');
        $('#tooltip').fadeTo('10', 1.0);

    }).mousemove(function (e) {

        //Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
        $('#tooltip').css('top', e.pageY + 10);
        $('#tooltip').css('left', e.pageX + 20);

    }).mouseout(function () {
        //Put back the title attribute's value
        $(this).attr('alt', $('.tipBody').html());

        //Remove the appended tooltip template
        $('body').children('div#tooltip').remove();
    });

    //Select all anchor tag with rel set to tooltip
    $('a[rel=tooltip]').mouseover(function (e) {
        //Grab the title attribute's value and assign it to a variable
        var tip = $(this).attr('popup');

        var width = $(this).attr('tooltipwidth');
        var height = $(this).attr('tooltipheight');

        //Remove the title attribute's to avoid the native tooltip from the browser
        //$(this).attr('title', '');

        //Append the tooltip template and its value
        $('body').append('<div id="tooltip" style="width:' + (parseInt(width) + 2).toString() + 'px; height:' + (parseInt(height) + 2).toString() + 'px; padding:0px;"><div class="tipHeader"></div><div class="tipBody" style="padding:0px;">' + tip + '</div><div class="tipFooter"></div></div>');

        //Show the tooltip with faceIn effect
        $('#tooltip').fadeIn('500');
        $('#tooltip').fadeTo('10', 1);

    }).mousemove(function (e) {

        //Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
        var tooltip = $("#tooltip");
        var width = tooltip.outerWidth();
        var height = tooltip.outerHeight();

        $('#tooltip').css('top', e.pageY - (height / 2));
        var windowWidth = $(window).width();
        if (e.pageX + 20 + width > windowWidth) {
            $('#tooltip').css('left', e.pageX - width - 20);
        }
        else {
            $('#tooltip').css('left', e.pageX + 20);
        }
        

    }).mouseout(function () {
        //Put back the title attribute's value
        //$(this).attr('title', $('.tipBody').html());

        //Remove the appended tooltip template
        $('body').children('div#tooltip').remove();
    });
});

var totalItems = 0;
var paddingSize = 0;
var currentListSize = 1;

// MAIN MENU sizing script
$(window).bind('load', function () {
    try {
        //if (currentListSize != totalItems) {
        var menuWidth = $('.menu').width();

        // Counts number of items
        var itemNum = $('.menu > li').size();

        // Determines accumulated width of items
        var accumWidth = 0;
        $('.menu > li').each(function () {
            accumWidth += $(this).innerWidth();
        });

        // Determines remaining width in container
        var remainingWidth = (menuWidth - accumWidth);

        // Calculates padding size
        paddingSize = (remainingWidth / (itemNum - 1));

        jQuery.cookie("menuPaddingSize", paddingSize.toString());
        jQuery.cookie("totalMenuItems", itemNum);

        //alert(paddingSize);

        // Applies style        
        $('.menu > li').css({ 'margin-right': paddingSize + 'px' });
        $('.menu > li:last').css({ 'margin-right': '0px' });
        //}
    } catch (e) {
        alert(e.message);
    }
});


$(document).ready(function () {
    totalItems = parseInt(jQuery.cookie("totalMenuItems"));
    if (totalItems == NaN) {
        totalItems = 0;
    }
    var menuItems = $('.menu > li');
    currentListSize = menuItems.length;

    if (totalItems) {
        if (totalItems > 0 && currentListSize == totalItems) {
            $('.menu > li:last').css({ 'margin-right': '0px' });
        }
    }
});


//  // FLYOUT positioning script //  //
$(window).bind('load', function () {

    var subMenuWidth = 0;
    var itemWidth = 0;

    // Determine Width of menu items
    var subMenuWidth = $('.sub').outerWidth();

    // Find width of widest drop down menu
    $('.sub').each(function () {
        itemWidth = parseInt($(this).css('width'));
        if (parseInt($(this).css('width')) > subMenuWidth) {
            subMenuWidth = itemWidth;
        }
    });
    
    // Set width of menu and sub-menus
    $('.sub').css({ 'width': subMenuWidth + 'px' })
    $('.flyout, .flyout2, .flyout3, .flyout4').css({ 'width': subMenuWidth + 'px' })

    // Adjust positioning based on parent element's width
    $('.flyout, .flyout2, .flyout3, .flyout4').css({ 'left': subMenuWidth + 'px' })
 //   $('.flyout, .flyout2, .flyout3, .flyout4').css({ 'margin-top': '-23px' })

});




//  // PRODUCT INFORMATION MODULE styles //  //
$(window).bind('load', function () {
    var infoImageWidth = $('img.productImageLarge').outerWidth();
    var accumInfoHeight = 0;
    var productInfoHeight = $('.productInfoContainer .productInfo').outerHeight();
    var productImageHeight = $('.productInfoContainer .productInfo .productImage').outerHeight();

    $('.productInfo > div').each(function () {
        accumInfoHeight = parseInt($(this).outerHeight());
        if (parseInt($(this).outerHeight()) > productInfoHeight) {
            productInfoHeight = accumInfoHeight;
        } else {
            productInfoHeight = productImageHeight;
        }

    })

    $('.productInfoContainer .productImage').css({ 'width': (infoImageWidth + 50) + 'px' });
    $('.productInfo').css({ 'height': productInfoHeight + 'px' });
    $('.productImage').css({ 'height': productInfoHeight + 'px' });
    $('.info').css({ 'height': productInfoHeight + 'px' });

});



/* User Information Scripts */
function copyText(checkboxID, originalObj, copiedID) {
    var checkbox = $("#" + checkboxID)[0];
    var copied = $("#" + copiedID)[0];
    if (checkbox.checked) {
        if (originalObj.options != null) {
            copied.selectedIndex = originalObj.selectedIndex;
        } else {        
            copied.value = originalObj.value;        
        }
    }
}


function CheckOver13AndValidate(chkboxID, lblError, validationGroup) {
    var checkbox = $('#' + chkboxID)[0];
    var lblError = $('#' + lblError);
    
    var success = Page_ClientValidate(validationGroup);
    var over13success = checkbox.checked;

    if (!over13success) {
        lblError.css('display', '');
    } else {
        lblError.css('display', 'none');
    }
    return over13success && success;
}
