var timeout;
var currShoe = 'none';
var prevShoe = 'none';
var currStrap = 'dflt';
var prevStrap = 'dflt';
var shoeCat = 'view all';
var strapCat = 'view all';
var loadedImgs = new Array();
var dfltDropBoxWidth = 42;
var handleHeight = 36;
var colPadding = 0;
var filterItems = {};
var postRegObj;
var needToAddStrap = false;
var cart = new Array();
var unableToAdd = false;

$(function() {
    if ($.browser.msie && $.browser.version == '6.0') {
        colPadding = 7;
    }

    $('div.colTopBox').each(function() {
        if ($(this).attr('_showing') == null) {
            $(this).attr('_showing', 'false');
        }
        $(this).attr('_height', $(this).height());
    });
    //resizeColumns();

    //$(window).resize(resizeColumns);

    if ($.browser.msie) {
        if ($.browser.version == '6.0') {
            $('#currentShoe1, #currentShoe2, #currentShoe3').wrap('<div></div>');
            $('#currentShoe1').attr('id', 'currShoeImg1').parent().attr('id', 'currentShoe1');
            $('#currentShoe2').attr('id', 'currShoeImg2').parent().attr('id', 'currentShoe2');
            $('#currentShoe3').attr('id', 'currShoeImg3').parent().attr('id', 'currentShoe3');
        }
        $('#currentShoe1, #currentShoe2, #currentShoe3').css({ 'background-color': 'transparent', 'opacity': 0 });
    }
    $('div.dropBox ul').hide();
    setTimeout(function() { $('div.dropBox ul').css('opacity', 1); }, 1000);
    $('div.dropBox').click(function(evt) {
        if ($(this).children('ul').css('display') == 'none') {
            hideDropBoxes(this.id);
            $(this).css('z-index', '2');
            var ul = $(this).children('ul');
            // if width is 0 then it is likely hidden inside another div, don't reset the width
            if (ul.width() < dfltDropBoxWidth && ul.width() != 0) {
                $(this).children('ul').width(dfltDropBoxWidth);
            }
            $(this).children('ul').slideDown(300);
        } else {
            hideDropBoxes(null, this.id);
        }
    }).mouseout(function(evt) {
        $(this).attr('_overCount', parseInt($(this).attr('_overCount')) - 1);
        clearTimeout($(this).attr('_hider'));
        if ($(this).attr('_overCount') <= 0) {
            $(this).attr({ '_overCount': 0, '_hider': setTimeout('hideDropBoxes()', 1000) });
        }
    }).mouseover(function(evt) {
        $(this).attr('_overCount', parseInt($(this).attr('_overCount')) + 1);
        clearTimeout($(this).attr('_hider'));
        $(this).removeAttr('_hider');
    }).attr('_overCount', 0).each(function() {
        if ($.browser.msie) {
            $(this).trigger('click');
            hideDropBoxes();
        }
    });
    //    $('div.dropBox a').click(function(evt) {
    //        alert('test');
    //        evt.preventDefault();
    //        evt.stopPropagation();
    //        var newVal = $(this).attr('_dropVal');
    //        if (newVal == null || newVal == '') {
    //            newVal = $(this).html();
    //        }
    //        var dropBox = $(this).parents('div.dropBox');
    //        dropBox.attr('_prevVal', dropBox.children('span.title').html());
    //        dropBox.children('span.title').html(newVal);
    //        hideDropBoxes(null, dropBox[0].id);
    //        // this little bit of code handles a callback of sorts to notify when
    //        // the value of the dropbox has changed
    //        if (dropBox.attr('_selFunc') != null) {
    //            eval('var func = ' + dropBox.attr('_selFunc'));
    //            func(dropBox);
    //        }
    //    })


    $('#shoeSquiggle, #strapSquiggle').each(function() {
        $(this).attr('_oldTop', $(this).position()['top']);
    })

    $('div.shopByCol').attr('_hilited', 'false').mouseover(function() {
        $(this).attr('_overCount', parseInt($(this).attr('_overCount')) + 1);
        clearTimeout($(this).attr('_hider'));
        $(this).removeAttr('_hider');
        if ($(this).children('div.shopByBody').height() == 0 && $(this).attr('_hilited') == 'false') {
            $(this).attr('_hilited', 'true').animate({ 'opacity': 1 }, 300);
            if (this.id == 'shoeShopBy') {
                $('#shoeSquiggle').animate({ 'top': (parseInt($('#shoeSquiggle').attr('_oldTop')) + 12) }, 200);
            } else {
                $('#strapSquiggle').animate({ 'top': (parseInt($('#strapSquiggle').attr('_oldTop')) + 12) }, 200);
            }
        }
    }).mouseout(function() {
        $(this).attr('_overCount', parseInt($(this).attr('_overCount')) - 1);
        clearTimeout($(this).attr('_hider'));
        if ($(this).attr('_overCount') <= 0) {
            var timeout = 1500;
            if ($(this).children('div.shopByBody').height() == 0) {
                // should be a shorter timeout
                timeout = 250;
            }
            $(this).attr({ '_overCount': 0, '_hider': setTimeout('hideShopBy("#' + this.id + '")', timeout) });
        }
    }).each(function() {
        $(this).attr('_overCount', 0);
    }).click(function(evt) {
        evt.preventDefault();
        evt.stopPropagation();
        if ($(this).children('div.shopByBody').height() == 0) {
            if ($.browser.msie && $.browser.version == '7.0') {
                $(this).animate({ 'height': $('#shoeCol').height() + 42 }, 450);
            }
            $(this).children('div.shopByBody').animate({ 'opacity': 1, 'height': $('#shoeCol').height() + 2 }, 500,
				function() { $(this).children('div.shopBottom').css('display', 'block'); });
            $('#' + this.id + ' span.shopDrop').addClass('shopClose').removeClass('shopDrop');
            var squigId = '#shoeSquiggle';
            if (this.id == 'strapShopBy') {
                squigId = '#strapSquiggle';
            }
            $(squigId).animate({ 'top': $('#shoeCol').height() + 40 }, 700);
        } else {
            hideShopBy('#' + this.id, true);
        }
    }).css('opacity', 0);
    $('#shopBySearch').click(function(evt) {
        evt.preventDefault();
        evt.stopPropagation();
    });
    $('#shoeShopBody .fltrOpt').click(function(evt) {
        var fname = $(this).attr('_filter');
        $('#shoeFilterName span.shopByLabel, #shoeFilter span.shopByLabel').html(fname);
        $.getScript(location.protocol + '//' + location.hostname + $(this).attr('href') + '&js=true&fltr=shoe' + escape(fname), function() {
            // doing this timeout for good ol' frizari
            setTimeout('filterList("shoe", "shoe' + fname + '")', 50);
        });
    });
    $('#strapShopBody .fltrOpt').click(function(evt) {
        var fname = $(this).attr('_filter');
        $('#strapFilterName span.shopByLabel, #strapFilter span.shopByLabel').html(fname);
        $.getScript(location.protocol + '//' + location.hostname + $(this).attr('href') + '&js=true&fltr=strap' + escape(fname), function() {
            // doing this timeout for good ol' frizari
            setTimeout('filterList("strap", "strap' + fname + '")', 50);
        });
    });
    $('#strapShopBody').each(function() {
        // doing this inside as a sort of conditional check
        $('#shoesStraps .fltrOpt, #forKids .fltrOpt').click(function(evt) {
            var fname = $(this).attr('_filter');
            $('#strapFilterName span.shopByLabel, #strapFilter span.shopByLabel').html(fname);
            $.getScript(location.protocol + '//' + location.hostname + $(this).attr('href') + '&js=true&fltr=strap' + escape(fname), function() {
                // doing this timeout for good ol' frizari
                setTimeout('filterList("strap", "strap' + fname + '")', 50);
            });
        })
    });
    $('#saveToFavs').mouseover(function(evt) {
        $(this).attr('_overCount', parseInt($(this).attr('_overCount')) + 1);
        clearTimeout($(this).attr('_hider'));
        $(this).children('span').animate({ 'opacity': 1 }, 300);
    }).mouseout(function(evt) {
        $(this).attr('_overCount', parseInt($(this).attr('_overCount')) - 1);
        clearTimeout($(this).attr('_hider'));
        if (parseInt($(this).attr('_overCount')) <= 0) {
            $(this).attr('_overCount', 0);
            $(this).attr('_hider', setTimeout(hideSave, 250));
        }
    }).attr({ '_overCount': 0, '_dragging': 'false' }).css('opacity', 0);

    $('#shoeThumbFull, #shoeThumbHoriz').click(function(evt) {
        evt.preventDefault();
        evt.stopPropagation();
        if (currStrap == 'dflt') {
            toggleAltShoe();
        }
    }).css('opacity', 0);

    $('a.addItem').click(function(evt) {
        evt.preventDefault();
        evt.stopPropagation();
        var id = 0;
        var size = '';
        var qty = '';
        if (this.id == 'addShoe') {
            startWorking(this);
            id = shoes[currShoe]['pid'];
            size = $('#shoeSize span.title').text();
            size = (size == 'KL' ? 'Large' : (size == 'KM' ? 'Medium' : (size == 'KXL' ? 'X-Large' : (size == 'KS' ? 'Small' : size))));
            qty = $('#shoeQty span.title').text();
        } else if (this.id == 'addAccessory') {
            id = $(this).attr('_id');
            size = 'accessory';
            qty = $('#accessoryQty span.title').text();
            hideAccessoriesPopup();
        } else {
            startWorking(this);
            id = straps[currStrap]['pid'];
            size = $('#strapSize span.title').text();
            size = (size == 'L' ? 'Large' : (size == 'M' ? 'Medium' : (size == 'KL' ? 'Large' : (size == 'KM' ? 'Medium' : 'Small'))));
            qty = $('#strapQty span.title').text();
        }
        $.getScript(location.protocol + '//' + location.hostname + rootDir + 'cart/modules/Lulu_Custom/cart.php?mode=add&productid=' + id + '&psize=' + size + '&amount=' + qty, function() {
            setTimeout(updateCartGlance, 10);
            hideWorking();
        })
    });

    // setup position of the drag handle.  I know I could do this above, but it seems to cause a pause
    // in the display of the page, so I'm putting it here to get everything on the page first
    $('div.colTopBox').each(function() {
        if ($(this).attr('_showing') == 'true') {
            var colScroll = $(this).parent().children('div.colScroll');
            colScroll.css('top', colScroll.position()['top'] + $(this).height());
        }
    });

    $('input.dfltText').each(function() {
        $(this).attr('_dfltText', $(this).val());
    }).focus(function(evt) {
        if ($(this).val() == $(this).attr('_dfltText')) {
            $(this).val('');
        }
    }).blur(function(evt) {
        if ($.trim($(this).val()) == '') {
            $(this).val($(this).attr('_dfltText'));
        }
    });

    $('.myFavLink').click(function(evt) {
        if (!$(this).hasClass('myFavoritesTitle')) {
            evt.preventDefault();
            evt.stopPropagation();
        }
        favLinkClicked(this);
    });
    $('a.regPopClose').click(function(evt) {
        hidePopup(evt);
        hideWorking();
    })


    // FUNCTION
    $('a.LoginPopClose').click(function(evt) {
        hideLoginPopup(evt);
    })
    //END  FUNCTION

    /*
    
    $('#popSignIn').click(function(evt) {
    evt.preventDefault();
    evt.stopPropagation();
    startWorking(this);
    loginUser($('#popUname'), $('#popPasswd'));
    });
    $('#regPopBtn').click(function(evt) {
    evt.preventDefault();
    evt.stopPropagation();
    startWorking(this);
    registerUser('pop');
    });
    
    */

    setTimeout(function() { setupColumnList('shoe'); }, 500);
    setTimeout(function() { setupColumnList('strap'); }, 500);
    checkChangedHash();
    $('a.popup').click(popitup);

    $('#shoeDrag').attr('_timer', setTimeout(function() { animDrag($('#shoeDrag')); }, 3000));
    $('#strapDrag').attr('_timer', setTimeout(function() { animDrag($('#strapDrag')); }, 3000));

    // x-cart does this thing where it converts extended chars to their html entities but we need
    // the literal character
    if (typeof (currency) != 'undefined' && currency == '&#8356;') currency = 'â‚¤';

    $('#viewNewAll').click(function() {
        $('a.newArrivalsTitle').trigger('click');
        return false;
    });

});
/*
function resizeColumns() {
var diffHeight = calcDiffHeight();
$('div.col').height(484 + diffHeight).each(function() {
var topBox = $(this).children('div.colTopBox');
var infoDiff = topBox.attr('_showing') == 'true' ? parseInt(topBox.attr('_height')) : 0;
$(this).children('div.colContainer').height(484 + diffHeight + colPadding - infoDiff);
$(this).children('div.colScroll').height(476 + diffHeight - colPadding - infoDiff);
});
recalcScrolls();
}
*/

/*function resizeColumns() {
var diffHeight = calcDiffHeight();
$('div.col').height(565 + diffHeight).each(function() {
var topBox = $(this).children('div.colTopBox');
var infoDiff = topBox.attr('_showing') == 'true' ? parseInt(topBox.attr('_height')) : 0;
$(this).children('div.colContainer').height(565 + diffHeight + colPadding - infoDiff);
$(this).children('div.colScroll').height(557 + diffHeight - colPadding - infoDiff);
});
recalcScrolls();
}*/


// default calculation for getting the difference height to the minimum of the column height
// other js files may override this to get a different value
function calcDiffHeight() {
    var winHeight = $(window).height();
    if (winHeight < 630) {
        winHeight = 630;
    }
    return winHeight - 630;
}
// pass in a specific column (jquery wrapped) if only a specific scrollbar should be recalculated
function recalcScrolls(column) {
    if (column == null) {
        column = $('div.col');
    }
    column.each(function() {
        var container = $(this).children('div.colContainer');
        var colList = container.children('div.colList');
        var maxShoe = -(colList.height() - container.height());
        var colScroll = $(this).children('div.colScroll');
        if (maxShoe > 0) {
            // the list is shorter than the container
            colScroll.children('div.colHandle').css('top', 0);
            // just a dummy check, make sure the list is scrolled to the top
            colList.css('top', 0);
        } else if (colList.position()['top'] < maxShoe) {
            colList.css('top', maxShoe);
            colScroll.children('div.colHandle').css('top', (colScroll.height() - handleHeight));
        } else {
            colScroll.children('div.colHandle').css('top', (colScroll.height() - handleHeight) * (colList.position()['top'] / maxShoe));
        }
    });
}
function flick(id) {
    if (id == null) {
        id = 'div.col';
    }
    $(id).each(function() {
        var container = $(this).children('div.colContainer');
        var colList = container.children('div.colList');
        var colHandle = $(this).children('div.colScroll').children('div.colHandle');
        colList.draggable({ 'axis': 'y', 'distance': 5,
            'start': function(e, ui) {
                $(this).attr('maxHeight', -($(this).height() - $(this).parent().height() + 55));
                $(this).attr('prevY', 0);
                $(this).attr('distance', $(this).position()['top']);
                var colScroll = $(this).parents('div.col').children('div.colScroll');
                $(this).attr('scrollMax', colScroll.height() - handleHeight);
                if (this.id.substring(0, 4) == 'shoe') {
                    clearTimeout($('#shoeDrag').attr('_timer'));
                    $('#shoeDrag').stop().remove();
                } else if (this.id.substring(0, 5) == 'strap') {
                    clearTimeout($('#strapDrag').attr('_timer'));
                    $('#strapDrag').stop().remove();
                }
            },
            'drag': function(e, ui) {
                var jThis = $(this);
                var thisTop = $(this).position()['top'];
                jThis.attr('flick', 'true');
                var jHandle = jThis.parents('div.col').children('div.colScroll').children('div.colHandle');
                var scrollHeight = jThis.attr('scrollMax');
                var handleTop = (thisTop / jThis.attr('maxHeight')) * scrollHeight;
                if (handleTop > scrollHeight) {
                    handleTop = scrollHeight;
                } else if (handleTop < 0) {
                    handleTop = 0;
                }
                jHandle.css('top', handleTop);
            },
            'stop': function(e, ui) {
                var currTop = $(this).position()['top'];
                var maxHeight = parseInt($(this).attr('maxHeight'));
                if (currTop > 0 || currTop < maxHeight) {
                    // need to bump back to within its limits
                    var moveTo = maxHeight;
                    if (currTop > 0) {
                        moveTo = 0;
                    }
                    $(this).animate({ 'top': moveTo }, 500, 'easeOutExpo', function() {
                        $(this).attr('flick', 'false');
                    });
                } else {
                    var id = this.id;
                    setTimeout(function() {
                        $('#' + id).attr('flick', 'false');
                    }, 10);
                }
            }
        }).attr('flick', 'false');
        colHandle.draggable({ 'axis': 'y', 'containment': 'parent',
            'start': function(e, ui) {
                var container = $(this).parents('div.col').children('div.colContainer');
                var colList = container.children('div.colList');
                // 55 is in there to help the scroll function properly so it shows the entire
                // shoe at the bottom of the scrolling
                colList.attr('maxHeight', -(colList.height() - (container.height() - 55)));
                $(this).attr('_dragging', 'true');
                if ($('#shoeInfo1').css('display') == 'block') {
                    $('#shoeInfo1').attr("style", "display:none");
                }
                if ($('#strapInfo').css('display') == 'block') {
                    $('#strapInfo').attr("style", "display:none");
                }


                if (this.id.substring(0, 4) == 'shoe') {
                    clearTimeout($('#shoeDrag').attr('_timer'));
                    $('#shoeDrag').stop().remove();
                } else if (this.id.substring(0, 5) == 'strap') {
                    clearTimeout($('#strapDrag').attr('_timer'));
                    $('#strapDrag').stop().remove();
                }
            },
            'drag': function(e, ui) {
                var colScroll = $(this).parent();
                var colList = colScroll.parent().children('div.colContainer').children('div.colList');
                colScroll.attr('dragged', 'true');
                var handleTop = $(this).position()['top'];
                var posPct = handleTop / (colScroll.height() - handleHeight);
                posPct = (posPct > 1 ? 1 : (posPct < 0 ? 0 : posPct));
                colList.css('top', colList.attr('maxHeight') * posPct);
            },
            'stop': function(e, ui) {
                if (parseInt($(this).attr('_overCount')) == 0) {
                    clearTimeout($(this).attr('_hider'));
                    $(this).attr('_dragging', 'false');
                } else {
                    clearTimeout($(this).attr('_hider'));
                    $(this).attr('_dragging', 'false');
                }
            }
        });

    });
}

function animDrag(id) {
    // yeah, yeah I know I can do this recursively
    $(id).animate({ 'top': 74 }, 1000, 'easeOutQuad', function() {
        $(id).animate({ 'top': 184 }, 200, 'easeOutQuad', function() {
            $(id).animate({ 'top': 74 }, 600, 'easeOutQuad', function() {
                $(id).animate({ 'top': 184 }, 300, function() {
                    $(id).attr('_timer', setTimeout(function() {
                        animDrag(id);
                    }, 3000));
                });
            })
        });
    });
}
function updateShoe() {
    var folderName = "";

    if (currShoe != 'none')
        folderName = shoes[currShoe]['Image'];

    if (currShoe != prevShoe && currShoe != 'none') {


        // do info box stuff and hiliter
        //alert(shoes[currShoe]['Size']);
        //$('#shoeSizeDrop').html(shoes[currShoe]['Size']);
        $('#shoeTitle').html($('#' + currShoe).text());
        document.getElementById('shoeID').value = shoes[currShoe]['pid'];
        //$("#shoeMoreInfo").attr("href", "Product.aspx?ProductId=" + shoes[currShoe]['pid'] + "&iCat=" + shoes[currShoe]['cid']);
        $("#shoeMoreInfo").attr("href", "" + shoes[currShoe]['seoname']);




        $('#shoeSizeDrop').html(shoes[currShoe]['size']);
        var jsShoe = shoes[currShoe];


        $('#shoeColor').html(jsShoe['subname']);


        $('#shoeDesc').html(jsShoe['desc']);
        $('#shoePrice').html(currency + jsShoe['price']);
        prevShoe = currShoe;
        $('#shoeHiliter').each(function() {
            $(this).css('opacity', 0).children('span').css('opacity', 0);
        }).css('top', parseInt($('#' + currShoe).position()['top']) + 25)
		.animate({ 'opacity': 1 }, 300, function() {
		    $(this).children('span').animate({ 'opacity': 1 }, 300, function() {
		        $(this).animate({ 'opacity': 0 }, 300);
		    });
		    $('#shoeTitleHilite').animate({ 'opacity': 1 }, 300, function() {
		        $(this).animate({ 'opacity': 0 }, 300);
		    })
		});
        ensureVisible('shoe');
    }
    if (currStrap != prevStrap && currStrap != 'dflt') {

        var iDefault = straps[currStrap]['size'];

        if (iDefault.indexOf('Default') != -1) {
            $('#strapSize').attr("style", "display:none");
            $('#strapSize').attr("_isDef", "0");
        }
        else {

            $('#strapSizeDrop').html(straps[currStrap]['size']);
        }

        $('#strapColor').html(straps[currStrap]['subname']);

        $('#strapTitle').html($('#' + currStrap).text());

        document.getElementById('strapID').value = straps[currStrap]['pid'];

        //        $("#strapMoreInfo").attr("href", "Product.aspx?ProductId=" + straps[currStrap]['pid'] + "&iCat=" + straps[currStrap]['cid']);
        $("#strapMoreInfo").attr("href", "" + straps[currStrap]['seoname']);

        var jsStrap = straps[currStrap];

        $('#strapDesc').html(jsStrap['desc']);
        $('#strapPrice').html(currency + jsStrap['price']);
        prevStrap = currStrap;
        $('#strapHiliter').each(function() {
            $(this).css('opacity', 0).children('span').css('opacity', 0);
        }).css('top', parseInt($('#' + currStrap).position()['top']) + 35)
		.animate({ 'opacity': 1 }, 300, function() {
		    $(this).children('span').animate({ 'opacity': 1 }, 300, function() {
		        $(this).animate({ 'opacity': 0 }, 300);
		    });
		    $('#strapTitleHilite').animate({ 'opacity': 1 }, 300, function() {
		        $(this).animate({ 'opacity': 0 }, 300);
		    })
		});
        ensureVisible('strap');
    } else if (currStrap == 'dflt' && currStrap != prevStrap) {
        prevStrap = currStrap;
    }
    if (currShoe == 'none') {
        // no shoe selected, just return
        return;
    }
    if ($('#instructions').css('display') != 'none') {
        $('#instructions').animate({ 'opacity': 0 }, 500, function() {
            $(this).css('display', 'none');
        });
        $('#viewNewAll').hide();
        $('#loading').animate({ 'opacity': 1 }, 500);
    }
    var newShoe = '#currentShoe2';
    var oldShoe = '#currentShoe1';
    if ($('#currentShoe1').attr('_showing') == 'false') {
        newShoe = '#currentShoe1';
        oldShoe = '#currentShoe2';
    }

    var itag = document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_iCatagory').value;

    // Updated anish mm -- anishmm@gmail.com
    //var shoeName = currStrap + '_' + currShoe;

    var imgPath = "";



    var shoeName = currShoe;
    if (currStrap == "dflt")
        imgPath = location.protocol + '//' + location.hostname + rootDir + 'picture_library/' + folderName + '/462/' + shoeName + '.png';
    //imgPath = location.protocol + '//' + location.hostname + rootDir + 'picture_library/' + folderName + '/462/' + shoeName + '-34-2.jpg';
    else
        imgPath = location.protocol + '//' + location.hostname + rootDir + 'picture_library/' + folderName + 'MixnMatch/' + currStrap + '-' + shoeName + '.png';

    //alert(imgPath);
    //
    //document.getElementById('Result').innerHTML =  shoes[currShoe]['pid'];
    //document.getElementById('shoeID').value = shoes[currShoe]['pid'];


    loadAndDisplayImage(shoeName, imgPath, function() {
        displayShoe(newShoe, imgPath);
    });
    if (currStrap == 'dflt') {
        setupAltShoeViewer();
    } else {
        hideAltShoeViewer();
    }

    $(oldShoe + ', #currentShoe3').attr('_showing', 'false').css('z-index', 0).animate({ 'opacity': 0 }, 500);
}
function loadAndDisplayImage(id, imgPath, dispFunc) {
    if ($.inArray(id, loadedImgs) == -1) {
        loadedImgs.push(id);
        var img = new Image();
        $(img).load(function() {
            dispFunc();
        }).attr('src', imgPath);
    } else {
        dispFunc();
    }

}
function displayShoe(shoeImg, path) {
    if ($.browser.msie && $.browser.version == '6.0') {
        // IE 6 of course doesn't work with PNG alpha channels except through background image filters
        // so this has to be done
        $(shoeImg).css({ 'z-index': 1, 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + path + '",sizingMethod="crop")',
            'opacity': 0
        }).attr('_showing', 'true').animate({ 'opacity': 1 }, 500);
    } else {
        $(shoeImg).attr({ '_showing': 'true', 'src': path }).animate({ 'opacity': 1 }, 500).css('z-index', 1);
    }
    if ($('#saveToFavs').css('opacity') == '0') {
        $('#saveToFavs').animate({ 'opacity': 1 }, 500);
        $('#instructions').animate({ 'opacity': 0 }, 500);
        $('#viewNewAll').hide();
    }
}
function showTopBox(id, callBack) {
    var colTopBox = $(id).children('div.colTopBox');
    if (colTopBox.attr('_showing') == 'false') {
        colTopBox.attr('_showing', 'true');
        var boxHeight = parseInt(colTopBox.attr('_height'));
        colTopBox.slideDown(500);
        var container = $(id).children('div.colContainer');
        var colScroll = $(id).children('div.colScroll');
        container.animate({ 'height': container.height() + colPadding - boxHeight }, 500, function() {
            callBack();
            recalcScrolls($(id));
        });
        $(id).children('div.colDrag').remove();
        colScroll.css('top', colScroll.position()['top'] + boxHeight).height(colScroll.height() - boxHeight);
    }
}
function hideTopBox(id, callBack) {
    var colTopBox = $(id).children('div.colTopBox');
    if (colTopBox.attr('_showing') == 'true') {
        colTopBox.attr('_showing', 'false');
        var boxHeight = parseInt(colTopBox.attr('_height'));
        colTopBox.slideUp(500);
        var container = $(id).children('div.colContainer');
        var colScroll = $(id).children('div.colScroll');
        var newContHeight = container.height() + boxHeight - colPadding;
        container.animate({ 'height': newContHeight }, 500, callBack);
        colScroll.css('top', colScroll.position()['top'] - boxHeight).height(colScroll.height() + boxHeight);
        // check that the list doesn't get squished up too high when closing, else bring down
        var colList = container.children('div.colList');
        if (-colList.position()['top'] + newContHeight + 25 > colList.height()) { // 25 is the padding that doesn't show up in the height
            var newListTop = newContHeight - 50 - colList.height();
            colList.animate({ 'top': newListTop }, 500, function() {
                recalcScrolls($(id));
            });
        }
    }
}
function hideDropBoxes(exceptFor, forceClose) {
    $('div.dropBox').each(function() {
        if (this.id == forceClose || (this.id != exceptFor && parseInt($(this).attr('_overCount')) <= 0)) {
            var id = this.id;
            $(this).css('z-index', '1').children('ul').slideUp(300, function() { $('#' + id).css('z-index', '0'); });
        }
    })
}
function hideShopBy(id, forceClose) {
    if (parseInt($(id).attr('_overCount')) <= 0 || forceClose) {
        var squigId = '#shoeSquiggle';
        if (id == '#strapShopBy') {
            squigId = '#strapSquiggle';
        }
        if ($(id).children('div.shopByBody').height() == 0) {
            $(id).attr('_hilited', 'false').animate({ 'opacity': 0 }, 300);
            $(squigId).animate({ 'top': $(squigId).attr('_oldTop') }, 200);
        } else {
            if ($.browser.msie && $.browser.version == '7.0') {
                $(id).animate({ 'height': 0 }, 500);
            }
            $(id).children('div.shopByBody').animate({ 'opacity': 0, 'height': 0 }, 500, 'easeInQuint')
				.children('div.shopBottom').css('display', 'none');
            $(id + ' span.shopClose').addClass('shopDrop').removeClass('shopClose');
            if (forceClose != null) {
                $(squigId).animate({ 'top': parseInt($(squigId).attr('_oldTop')) + 12 }, 800, function() {
                    if (parseInt($(id).attr('_overCount')) == 0) {
                        $(id).attr('_hilited', 'false').animate({ 'opacity': 0 }, 500);
                        $(squigId).animate({ 'top': $(squigId).attr('_oldTop') }, 200);
                    }
                });
            } else {
                $(squigId).animate({ 'top': $(squigId).attr('_oldTop') }, 500, function() {
                    if (parseInt($(id).attr('_overCount')) == 0) {
                        $(id).attr('_hilited', 'false').animate({ 'opacity': 0 }, 500);
                    }
                });
            }
        }
    }
}
function hideSave() {
    if (parseInt($('#saveToFavs').attr('_overCount')) == 0) {
        $('#saveToFavs span').animate({ 'opacity': 0 }, 300);
    }
}
// just make sure that the clicked on item is visible in its respective column
function ensureVisible(type) {
    var item = $('#' + (type == 'shoe' ? currShoe : currStrap));
    var container = $('#' + type + 'Container');
    scrollToItem(item, container);
}
// function to scroll a list to where a particular item is in it, just pass the
// jquery wrapped item and the column container it is within.
function scrollToItem(item, container) {
    var list = $(container).children('div.colList');
    var listTop = list.position()['top'];
    var itemTop = item.position()['top'];
    if (itemTop + listTop - 20 < 0) {
        list.animate({ 'top': listTop - (itemTop + listTop - 20) }, 300); // 20 is to give it a slight padding above the item
    } else if (itemTop + listTop + item.height() + 20 > container.height()) {
        list.animate({ 'top': listTop - (itemTop + listTop + item.height() - container.height() + 20) }, 300); // 20 is t give it a slight padding below the item
    }
}
function setupAltShoeViewer() {
    var setupFunc = function() {

        var folderName = shoes[currShoe]['Image'];
        //alert(folderName);

        var itag = document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_iCatagory').value;
        //var imgId = currStrap + '_' + currShoe;
        var imgId = currShoe
        $('#shoeThumbFull').attr('src', location.protocol + '//' + location.hostname + rootDir + 'picture_library/' + folderName + '/80/' + imgId + '-34-2.jpg');


        //var imgPath = location.protocol + '//' + location.hostname + rootDir + 'picture_library/thumbs/' + imgId + '-34.png';


        var imgPath = location.protocol + '//' + location.hostname + rootDir + 'picture_library/' + folderName + '/80/' + imgId + '-34.jpg';
        loadAndDisplayImage(imgId + '_thumb34', imgPath, function() {
            $('#shoeThumbHoriz').attr('src', imgPath).animate({ 'opacity': 1 }, 500).attr('_showing', 'true');
        });
    };
    // make sure the old alt view is hidden if visible
    if (hideAltShoeViewer()) {
        setTimeout(setupFunc, 500);
    } else {
        setupFunc();
    }
}
function hideAltShoeViewer() {
    var hiding = false;
    if ($('#shoeThumbFull').attr('_showing') == 'true') {
        hiding = true;
        $('#shoeThumbFull').animate({ 'opacity': 0 }, 500).attr('_showing', 'false');
    } else {
        $('#shoeThumbFull').css('opacity', 0).attr('_showing', 'false');
    }
    if ($('#shoeThumbHoriz').attr('_showing') == 'true') {
        hiding = true;
        $('#shoeThumbHoriz').animate({ 'opacity': 0 }, 500).attr('_showing', 'false');
    } else {
        $('#shoeThumbHoriz').css('opacity', 0).attr('_showing', 'false');
    }
    return hiding;
}
function toggleAltShoe() {
    var showThumb = '#shoeThumbHoriz';
    var hideThumb = '#shoeThumbFull';
    var newShoe = '#currentShoe3';
    var shoeName = currStrap + '_' + currShoe;


    var itag = document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_iCatagory').value;

    var folderName = shoes[currShoe]['Image'];


    //var imgPath = location.protocol + '//' + location.hostname + rootDir + 'picture_library/full/' + currStrap + '_' + currShoe;

    var imgPath = location.protocol + '//' + location.hostname + rootDir + 'picture_library/' + folderName + '/462/' + currShoe

    if ($('#shoeThumbFull').attr('_showing') == 'false') {
        imgPath = location.protocol + '//' + location.hostname + rootDir + 'picture_library/' + folderName + '/265/' + currShoe + "-34.png";
        // show the horizontal image
        //shoeName += '-34';
        //imgPath += '-34.png';
        $('#currentShoe1, #currentShoe2').css('z-index', 0).animate({ 'opacity': 0 }, 500);
    } else {
        //imgPath += '-34-2.jpg';
        imgPath = location.protocol + '//' + location.hostname + rootDir + 'picture_library/' + folderName + '/462/' + currShoe + ".png";
        $('#currentShoe3').css('z-index', 0).animate({ 'opacity': 0 }, 500);
        showThumb = '#shoeThumbFull';
        hideThumb = '#shoeThumbHoriz';
        newShoe = '#currentShoe1';
    }

    loadAndDisplayImage(shoeName, imgPath, function() {
        displayShoe(newShoe, imgPath);
    })
    $(showThumb).animate({ 'opacity': 0 }, 500).attr('_showing', 'false');
    $(hideThumb).animate({ 'opacity': 1 }, 500).attr('_showing', 'true');
}
function setupColumnList(listName) {
    // setup the items in the shoe list
    $('#' + listName + 'List a.shoeThumb').click(function(evt) {
        if ($(this).parent()[0].id == 'shoeList' && $('#shoeList').attr('flick') == 'false') {
            currShoe = this.id;
            currStrap = 'dflt';
            updateHash();
            showTopBox('#shoeCol', function() {
                ensureVisible('shoe');
            });
            updateShoe();
            hideTopBox('#strapCol', function() {
                $('#strapHiliter').css('top', -27);
            });
            logView('prod');

            // need to check on half sizes for snap shoes
            if (this.id.match('^jordi')) {
                $('#shoeSizeDrop li.halfSize').hide();
            } else {
                $('#shoeSizeDrop li.halfSize').show();
            }

        }
        evt.preventDefault();
        evt.stopPropagation();
    });
    // setup the items in the strap list
    $('#' + listName + 'List a.strapThumb').click(function(evt) {
        if ($(this).parent()[0].id == 'strapList' && $('#strapList').attr('flick') == 'false') {
            currStrap = this.id;
            updateHash();
            showTopBox('#strapCol', function() {
                ensureVisible('strap');
            });
            updateShoe();
            logView('prod');
        }
        evt.preventDefault();
        evt.stopPropagation();
    })
    flick('#' + listName + 'Col');
}
function logView(type) {
    var urlArgs = '?type=' + type;
    var url = location.protocol + '//' + location.hostname + rootDir + 'cart/modules/Lulu_Custom/stats.php';

    if (type == 'prod') {
        if (currShoe != 'none') {
            urlArgs += '&shoeid=' + shoes[currShoe]['pid'];
        } else {
            urlArgs += '&shoeid=0';
        }
        if (currStrap != 'dflt') {
            urlArgs += '&strapid=' + straps[currStrap]['pid'];
        } else {
            urlArgs += '&strapid=0';
        }
    }
    // just give the main focus, displaying shoes, some breathing room first, and spin this
    // off for 1/10 of a second
    setTimeout(function() {
        // log to x-cart's stats
        //		$('#statsImg').attr('src', url + urlArgs);
        $.ajax({ 'url': url + urlArgs, 'dataType': 'text' });
        // log to google analytics
        //urchinTracker(rootDir + 'cart/home.php' + urlArgs);
    }, 100);
}
function filterList(id, filter) {
    if (id == 'strap') {
        if (filter == strapCat) {
            return;
        } else {
            strapCat = filter;
        }
    } else {
        if (filter == shoeCat) {
            return;
        } else {
            shoeCat = filter;
        }
    }
    var items = shoes;
    var currItem = currShoe;
    if (filter == id + 'view all') {
        updateHash();
        // just loop through the list and show all
        $('#' + id + 'List a.' + id + 'Thumb').each(function() {
            $(this).slideDown(350);
        });
        $('#' + id + 'List').animate({ 'top': 0 }, 400);
        setTimeout('moveHiliter("' + id + '")', 360);
        return;
    } else if (id == 'strap') {
        items = straps;
        currItem = currStrap;
    }
    var fltrList = filterItems[filter];
    for (var x in items) {
        var found = false;
        for (var y in fltrList) {
            if (fltrList[y] == items[x]['pid']) {
                found = true;
                fltrList.splice(y, 1);
                break;
            }
        }
        if (found) {
            $('#' + items[x]['id']).slideDown(350);
        } else {
            $('#' + items[x]['id']).slideUp(350);
            if (items[x]['id'] == currItem) {
                // need to hide the selection
                if (id == 'shoe') {
                    currShoe = 'none';
                    currStrap = 'dflt';
                    hideTopBox('#shoeCol', function() {
                        $('#shoeHiliter').css('top', -27);
                    });
                    resetMiddle();
                } else {
                    currStrap = 'dflt';
                }
                updateShoe();
                hideTopBox('#strapCol', function() {
                    $('#strapHiliter').css('top', -27);
                });
                $('#' + id + 'List').animate({ 'top': 0 }, 400);
            }
        }
    }
    updateHash();
    setTimeout('recalcScrolls($("#' + id + 'Col"))', 360);
    setTimeout('moveHiliter("' + id + '")', 360);
}
function moveHiliter(id) {
    if (id == 'shoe' && currShoe != 'none') {
        // need to reset the hiliter to the correct position
        $('#shoeHiliter').css('top', parseInt($('#' + currShoe).position()['top']) + 25)
        ensureVisible(id);
    } else if (currStrap != 'dflt') {
        // need to reset the hiliter to the correct position
        $('#strapHiliter').css('top', parseInt($('#' + currStrap).position()['top']) + 25)
        ensureVisible(id);
    }
}
function updateCartGlance() {
    if (unableToAdd) {
        unableToAdd = false;
        return;
    }
    if (cart['item_count'] == 0) {
        $('#bagCount').html('no items');
    } else if (cart['item_count'] == 1) {
        $('#bagCount').html('1 style');
    } else {
        $('#bagCount').html(cart['item_count'] + ' styles');
    }
    $('#bagCount').animate({ 'backgroundColor': '#76644a', 'color': '#ffffff' }, 200, function() {
        $(this).animate({ 'backgroundColor': 'transparent', 'color': '#76644a' }, 800);
    });
}
function updateHash() {
    location.replace('#shoe=' + currShoe + '&strap=' + currStrap);
}
function checkChangedHash() {
    if (location.hash == '') {
        return;
    }
    var rawHash = location.hash.substring(1).split('&');
    var changedProduct = false;
    for (var x in rawHash) {
        var pair = rawHash[x].split('=');
        if (pair[0] == 'shoe') {
            if (pair[1] != currShoe) {
                currShoe = pair[1];
                currStrap = 'dflt';
                changedProduct = true;
                filterList('shoe', 'view all');
            }
        } else if (pair[0] == 'strap') {
            if (pair[1] != currStrap) {
                currStrap = pair[1];
                changedProduct = true;
                filterList('strap', 'view all');
            }
        }
    }
    if (changedProduct) {
        updateShoe();
        if (currStrap == 'dflt') {
            hideTopBox('#strapCol', function() {
                $('#strapHiliter').css('top', -27);
            });
        } else {
            showTopBox('#strapCol', function() {
                ensureVisible('strap');
            });
        }
        if (currShoe == 'none') {
            hideTopBox('#shoeCol', function() {
                $('#shoeHiliter').css('top', -27);
            });
            resetMiddle();
        } else {
            showTopBox('#shoeCol', function() {
                ensureVisible('shoe');
            });
            // let's just make sure the hiliter is properly placed
            setTimeout(function() {
                $('#shoeHiliter').css('top', parseInt($('#' + currShoe).position()['top']) + 25)
            }, 500);
        }
        logView('prod');
    }
}
function resetMiddle() {
    $('#currentShoe1, #currentShoe2, #currentShoe3').attr('_showing', 'false').css('z-index', 0).animate({ 'opacity': 0 }, 500);
    $('#instructions').animate({ 'opacity': 1 }, 500).css('display', 'block');
    $('#viewNewAll').show();
    $('#shoeThumbFull, #shoeThumbHoriz, #saveToFavs, #loading').animate({ 'opacity': 0 }, 500);
}
function favLinkClicked(link) {
    startWorking(link);
    if (!loggedIn) {
        // not logged in, show the login dialog
        postRegObj = link;
        showLogin();
    } else {
        // user is logged in, determine what to do
        if (link.id == 'saveToFavs') {
            var id = shoes[currShoe]['pid'];
            var size = $('#shoeSize span.title').text();
            var qty = $('#shoeQty span.title').text();
            var postVars = { 'productid': id, 'psize': size, 'amount': qty, 'mode': 'add2wl' };
            var strapItems = '';
            var strapId = '';
            var strapSize = '';
            var strapQty = '';
            if (currStrap != 'dflt') {
                strapId = straps[currStrap]['pid'];
                postVars['strapid'] = strapId;
                strapSize = $('#strapSize span.title').text();
                strapSize = (strapSize == 'L' ? 'Large' : (strapSize == 'M' ? 'Medium' : (strapSize == 'KL' ? 'Large' : (strapSize == 'KM' ? 'Medium' : 'Small'))));
                strapQty = $('#strapQty span.title').text();
            }
            $.post(rootDir + 'cart/modules/Lulu_Custom/cart.php', postVars, function(data) {
                eval(data);
                if (needToAddStrap) {
                    needToAddStrap = false;
                    postVars = { 'productid': strapId, 'psize': strapSize, 'amount': strapQty, 'mode': 'add2wl' };
                    $.post(rootDir + 'cart/modules/Lulu_Custom/cart.php', postVars, function(data) {
                        eval(data);
                        setTimeout(updateCartGlance, 10);
                        hideWorking();
                        showMessage('Added to favorites.');
                    })
                } else {
                    setTimeout(updateCartGlance, 10);
                    hideWorking();
                    showMessage('Added to favorites.');
                }
            })
        } else {
            var fname = $(link).attr('_filter');
            // TODO Generalize this code so it can be used here and in filterList()
            var type;
            var prodList;
            var currItem;
            if ($(link).parents('div.col').attr('id') == 'shoeCol') {
                // filter on my favs for the shoes
                prodList = $('#shoeList a.shoeThumb');
                type = 'shoe';
                currItem = currShoe;
                $('#shoeFilterName span.shopByLabel, #shoeFilter span.shopByLabel').html(fname);
            } else {
                // filter on my favs for the straps
                prodList = $('#strapList a.strapThumb');
                type = 'strap';
                currItem = currStrap;
                $('#strapFilterName span.shopByLabel, #strapFilter span.shopByLabel').html(fname);
            }
            prodList.each(function() {
                var found = false;
                for (var x in wishlist) {
                    if (wishlist[x]['id'] == this.id) {
                        found = true;
                        break;
                    }
                }
                if (found) {
                    $(this).slideDown(350);
                } else {
                    $(this).slideUp(350);
                    if (this.id == currItem) {
                        // need to hide the selection
                        if (type == 'shoe') {
                            currShoe = 'none';
                            currStrap = 'dflt';
                            hideTopBox('#shoeCol', function() {
                                $('#shoeHiliter').css('top', -27);
                            });
                            resetMiddle();
                        } else {
                            currStrap = 'dflt';
                        }
                        updateShoe();
                        hideTopBox('#strapCol', function() {
                            $('#strapHiliter').css('top', -27);
                        });
                        $('#' + type + 'List').animate({ 'top': 0 }, 400);
                    }
                }
            });
            updateHash();
            setTimeout('recalcScrolls($("#' + type + 'Col"))', 360);
            setTimeout('moveHiliter("' + type + '")', 360);
        }
    }
}
var mailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
function loginUser(unameInput, passwordInput) {
    if ($.trim(unameInput.val()) == '' || !mailRegex.test(unameInput.val())) {
        alert('Invalid Email address.');
        unameInput.focus();
        hideWorking('popSignIn');
        return;
    }
    if ($.trim(passwordInput.val()) == '') {
        alert('Blank password not valid.');
        passwordInput.focus();
        hideWorking('popSignIn');
        return;
    }
    var postVars = { 'username': unameInput.val(),
        'password': passwordInput.val(),
        'xid': $.cookie('xid'),
        'usertype': 'C',
        'mode': 'login'
    };
    $.post(location.protocol + '//' + location.host + rootDir + 'cart/include/login.php?js_login=true', postVars, function(data) {
        eval(data);
    })
}
//function registerUser(id) {
//    if ($.trim($('#' + id + 'Email').val()) == '' || !mailRegex.test($('#' + id + 'Email').val())) {
//        alert('Invalid Email address');
//        $('#' + id + 'Email').focus();
//        hideWorking('regPopBtn');
//        return;
//    }
//    if ($.trim($('#' + id + 'Passwd1').val()) == '') {
//        $('#' + id + 'Passwd1').focus();
//        hideWorking('regPopBtn');
//        return;
//    }
//    if ($('#' + id + 'Passwd1').val() != $('#' + id + 'Passwd2').val()) {
//        alert('Passwords do not match.  Please re-enter');
//        $('#' + id + 'Passwd1').val('').focus();
//        $('#' + id + 'Passwd2').val('');
//        hideWorking('regPopBtn');
//        return;
//    }
//    var postVars = { 'email': $('#' + id + 'Email').val(),
//        'uname': $('#' + id + 'Email').val(),
//        'passwd1': $('#' + id + 'Passwd1').val(),
//        'passwd2': $('#' + id + 'Passwd2').val(),
//        'usertype': 'C',
//        'xid': $.cookie('xid'),
//        'js_reg': 'true'
//    }
//    $.post(location.protocol + '//' + location.host + rootDir + 'cart/register.php?xid=' + $.cookie('xid'), postVars, function(data) {
//        eval(data);
//    });
//}
function loginSuccess() {
    loggedIn = true;
    $('#regPopTop a.regPopClose').trigger('click');
    $(postRegObj).trigger('click');
    updateCartGlance();
}
function hidePopup(evt) {
    evt.preventDefault();
    evt.stopPropagation();
    if ($.browser.msie) {
        $('#shade').css('display', 'none');
    } else {
        $('#shade').fadeOut(500);
    }
    $('#regPop').fadeOut(500);
    //    $('#regPop').fadeOut(500, function() {
    //        // reset the popup in case they come across it again.
    //        switchPopup('regPop');
    //    });
}

// FUNCTION (comment line of code in function hidePopup(evt) for show all the popup
function hideLoginPopup(evt) {
    evt.preventDefault();
    evt.stopPropagation();
    if ($.browser.msie) {
        $('#shade').css('display', 'none');
    } else {
        $('#shade').fadeOut(500);
    }
    $('#LoginPopup').fadeOut(500);
    //$('#LoginPopup').fadeOut(500, function() {
    // reset the popup in case they come across it again.
    //  switchPopup('LoginPopup');
    //});
}

function hideLoginPopUP() {
    if ($.browser.msie) {
        $('#shade').css('display', 'none');
    } else {
        $('#shade').fadeOut(500);
    }
    $('#LoginPopup').fadeOut(500, function() {
        // reset the popup in case they come across it again.
        switchPopup('LoginPopup');
    });
}



//END  FUNCTION

function recoverPasswd(evt) {
    evt.preventDefault();
    evt.stopPropagation();
    if ($('#recoverPasswdTop').size() == 0) {
        $('<div>').addClass('top').attr('id', 'recoverPasswdTop').html('<span>Forgot your password?</span><a href="#" class="regPopClose"></a>').insertAfter('#regPopTop');
        $('#recoverPasswdTop a.regPopClose').click(function(evt) { hidePopup(evt); hideWorking(); });
        $('<div>').addClass('body').attr('id', 'recoverPasswdBody').html('<p>Please enter your e-mail address to recover your password.  Your account information will be sent shortly.<table><tr><td class="label">Email</td><td><input type="text" name="username" id="recoverEmail"/></td><td><a href="#" class="submitButton" id="recoverSubmit"></a></td></tr></table>')
			.insertAfter('#regPopBody');
        $('#recoverSubmit').click(submitRecoverPasswd);
    }
    switchPopup('recoverPasswd');
}
function submitRecoverPasswd(evt) {
    startWorking(this);
    evt.preventDefault();
    evt.stopPropagation();
    if ($.trim($('#recoverEmail').val()) == '' || !mailRegex.test($('#recoverEmail').val())) {
        alert('Invalid Email address');
        return;
    }
    var postVars = { 'email': $('#recoverEmail').val(),
        'action': 'recover_password'
    };
    $.post(location.protocol + '//' + location.host + rootDir + 'cart/help.php?section=Password_Recovery&js_confirm=true', postVars, function(data) {
        eval(data);
        hideWorking('recoverSubmit');
    })
}
function switchPopup(switchTo) {
    $('#regPop div.top').each(function() {
        if (this.id == switchTo + 'Top') {
            $(this).show();
        } else {
            $(this).hide();
        }
    });
    $('#regPop div.body').each(function() {
        if (this.id == switchTo + 'Body') {
            $(this).show();
        } else {
            if (switchTo == 'popRecover' && this.id == 'regPopBody' ||
				switchTo == 'regPop' && this.id == 'popRecoverBody') {
                $('#regPopBody').show();
            } else {
                $(this).hide();
            }
        }
    });
}
function showMessage(message) {
    alert(message);
}
function startWorking(item) {
    var pos = $(item).position();
    var div = $('<div>').addClass('working').css({ width: $(item).width(), height: $(item).height(),
        top: pos['top'], left: pos['left']
    }).attr('id', item.id + 'Working');
    var id = item.id;
    if (id == 'saveToFavs') {
        div.css({ 'background-image': 'url(../images/save_to_favs_working.gif)',
            'left': pos['left'] - 2, 'margin-left': $(item).css('margin-left')
        });
    } else if (id == 'addShoe') {
        div.css({ 'background-image': 'url(../images/add_shoe_working.gif)',
            'margin-left': $(item).css('margin-left'), 'margin-top': $(item).css('margin-top')
        });
    } else if (id == 'addStrap') {
        div.css({ 'background-image': 'url(../images/add_strap_working.gif)',
            'margin-left': $(item).css('margin-left'), 'margin-top': $(item).css('margin-top')
        });
    } else if (id == 'recoverSubmit') {
        div.css({ 'background-image': 'url(../images/submit_working.gif)',
            'top': pos['top'] - 1, 'height': $(item).height() + 3
        });
    } else if (id == 'popSignIn' || id == 'regPopBtn') {
        div.css({ 'background-image': 'url(../images/signin_working.gif)',
            'top': pos['top'] - 1, 'height': $(item).height() + 3
        });
    }
    div.insertAfter(item);
}
function hideWorking(id) {
    if (id == null) {
        $('div.working').remove();
    } else {
        // this has to be done this way because cloning actually doubles up some of the
        // elements with the same id.  Dunno a quick fix for that so this will remedy it.
        id = id + 'Working';
        $('div.working').each(function() {
            if (this.id == id) {
                $(this).remove();
            }
        });
    }
}
function showLogin() {
    var width = $('#regPop').width() / 2;
    var height = $('#regPop').height() / 2;
    $('#regPop').css({ marginLeft: -width, marginTop: $(window).scrollTop() - height });
    $('#shade').width($(document).width()).height($(document).height());
    if ($.browser.msie) {

        $('#shade').css('display', 'block');
    } else {

        $('#shade').fadeIn(500);
    }
    $('#regPop').fadeIn(500);

}
function popitup(evt) {
    newwindow = window.open($(this).attr('href'), 'name', 'height=511,width=578');
    if (window.focus) { newwindow.focus() }
    evt.preventDefault();
    evt.stopPropagation();
}
function rollbackDropbox(dropbox) {
    if (dropbox.attr('_prevVal')) {
        dropbox.children('span.title').html(dropbox.attr('_prevVal'));
    }
}
function refreshHomePage() {
    window.location.href = baseUrl + 'home/index.html?t=' + new Date().getTime();
}


jQuery.easing.easeOutQuart = function(x, t, b, c, d) {
    var abc = -c * ((t = t / d - 1) * t * t * t - 1) + b;
    alert(abc);
    return abc;
};


/*---------------------------------------Mix and Mach anishmm@gmail.com------------------------------------------*/
var MxiFlag = 0;
var mailRegex1 = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;


function handleSliderChange(e, ui) {
    var maxScroll = $("#content-scroll").attr("scrollWidth") -
                  $("#content-scroll").width();
    $("#content-scroll").animate({ scrollLeft: ui.value *
     (maxScroll / 100)
    }, 1000);
}

function handleSliderSlide(e, ui) {
    var maxScroll = $("#content-scroll").attr("scrollWidth") -
                  $("#content-scroll").width();
    $("#content-scroll").attr({ scrollLeft: ui.value * (maxScroll / 100) });


}

$(document).ready(function () {

    //FILTER MY FAVOURATE SHOES
    $("#LeftFavourate").click(function () {
        $find('MixnMatchLoading').show();
        $('#shoeInfo1').hide();
        $('#strapInfo').hide();
        $.ajax({
            type: "POST",
            url: "jQuery-Page-Method/Default.aspx/MyFavorateGenShoes",
            contentType: "application/json; charset=utf-8",
            data: "{id:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_hdnMyFavShoesID').value + "'}",
            dataType: "json",
            success: function (msg) {
                if (msg.d == "0") {
                    $find('MixnMatchLoading').hide();
                    MxiFlag = 1;
                    showLogin();
                } else {
                    $("#LeftFavourate").attr("style", "display:none;");
                    $("#shoesShowAll").attr("style", "display:block;");
                    $("#shoeList").html('');
                    $("#shoeList").html(msg.d);
                    $('#shoeList').animate({ 'opacity': 1 }, "slow");
                    setTimeout(function () { setupColumnList('shoe'); }, 500);
                    setTimeout(function () { setupColumnList('strap'); }, 500);
                    $find('MixnMatchLoading').hide();
                }
            }
        });
    });




    //FILTER MY FAVOURATE STRAPS
    $("#RightFavourate").click(function () {
        $find('MixnMatchLoading').show();
        $('#shoeInfo1').hide();
        $('#strapInfo').hide();
        $.ajax({
            type: "POST",
            url: "jQuery-Page-Method/Default.aspx/MyFavorateGenStrap",
            contentType: "application/json; charset=utf-8",
            data: "{id:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_hdnMyFavStrapsID').value + "'}",
            dataType: "json",
            success: function (msg) {
                if (msg.d == "0") {
                    $find('MixnMatchLoading').hide();
                    MxiFlag = 2;
                    showLogin();
                } else {
                    $("#RightFavourate").attr("style", "display:none;");
                    $("#StrapShowAll").attr("style", "display:block;");
                    $("#strapList").html('');
                    $("#strapList").html(msg.d);
                    $('#strapList').animate({ 'opacity': 1 }, "slow");
                    setTimeout(function () { setupColumnList('shoe'); }, 500);
                    setTimeout(function () { setupColumnList('strap'); }, 500);
                    $find('MixnMatchLoading').hide();
                }
            }
        });
    });





    //SHOW ALL SHOES
    $("#shoesShowAll").click(function () {
        $find('MixnMatchLoading').show();
        $('#shoeInfo1').hide();
        $('#strapInfo').hide();
        $("#LeftFavourate").attr("style", "display:block;");
        $("#shoesShowAll").attr("style", "display:none;");

        $.ajax({
            type: "POST",
            url: "jQuery-Page-Method/Default.aspx/ShowAllShoes",
            contentType: "application/json; charset=utf-8",
            data: "{id:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_hdnMyFavShoesID').value + "'}",
            dataType: "json",
            success: function (msg) {
                $("#shoeList").html(msg.d);
                $('#shoeList').animate({ 'opacity': 1 }, "slow");
                setTimeout(function () { setupColumnList('shoe'); }, 500);
                setTimeout(function () { setupColumnList('strap'); }, 500);
                $find('MixnMatchLoading').hide();
            }
        });
    });




    //SHOW ALL STRAPS
    $("#StrapShowAll").click(function () {
        $find('MixnMatchLoading').show();
        $('#shoeInfo1').hide();
        $('#strapInfo').hide();
        $("#RightFavourate").attr("style", "display:block;");
        $("#StrapShowAll").attr("style", "display:none;");
        $.ajax({
            type: "POST",
            url: "jQuery-Page-Method/Default.aspx/ShowAllStrap",
            contentType: "application/json; charset=utf-8",
            data: "{id:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_hdnMyFavStrapsID').value + "'}",
            dataType: "json",
            success: function (msg) {
                $("#strapList").html('');
                $("#strapList").html(msg.d);
                $('#strapList').animate({ 'opacity': 1 }, "slow");
                setTimeout(function () { setupColumnList('shoe'); }, 500);
                setTimeout(function () { setupColumnList('strap'); }, 500);
                $find('MixnMatchLoading').hide();
            }
        });
    });


    $.easing.easeOutQuart = function (x, t, b, c, d) {
        var abc = -c * ((t = t / d - 1) * t * t * t - 1) + b;
        //alert(abc);
        return abc;
    };


    var cartCount = $("#cartCount").text();
    if (cartCount > 0) {
        $('#cartbag').attr('class', "viewBag active");
        $("#checkoutlink").attr("style", "display:block;");
    }
    else {
        $('#cartbag').attr('class', "viewBag");
        $("#checkoutlink").attr("style", "display:none;");
    }


    $("#strapaddtocart").click(function () {
        $(".cartloadingright").attr("style", "display:block;");
        var param2 = '';

        var iCat = document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_iCatagory2').value;

        var SizeName = $('#strapSize span.title').text();
        var SizeSpan = $('#strapSize span');
        var Size = SizeSpan.attr("_sizeid");
        var _MinStock = SizeSpan.attr("_MinStock");


        var iDefault = straps[currStrap]['size'];
        var iIndex = iDefault.indexOf('Default');

        var abc = $('#strapSize').attr("_isDef");

        if (parseInt(abc) != 0) {
            if (_MinStock == -1) {
                $(".cartloadingright").attr("style", "display:none;");
                alert("Please select size !");
                return;
            }
        }

        var _Stock = SizeSpan.attr("_Stock");




        if (parseInt(_Stock) < parseInt(_MinStock)) {
            $(".cartloadingright").attr("style", "display:none;");
            strapfavorites();

        }
        else {
            if ($('#strapSize span.title').text() == "select size")
                Size = "N/A";

            param2 = "{PID:" + document.getElementById('strapID').value + ",Size:'" + Size + "',SizeName:'" + SizeName + "',Type:'straps',Tag:'" + iCat + "'}";
            //alert(param2);
            $.ajax({
                type: "POST",
                url: "jQuery-Page-Method/Default.aspx/addtoCart",
                contentType: "application/json; charset=utf-8",
                data: param2,
                dataType: "json",
                success: function (msg) {

                    var myIDs = new Array();
                    myIDs = msg.d.split('|');



                    if (myIDs.length > 1) {

                        if (myIDs[1].toLowerCase() == 'false') {
                            alert("The product is out of stock !");
                            $("#ctl00_ctrlheader_hypCart").html(myIDs[0]);
                        }
                    }
                    else {
                        $("#ctl00_ctrlheader_hypCart").html(msg.d);
                    }

                    GetSmallCart();
                    //attr("title")


                    $('#ctl00_ctrlheader_hypCart').animate({ 'backgroundColor': '#76644a', 'color': '#ffffff' }, 200, function () {
                        $(this).animate({ 'backgroundColor': 'transparent', 'color': '#76644a' }, 800);
                        $('#cartbag').attr('class', "viewBag active");
                        $("#checkoutlink").attr("style", "display:block;");
                        $(".cartloadingright").attr("style", "display:none;");

                    });
                }
            });
        }
    });

    $("#shoeaddtocart").click(function () {

        $(".cartloadingleft").attr("style", "display:block;");
        var param = '';
        var iCat = document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_iCatagory').value;
        var SizeName = ($('#shoeSize span.title').text());
        var SizeSpan = $('#shoeSize span');
        var Size = SizeSpan.attr("_sizeid");

        var _Stock = SizeSpan.attr("_Stock");

        var _MinStock = SizeSpan.attr("_MinStock");

        //alert(_MinStock);

        if (_MinStock == -1) {
            $(".cartloadingleft").attr("style", "display:none;");
            alert("Please select size !");
            return;
        }


        if (parseInt(_Stock) < parseInt(_MinStock)) {
            $(".cartloadingleft").attr("style", "display:none;");
            shoefavorites();
        }
        else {
            //var Size = $('##shoeSize span.title').attr("_sizeid");
            if ($('#shoeSize span.title').text() == "select size")
                Size = 'N/A';

            param = "{PID:" + document.getElementById('shoeID').value + ",Size:'" + Size + "',SizeName:'" + SizeName + "',Type:'shoes',Tag:'" + iCat + "'}";
            // alert(param);

            $.ajax({
                type: "POST",
                url: "jQuery-Page-Method/Default.aspx/addtoCart",
                contentType: "application/json; charset=utf-8",
                data: param,
                dataType: "json",
                success: function (msg) {

                    var myIDs = new Array();
                    myIDs = msg.d.split('|');



                    if (myIDs.length > 1) {
                        if (myIDs[1].toLowerCase() == 'false') {
                            alert("The product is out of stock !");
                            $("#ctl00_ctrlheader_hypCart").html(myIDs[0]);
                        }
                    }
                    else {
                        $("#ctl00_ctrlheader_hypCart").html(msg.d);
                    }

                    GetSmallCart();

                    $('#ctl00_ctrlheader_hypCart').animate({ 'backgroundColor': '#76644a', 'color': 'transparent' }, 200, function () {
                        $(this).animate({ 'backgroundColor': 'transparent', 'color': '#76644a' }, 800);
                        $('#cartbag').attr('class', "viewBag active");
                        $("#checkoutlink").attr("style", "display:block;");
                        $(".cartloadingleft").attr("style", "display:none;");
                    });
                }
            });
        }
    });



    // function design by manoj on 02-July-10
    $("#productaddtocart").click(function () {
        $(".productcartloadingright").attr("style", "display:block;");
        document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_hdnForBackPage').value = 1;
        var param = '';
        var iCat = document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_iCatagory').value;
        var Type = document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_hidiCatagory').value;

        var SizeName = 0;
        var SizeSpan = 0;
        var Size = 0;
        var name = 0;

        if (Type == 'Snaps') {
            SizeName = "select size";
            name = "select size";
            SizeSpan = 0;
            Size = 'N/A';

        }
        else if (Type == 'Scarf') {
            SizeName = "select size";
            name = "select size";
            SizeSpan = 0;
            Size = 'N/A';

        }
        else if (Type == 'bags') {
            SizeName = "select size";
            name = "select size";
            SizeSpan = 0;
            Size = 'N/A';

        }
        else {
            SizeName = document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_ddlSize').options[document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_ddlSize').selectedIndex].text;

            if (Type == 'Straps') {
                name = SizeName.substr(0, 1);
            }
            else {
                name = SizeName.substr(SizeName.length - 1, 1);
            }
            SizeSpan = document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_ddlSize').value;
            Size = document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_ddlSize').value;
        }

        var _Stock = document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_ddlQuantity').value;

        var _MinStock = document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_ddlQuantity').value;

        //alert(_MinStock);

        if (_MinStock == -1) {
            $(".productcartloadingright").attr("style", "display:none;");
            alert("Please select size !");
            return;
        }


        if (parseInt(_Stock) < parseInt(_MinStock)) {
            shoefavorites();
        }
        else {
            //var Size = $('##shoeSize span.title').attr("_sizeid");
            if ($('#shoeSize span.title').text() == "select size")
                Size = 'N/A';

            param = "{PID:" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_pID').value + ",Size:'" + Size + "',SizeName:'" + name + "',Type:'" + Type + "',Tag:'" + Type + "'}";

            //alert(param);

            $.ajax({
                type: "POST",
                url: "jQuery-Page-Method/Default.aspx/addtoCart",
                contentType: "application/json; charset=utf-8",
                data: param,
                dataType: "json",
                success: function (msg) {

                    var myIDs = new Array();
                    myIDs = msg.d.split('|');



                    if (myIDs.length > 1) {
                        if (myIDs[1].toLowerCase() == 'false') {
                            alert("The product is out of stock !");
                            $("#ctl00_ctrlheader_hypCart").html(myIDs[0]);
                        }
                    }
                    else {
                        $("#ctl00_ctrlheader_hypCart").html(msg.d);
                    }

                    GetSmallCart();
                    
                    $('#ctl00_ctrlheader_hypCart').animate({ 'backgroundColor': '#76644a', 'color': 'transparent' }, 200, function () {
                        $(this).animate({ 'backgroundColor': 'transparent', 'color': '#76644a' }, 800);
                        $('#cartbag').attr('class', "viewBag active");
                        $("#checkoutlink").attr("style", "display:block;");
                        $(".productcartloadingright").attr("style", "display:none;");
                    });
                }
            });
        }
    });
    //end of function



    $("#shoefavorites").click(function () {
        shoefavorites();
    });

    $("#strapfavorites").click(function () {
        strapfavorites();
    });



    // FUNCTION FOR SHOW CHANGE PASSWORD POP UP
    $("#changepassword").click(function () {
        showChangePasswordPopup();
    });

    function showChangePasswordPopup() {
        var width = $('#changepassPop').width() / 2;
        var height = $('#changepassPop').height() / 2;
        //$('#changepassPop').css({ marginLeft: -width, marginTop: $(window).scrollTop() - height });
        //$('#shade').width($(document).width()).height($(document).height());
        if ($.browser.msie) {
            $('#shade').css('display', 'block');
        } else {
            $('#shade').fadeIn(500);
        }
        $('#changepassPop').fadeIn(500);

    }

    $('a.changepassPopClose').click(function (evt) {
        hideChangePassPopup(evt);
    })

    function hideChangePassPopup(evt) {
        if ($.browser.msie) {
            $('#shade').css('display', 'none');
        } else {
            $('#shade').fadeOut(500);
        }
        $('#changepassPop').fadeOut(500);
        document.getElementById('txtNewPass').value = "";
        document.getElementById('txtConfirmNewPass').value = "";
    }

    $("#ChangePass").click(function () {
        if ($("#txtNewPass").val() == "") {
            alert('Please enter new password');
            $("#txtNewPass").focus();
            return false;
        }
        if ($("#txtConfirmNewPass").val() == "") {
            alert('Please enter confirm password');
            $("#txtConfirmNewPass").focus();
            return false;
        }
        if ($("#txtNewPass").val() != $("#txtConfirmNewPass").val()) {
            alert('Confirm password not matching');
            $("#txtConfirmNewPass").focus();
            return false;
        }

        changepassword($("#txtNewPass").val(), $("#txtNewPass").val());

    });

    function changepassword(CurrPass, NewPass) {
        $.ajax({ type: "POST",
            url: "jQuery-Page-Method/Default.aspx/ChangePassword",
            contentType: "application/json; charset=utf-8",
            data: "{CurrentPassword:'" + CurrPass + "',NewPassword:'" + NewPass + "'}",
            dataType: "json",
            success: function (msg) {
                if (msg.d == "0") {
                    if ($.browser.msie) {
                        $('#shade').css('display', 'none');
                    } else {
                        $('#shade').fadeOut(500);
                    }
                    $('#changepassPop').fadeOut(500);
                    document.getElementById('txtNewPass').value = "";
                    document.getElementById('txtConfirmNewPass').value = "";
                }
                else {
                    alert('Current password is not matching');
                }
            }
        });
    }

    //END CHANGE PASSWORD POPUP



    // NEW FUNCTION
    $("#AmyAccount").click(function () {
        document.getElementById('hdnVal').value = 'MYACCOUNT';
        showMyAccountAndFavourate(document.getElementById('hdnVal').value);
    });
    $("#AFavourate").click(function () {
        document.getElementById('hdnVal').value = 'FAVOURATE';
        showMyAccountAndFavourate(document.getElementById('hdnVal').value);
    });

    function showMyAccountAndFavourate(id) {
        $.ajax({
            type: "POST",
            url: "jQuery-Page-Method/Default.aspx/GoToMyAccount",
            contentType: "application/json; charset=utf-8",
            data: "{id:'" + id + "'}",
            dataType: "json",
            success: function (msg) {
                if (msg.d == "0") {

                    var width = $('#LoginPopup').width() / 2;
                    var height = $('#LoginPopup').height() / 2;
                    $('#LoginPopup').css({ marginLeft: -width, marginTop: $(window).scrollTop() - height });
                    $('#shade').width($(document).width()).height($(document).height());
                    if ($.browser.msie) {
                        $('#shade').css('display', 'block');
                    } else {
                        $('#shade').fadeIn(500);
                    }
                    $('#LoginPopup').fadeIn(500);
                }
                else {
                    hideLoginPopUP();
                    if (id == "FAVOURATE")
                        window.location = "favorites.aspx";
                    else
                        window.location = "Myaccount.aspx";

                }
            }
        });
    }
    //END  FUNCTION


    $("#popSignIn").click(function () {

        if ($.trim(document.getElementById('MMpopUname').value == '') || !mailRegex1.test(document.getElementById('MMpopUname').value)) {
            alert('Invalid Email address.');
            document.getElementById('MMpopUname').focus();
            hideWorking('popSignIn');
            return;
        }
        if ($.trim(document.getElementById('MMpopPasswd').value) == '') {
            alert('Blank password not valid.');
            document.getElementById('MMpopPasswd').focus();
            hideWorking('popSignIn');
            return;
        }
        loginme();
    });

    $('#regPopBtn').click(function (evt) {
        evt.preventDefault();
        evt.stopPropagation();
        startWorking(this);
        registerUser('MMpop');
    });

    // FUNCTION
    $("#LoginpopSignIn").click(function () {
        if ($.trim($('#popUname').val()) == '' || !mailRegex.test($('#popUname').val())) {

            alert('Invalid Email address');
            $('#popUname').focus();
            return;
        }
        if ($.trim(document.getElementById('popPasswd').value) == '') {
            alert('Blank password not valid.');
            document.getElementById('popPasswd').focus();
            return;
        }
        loginFromLoginPopup();
    });
    function loginFromLoginPopup() {
        var param = '';
        param = "{Uname:'" + document.getElementById('popUname').value + "',Passwd:'" + document.getElementById('popPasswd').value + "'}";
        $.ajax({
            type: "POST",
            url: "jQuery-Page-Method/Default.aspx/Login",
            contentType: "application/json; charset=utf-8",
            data: param,
            dataType: "json",
            success: function (msg) {
                if (msg.d == "False") {
                    alert("Invalid username/password");
                }
                else {
                    $('#popUname').val('');
                    $('#popPasswd').val('');
                    hideLoginPopUP();
                    if (document.getElementById('hdnVal').value == "FAVOURATE")
                        window.location = "favorites.aspx";
                    else
                        window.location = "myaccount.aspx";
                }
            }
        });
    }






    $('#LoginPopBtn').click(function (evt) {
        evt.preventDefault();
        evt.stopPropagation();
        if ($.trim($('#popEmail').val()) == '' || !mailRegex.test($('#popEmail').val())) {
            alert('Invalid Email address');
            $('#popEmail').focus();
            return;
        }
        if ($.trim($('#popFName').val()) == '') {
            alert('Invalid First Name address');
            $('#popFName').focus();
            //hideWorking('regPopBtn');
            return;
        }

        if ($.trim($('#popPasswd1').val()) == '') {
            $('#popPasswd1').focus();
            alert('Invalid Password');
            //hideWorking('regPopBtn');
            return;
        }
        if ($('#popPasswd1').val() != $('#popPasswd2').val()) {
            alert('Passwords do not match.  Please re-enter');
            $('#popPasswd1').val('').focus();
            $('#popPasswd2').val('');
            //hideWorking('regPopBtn');
            return;
        }

        registrationFromLoginPopUP('pop');
    });




    function registrationFromLoginPopUP(id) {
        var param = '';
        param = "{Email:'" + $.trim($('#' + id + 'Email').val()) + "',FName:'" + $.trim($('#' + id + 'FName').val()) + "',LName:'" + $.trim($('#' + id + 'LName').val()) + "',Passwd:'" + $.trim($('#' + id + 'Passwd1').val()) + "'}";
        $.ajax({
            type: "POST",
            url: "jQuery-Page-Method/Default.aspx/registraion",
            contentType: "application/json; charset=utf-8",
            data: param,
            dataType: "json",
            success: function (msg) {

                if (msg.d == "False") {
                    alert("This e-mail address already in our database, please use another e-mail address");
                }
                else {
                    $('#popEmail').val('');
                    $('#popFName').val('');
                    $('#popPasswd1').val('');
                    $('#popPasswd2').val('');
                    hideLoginPopUP();
                    if (document.getElementById('hdnVal').value == "FAVOURATE")
                        window.location = "favorites.aspx";
                    else
                        window.location = "myaccount.aspx";
                }
            }
        });
    }

    //END  FUNCTION




    $('#Shoes').click(function (evt) {
        $find('MPLoading').show();
        $('#lblTyle').text('Straps');
        $('#lblTyle').text('Shoes');
        document.getElementById('hdnShorNameColor').value = '';
        $('#lblColor').text('');
        $('#lblStyle').text('');
        document.getElementById('hidKey').value = '';
        $('#sliderData').animate({ 'opacity': 0 }, 500);
        GetColors(1664);
        GetStyle(1664);
        GetShoes(1664, 1664);               // 1664 Shoe
        $("#Straps").attr("class", "");
        $("#Shoes").attr("class", "active");
        $("#Shoes_arrival").attr("class", "");

    });

    $('#Straps').click(function (evt) {
        $find('MPLoading').show();
        $('#lblTyle').text('Straps');
        document.getElementById('hdnShorNameColor').value = '';
        $('#lblColor').text('');
        $('#lblStyle').text('');
        document.getElementById('hidKey').value = '';
        $('#sliderData').animate({ 'opacity': -1 }, 500);
        GetColors(1630);
        GetStyle(1630);
        GetShoes(1630, 1630);               // 1630 Strap
        $("#Straps").attr("class", "active");
        $("#Shoes").attr("class", "");
        $("#Shoes_arrival").attr("class", "");
    });



    $('#Shoes_arrival').click(function (evt) {
        document.getElementById('hdnShorNameColor').value = '';
        $('#lblColor').text('');
        $('#lblStyle').text('');
        document.getElementById('hidKey').value = '';
        var myRef = $("#Shoes_arrival").attr("ref");
        var myIDs = new Array();
        myIDs = myRef.split('|');
        GetShoes(myIDs[0], myIDs[1]);
        $("#Shoes_arrival").attr("class", "active");

    });


    $('#SnapShoes').click(function (evt) {
        $('#lblTyle').text('Snaps');
        document.getElementById('hidKey').value = '';
        document.getElementById('hdnShorNameColor').value = '';
        $('#lblColor').text('');
        $('#lblStyle').text('');
        $('#sliderData').animate({ 'opacity': 0 }, 500);
        GetColors(1727);
        GetStyle(1727);
        GetShoes(1727, 1727);               // 1727 Shoe
        $("#Snaps").attr("class", "");
        $("#SnapShoes").attr("class", "active");
        $("#Shoes_arrival").attr("class", "");
        $('#sliderData').animate({ 'opacity': 1 }, 500);

    });


    $('#Snaps').click(function (evt) {
        $('#lblTyle').text('Snaps');
        document.getElementById('hdnShorNameColor').value = '';
        $('#lblColor').text('');
        $('#lblStyle').text('');
        document.getElementById('hidKey').value = '';
        $('#sliderData').animate({ 'opacity': -1 }, 500);
        GetColors(1731);
        GetStyle(1731);
        GetShoes(1731, 1731);               // 1737 snap
        $("#Snaps").attr("class", "active");
        $("#SnapShoes").attr("class", "");
        $("#Shoes_arrival").attr("class", "");
        $('#sliderData').animate({ 'opacity': 1 }, 7500);
    });

    $('#Shoes_arrival').click(function (evt) {

        document.getElementById('hdnShorNameColor').value = '';
        $('#lblColor').text('');
        document.getElementById('hidKey').value = '';
        var myRef = $("#Shoes_arrival").attr("ref");
        var myIDs = new Array();
        myIDs = myRef.split('|');
        GetShoes(myIDs[0], myIDs[1]);
        $("#Shoes_arrival").attr("class", "active");

    });

    $('#clearFilters').click(function (evt) {
        document.getElementById('hdnShorNameColor').value = '';
        $('#lblColor').text('');
        $('#lblStyle').text('');

        document.getElementById('hidKey').value = '';
        if ($("#Shoes").attr("class") == "active")
            GetShoes(1664, 1664);
        else
            GetShoes(1630, 1630);
    });


    $('#clearFiltersSnap').click(function (evt) {

        document.getElementById('hdnShorNameColor').value = '';
        $('#lblColor').text('');
        $('#lblStyle').text('');
        document.getElementById('hidKey').value = '';
        if ($("#SnapShoes").attr("class") == "active")
            GetShoes(1727, 1727);
        else
            GetShoes(1731, 1731);
    });


    $('#clearSingle').click(function (evt) {
        document.getElementById('hdnShorNameColor').value = '';
        $('#lblColor').text('');
        $('#lblStyle').text('');
        document.getElementById('hidKey').value = '';
        GetShoes(document.getElementById('ctl00_ContentPlaceHolder1_ctrlCatalog2_hidCatID').value, document.getElementById('ctl00_ContentPlaceHolder1_ctrlCatalog2_hidCatID').value);
    });


    $("#itemfavorites").click(function () {
        itemfavorites();
    });


    ////    $("#cartitemfavorites").click(function() {
    ////        cartitemfavorites();
    ////    });

    $('#pshoeThumbFull, #pshoeThumbHoriz').click(function (evt) {
        evt.preventDefault();
        evt.stopPropagation();
        ptoggleAltShoe();
    }).css('opacity', 0);


    //$('.my-dropdown').change(function() { alert('changed') });


    //$('#pshoeThumbHoriz').animate({ 'opacity': 1 }, 500).attr('_showing', 'true');

    $('#ShoesWholeSale').click(function (evt) {
        $find('MPLoading').show();
        document.getElementById('hidKey').value = '';
        $('#BoxMiddle').animate({ 'opacity': 0 }, 500);
        GetColorsWholeSale(1664);
        GetStyleWholeSale(1664);
        GetShoes(1664, 1664);               // 1664 Shoe
        GetWholeSaleProduct(1664, 1664);
        $("#StrapsWholeSale").attr("class", "");
        $("#ShoesWholeSale").attr("class", "active");
        $("#Shoes_arrival").attr("class", "");

    });

    $('#StrapsWholeSale').click(function (evt) {
        $find('MPLoading').show();
        document.getElementById('hidKey').value = '';
        $('#BoxMiddle').animate({ 'opacity': 0 }, 500);
        GetColorsWholeSale(1630);
        GetStyleWholeSale(1630);
        GetShoes(1630, 1630);               // 1630 Strap
        GetWholeSaleProduct(1630, 1630);
        $("#StrapsWholeSale").attr("class", "active");
        $("#ShoesWholeSale").attr("class", "");
        $("#Shoes_arrival").attr("class", "");

    });



    $('#slick-slidetoggle').click(function () {
        timeout = setTimeout(function () {
            $("#slickbox").hide('blind', {}, 400)
        }, 5000);
    });

    $('#slickbox').mouseover(function () {
        clearTimeout(timeout);
    });
    $('#slickbox').mouseout(function () {
        timeout = setTimeout(function () {
            $("#slickbox").hide('blind', {}, 400)
        }, 2000);
    });


//    $('#hypshoesstraps').mouseover(function () {    
//        $('#divshopstrapshoes').slidetoggle(600);
//    });

//    $('#shopsnap').mouseover(function () {
//        $('#divshopsnapshoes').slidetoggle(600);
//    });


//    $('#shopkids').mouseover(function () {
//        $('#divshopforkids').slidetoggle(600);
//    });
    
    
    
});


function GetWholeSaleProduct(ID, ParentID) {
    $.ajax({ type: "POST",
        url: location.protocol + '//' + location.hostname + rootDir + "jQuery-Page-Method/Default.aspx/GetWholeSaleProduct",
        contentType: "application/json; charset=utf-8",
        data: "{ID:'" + ID + "',ParentID:'" + ParentID + "'}",
        dataType: "json",
        success: function(msg) {
            $("#BoxMiddle").html(msg.d);
            $('#BoxMiddle').animate({ 'opacity': 1 }, "slow");
            $find('MPLoading').hide();
        }
    });
}

function GetShoesMenyWholeSale(ID, PerentID) {
    $find('MPLoading').show();
    $('#BoxMiddle').animate({ 'opacity': 0 }, 500);
    $("#" + ID).attr("class", "active");
    var ihidKey = "";
    if (ID == PerentID) {
        var StyleVal = document.getElementById('hidKey').value.split(',');
        for (var i = 1; i < StyleVal.length; i++) {
            $("#" + StyleVal[i]).removeClass("active");
        }
        document.getElementById('hidKey').value = "";
        ihidKey = ',' + ID;
        $("#" + ID).attr("class", "active");
    }
    else {
        var ihidKey = document.getElementById('hidKey').value;
        ihidKey = ihidKey + ',' + ID;
        document.getElementById('hidKey').value = ihidKey;
        $("#" + PerentID).removeClass("active");
    }


    $.ajax({ type: "POST",
        url: location.protocol + '//' + location.hostname + rootDir + "jQuery-Page-Method/Default.aspx/GetMultiCatWholeSaleProduct",
        contentType: "application/json; charset=utf-8",
        data: "{QString:'" + ihidKey + "',PerentID:'" + PerentID + "'}",
        dataType: "json",
        success: function(msg) {
            $("#BoxMiddle").html(msg.d);
            $('#BoxMiddle').animate({ 'opacity': 1 }, "slow");
            $find('MPLoading').hide();

        }

    });
}

function GetStyleWholeSale(ID) {
    $.ajax({ type: "POST",
        url: location.protocol + '//' + location.hostname + rootDir + "jQuery-Page-Method/Default.aspx/GetStyleWholeSale",
        contentType: "application/json; charset=utf-8",
        data: "{ID:'" + ID + "'}",
        dataType: "json",
        success: function(msg) {
            $('#style').html(msg.d).resetSS();
            $('#style').change(function() {
                $find('MPLoading').show();
                $('#BoxMiddle').animate({ 'opacity': 0 }, 500);
                var iPerentID = $('#style').getSSRef();
                var myarr = new Array();
                myarr = iPerentID.split('|');
                GetShoesbySize(myarr[0], myarr[0]);
                GetWholeSaleProduct(myarr[0], myarr[1]);

            });
        }
    });
}


function GetColorsWholeSale(ID) {
    $.ajax({ type: "POST",
        url: location.protocol + '//' + location.hostname + rootDir + "jQuery-Page-Method/Default.aspx/GetColorsWholeSale",
        contentType: "application/json; charset=utf-8",
        data: "{ID:'" + ID + "'}",
        dataType: "json",
        success: function(msg) {
            $("#style_Box").html(msg.d);
        }
    });
}


function ptoggleAltShoe() {


    var showThumb = '#pshoeThumbHoriz';
    var hideThumb = '#pshoeThumbFull';
    var hidImage1 = document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_hidImage1').value;
    var hidImage2 = document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_hidImage2').value;


    if ($('#pshoeThumbFull').attr('_showing') == 'false') {
        var Image1 = $('#pshoeThumbHoriz').attr('src').replace('80', '600').replace('46', '600');

        $("#zoom1").attr("href", Image1);

        $('*', '#BigImage').each(function() {
            if (this.tagName.toLowerCase() == 'img') {
                $('#BigImage img').attr('src', Image1);
            }
        });


    } else {


        var Image2 = $('#pshoeThumbFull').attr('src').replace('80', '600').replace('46', '600');

        $("#zoom1").attr("href", Image2);
        $('*', '#BigImage').each(function() {
            if (this.tagName.toLowerCase() == 'img') {
                $('#BigImage img').attr('src', Image2);
            }
        });

        showThumb = '#pshoeThumbFull';
        hideThumb = '#pshoeThumbHoriz';
    }

    $(showThumb).animate({ 'opacity': 0 }, 500).attr('_showing', 'false').attr('style', 'display:none');
    $(hideThumb).animate({ 'opacity': 1 }, 500).attr('_showing', 'true').attr('style', 'display:block');
}


function GetColors(ID) {
    $.ajax({ type: "POST",
        url: "jQuery-Page-Method/Default.aspx/GetColors",
        contentType: "application/json; charset=utf-8",
        data: "{ID:'" + ID + "'}",
        dataType: "json",
        success: function(msg) {
            $("#style_Box").html(msg.d);
        }
    });
}

function GetColors2(ID) {
    $.ajax({ type: "POST",
        url: "jQuery-Page-Method/Default.aspx/GetColors2",
        contentType: "application/json; charset=utf-8",
        data: "{ID:'" + ID + "'}",
        dataType: "json",
        success: function(msg) {
            $("#style_Box").html(msg.d);
        }
    });
}


function GetStyle2(ID) {
    $.ajax({ type: "POST",
        url: "jQuery-Page-Method/Default.aspx/GetStyle2",
        contentType: "application/json; charset=utf-8",
        data: "{ID:'" + ID + "'}",
        dataType: "json",
        success: function(msg) {
            $("#style_Box2").html(msg.d);
        }
    });
}


function GetStyle(ID) {
    $.ajax({ type: "POST",
        url: "jQuery-Page-Method/Default.aspx/GetStyle",
        contentType: "application/json; charset=utf-8",
        data: "{ID:'" + ID + "'}",
        dataType: "json",
        success: function(msg) {
            $('#style').html(msg.d).resetSS();
            $('#style').change(function() {
                $find('MPLoading').show();
                $('#sliderData').animate({ 'opacity': 0 }, 500);
                var istyle = $('#style').getSetSSValue();

                if (istyle != 'Style') {
                    $('#lblStyle').text(istyle);
                }
                else {
                    $('#lblStyle').text('');
                }

                var iPerentID = $('#style').getSSRef();

                var myarr = new Array();
                myarr = iPerentID.split('|');
                GetShoes(myarr[0], myarr[1]);

            });
        }
    });
}


function GetSize(ID) {
    $.ajax({ type: "POST",
        url: "jQuery-Page-Method/Default.aspx/GetSize",
        contentType: "application/json; charset=utf-8",
        data: "{ID:'" + ID + "'}",
        dataType: "json",
        success: function(msg) {
            $('#size').html(msg.d).resetSS();
            $('#size').change(function() {
                $find('MPLoading').show();
                $('#sliderData').animate({ 'opacity': 0 }, 500);
                var istyle = $('#size').getSetSSValue();

                if (istyle != 'size') {
                    $('#lblStyle').text(istyle);
                }
                else {
                    $('#lblStyle').text('');
                }

                var iPerentID = $('#size').getSSRef();

                var myarr = new Array();
                myarr = iPerentID.split('|');
                GetShoesbySize(myarr[0], myarr[1]);
                GetShoesbySize(myarr[0], myarr[1]);
            });
        }
    });
}



function GetShoes(ID, PerentID) {
    $.ajax({ type: "POST",
        url: "jQuery-Page-Method/Default.aspx/GetShoes",
        contentType: "application/json; charset=utf-8",
        data: "{ID:'" + ID + "',PerentID:'" + PerentID + "'}",
        dataType: "json",
        success: function (msg) {
            var iimessage = msg.d;
            var myCars = new Array();
            myCars = iimessage.split('|');
            if (ID == 1630) { $("#sliderData").html(myCars[0]); } else {
                $("#sliderData").html(myCars[0]);
            }
            $find('MPLoading').hide();
            $('#sliderData').animate({ 'opacity': 1 }, "slow");
            var container = $('div.sliderGallery');
            var ul = $('ul', container);
            var itemsWidth = myCars[1];

            if (itemsWidth < 0) itemsWidth = 0;

            $('.slider', container).slider({
                min: 0,
                max: itemsWidth,
                stop: function (event, ui) {
                    adjustHandle();
                    ul.animate({ 'left': ui.value * -1 }, 500);
                },
                slide: function (event, ui) {
                    adjustHandle();
                    ul.css('left', ui.value * -1);
                }
            });

            function adjustHandle() {
                var slider = $('.slider');
                var handle = $('.ui-slider-horizontal .ui-slider-handle');
                var position = handle.position().left;
                
                var halfHandle = handle.width() * 0.5;
             
                if (position > halfHandle) {
                   
                    handle.css({ "margin-left": -handle.width() });
                } else {

                    handle.css({ "margin-left": "0px" });
                }
            }

            $("#style_Box a").removeClass('active');
            $("#" + ID + "").attr("class", "active");
            $("#preloading").css("display", "none");
            $("#Shoes_arrival").attr("ref", myCars[2] + "|" + ID);
        }
    });

}

function GetShoesbySize(ID, PerentID) {
    $.ajax({ type: "POST",
        url: "jQuery-Page-Method/Default.aspx/GetShoesbySize",
        contentType: "application/json; charset=utf-8",
        data: "{ID:'" + ID + "',PerentID:'" + PerentID + "'}",
        dataType: "json",
        success: function(msg) {
            var iimessage = msg.d;
            var myCars = new Array();
            myCars = iimessage.split('|');
            $("#sliderData").html(myCars[0]);
            $find('MPLoading').hide();
            $('#sliderData').animate({ 'opacity': 1 }, "slow");
            var container = $('div.sliderGallery');
            var ul = $('ul', container);
            //var itemsWidth = ul.innerWidth() - container.outerWidth();
            var itemsWidth = myCars[1];

            //            $("#content-slider").slider({
            //                animate: true,
            //                change: handleSliderChange,
            //                slide: handleSliderSlide
            //            });

            $('.slider', container).slider({
                min: 0,
                max: itemsWidth,
                handle: '.handle',
                stop: function(event, ui) {
                    ul.animate({ 'left': ui.value * -1 }, 500);
                },
                slide: function(event, ui) {
                    ul.css('left', ui.value * -1);
                }
            });

            $("#style_Box a").removeClass('active');
            $("#" + ID + "").attr("class", "active");
            $("#Shoes_arrival").attr("ref", myCars[2] + "|" + ID);
        }
    });

}

function GetShoesMeny(ID, PerentID) {
    $find('MPLoading').show();
    $('#sliderData').animate({ 'opacity': 0 }, 500);
    var ihidKey = document.getElementById('hidKey').value;
    var ihidName = document.getElementById('hdnShorNameColor').value;

    if (ID == PerentID) {
        document.getElementById('hidKey').value = ',' + ID;
        document.getElementById('hdnShorNameColor').value = ',' + $('#' + ID).text();
    }
    else {
        ihidKey = ihidKey + ',' + ID;
        document.getElementById('hidKey').value = ihidKey;
        ihidName = ihidName + ',' + $('#' + ID).text();
        document.getElementById('hdnShorNameColor').value = ihidName;
    }


    var currentId = $(this).attr('id');

    var ivar = $('#' + ID).attr('class');

    if ((ivar == 'active') && (ID != PerentID)) {


        var myIDS = new Array();
        myIDS = document.getElementById('hidKey').value.split(',');


        var myColor = new Array();
        myColor = document.getElementById('hdnShorNameColor').value.split(',');
        var newID = "";
        var newColor = "";
        for (var xi in myColor) {
            if (isNaN(xi)) { } else {
                if (myColor[xi].trim().length > 0) {
                    if (myColor[xi] != $('#' + ID).text()) {
                        newColor = newColor + "," + myColor[xi];
                    }
                }
            }
        }


        for (var xi in myIDS) {
            if (isNaN(xi)) { } else {
                if (myIDS[xi].trim().length > 0) {
                    if (myIDS[xi] != ID) {
                        newID = newID + "," + myIDS[xi];

                    }
                }
            }
        }
        document.getElementById('hidKey').value = newID;
        document.getElementById('hdnShorNameColor').value = newColor;
    }

    ihidKey = document.getElementById('hidKey').value;
    ihidName = document.getElementById('hdnShorNameColor').value;

    if (ihidKey != "") {

        $.ajax({ type: "POST",
            url: "jQuery-Page-Method/Default.aspx/GetMultiCat",
            contentType: "application/json; charset=utf-8",
            data: "{QString:'" + ihidKey + "',PerentID:'" + PerentID + "'}",
            dataType: "json",
            success: function(msg) {
                var iimessage = msg.d;
                var myCars = new Array();
                myCars = iimessage.split('|');
                $("#sliderData").html(myCars[0]);
                var container = $('div.sliderGallery');
                var ul = $('ul', container);
                //var itemsWidth = ul.innerWidth() - container.outerWidth();
                var itemsWidth = myCars[1];
                $('#handle').removeClass('ui-slider-handle-active');
                //$("#handle").attr("class", "handle");
                // ui-slider-handle-active
                $('.slider', container).slider({
                    min: 0,
                    max: itemsWidth,
                    handle: '.handle',
                    stop: function(event, ui) {
                        ul.animate({ 'left': ui.value * -1 }, 500);
                    },
                    slide: function(event, ui) {
                        ul.css('left', ui.value * -1);
                    }
                });

                $("#style_Box a").removeClass('active');

                $("#style_Box2 a").removeClass('active');

                var myIDS = new Array();
                myIDS = ihidKey.split(',');
                for (var xi in myIDS) {
                    if (isNaN(xi)) { } else {
                        if ((myIDS[xi] != "") || (myIDS[xi] != "undefined")) {
                            $("#" + myIDS[xi] + "").attr("class", "active");
                        }
                    }

                }

                var val = ihidName.split(",");
                var showVal = "";
                for (var i = 0; i < val.length; i++) {
                    showVal = showVal + " " + val[i];
                }
                $('#lblColor').text('');
                $('#lblColor').text(showVal);


                $("#Shoes_arrival").attr("ref", myCars[2] + "|" + ID);
                $find('MPLoading').hide();
                $('#sliderData').animate({ 'opacity': 1 }, 5000);
            }
        });
    }
    else {
        GetShoes(PerentID, PerentID);
    }
}

/*
function GetShoesMeny(ID, PerentID) {

var ihidKey = document.getElementById('hidKey').value;
//var Myref = $(this).attr('href');
//  return $(this).find(':selected').attr("ref");
// var Myref = $(this).attr("ref");

if (ID == PerentID)
document.getElementById('hidKey').value = ',' + ID;
else {
ihidKey = ihidKey + ',' + ID;
document.getElementById('hidKey').value = ihidKey;
}

ihidKey = document.getElementById('hidKey').value;

   

$.ajax({ type: "POST",
url: "jQuery-Page-Method/Default.aspx/GetMultiCat",
contentType: "application/json; charset=utf-8",
data: "{QString:'" + ihidKey + "',PerentID:'" + PerentID + "'}",
dataType: "json",
success: function(msg) {
var iimessage = msg.d;
var myCars = new Array();
myCars = iimessage.split('|');
$("#sliderData").html(myCars[0]);

var container = $('div.sliderGallery');
var ul = $('ul', container);
//var itemsWidth = ul.innerWidth() - container.outerWidth();
var itemsWidth = myCars[1];
$('#handle').removeClass('ui-slider-handle-active');
//$("#handle").attr("class", "handle");
// ui-slider-handle-active
$('.slider', container).slider({
min: 0,
max: itemsWidth,
handle: '.handle',
stop: function(event, ui) {
ul.animate({ 'left': ui.value * -1 }, 500);
},
slide: function(event, ui) {
ul.css('left', ui.value * -1);
}
});

$("#style_Box a").removeClass('active');

$("#style_Box2 a").removeClass('active');

var myIDS = new Array();
myIDS = ihidKey.split(',');

for (var xi in myIDS) {
$("#" + myIDS[xi] + "").attr("class", "active");
}

$("#Shoes_arrival").attr("ref", myCars[2] + "|" + ID);
}
});
}

*/

function hideLogin() {
    if ($.browser.msie) {
        $('#shade').css('display', 'none');
    } else {
        $('#shade').fadeOut(500);
    }
    $('#regPop').fadeOut(500, function() {
        // reset the popup in case they come across it again.
        switchPopup('regPop');
    });
}

//this is for add(mistake)
function shoefavorites() {
    var param = '';
    var qty = $('#shoeSize span.title').text();
    var iCat = document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_iCatagory').value;
    param = "{PID:'" + document.getElementById('shoeID').value + "',Size:'" + qty + "',Type:'shoes',Tag:'" + iCat + "'}";
    //alert(param);

    $.ajax({
        type: "POST",
        url: "jQuery-Page-Method/Default.aspx/addtoWishList",
        contentType: "application/json; charset=utf-8",
        data: param,
        dataType: "json",
        success: function(msg) {
            if (msg.d == "0") {
                MxiFlag = 1;
                showLogin();
            }
            else {

                $("#AFavourate").text(msg.d);
                $('#AFavourate').animate({ 'backgroundColor': '#76644a', 'color': '#ffffff' }, 200, function() {
                    $(this).animate({ 'backgroundColor': 'transparent', 'color': '#76644a' }, 800);
                });
            }
        }
    });
}

function GetSmallCart() {
    $.ajax({ type: "POST",
        url: "jQuery-Page-Method/Default.aspx/GetSmaCart",
        contentType: "application/json; charset=utf-8",
        data: "{id:'D'}",
        dataType: "json",
        success: function(msg) {

            var myIDS = new Array();
            myIDS = msg.d.split('|');

            $("#photos_Data").html(myIDS[0]);
            $("#total_item").html(myIDS[1] + " Items <a href=checkout.aspx>Checkout</a>");

            if(myIDS[0] != '<ul></ul>')
            {
                $('#photos').serialScroll({
                    items: 'li',
                    prev: '#photoprev',
                    next: '#photonext',
                    offset: -5, //when scrolling to photo, stop 230 before reaching it (from the left)
                    start: 0, //as we are centering it, start at the 2nd
                    duration: 300,
                    //interval: 3000,
                    axis: 'xy', // The default is 'y' scroll on both ways
                    event: 'click',
                    force: false,
                    stop: true,
                    lock: false,
                    exclude: 1,
                    cycle: true, //don't pull back once you reach the end
                    easing: 'easeOutQuart', //use this easing equation for a funny effect
                    jump: false, //click on the images to scroll to them
                    lazy: true
                });
            }
            if (myIDS[1] > 0) {
                $('#slickbox').show(400);
                $("#slick-slidetoggle").attr("class", "active");
                timeout = setTimeout(function() {
                    $("#slickbox").hide('blind', {}, 400)
                }, 5000);
            }
        }
    });
}

//this is for add (mistake)
function strapfavorites() {
    var param2 = '';

    var iCat = document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_iCatagory2').value;
    var qty2 = $('#strapSize span.title').text();
    param2 = "{PID:'" + document.getElementById('strapID').value + "',Size:'" + qty2 + "',Type:'straps',Tag:'" + iCat + "'}";
    $.ajax({
        type: "POST",
        url: "jQuery-Page-Method/Default.aspx/addtoWishList",
        contentType: "application/json; charset=utf-8",
        data: param2,
        dataType: "json",
        success: function(msg) {
            if (msg.d == "0") {
                MxiFlag = 2;
                showLogin();
            }
            else {
                $("#AFavourate").text(msg.d);
                $('#AFavourate').animate({ 'backgroundColor': '#76644a', 'color': '#ffffff' }, 200, function() {
                    $(this).animate({ 'backgroundColor': 'transparent', 'color': '#76644a' }, 800);
                });
            }
        }
    });
}



function GetMyFavourites() {
    $.ajax({ type: "POST",
        url: "jQuery-Page-Method/Default.aspx/MyFavourites",
        contentType: "application/json; charset=utf-8",
        data: "{ID:'1630',PerentID:'1630'}",
        dataType: "json",
        success: function(msg) {
            var iimessage = msg.d;
            var myCars = new Array();
            myCars = iimessage.split('|');
            $("#sliderData").html(myCars[0]);
            $('#sliderData').animate({ 'opacity': 1 }, "slow");
            var container = $('div.sliderGallery');
            var ul = $('ul', container);
            var itemsWidth = myCars[1];

            $('.slider', container).slider({
                min: 0,
                max: itemsWidth,
                handle: '.handle',
                stop: function(event, ui) {
                    ul.animate({ 'left': ui.value * -1 }, 500);
                },
                slide: function(event, ui) {
                    ul.css('left', ui.value * -1);
                }
            });


        }
    });
}






function loginme() { 
    var param = '';
    param = "{Uname:'" + document.getElementById('MMpopUname').value + "',Passwd:'" + document.getElementById('MMpopPasswd').value + "'}";
    $.ajax({
        type: "POST",
        url: "jQuery-Page-Method/Default.aspx/Login",
        contentType: "application/json; charset=utf-8",
        data: param,
        dataType: "json",
        success: function(msg) {
            if (msg.d == "False") {
                alert("Invalid username/password");
                hideWorking('popSignIn');
            }
            else {
                $("#ctl00_ctrlheader_divLogoutCp").html('');
                $("#ctl00_ctrlheader_divLogoutCp").html("<a href='Logout.aspx' id='logout'>Logout</a>");
                hideLogin();                                  
                if (MxiFlag == 1) {
                   //shoefavorites();                                      
                    showFavourateLeft();
                }
                else if (MxiFlag == 2) {
                    //strapfavorites();
                    showFavourateRight();
                } else if (MxiFlag == 3) {
                    itemfavorites();
                }
            }
        }
    });
}

function registerUser(id) {

    if ($.trim($('#' + id + 'Email').val()) == '' || !mailRegex.test($('#' + id + 'Email').val())) {
        alert('Invalid Email address');
        $('#' + id + 'Email').focus();
        hideWorking('regPopBtn');
        return;
    }


    if ($.trim($('#' + id + 'FName').val()) == '') {
        alert('Invalid First Name address');
        $('#' + id + 'FName').focus();
        hideWorking('regPopBtn');
        return;
    }

    if ($.trim($('#' + id + 'LName').val()) == '') {
        alert('Invalid Last Name address');
        $('#' + id + 'LName').focus();
        hideWorking('regPopBtn');
        return;
    }

    if ($.trim($('#' + id + 'Passwd1').val()) == '') {
        $('#' + id + 'Passwd1').focus();
        alert('Invalid Password');
        hideWorking('regPopBtn');
        return;
    }
    if ($('#' + id + 'Passwd1').val() != $('#' + id + 'Passwd2').val()) {
        alert('Passwords do not match.  Please re-enter');
        $('#' + id + 'Passwd1').val('').focus();
        $('#' + id + 'Passwd2').val('');
        hideWorking('regPopBtn');
        return;
    }

    registration(id);
}

function registration(id) {
    var param = '';

    param = "{Email:'" + $.trim($('#' + id + 'Email').val()) + "',FName:'" + $.trim($('#' + id + 'FName').val()) + "',LName:'" + $.trim($('#' + id + 'LName').val()) + "',Passwd:'" + $.trim($('#' + id + 'Passwd1').val()) + "'}";
    $.ajax({
        type: "POST",
        url: "jQuery-Page-Method/Default.aspx/registraion",
        contentType: "application/json; charset=utf-8",
        data: param,
        dataType: "json",
        success: function(msg) {

            if (msg.d == "False") {
                alert("This e-mail address already in our database, please use another e-mail address");
                hideWorking('regPopBtn');
            }
            else {
                hideLogin();
                if (MxiFlag == 1) {
                    shoefavorites();
                }
                else if (MxiFlag == 2) {
                    strapfavorites();
                }
                else if (MxiFlag == 3) {
                    itemfavorites();
                }
            }
        }
    });
}


//function for favorite 
function itemfavorites() {
    var param2 = '';

    // alert(document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_HidPType').value);

    // param2 = "{PID:" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_HidPID').value + ",Size:" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_ddlSize').value + ",Type:" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_HidPType').value + "}";
    var type = document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_HidPType').value;
    //alert(type);
    if (type = "Snaps") {
        param2 = "{PID:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_HidPID').value + "',Size:'select size',Type:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_HidPType').value + "',Tag:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_hidiCatagory').value + "'}";
    }
    else {
        param2 = "{PID:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_HidPID').value + "',Size:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_ddlSize').value + "',Type:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_HidPType').value + "',Tag:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_hidiCatagory').value + "'}";
    }

    $.ajax({
        type: "POST",
        url: "jQuery-Page-Method/Default.aspx/addtoWishList",
        contentType: "application/json; charset=utf-8",
        data: param2,
        dataType: "json",
        success: function(msg) {
            if (msg.d == "0") {
                MxiFlag = 3;
                showLogin();
            }
            else {
                $("#AFavourate").text(msg.d);
                $('#AFavourate').animate({ 'backgroundColor': '#76644a', 'color': '#ffffff' }, 200, function() {
                    $(this).animate({ 'backgroundColor': 'transparent', 'color': '#76644a' }, 800);
                });
            }
        }
    });
}

//function for favorite 
function cartitemfavorites(id) {
    var param2 = '';
    // alert(id);
    // alert(document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_HidPType').value);

    // param2 = "{PID:" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_HidPID').value + ",Size:" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_ddlSize').value + ",Type:" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlProductsDetails_HidPType').value + "}";

    var type = document.getElementById('ctl00_ContentPlaceHolder1_ctrlCart_reptCart_ctl0' + id + '_HidPType').value;
    //alert(type);
    if (type = "Snaps") {
        param2 = "{PID:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlCart_reptCart_ctl0' + id + '_HidPID').value + "',Size:'select size',Type:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlCart_reptCart_ctl0' + id + '_HidPType').value + "',Tag:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlCart_reptCart_ctl0' + id + '_Hidcategory').value + "'}";
    }
    else {
        param2 = "{PID:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlCart_reptCart_ctl0' + id + '_HidPID').value + "',Size:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlCart_reptCart_ctl0' + id + '_ddlSize').value + "',Type:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlCart_reptCart_ctl0' + id + '_HidPType').value + "',Tag:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlCart_reptCart_ctl0' + id + '_Hidcategory').value + "'}";
    }
    //alert(param2);
    $.ajax({
        type: "POST",
        url: "jQuery-Page-Method/Default.aspx/addtoWishList",
        contentType: "application/json; charset=utf-8",
        data: param2,
        dataType: "json",
        success: function(msg) {
            //      alert(msg.d);
            if (msg.d == "0") {
                MxiFlag = 3;
                showLogin();
            }
            else {
                window.location.href = 'cart.aspx';

                $("#AFavourate").text(msg.d);
                $('#AFavourate').animate({ 'backgroundColor': '#76644a', 'color': '#ffffff' }, 200, function() {
                    $(this).animate({ 'backgroundColor': 'transparent', 'color': '#76644a' }, 800);
                });
            }
        }
    });
}


function showsizefun(id) {
    var theID = $('#' + id).attr("_dropval");
    var _sizeid = $('#' + id).attr("_sizeid");
    var dropBox = $('#' + id).parents('div.dropBox');

    var _Stock = $('#' + id).attr("_Stock");

    var _MinStock = $('#' + id).attr("_MinStock");

    dropBox.attr('_prevVal', dropBox.children('span.title').html());
    dropBox.children('span.title').html(theID);
    dropBox.children('span.title').attr('_SizeID', _sizeid);

    dropBox.children('span.title').attr('_Stock', _Stock);

    dropBox.children('span.title').attr('_MinStock', _MinStock);

    hideDropBoxes(null, dropBox[0].id);
    if (dropBox.attr('_selFunc') != null) {
        eval('var func = ' + dropBox.attr('_selFunc'));
        func(dropBox);
    }

}

//function showsizefun(id, value) {
//    alert(id);
//    var dropBox = $('#' + id).parents('div.dropBox');
//    dropBox.attr('_prevVal', dropBox.children('span.title').html());
//    dropBox.children('span.title').html('size ' + value);
//    hideDropBoxes(null, dropBox[0].id);
//    if (dropBox.attr('_selFunc') != null) {
//        eval('var func = ' + dropBox.attr('_selFunc'));
//        func(dropBox);
//    }

//}


function showtips(productid) {

    for (var i = 1; i <= 8000; i = i + 1) {
        $("#t" + i).attr("style", "display:none");
    }
    $("#t" + productid).attr("style", "display:block");
    //$("#t" + i).toggle("slow");


    //$("#" + productid).animate({ opacity: "show", right: "-240" }, "slow");
    //var hoverText = $(this).attr("title");

}

function hidetips(productid) {

    $("#t" + productid).attr("style", "display:none");
    //$("#" + productid).animate({ opacity: "hide", right: "-240" }, "fast");
    //var hoverText = $(this).attr("title");
}





function catalogfavorites(id) {
    var param = '';
    //alert(id);
    var qty = "0";
    var iCat = document.getElementById('hidiCatagory' + id + '').value;
    param = "{PID:'" + id + "',Size:'" + qty + "',Type:'shoes',Tag:'" + iCat + "'}";
    //alert(param);

    $.ajax({
        type: "POST",
        url: "jQuery-Page-Method/Default.aspx/addtoWishList",
        contentType: "application/json; charset=utf-8",
        data: param,
        dataType: "json",
        success: function(msg) {
            if (msg.d == "0") {
                MxiFlag = 1;
                //alert(msg.d);
                showLogin();
            }
            else {

                $("#AFavourate").text(msg.d);
                $('#AFavourate').animate({ 'backgroundColor': '#76644a', 'color': '#ffffff' }, 200, function() {
                    $(this).animate({ 'backgroundColor': 'transparent', 'color': '#76644a' }, 800);
                });
            }
        }
    });
}

function catalogaddtofavorites(id) {
    var param = '';
    //alert(id);
    var qty = "0";


    var iCat = document.getElementById('hidiCatagory' + id + '').value;
    param = "{PID:'" + id + "',Size:'" + qty + "',Type:'shoes',Tag:'" + iCat + "'}";
    //alert(param);

    $.ajax({
        type: "POST",
        url: "jQuery-Page-Method/Default.aspx/addtoWishList",
        contentType: "application/json; charset=utf-8",
        data: param,
        dataType: "json",
        success: function(msg) {
            if (msg.d == "0") {
                MxiFlag = 1;
                //alert(msg.d);
                showLogin();
            }
            else {

                $("#AFavourate").text(msg.d);
                $('#AFavourate').animate({ 'backgroundColor': '#76644a', 'color': '#ffffff' }, 200, function() {
                    $(this).animate({ 'backgroundColor': 'transparent', 'color': '#76644a' }, 800);
                });
            }
        }
    });
}

function catalogaddtocart(id) {
    $(".cartloadingleft").attr("style", "display:block;");

    var param = '';
    var iCat = document.getElementById('hidiCatagory' + id + '').value;
    var Type = document.getElementById('HidPType' + id + '').value;

    var SizeName = 0;
    var SizeSpan = 0;
    var Size = 0;
    var name = 0;
    //alert(Type);
    if (Type == 'snaps') {
        SizeName = "select size";
        name = "select size";
        SizeSpan = 0;
        Size = 'N/A';

    }
    else if (Type == 'scarf') {
        SizeName = "select size";
        name = "select size";
        SizeSpan = 0;
        Size = 'N/A';

    }
    else if (Type == 'bags') {
        SizeName = "select size";
        name = "select size";
        SizeSpan = 0;
        Size = 'N/A';

    }
    else {
        SizeName = document.getElementById('my-dropdown').options[document.getElementById('my-dropdown').selectedIndex].text;

        if (Type == 'Straps') {
            name = SizeName.substr(0, 1);
        }
        else {
            name = SizeName.substr(SizeName.length - 1, 1);
        }
        SizeSpan = document.getElementById('my-dropdown').value;
        Size = document.getElementById('my-dropdown').value;
    }

    var _Stock = 0;

    var _MinStock = 0;

    //alert(_MinStock);

    if (_MinStock == -1) {
        $(".cartloadingleft").attr("style", "display:none;");
        alert("Please select size !");
        return;
    }


    if (parseInt(_Stock) < parseInt(_MinStock)) {
        shoefavorites();
    }
    else {
        //var Size = $('##shoeSize span.title').attr("_sizeid");
        if ($('#shoeSize span.title').text() == "select size")
            Size = 'N/A';

        param = "{PID:" + document.getElementById('HidPID' + id + '').value + ",Size:'" + Size + "',SizeName:'" + name + "',Type:'" + Type + "',Tag:'" + Type + "'}";

        //alert(param);

        $.ajax({
            type: "POST",
            url: "jQuery-Page-Method/Default.aspx/addtoCart",
            contentType: "application/json; charset=utf-8",
            data: param,
            dataType: "json",
            success: function (msg) {

                var myIDs = new Array();
                myIDs = msg.d.split('|');



                if (myIDs.length > 1) {
                    if (myIDs[1].toLowerCase() == 'false') {
                        alert("The product is out of stock !");
                        $("#ctl00_ctrlheader_hypCart").html(myIDs[0]);
                    }
                }
                else {
                    $("#ctl00_ctrlheader_hypCart").html(msg.d);
                }

                GetSmallCart();

                $('#ctl00_ctrlheader_hypCart').animate({ 'backgroundColor': '#76644a', 'color': 'transparent' }, 200, function () {
                    $(this).animate({ 'backgroundColor': 'transparent', 'color': '#76644a' }, 800);
                    $('#cartbag').attr('class', "viewBag active");
                    $("#checkoutlink").attr("style", "display:block;");
                    $(".cartloadingleft").attr("style", "display:none;");
                });
            }
        });
    }
    
}


  function showFavourateLeft()
     {      
        $find('MixnMatchLoading').show();
        $('#shoeInfo1').hide();
        $('#strapInfo').hide();        
        $.ajax({
            type: "POST",
            url: "jQuery-Page-Method/Default.aspx/MyFavorateGenShoes",
            contentType: "application/json; charset=utf-8",
            data: "{id:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_hdnMyFavShoesID').value + "'}",
            dataType: "json",
            success: function(msg) {
                if (msg.d == "0") {
                    $find('MixnMatchLoading').hide();
                    MxiFlag = 1;
                    showLogin();
                } else {
                    $("#LeftFavourate").attr("style", "display:none;");
                    $("#shoesShowAll").attr("style", "display:block;");
                    $("#shoeList").html('');
                    $("#shoeList").html(msg.d);
                    $('#shoeList').animate({ 'opacity': 1 }, "slow");
                    setTimeout(function() { setupColumnList('shoe'); }, 500);
                    setTimeout(function() { setupColumnList('strap'); }, 500);
                    $find('MixnMatchLoading').hide();
                }
            }
        });
     }
     
     function showFavourateRight()
     {
       $find('MixnMatchLoading').show();
        $('#shoeInfo1').hide();
        $('#strapInfo').hide();
        $.ajax({
            type: "POST",
            url: "jQuery-Page-Method/Default.aspx/MyFavorateGenStrap",
            contentType: "application/json; charset=utf-8",
            data: "{id:'" + document.getElementById('ctl00_ContentPlaceHolder1_ctrlmixmach_hdnMyFavStrapsID').value + "'}",
            dataType: "json",
            success: function(msg) {
                if (msg.d == "0") {
                    $find('MixnMatchLoading').hide();
                    MxiFlag = 1;
                    showLogin();
                } else {
                    $("#RightFavourate").attr("style", "display:none;");
                    $("#StrapShowAll").attr("style", "display:block;");
                    $("#strapList").html('');
                    $("#strapList").html(msg.d);
                    $('#strapList').animate({ 'opacity': 1 }, "slow");
                    setTimeout(function() { setupColumnList('shoe'); }, 500);
                    setTimeout(function() { setupColumnList('strap'); }, 500);
                    $find('MixnMatchLoading').hide();
                }
            }
        });
     }

     function ShowImage(filename) {
         $("#zoom1").attr("href", filename);
         $('*', '#BigImage').each(function() {
             if (this.tagName.toLowerCase() == 'img') {
                 $('#BigImage img').attr('src', filename);
             }
         });
     }
