
// 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);
  if(this.console) {
    arguments.callee = arguments.callee.caller;
    var newarr = [].slice.call(arguments);
    (typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr));
  }
};

// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,clear,count,debug,dir,dirxml,error,exception,firebug,group,groupCollapsed,groupEnd,info,log,memoryProfile,memoryProfileEnd,profile,profileEnd,table,time,timeEnd,timeStamp,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());


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

/**
 * jQLiteCycle - Lightweight jQuery cycle plugin
 * @version: 1.5 (2011/09/10)  
 * @author Maciej Lisiewski
 * Some of the code was copied from or inspired by: jQuery Cycle Plugin by M. Alsup and jqFancyTransitions/coin slider by Ivan Lazarevic
 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
**/

(function($) {
	var opts = new Array;	
	var img = new Array;
	var imgInc = new Array;	
	var interval = new Array;		
	
	$.fn.jQLiteCycle = $.fn.jqlitecycle = function(options){
	
		//initialize variables
		init = function(el){
			jQuery.fx.interval = 16;
			opts[el.id] = $.extend({}, $.fn.jQLiteCycle.defaults, options);			
			img[el.id] = new Array(); // array for image links					
			imgInc[el.id] = 0;
			//opts[el.id].width = $(el).width();
			//opts[el.id].height = $(el).height();	
			
			//append lazy loaded content, it's recommended to have at least 1 image loaded "normally" for purely aesthetic reasons
			if (opts[el.id].lazyLoad != false)
			{
				$(el).append(opts[el.id].lazyLoad);
			}
			
			$(el).addClass('jql-'+el.id);
			
			//fetch images, links, titles, set animation interval		
			$.each($('#'+el.id+' img'), function(i,item){
				if ($(item).parent().is('a')){
					img[el.id][i] = $(item).parent();
					$(img[el.id][i]).css({						
						//'display':'block',
						//'position':'absolute'
					}).hide();
				}
				else
				{
					img[el.id][i] = $(item);
					$(img[el.id][i]).css({						
						//'position':'absolute'
					}).hide();
				}				
				
				$(item).css({
					//'width':opts[el.id].width,
					//'height':opts[el.id].height
				});
			});			
			
			// reset opacity, show 1st element
			$(img[el.id][0]).css({'opacity':1}).show();				
			
			//$.navigation(el);
			
			$('.jql-'+el.id).mouseover(function(){
				$('#jql-nav-'+el.id).show();
				opts[el.id].pause = true;
			});
		
			$('.jql-'+el.id).mouseout(function(){
				$('#jql-nav-'+el.id).hide();
				opts[el.id].pause = false;
			});			
				
			interval[el.id] = setInterval(function() { $.transition(el,'next')  }, opts[el.id].delay);					
		}		
						
		// navigation
		$.navigation = function(el){
			
			// create prev and next
			$(el).append("<div id='jql-nav-"+el.id+"'><a href='#' id='jql-prev-"+el.id+"' class='jql-prev'>"+opts[el.id].prev+"</a><a href='#' id='jql-next-"+el.id+"' class='jql-next'>"+opts[el.id].next+"</a></div>");
			$('#jql-nav-'+el.id).hide();
			var navH = parseInt(opts[el.id].height)/2 - 15;	
		
			// bind prev and next actions
			$('#jql-prev-'+el.id).css({
				'position' 	: 'relative',					
				'float'		: 'left',
				'z-index' 	: 1001,
				'line-height': '30px',
				'opacity'	: 0.7,
				'top'	: navH
			}).click( function(e){
				e.preventDefault();
				$.transition(el,'prev',1);						
			});

			$('#jql-next-'+el.id).css({
				'position' 	: 'relative',						
				'float'		: 'right',
				'z-index' 	: 1001,
				'line-height': '30px',
				'opacity'	: 0.7,
				'top': navH
			}).click( function(e){
				e.preventDefault();
				$.transition(el,'next',1);				
			});
		}
		
		// trigger transition animation
		$.transition = function(el,direction,force){

			if(opts[el.id].pause == true && force === undefined) return;			
		
			opts[el.id].pause = true;
			clearInterval(interval[el.id]);
		
			var current = imgInc[el.id];
		
			if(direction == 'next')
				imgInc[el.id]++;
			else			
				imgInc[el.id]--;			

			if  (imgInc[el.id] == img[el.id].length) {
				imgInc[el.id] = 0;
			}
					
			if (imgInc[el.id] == -1){
				imgInc[el.id] = img[el.id].length-1;
			}	
					
			$(img[el.id][imgInc[el.id]]).fadeIn(opts[el.id].transitionSpeed);
			$(img[el.id][current]).fadeOut(opts[el.id].transitionSpeed, function(){
				opts[el.id].pause = false;
				interval[el.id] = setInterval(function() { $.transition(el,'next')  }, opts[el.id].delay);
			});			
		}		
		
		this.each (
			function(){ init(this); }
		);			
	}
	
	// default values
	$.fn.jQLiteCycle.defaults = {		
		delay: 5000, // delay between images in ms
		transitionSpeed: 5000, // image transition speed in ms		
		navigation: false, // prev next and buttons		
		prev: 'prev', // previous button text
		next: 'next', // next button text		 		
		lazyLoad: false // html to be appended inside container to provide lazy loading of images beyons 1st one 
	};
	
})(jQuery);


(function($){
	
	$.randomImage = {
		defaults: {
			
			//you can change these defaults to your own preferences.
			path: 'img/kluka/references/', //change this to the path of your images
			myImages: ['moon_3_-0519.jpg','moon_2_0414.jpg','Jenny_0737.jpg','JEANS_08_7402.jpg','JEANS_01.jpg','ELIJENT_01_5818.jpg','FRIDAY_Mantel_Chardonnay_Rot_1999.jpg','FRIDAY_Mantel_Coffee_Beige_-0476.jpg','edison16.jpg','edison10.jpg','edison06.jpg','Cyril06_kluka.jpg','boystoys_05.jpg' ] //put image names in this bracket. ex: 'harold.jpg', 'maude.jpg', 'etc'
			
		}			
	}
	
	$.fn.extend({
			randomImage:function(config) {
				
				var config = $.extend({}, $.randomImage.defaults, config); 
				
				 return this.each(function() {
						
						var imageNames = config.myImages;
						
						//get size of array, randomize a number from this
						// use this number as the array index

						var imageNamesSize = imageNames.length;

						var lotteryNumber = Math.floor(Math.random()*imageNamesSize);

						var winnerImage = imageNames[lotteryNumber];

						var fullPath = config.path + winnerImage;
						
						
						//put this image into DOM at class of randomImage
						// alt tag will be image filename.
						$(this).attr( {
										src: fullPath,
										alt: winnerImage
									});
				
						
				});	
			}
			
	});
	
	
	
})(jQuery);


