// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(function() {
  
  $("a.animated").live('click', function(event) {
    var action = $(this).attr("href");
    event.preventDefault();
    $('body').animate({
      opacity: 0, 
      backgroundColor: '#fff'
    }, 200, '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;
    }
  });
  
  $("#username").focus();
  
  $(".fancybox").fancybox({
    'hideOnContentClick': true,
    'padding': 0,
    'width': '95%',
    'height': '95%',
    'overlayColor': '#555',
    'opacity': true,
    'overlayOpacity': 0.95,
    'titlePosition': 'over',
    'showCloseButton': false
  });
  
  setTimeout("$('.message_container').fadeOut('slow')", 5000);
  
});

// adjust the footer to the window bottom
window.onload = function () {
  $('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');
    });
  });
}

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";
}
