/*
  * Copyright (c) 2008, Roman Riska
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
  *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
  *     * Redistributions in binary form must reproduce the above copyright
  *       notice, this list of conditions and the following disclaimer in the
  *       documentation and/or other materials provided with the distribution.
  *     * Neither the name of the <organization> nor the
  *       names of its contributors may be used to endorse or promote products
  *       derived from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

function addLoadEvent(func) {
  var oldonload = window.onload;

  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function addUnLoadEvent(func) {
  var oldunload = window.unload;

  if (typeof window.unload != 'function') {
    window.unload = func;
  } else {
    window.unload = function() {
      if (oldunload) {
        oldunload();
      }
      func();
    }
  }
}

// local scroll
jQuery(function( $ ){
  /**
   * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
   * @see http://flesler.webs.com/jQuery.ScrollTo/
   * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
   */

  var target = $('#contentText').get(0);//the scrolled div

  /**
   * restart the scroll position to ( 0, 0 ) (Firefox doesn't reset it)
   * could use $(target).scrollTo( 0, {axis:'xy'));
   * but this needs to be quick(synchronous), to reset before $.localScroll.hash() begins
   */
  target.scrollLeft = target.scrollTop = 0;

  //scroll initially if there's a hash (#something) in the url
  $.localScroll.hash({
    target: target, //could be a selector or a jQuery object too.
    axis:'xy',//the default is 'y'
    queue:true,
    duration:1500
  });

  var $last = $([]);//save the last link

  /**
   * NOTE: In the former version of the demo, I called $('#navigation').localScroll()
   * Now I want to also affect the >> and << links, so I'll use $.localScroll() instead
   */
  $.localScroll({
    target: target, //could be a selector or a jQuery object too.
    axis:'xy', //the default is 'y'
    queue:true,
    duration:1000,
    hash:true,
    onBefore:function( e, anchor, $target ){//'this' is the clicked link
      $last.removeClass('scrolling');
      $last = $(this).addClass('scrolling');
      if( this.blur )
        this.blur();//remove the awful outline
    },
    onAfter:function( anchor ){
      $last.removeClass('scrolling');
    }
  });
});

// lightbox
$(document).ready(function(){
  $(".lightbox").lightbox();
});

// Google Maps
function openMap() {
  var url = '/google-map';

  Winn = open(url, "InKat_Map", "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no,top=10,left=10");
}
