// From John Resig's blog > http://ejohn.org/blog/simple-javascript-inheritance/
// Inspired by base2 and Prototype
(function(){var initializing=false,fnTest=/xyz/.test(function(){xyz;})?/\b_super\b/:/.*/;this.Class=function(){};Class.extend=function(prop){var _super=this.prototype;initializing=true;var prototype=new this();initializing=false;for(var name in prop){prototype[name]=typeof prop[name]=="function"&&typeof _super[name]=="function"&&fnTest.test(prop[name])?(function(name,fn){return function(){var tmp=this._super;this._super=_super[name];var ret=fn.apply(this,arguments);this._super=tmp;return ret;};})(name,prop[name]):prop[name];}
function Class(){if(!initializing&&this.init)
this.init.apply(this,arguments);}
Class.prototype=prototype;Class.constructor=Class;Class.extend=arguments.callee;return Class;};})();


var K = Class.extend({
	
	init: function() {
		
		_this = this;
		
		_this.startCycle();
		
		$('.goback').bind('click', function() {
			window.history.back();
			return false;
		});
		
		$('.print a').bind('click', function() {
			
			// we add pagebreaks so only 4 pictures pr page will be shown
			$('.model-pictures img').each(function(i) {
				if(i%4 === 3) {
					if($(this).next().attr('class') != 'pagebreak') {
						$(this).after($('<div>&nbsp;</div>')
							.attr('class', 'pagebreak')
							.css({
								'overflow': 'hidden', 
								'height': '1px', 
								'width': 'auto', 
								'page-break-after': 'always', 
								'clear': 'both'
							})
						);
					}
				}
			});
			
			// fire up print window
			window.print();
			
			// remove pagebreaks again
			$('.model-pictures .pagebreak').remove();
			
			return false;
		});
		
	},
	
	startCycle: function() {
		
		$('.model-pictures').cycle({
			height: 380,
			next: '.model-pictures',
			speed: 400,
			timeout: 3000,
			pause: 1
		});
		
		$('.page-pictures').cycle({
			height: 380,
			next: '.page-pictures',
			speed: 400,
			timeout: 3000,
		});
		
	},
	
	stopCycle: function() {
		$('.model-pictures').cycle('destroy');
		$('.page-pictures').cycle('destroy');
	}
	
});