var globalSettings = {};
globalSettings.siteURL = 'http://' + document.domain + '/';
document.getElementsByTagName('html')[0].className = 'js';
var isIE6 = false;
if ($.browser.msie && $.browser.version.substr(0,1)<7) {
    isIE6 = true;
}
$.fn.reverse = [].reverse; 

//Set Page Size to larger than the existing window size
function setPageSize() {
    var pageHeight = $(window).height();
    
    if (pageHeight > 900) {
        $('.page').height(pageHeight + 'px');
    }
    
    if (pageHeight > 622) {
        $('body.home #content').css('paddingTop', parseInt((pageHeight-622)/2) + 'px');
    } else {
      $('body.home #content').css('paddingTop', '0px');
    }
}

function pastView(posTop){
    if ($(window).scrollTop() < posTop)
        return false;
    return true;
};

function scrollerAnimation(index, direction) {
    var context = globalSettings.scroller[index].context;
    var currentPosition = globalSettings.scroller[index].currentPosition;
    var slideWidth = globalSettings.scroller[index].slideWidth;
    var numberOfSlides = globalSettings.scroller[index].numberOfSlides;
    
    if (direction == 'previous') {
        currentPosition -= 1;
        if (currentPosition < 0) {
            currentPosition = numberOfSlides-1;
        }
    }
    else {
        currentPosition += 1;
        if (currentPosition >= numberOfSlides) {
            currentPosition = 0;
        }
    }
    globalSettings.scroller[index].currentPosition = currentPosition;
    
    $('.module-content ul', context).animate({
        'left' : slideWidth*(-currentPosition)
    });
}

function scrollerInit() {

    if (globalSettings.scroller == undefined)
        globalSettings.scroller = new Array();
    
    $('.scroller').each(function (index) {
        if (!$(this).hasClass('scroller-enabled') && $('li', $(this)).size() > 1) {
            
            $(this).addClass('scroller-enabled');
            globalSettings.scroller[index] = {};
            globalSettings.scroller[index].currentPosition = 0;
            var context = globalSettings.scroller[index].context = $(this);
            var slides = $('.module-content ul li', globalSettings.scroller[index].context);
            var slideWidth = globalSettings.scroller[index].slideWidth = $(slides).eq(0).outerWidth();
            var numberOfSlides = globalSettings.scroller[index].numberOfSlides = slides.length;
            
            $('.module-content ul', context).css('width', slideWidth * numberOfSlides);
            
            // Insert left and right arrow controls in the DOM
            $('.module-footer', context)
                .prepend('<a class="control" id="prevControl" href="#">Prev</a>')
                .append('<a class="control" id="nextControl" href="#">Next</a>');
            
            $('#nextControl', context).click(function() {
                scrollerAnimation(index);
                return false;
            });
            
            $('#prevControl', context).click(function() {
                scrollerAnimation(index, 'previous');
                return false;
            });
        }
    })
}

$(document).ready(function() {
    if ($('body').hasClass('restaurant') || $('body').hasClass('cocktail')) {
      $('.nav ol').localScroll({duration: 400});
      $('a.scroll').localScroll({duration: 400});
      $('.nav li a').eq(1).addClass('active');
      $('.nav li a').click(function () {
        $('.nav li a').removeClass('active');
        $(this).addClass('active');
      })
      scrollerInit();
      
      if (isIE6) {
        if ($('body.restaurant').size() > 0) {
          $(window).scroll(function() {  
            $('body.restaurant .header').css('top', $(window).scrollTop());
          });
        }
        if ($('body.cocktail').size() > 0) {
          $(window).scroll(function() {
            $('body.cocktail .header').css('top', $(window).scrollTop());
          });
        }
      }
    }
    if ($('body').hasClass('home')) {
        swfobject.embedSWF("flash/logo.swf", "logo-flash", "332", "283", "9.0.0", '', '', {'wmode': 'transparent'});
        setPageSize();
        $(window).resize(function() {
            setPageSize();
        });
    }

    $("a[rel=external]").attr("target", "_blank");
})