// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(function() {
  
  initScrollpane();
   
  $("a.animated").live('click', function(event) {
    var action = $(this).attr("href");
    event.preventDefault();
    $('body').animate({
      opacity: 0, 
      backgroundColor: '#fff'
    }, 100, 'swing', function() {
      document.location.href = action;
    });
  });
  
  // open specific links in a new window
  $("a.popup").live('click', function(event) {
    window.open($(this).attr("href"), "popup");
    event.preventDefault();
  });
  // open specific divs in a new window
  $("div.popup").live('click', function(event) {
    window.open($(this).attr("data-url"), "popup");
  });
  // open specific divs in the same window
  $("div.linked").live('click', function(event) {
    document.location.href = $(this).attr("data-url");
  });
  // add pointer cursor to linked layers
  $("div.popup, div.linked").addClass("cursor-pointer");
  
  $("a.delete").live('click', function(event) {
    if(confirm("Sure?")) {
      $(this).next().submit();
      event.preventDefault();
    } else {
      return false;
    }
  });
  
  $.datepicker.setDefaults($.datepicker.regional['de']);
  $(".datepicker").datepicker({dateFormat: 'yy-mm-dd' });
  
  $(".slideshow").cycle({
    fx: 'fade',
    speed:   500,
    timeout: 0,
    slideExpr: "img",
    next: ".slideshow, .next",
    prev: ".prev"
  }).cycle("pause");
  
  $("#loginform #username").focus();
  
  $(".scroll-pane").live({
    mouseenter: function() {
      $(".jspVerticalBar", this).fadeIn('slow');
    },
    mouseleave: function() {
      $(".jspVerticalBar", this).fadeOut('slow');
    }
  });
  
});

// adjust the footer to the window bottom
window.onload = function () {
  $('body.home').animate({
    opacity: 1.0, 
    backgroundColor: '#ffee2e'
  }, 600, 'swing', function() {
    $("#main_container.animated").animate({opacity: 1}, 600);
  });
  
  $('body').animate({
    opacity: 1.0
  }, 300, 'swing', function() {   
    $("img.animated").each(function(index) {
      $(this).delay(100*index).animate({opacity: 1}, 400, 'swing');
    });
    $(".thumb").each(function(index) {
      $(this).delay(100*index).animate({opacity: 1}, 400, 'swing');
    });
  });
}

$(window).resize(function() {
});

function initScrollpane() {
  $('.scroll-pane').jScrollPane({
    autoReinitialise: true,
    hideFocus: true
  });
}

function isMobileDevice() {
  //return navigator.userAgent.toLowerCase().match(/(iphone|ipod|ipad|android)/);
  return /Apple.*Mobile/.test(navigator.userAgent);
}
function isIE6() {
  return $.browser.msie && $.browser.version=="6.0";
}
function isIE7() {  
  return $.browser.msie && $.browser.version=="7.0";
}
function isIE8() {  
  return $.browser.msie && $.browser.version=="8.0";
}
