
// Disable drag of images/text

window.onload = init;
 
function init() {
  disableDraggingFor(document.getElementById("fancybox-wrap"));
}
 
function disableDraggingFor(element) {
  // this works for FireFox and WebKit in future according to http://help.dottoro.com/lhqsqbtn.php
  element.draggable = false;
  // this works for older web layout engines
  element.onmousedown = function(event) {
                event.preventDefault();
                return false;
              };
}


// Disable right-click

  function disableselect(e){
	  return false
	  }
	  function reEnable(){
	  return true
	  }
   document.onselectstart=new Function ("return false")
   document.oncontextmenu=new Function ("return false")


$(document).ready(function() {

// Background Images
 
  var ic = $('#background_images'); //images container
  var images = $('#background_images img');
  var sizes = new Array();
  jQuery.each(images, function(i, v) {
    var tmp = i;
    $(images[tmp]).get(0).onload =  function (e){
      sizes[tmp] = new Object();
      sizes[tmp].w = $(v).width();
      sizes[tmp].h = $(v).height();

      if(tmp==0) {
        resizeImage($(ic).width(), $(ic).height(), sizes[0].w, sizes[0].h, $(active_image), 'fill', true);
      }
    };
  });

  $('#background_images').cycle({
    fx: 'fade',
    speed: 500,
    timeout: 0,
    pager: '#pager'
  });

  // remove delay if not a suitable fix
  var active_image = $('#background_images img:first-child');

  $(ic).resize(function() {
    active_image = $('#background_images img:visible');
    idx = $('#background_images img').index(active_image);
    if(sizes[idx]) {
      resizeImage($(ic).width(), $(ic).height(), sizes[idx].w, sizes[idx].h, $(active_image), 'fill', true);
    }
	// window.alert('This box is displayed every time the browser window is resized.');
  });


  $('#content_btn').click(function() {	
	$(this).toggleClass('close');					   
	$("#content").animate({width:'toggle'},800);
	$("#content_inner").fadeToggle(800);
  });

});

(function($,h,c){
  var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";
  e[b]=250;
  e[f]=true;
  $.event.special[j]={
    setup:function(){
      if(!e[f]&&this[k]){
        return false
      }
      var l=$(this);
      a=a.add(l);
      l.data(d,{
        width:l.width(),
        height:l.height()
      });
      if(a.length===1){
        g()
      }
    },
    teardown:function(){
      if(!e[f]&&this[k]){
        return false
      }
      var l=$(this);
      a=a.not(l);
      l.removeData(d);
      if(!a.length){
        clearTimeout(i)
      }
    },
    add:function(l){
      if(!e[f]&&this[k]){
        return false
      }
      var n;
      function m(s,o,p){
        var q=$(this),r=q.data(d);
        r.w=o!==c?o:q.width();
        r.h=p!==c?p:q.height();
        n.apply(this,arguments)
      }
      if($.isFunction(l)){
        n=l;
        return m
      }else{
        n=l.handler;
        l.handler=m
      }
    }
  };

  function g(){
    a.each(function(){
      var n=$(this),m=n.width(),l=n.height(),o=n.data(d);
      if(m!==o.w||l!==o.h){
        n.trigger(j,[o.w=m,o.h=l])
      }
    });
    i=h[k](g,e[b])
  }
})(jQuery,this);


var CJ_Image = {
   Calculate: function(options) {
      // declare some local variables
      var ratioX, ratioY, scale, newWidth, newHeight;
      // Check to make sure all the required variables were sent and pass validation
      if (typeof options.srcWidth !== "number" || typeof options.srcHeight !== "number" || typeof options.destWidth !== "number" || typeof options.destHeight !== "number" || typeof options.method !== "string") {
         return;
      }
      // Grab scale ratios
      ratioX = options.destWidth / options.srcWidth;
      ratioY = options.destHeight / options.srcHeight;
      // Determine which algorithm to use
      if (options.method === "fit") {
         scale = ratioX < ratioY ? ratioX: ratioY;
      } else if (options.method === "fill") {
         scale = ratioX > ratioY ? ratioX: ratioY;
      }
      // Set new dimensions
      newWidth = parseInt(options.srcWidth * scale, 10);
      newHeight = parseInt(options.srcHeight * scale, 10);
      // Return the new dimensions, plus the offsets, and if the destination box
      // is smaller or equal to the source image dimensions
      return {
         width: newWidth,
         height: newHeight,
         offset: {
            x: parseInt((options.destWidth - newWidth) / 2, 10),
            y: parseInt((options.destHeight - newHeight) / 2, 10)
         },
         fits: options.srcWidth >= options.destWidth && options.srcHeight >= options.destHeight ? true: false
      };
   }
};

function resizeImage(cW, cH, iW, iH, img, method, animate) {
  var thumbNail = CJ_Image.Calculate({
    srcWidth: iW,
    srcHeight: iH,
    destWidth: cW,
    destHeight: cH,
    method: method
  });
  
  if(animate) {
    img.animate({
      width: thumbNail.width,
      height: thumbNail.height,
      top: thumbNail.offset.y,
      left: thumbNail.offset.x
    });
  }
  
  return thumbNail;
}

/*
 * Special event for image load events
 * Needed because some browsers does not trigger the event on cached images.

 * MIT License
 * Paul Irish     | @paul_irish | www.paulirish.com
 * Andree Hansson | @peolanha   | www.andreehansson.se
 * 2010.
 *
 * Usage:
 * $(images).bind('load', function (e) {
 *   // Do stuff on load
 * });
 * 
 * Note that you can bind the 'error' event on data uri images, this will trigger when
 * data uri images isn't supported.
 * 
 * Tested in:
 * FF 3+
 * IE 6-8
 * Chromium 5-6
 * Opera 9-10
 */
(function ($) {
	$.event.special.load = {
		add: function (hollaback) {
			if ( this.nodeType === 1 && this.tagName.toLowerCase() === 'img' && this.src !== '' ) {
				// Image is already complete, fire the hollaback (fixes browser issues were cached
				// images isn't triggering the load event)
				if ( this.complete || this.readyState === 4 ) {
					hollaback.handler.apply(this);
				}

				// Check if data URI images is supported, fire 'error' event if not
				else if ( this.readyState === 'uninitialized' && this.src.indexOf('data:') === 0 ) {
					$(this).trigger('error');
				}
				
				else {
					$(this).bind('load', hollaback.handler);
				}
			}
		}
	};
}(jQuery));
