
// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});


// place any jQuery/helper plugins in here, instead of separate, slower script files.

// JavaScript Document
// NEW GALLERY!
var ran=0;
var origHeight = 0;
var origWidth = 0;	
(function($){
	$.fn.fullSizeImage = function(options, refreshOptions) {

		// this is to keep from overriding our "defaults" object.
		var opts = $.extend({}, $.fn.fullSizeImage.defaults, options);
		var base = this;
		var baseImg = this.find('img');
	    var theOffset = new Array();
		if (ran==0) {
			origHeight = baseImg.height();
			origWidth = baseImg.width();	
		};
		
        base.init = function(){
        	ran++;
        	if(opts.offset!=null) {
        		theOffset = opts.offset.split(',');
        	}
	        if(opts.position=='fixed') {
	        	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
					base.css({
						'position':'absolute',
						'left':parseInt(theOffset[0]),
						'top':parseInt(theOffset[1])
					});
					$(window).bind('scroll',function(){base.scrollPage()});
				} else {
					base.css('position','fixed');
				}
	        }
	        base.resizeImage();
	        $(window).bind('resize',function(){base.resizeImage()});
		};

        base.scrollPage = function(){
	        base.css({
				'top':$(window).scrollTop()
			});
		};	
		
        base.repositionImage = function(){
	        if(opts.offset!=null) {
		        if(opts.position!='fixed') {
		        	baseImg.css({
			        	'left':(($(window).width() - parseInt(theOffset[0]) ) - baseImg.width()) / 2,
			        	'top':(($(document).height() - parseInt(theOffset[1])) - baseImg.height()) / 2
			        });
			    } else {
		        	baseImg.css({
			        	'left':(($(window).width() - parseInt(theOffset[0]) ) - baseImg.width()) / 2,
			        	'top':(($(window).height() - parseInt(theOffset[1])) - baseImg.height()) / 2
			        });
			    }
	        } else {
		        if(opts.position!='fixed') {
		        	baseImg.css({
			        	'left':($(window).width() - baseImg.width()) / 2,
			        	'top':($(document).height() - baseImg.height()) / 2
			        });
			    } else {
		        	baseImg.css({
			        	'left':($(window).width() - baseImg.width()) / 2,
			        	'top':($(window).height() - baseImg.height()) / 2
			        });
			    }
	        }
		};	
		
        base.resizeImage = function(){
        	imageRatio = baseImg.width() / baseImg.height();
        	
        	if( baseImg.width() > $(window).width() ||  baseImg.width() < $(window).width() ){
		        if(opts.offset!=null) {
		        	baseImg.css({
			        	'width': ($(window).width()- parseInt(theOffset[0]) ),
			        	'height': ($(window).width()- parseInt(theOffset[0]) ) / imageRatio
			        });
			    } else {
		        	baseImg.css({
			        	'width': $(window).width(),
			        	'height': $(window).width() / imageRatio
			        });
			    }
        	}
        	
        	if( baseImg.height() < $(document).height() ) {
		        if(opts.position!='fixed') {
		        	if(opts.offset!=null) {
			        	baseImg.css({
				        	'width': $(document).height() * imageRatio,
				        	'height': $(document).height()
				        });
			    	} else {
			        	baseImg.css({
				        	'width': $(document).height() * imageRatio,
				        	'height': $(document).height()
				        });
			    	}
		  	  } else {
		        	if(opts.offset!=null) {
		        		if (($(window).height() - parseInt(theOffset[1])) * imageRatio > ($(window).width()- parseInt(theOffset[0]) )) {
				        	baseImg.css({
					        	'width': ($(window).height() - parseInt(theOffset[1])) * imageRatio,
					        	'height': ($(window).height() - parseInt(theOffset[1]))
					        });
					    };
			    	} else {
			    		if ($(window).width() > $(window).height() * imageRatio) {
			    			
				        	baseImg.css({
					        	'width': $(window).width(),
					        	'height': $(window).width() / imageRatio
					        });
			    		} else {
				        	baseImg.css({
					        	'width': $(window).height() * imageRatio,
					        	'height': $(window).height()
					        });
			    		};
			    	}		
			    }
        	}

	        if(opts.offset!=null) {
	        	base.css({
	        		'left':parseInt(theOffset[0]),
	        		'top':parseInt(theOffset[1]),
	        		'width':($(window).width()- parseInt(theOffset[0]) ),
	        		'height':$(window).height() - parseInt(theOffset[1])
	        	})
	        } else {
	        	base.css({
	        		'width':$(window).width(),
	        		'height':$(window).height()
	        	})
	        }

	        if(opts.repositionImage==true) {
	        	base.repositionImage();
	        	$(window).bind('resize',function(){base.repositionImage()});
	        }

	        if(opts.overlayLine==true) {
	        	if(baseImg.width() > origWidth && $('#overlay').size() < 1) {
	        		$('#full-screen-image').append('<div id="overlay">&nbsp;</div>');
	        	}

	        	if(baseImg.width() < origWidth) {
	        		$('#overlay').remove();
	        	} 

        		$('#overlay').css({
        			'width':base.width(),
        			'height':base.height()
        		})
	        }
		};	

        base.refreshPlugin = function(refreshOptions){
        	$(window).unbind('resize');
        	$.extend(opts, refreshOptions);
	        if(opts.repositionImage==false) {
	        	baseImg.css({'top':'0','left':'0'})
        	}
        	if(opts.overlayLine==false) {
        		$('#overlay').remove();
        	}
			base.init();
        }

		if(options == 'refresh') {
			base.refreshPlugin(refreshOptions);
		} else {
			base.init();	
		}
        	
	};
	
	$.fn.fullSizeImage.defaults = {
		repositionImage : true,
		overlayLine : false,
		offset : null,
		position : 'fixed'
	};
})(jQuery);

/**
 * jQuery.Preload - Multifunctional preloader
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com
 * Dual licensed under MIT and GPL.
 * Date: 3/25/2009
 * @author Ariel Flesler
 * @version 1.0.8
 */
(function($){var h=$.preload=function(c,d){if(c.split)c=$(c);d=$.extend({},h.defaults,d);var f=$.map(c,function(a){if(!a)return;if(a.split)return d.base+a+d.ext;var b=a.src||a.href;if(typeof d.placeholder=='string'&&a.src)a.src=d.placeholder;if(b&&d.find)b=b.replace(d.find,d.replace);return b||null}),data={loaded:0,failed:0,next:0,done:0,total:f.length};if(!data.total)return finish();var g=$(Array(d.threshold+1).join('<img/>')).load(handler).error(handler).bind('abort',handler).each(fetch);function handler(e){data.element=this;data.found=e.type=='load';data.image=this.src;data.index=this.index;var a=data.original=c[this.index];data[data.found?'loaded':'failed']++;data.done++;if(d.enforceCache)h.cache.push($('<img/>').attr('src',data.image)[0]);if(d.placeholder&&a.src)a.src=data.found?data.image:d.notFound||a.src;if(d.onComplete)d.onComplete(data);if(data.done<data.total)fetch(0,this);else{if(g&&g.unbind)g.unbind('load').unbind('error').unbind('abort');g=null;finish()}};function fetch(i,a,b){if(a.attachEvent&&data.next&&data.next%h.gap==0&&!b){setTimeout(function(){fetch(i,a,1)},0);return!1}if(data.next==data.total)return!1;a.index=data.next;a.src=f[data.next++];if(d.onRequest){data.index=a.index;data.element=a;data.image=a.src;data.original=c[data.next-1];d.onRequest(data)}};function finish(){if(d.onFinish)d.onFinish(data)}};h.gap=14;h.cache=[];h.defaults={threshold:2,base:'',ext:'',replace:''};$.fn.preload=function(a){h(this,a);return this}})(jQuery);
