function search(q) {
    if (q != '') {
        $('#results').html('');
        $('#loading').show();
		d = new Date();
        $.ajax({
            url: 'shop.php?q=' + q + '&_='+d.getTime(),
            success: function(data) {
                $('#loading').hide();
                $('#results').html(data);
            }
        });
    }
}

$(document).ready(function() {
    $.scrollTo('#place');

    var target = $('#content').get(0); //the scrolled div

    target.scrollLeft = target.scrollTop = 0;

    // scrolling options
    var scrollingOptions = {
        target: target,
        axis: 'yx',
        queue: true,
        duration: 700,
        hash: true,
        easing: 'easeInQuad',
        margin: true,
        onBefore: function(e, anchor, $target) {
            if (anchor.id == 'home') {
                $('#home-slide').cycle('resume');
            }
        },
        onAfter: function(anchor, settings) {
            if (anchor.id != 'home') {
                $('#home-slide').cycle('pause');
            }
        }
    };

    // int the scroll
    $.localScroll(scrollingOptions);

    //scroll initially if there's a hash (#something) in the url
    if (location.hash) {

    }

    // Navigation
    $('#nav li a').click(function() {
        $(this).parents('li').addClass('active').siblings('li').removeClass('active', 500);

        if ($(this).attr('id') == 'nav-coll')
            return false;
    });

    $('#nav li ul li a').click(function() {
        $(this).parents('li').parent().parent('li').addClass('active').siblings('li').removeClass('active', 500);
        $('#nav ul.sf-menu').superfish().hideSuperfishUl();
    });

    // Home slideshow
    $('#home-slide').cycle();

    // Superfish for the sub navigation
    $('#nav ul.sf-menu').superfish();

});

//REEL
$(document).ready(function() {
    moose = true;
    reelWidth = 702;
    currentReels = [];
    xPos = [];

    $('.reel-controls a.next').click(function() {
        whatReel = $(this).parent().parent().parent().attr('id');
        totalReel = $('#' + whatReel + ' .reel-content ul').size();

        if (currentReels[whatReel] == undefined)
            currentReels[whatReel] = 1;

        if (xPos[whatReel] == undefined)
            xPos[whatReel] = 0;

        if (moose == true && totalReel > currentReels[whatReel]) {
            xPos[whatReel] = xPos[whatReel] - reelWidth;
            currentReels[whatReel] = currentReels[whatReel] + 1;

        } else if (moose == true) {
            currentReels[whatReel] = 1;
            xPos[whatReel] = 0;
        }

        slideTo(xPos[whatReel], whatReel);
        return false;
    });

    $('.reel-controls a.prev').click(function() {
        whatReel = $(this).parent().parent().parent().attr('id');
        totalReel = $('#' + whatReel + ' .reel-content ul').size();

        if (currentReels[whatReel] == undefined)
            currentReels[whatReel] = 1;

        if (xPos[whatReel] == undefined)
            xPos[whatReel] = 0;

        if (moose == true && currentReels[whatReel] > 1) {
            xPos[whatReel] = xPos[whatReel] + reelWidth;
            currentReels[whatReel] = currentReels[whatReel] - 1;

        } else if (moose == true) {
            currentReels[whatReel] = totalReel;
            xPos[whatReel] = -(totalReel - 1) * reelWidth;
        }

        slideTo(xPos[whatReel], whatReel);
        return false;
    });

    function slideTo(newX, reel) {
        moose = false;
        $('#' + reel + ' .reel-content').animate({ left: newX }, reelWidth, 'easeInOutExpo', function() {
            moose = true;
        })
    }
});

// Press area with galleria
$(function() {
    $('ul#press-thumbs').galleria({
        history: false,
		clickNext: false,
        insert: '#press-big', // the containing selector for our main image
        onImage: function(image, caption, thumb) { // let's add some image effects for demonstration purposes

            // fade in the image & caption
            if (!($.browser.mozilla && navigator.appVersion.indexOf("Win") != -1)) { // FF/Win fades large images terribly slow
                image.css('display', 'none').fadeIn(1000);
            }
            caption.css('display', 'none').fadeIn(1000);

            // fetch the thumbnail container
            var _li = thumb.parents('li');

            // fade out inactive thumbnail
            _li.siblings().children('img.selected').fadeTo(500, 0.3);

            // fade in active thumbnail
            thumb.fadeTo('fast', 1).addClass('selected');

            // add a title for the clickable image
            image.attr('title', 'Next image >>');
        },
        onThumb: function(thumb) { // thumbnail effects goes here

            // fetch the thumbnail container
            var _li = thumb.parents('li');

            // if thumbnail is active, fade all the way.
            var _fadeTo = _li.is('.active') ? '1' : '0.3';

            // fade in the thumbnail when finnished loading
            thumb.css({ display: 'none', opacity: _fadeTo }).fadeIn(1500);

            // hover effects
            thumb.hover(
					function() { thumb.fadeTo('fast', 1); },
					function() { _li.not('.active').children('img').fadeTo('fast', 0.3); } // don't fade out if the parent is active
				)
        }
    });
});

$(function() {
    $(".collections img").lazyload({
        placeholder: "images/ll.gif",
        event: "sporty"
    });
});
$(document).ready(function() {
    var timeout = setTimeout(function() { $("img").trigger("sporty") }, 3000);
});