if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion=8)
  	//Cufon.replace('h1');      
	Cufon.replace('#main #fixed #rotate .box .text h1, #main #fixed #rotate .box .text h2, #main #spotlight .box .text h2, .main .banner h1');
 }
else
Cufon.replace('#main #fixed #rotate .box .text h1, #main #fixed #rotate .box .text h2, #main #spotlight .box .text h2, .main .banner h1, #main #smartBanner a.sbContentLink .sbContent .sbTitle');
(function ($) {
    $.fn.equalHeights = function () {
        var maxheight = 0;
        $(this).children().each(function () {
            maxheight = ($(this).height() > maxheight) ? $(this).height() : maxheight;
        });
        $(this).css('height', maxheight);
        $('#product .more-info .panel').hide();
        $('#product .more-info ul.items li.item').hide();
        $('#product .more-info ul.items li.item:first-child').show();
    }
})(jQuery);
$(document).ready(function () {
    $('body').addClass('js');
    $('#hdr .change ul').hide();
    $('#hdr .change strong').hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    }).click(function () {
        if ($(this).hasClass('on')) {
            $(this).removeClass('on');
            $(this).parent().find('ul').slideUp();
        } else {
            $(this).addClass('on');
            $(this).parent().find('ul').slideDown();
        }
    });
    $('#hdr ul li.search input.text').each(function () {
        if ($(this).attr('value') != '') {
            $('#hdr ul li.search').addClass('on');
        }
    }).focus(function () {
        $('#hdr ul li.search').addClass('on');
    }).blur(function () {
        if ($(this).attr('value') == '') {
            $('#hdr ul li.search').removeClass('on');
        }
    });
    $('#menu ul li').hover(function () {
        $(this).addClass('hover');
        $(this).find('.sub').stop(true, true).slideDown();
    }, function () {
        $(this).removeClass('hover');
        $(this).find('.sub').stop(true, true).slideUp();
    });
    $('.jcarousel-prev, .jcarousel-next').live('mouseover mouseout', function (event) {
        if (event.type == 'mouseover') {
            $(this).addClass('hover');
        } else {
            $(this).removeClass('hover');
        }
    });
    /*
    $('#rotate').cycle({ 
    pause: 0
    });
    */
    $('#banner .items').after('<a href="#" id="prev"></a><a href="#" id="next"></a>').cycle({
        prev: '#prev',
        next: '#next',
        pause: 1
    });
    noItems = $('#fixed .landing-listing ul > li').size();
    if (noItems > 4) {
        $('#fixed .landing-listing ul').jcarousel({
            scroll: 4
        });
    }
	noItems = $('#jclip .landing-listing ul > li').size();
    if (noItems > 4) {
        $('#jclip ul').jcarousel({
            scroll: 4
        });
    }
    $('.landing-listing li,.landing-listing2 li, .products-listing li, .get-the-look .shop li, .productChunk li').each(function () {
        $(this).find('.panel').hide();
        $(this).hover(function () {
            $(this).addClass('hover');
            $(this).find('.panel').stop(true, true).slideDown();
        }, function () {
            $(this).removeClass('hover');
            $(this).find('.panel').stop(true, true).slideUp();
        }).click(function () {
            theLink = $(this).find('a').attr('href');
            window.location = theLink;
        });
    });
    $('#product .overview input.submit').hover(function () {
        $(this).parent().addClass('hover');
    }, function () {
        $(this).parent().removeClass('hover');
    });
    $("#main .sorting .sort-by select, #whereToBuy .whereToBuySearch .international .sort-by select").sb({
        fixedWidth: false
    });
    $('#product .overview .choose-colour .rollover').hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    }).click(function () {
        $(this).parent().find('ul.items').slideToggle();
    });
    $('#product .overview .choose-colour ul.items li input').hide();
    $('#product .overview .choose-colour ul.items li').hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    }).click(function () {
        theEq = $(this).index();
        theImage = $('#product .details .colours li:eq(' + theEq + ') a').attr('href');
        $('#product .top .image img').fadeOut('slow', function () {
            $('<img />').attr('src', theImage).load(function () {
                $('#product .top .image').prepend($(this));
                $('#product .top .image img:first-child').hide().fadeIn('slow');
                $('#product .top .image img:last-child').remove();
            });
        });
        $(this).parent().parent().removeClass('off');
        $(this).find('input').attr('checked', 'checked');
        theName = $(this).find('h3').text();
        theInfo = $(this).find('.info').html();
        $('#product .overview .choose-colour .rollover h2').text(theName);
        $('#product .overview .choose-colour .rollover .info').html(theInfo);
        $(this).parent().slideUp();
        $('#main #product .details .colours ul li').removeClass('on');
        $('#product .details .colours li:eq(' + theEq + ')').addClass('on');
    });
    $('#product .details .colours li').hover(function () {
        $(this).addClass('hover');
        $(this).find('span.hover').show();
    }, function () {
        $(this).removeClass('hover');
        $(this).find('span.hover').hide();
    });
    
    $('#product .details #coloursInStock.colours li').click(function () {
        $(this).addClass('on').siblings().removeClass('on');
        $('#product .overview .choose-colour ul.items').hide();
        theEq = $(this).index();
        $('#product .overview .choose-colour ul.items li:eq(' + theEq + ')').find('input').attr('checked', 'checked');
        theURL = $(this).find('a').attr('href');
        theName = $(this).find('img').attr('alt');
        theImage = $(this).find('img').attr('src');
        theInfo = $(this).find('.hover em').text();
        $('#main #product .top .overview .choose-colour').removeClass('off');
        $('#product .overview .choose-colour .rollover h2').html(theName);
        $('#product .overview .choose-colour .rollover .info').html('<img src="' + theImage + '" alt="">' + theInfo);
        $('#product .top .image img').fadeOut('slow', function () {
            $('<img />').attr('src', theURL).load(function () {
                $('#product .top .image').prepend($(this));
                $('#product .top .image img:first-child').hide().fadeIn('slow');
                $('#product .top .image img:last-child').remove();
            });
        });
        return false;
    });

    $("#main #product .more-info ul.items").equalHeights();
    $('#product .more-info h2').hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    }).click(function () {
        $(this).toggleClass('on');
        $(this).parent().parent().find('.panel').slideToggle();
    });
    function tabsFn(parent, head) {
        $(parent).prepend("<ul class=\"nav\"><\/ul>");
        tabsArray = new Array();
        $(parent + " " + head).each(function () {
            thisIndex = $(parent + " " + head).index(this) + 1;
            $(parent + " ul.nav").append('<li id="nav-' + thisIndex + '"><a href="#' + tabsArray[thisIndex] + '">' + $(this).text() + '<\/a><\/li>');
        });
    }
    tabsFn("#product .more-info .panel", "h3");
    $('#product .more-info ul.nav li:first-child').addClass('on');
    $('#product .more-info ul.nav li a').click(function () {
        selectedItem = $(this).parent().attr('id').split('-').pop();
        selectedItem = selectedItem - 1;
        $('#product .more-info ul.nav li').removeClass('on');
        $(this).parent().addClass('on');
        $('#product .more-info ul.items li.item').hide();
        $('#product .more-info ul.items li.item:eq(' + selectedItem + ')').fadeIn('slow');
        return false;
    });
    $('#main #standard .form .submit input').hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    })
    $('#main #standard .form form').validate();
    if ($('#fixed').length > 0) {
        var imgs = [];
        $('#fixed .image img').each(function (index) {
            var i = new Image();
            i.onload = function () {
                var h = i.height;
                var w = i.width;
                imgs[index] = [w, h];
                $(window).trigger('resize');
            }
            i.src = $(this).attr('src');
        });
        var current = 0;
        var len = $('#rotate .slide').length;
        $('#rotate .slide').each(function (i) {
            $(this).css('z-index', len - i);
        });
        var z = len + 1;
        setInterval(function () {
            var next = (current + 1) % len;
            $('#rotate .slide').eq(next).css({
                'z-index': z
            }).hide().fadeIn(999);
            current = next;
            z += 1;
        }, 8000);
        $(window).resize(function () {
            var height = $(window).height() - ($('#hdr').outerHeight() + $('#basket').outerHeight() + $('#menu').outerHeight());
            height = Math.max(650, height);
            var width = $('#fixed').width();
            $('#fixed').height(height);
            $('#main #fixed #rotate > div').css('height', height + "px !important");
            $('#fixed .image').css({
                'width': width,
                'height': height
            });
            $('#fixed .image img').each(function (index) {
                var self = this;
                if (imgs[index] && imgs[index].length === 2) {
                    var w = imgs[index][0];
                    var h = imgs[index][1];
                    if ((height / width) > (h / w)) {
                        $(self).css({
                            'width': (w / h) * height,
                            'height': height
                        });
                    } else {
                        $(self).css({
                            'width': width,
                            'height': (h / w) * width
                        });
                    }
                }
            });
        }).trigger('resize');
    }
    var msie6 = $.browser == 'msie' && $.browser.version < 7;
    var floated = $('.basket-summary');
    if (!msie6 && floated.length > 0) {
        var top = floated.offset().top - parseFloat(floated.css('margin-top').replace(/auto/, 0));
        $(window).scroll(function (event) {
            // what the y position of the scroll is
            var y = $(this).scrollTop();
            // whether that's below the form
            if (y >= top - 10) {
                // if so, ad the fixed class
                floated.css({
                    'position': 'fixed',
                    'top': '10px'
                });
            } else {
                // otherwise remove it
                floated.css({
                    'position': 'relative',
                    'top': 'auto'
                });
            }
        });
    }
    // theHeight = $('#rotate .image:first-child img').height();
    // $('#rotate').css('height',theHeight);
});
