var first = 0;
var speed = 700;
var pause = 8000;
var imgsrc = '';
var htmll = '';
var htmll2 = '';
var count = 1;
var i = 0;
var desc = [];
$.easing.easeOutExpo = function(x, t, b, c, d) {
    return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
};
(function($) {
    $(window).load(function() {
    	
    	          if ($.browser.msie){
   $('.tooltip').css('backround','url("../media/hover_bg.gif") no-repeat scroll 0 0 transparent'); 
  }
        $('#caption').hide();
        $("#side-container").children().each(function() {
            var el = $(this);
            var itemid = el.attr('id');
            var thisid = '#' + itemid+ '-tooltip';
            $(this).find('a').tooltip({
                offset: [87, -10],
                position: 'left',
                effect: 'slide',
                tip: thisid,
                relative: true
            });
        });
        


        
        $('#intro-preloader').hide();
            $('#gallery-items').css('display', 'block');
            $('#side-container').css('display', 'block');


        function gal() {
            interval = setInterval(removeFirst, pause);
            $('#gallery-items li').each(function(i, el) {
                if (i % 2 !== 0) {
                    desc[count] = $(this).html();
                    $(this).remove();
                    count++;
                } else {
                    imgsrc = 'url(' + $(this).find('img').attr('src') + ')';
                    htmll += '<div id="image-one" class="gallery-slide" style="background-image:';
                    htmll += imgsrc;
                    htmll += ' ; background-position: top left;"></div>';
                    htmll2 += '<div id="image-two" class="gallery-slide" style="background-image:';
                    htmll2 += imgsrc;
                    htmll2 += ' ; background-position: top right;"></div>';
                    htmll += htmll2;
                    $(this).html(htmll);
                    htmll = '';
                    htmll2 = '';
                }
            });
            desc.reverse();
            count = 0;
        }
        gal();
        $('#start-one').animate({
            'width': '0'
        }, 2500, 'easeOutExpo', function() {});
        $('#start-two').animate({
            'width': '0'
        }, 2500, 'easeOutExpo', function() {
            $('#box1 , #box2 , #box3, #box4, #box5, #specials').animate({
                'opacity': '1'
            }, 500);
            $('#intro-sequence').remove();
            addCaption();
        });

        function removeFirst() {
            last = '<li>' + $('ul#gallery-items li:last').html() + '</li>';
            $('ul#gallery-items').prepend(last);
            $('ul#gallery-items li:last').children().css('width', '100%');
            $('#caption').fadeOut();
            $('ul#gallery-items li:last #image-one').animate({
                'width': '0'
            }, 2500, 'easeOutExpo', function() {});
            $('ul#gallery-items li:last #image-two').animate({
                'width': '0'
            }, 2500, 'easeOutExpo', function() {
                $('ul#gallery-items li:last').remove();
                addCaption();
            });
        }
        function addCaption() {
            $('#caption').html(desc[count]);
            $('#caption').fadeIn('fast');
            if (count == (desc.length - 1)) {
                count = 0;
            } else {
                count++;
            };
        }
    });
})(jQuery);
