/*
	Slimbox v1.7 - The ultimate lightweight Lightbox clone
	(c) 2007-2009 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
var Slimbox=(function(){var F=window,n=Browser.Engine.trident4,u,g,G=-1,o,w,E,v,y,M,s,m={},t=new Image(),K=new Image(),I,a,h,q,J,e,H,c,A,L,x,i,d,C;F.addEvent("domready",function(){$(document.body).adopt($$(I=new Element("div",{id:"lbOverlay",events:{click:D}}),a=new Element("div",{id:"lbCenter"}),H=new Element("div",{id:"lbBottomContainer"})).setStyle("display","none"));h=new Element("div",{id:"lbImage"}).injectInside(a).adopt(q=new Element("div",{styles:{position:"relative"}}).adopt(J=new Element("a",{id:"lbPrevLink",href:"#",events:{click:B}}),e=new Element("a",{id:"lbNextLink",href:"#",events:{click:f}})));c=new Element("div",{id:"lbBottom"}).injectInside(H).adopt(new Element("a",{id:"lbCloseLink",href:"#",events:{click:D}}),A=new Element("div",{id:"lbCaption"}),L=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}))});function z(){var N=F.getScroll(),O=F.getSize();$$(a,H).setStyle("left",N.x+(O.x/2));if(v){I.setStyles({left:N.x,top:N.y,width:O.x,height:O.y})}}function l(N){["object",n?"select":"embed"].forEach(function(P){Array.forEach(document.getElementsByTagName(P),function(Q){if(N){Q._slimbox=Q.style.visibility}Q.style.visibility=N?"hidden":Q._slimbox})});I.style.display=N?"":"none";var O=N?"addEvent":"removeEvent";F[O]("scroll",z)[O]("resize",z);document[O]("keydown",p)}function p(O){var N=O.code;return u.closeKeys.contains(N)?D():u.nextKeys.contains(N)?f():u.previousKeys.contains(N)?B():false}function B(){return b(w)}function f(){return b(E)}function b(N){if(N>=0){G=N;o=g[N][0];w=(G||(u.loop?g.length:0))-1;E=((G+1)%g.length)||(u.loop?0:-1);r();a.className="lbLoading";m=new Image();m.onload=k;m.src=o}return false}function k(){a.className="";d.set(0);h.setStyles({backgroundImage:"url("+o+")",display:""});q.setStyle("width",m.width);$$(q,J,e).setStyle("height",m.height);A.set("html",g[G][1]||"");L.set("html",(((g.length>1)&&u.counterText)||"").replace(/{x}/,G+1).replace(/{y}/,g.length));if(w>=0){t.src=g[w][0]}if(E>=0){K.src=g[E][0]}M=h.offsetWidth;s=h.offsetHeight;var P=Math.max(0,y-(s/2)),N=0,O;if(a.offsetHeight!=s){N=i.start({height:s,top:P})}if(a.offsetWidth!=M){N=i.start({width:M,marginLeft:-M/2})}O=function(){H.setStyles({width:M,top:P+s,marginLeft:-M/2,visibility:"hidden",display:""});d.start(1)};if(N){i.chain(O)}else{O()}}function j(){if(w>=0){J.style.display=""}if(E>=0){e.style.display=""}C.set(-c.offsetHeight).start(0);H.style.visibility=""}function r(){m.onload=$empty;m.src=t.src=K.src=o;i.cancel();d.cancel();C.cancel();$$(J,e,h,H).setStyle("display","none")}function D(){if(G>=0){r();G=w=E=-1;a.style.display="none";x.cancel().chain(l).start(0)}return false}Element.implement({slimbox:function(N,O){$$(this).slimbox(N,O);return this}});Elements.implement({slimbox:function(N,Q,P){Q=Q||function(R){return[R.href,R.title]};P=P||function(){return true};var O=this;O.removeEvents("click").addEvent("click",function(){var R=O.filter(P,this);return Slimbox.open(R.map(Q),R.indexOf(this),N)});return O}});return{open:function(P,O,N){u=$extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},N||{});x=new Fx.Tween(I,{property:"opacity",duration:u.overlayFadeDuration});i=new Fx.Morph(a,$extend({duration:u.resizeDuration,link:"chain"},u.resizeTransition?{transition:u.resizeTransition}:{}));d=new Fx.Tween(h,{property:"opacity",duration:u.imageFadeDuration,onComplete:j});C=new Fx.Tween(c,{property:"margin-top",duration:u.captionAnimationDuration});if(typeof P=="string"){P=[[P,O]];O=0}y=F.getScrollTop()+(F.getHeight()/2);M=u.initialWidth;s=u.initialHeight;a.setStyles({top:Math.max(0,y-(s/2)),width:M,height:s,marginLeft:-M/2,display:""});v=n||(I.currentStyle&&(I.currentStyle.position!="fixed"));if(v){I.style.position="absolute"}x.set(0).start(u.overlayOpacity);z();l(1);g=P;u.loop=u.loop&&(g.length>1);return b(O)}}})();

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
Slimbox.scanPage = function() {
	$$(document.links).filter(function(el) {
		return el.rel && el.rel.test(/^lightbox/i);
	}).slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
};
window.addEvent("domready", Slimbox.scanPage);

/*
Script: LavishMenu.js
	Add a Lavish menu effect to UL elements.

License:
	MIT-style license.

Copyright:
	Copyright (c) 2009 [Drew Gauderman](http://www.aspinvision.com)

Code & Documentation:
	[ASP Invision]http://www.aspinvision.com).

Inspiration:
	- http://devthought.com/blog/projects-news/2007/01/cssjavascript-true-power-fancy-menu/


Hot to use:

	//simple, but class and type
	$$('.lavishmenu ul').lavishmenu();
		
	//by id
	$('lavishmenu').lavishmenu();
		
	//advanced with options
	$$('.partners ul,.quicklinks ul').lavishmenu({
		'backgroundColor': '#fff',
		'opacity': 1
	});

*/

var LavishMenu = new Class({

	Implements: [Options],

	options: {
		'backgroundColorActive': '#ffffff',
		'backgroundColor': '#ffffff',
		'opacityActive': 0.4,
		'opacity': 0.8
	},

	// do initialize
	initialize: function( el, options) {
		//input custom options
		this.setOptions(options);

		//make sure its an element
		el = $(el);

		//if not an element exit
		if (!el || el.get('tag') != 'ul') return;

		//make sure link is above the background
		el.getElements('li').setStyles({'z-index': 10,'position': 'relative'});

		//get active menu item
		this.active = $pick(el.getElement('li.active'), el.getElement('li'));

		//li element
		this.liHover = new Element('li', {'class': 'liHover', 'html': '<div class="rtop">' +
			'	<b style="height: 1px;margin: 0 5px;"></b>' +
			'	<b style="height: 1px;margin: 0 3px;"></b>' +
			'	<b style="height: 1px;margin: 0 2px;"></b>' +
			'	<b style="height: 2px;margin: 0 1px;"></b>' +
			'</div>' +
			'<div class="middle" style="display:block;height: ' + (this.active.getSize().y-10) + 'px;"></div>' +
			'<div class="rbottom">' +
			'	<b style="height: 2px;margin: 0 1px;"></b>' +
			'	<b style="height: 1px;margin: 0 2px;"></b>' +
			'	<b style="height: 1px;margin: 0 3px;"></b>' +
			'	<b style="height: 1px;margin: 0 5px;"></b>' +
			'</div>'}).setStyles({
				'position': 'absolute',
				'opacity': 0,
				'padding': 0,
				'margin': 0
			});
			
		this.liHover.getElements('b').setStyles({'display': 'block','overflow': 'hidden'});

		//add li slider
		el.adopt(this.liHover).getElements('li').each(function(li) {
			li.addEvents({
				'mouseenter': function() {
					this.goto(li);
				}.bind(this),
				'mouseleave': function() {
					if (active = el.getElement('li.active'))
						this.goto(active);
					else
						this.liHover.morph({'opacity': 0});
				}.bind(this)
			});
		}.bind(this));

		if (active = el.getElement('li.active'))
			this.goto(active, true);
		else
			this.liHover.setStyle('width', el.getElement('li').getSize().x);
	},

	goto: function(el, noMorph) {
		if (el.hasClass('liHover')) return;

		var coord = el.getCoordinates();
		var effect = (noMorph == true ? 'setStyles' : 'morph');

		this.liHover[effect]({
			'top': coord.top - (Browser.Engine.trident ? 2 : 0) - el.getStyle('margin-top').toInt(),
			'left': coord.left - (Browser.Engine.trident ? 2 : 0) - el.getStyle('margin-left').toInt(),
			'height': coord.height,
			'width': coord.width,
			'opacity': (el.hasClass('active') ? this.options.opacityActive : this.options.opacity)
		}).getElement('div.middle')[effect]({
			'background-color': (el.hasClass('active') ? this.options.backgroundColorActive : this.options.backgroundColor),
			'height': (coord.height-10)
		}).getParent('li').getElements('b')[effect]({
			'background-color': (el.hasClass('active') ? this.options.backgroundColorActive : this.options.backgroundColor)
		});
	}
});

Element.implement({
	lavishmenu: function(options) {
		window.addEvent('load', function() {
			new LavishMenu(this, options);
		}.bind(this));
	}
});

var ImageFade = new Class({
	Implements: [Options],
	options: {
		delay: 5000,
		bikes: []
	},
	// do initialize
	initialize: function( el, elTitle, options) {
		//input custom options
		this.setOptions(options);

		this.nextIdx = 0;					//starting array index number
		this.bikes = $(el);					//holds the element that holds the images
		this.title = $(elTitle);			//holds the title element with the title for the image

		if (!this.bikes || this.options.bikes.length==0) return;

		this.bikes.setStyle('background-image', 'URL(' + this.getBike(0)[0] + ')');	//update image
		this.title.setStyle('background-image', 'URL(' + this.getBike(0)[1] + ')');	//update title image

		this.nextIdx = 1;					//starting array index number
		this.fadeOut.delay(this.options.delay, this);
	},
	fadeOut: function() {
		this.bikes.morph({'opacity': 0});

		if (this.getBike()[1] != this.getBike(this.getPrevID())[1]) this.title.morph({'opacity': 0});

		this.changeBG.delay(600, this);	//change images
		this.fadeIn.delay(650, this);	//fade in new images after image change
	},
	fadeIn: function() {
		$$(this.bikes,this.title).morph({'opacity': 1});

		this.fadeOut.delay(this.options.delay, this);
	},
	changeBG: function() {
		this.bikes.setStyle('background-image', 'URL(' + this.getBike()[0] + ')');	//update image
		this.title.setStyle('background-image', 'URL(' + this.getBike()[1] + ')');	//update title image

		this.nextIdx = this.getNextID();
	},
	getPrevID: function() {
		if ((this.nextIdx - 1) < 0)
			return this.options.bikes.length-1;
		else
			return (this.nextIdx - 1);
	},
	getNextID: function() {
		if ((this.nextIdx + 1) >= this.options.bikes.length)
			return 0;
		else
			return (this.nextIdx + 1);
	},
	getBike: function(id) {
		return this.options.bikes[id || this.nextIdx];
	}
});

var smallGallery = new Class({
	Implements: [Options],
	options: {
		size: 200,
		images: []
	},
	// do initialize
	initialize: function( el, options) {
		//input custom options
		this.setOptions(options);

		window.addEvent('domready', function() {
			this.gallery = $(el);

			this.options.images.each(function(item, idx) {
				new Element('a', {
					'href': 'resize.asp?Size=500&Path=' + item,
					'rel': 'lightbox'
				}).adopt(
					new Element('img', {
						'src': 'resize.asp?Size=' + this.options.size + '&Path=' + item,
						'styles': {
							'max-width': this.options.size,
							'max-height': this.options.size,
							'height': this.size
						}
					})
				).inject(this.gallery);
			}.bind(this));

			if (Slimbox)
				Slimbox.scanPage();
		}.bind(this));
	}
});

var Mooquee = new Class({
	Implements: [Options],

	options: {
		element: 'mooquee',
		cssitem: 'mooquee_item',
		firstitem:0,
		trans:{'tin':'up', 'tout':'fade'}, //each transition is up, down, left, right, fade
		pause: 1, //seconds (keep pause equal or higher to duration to allow time for items to reset) -1 = infinite pause/no loop
		duration: 1, //number of seconds to move marquee items
		overflow:'hidden', //if your item flows over how do you want to handle it. Auto(scroll) or Hidden work best...
		startOnLoad:true, // will start marquee when loaded
		pauseOnHover: true, //if true will pause all animations while mouse is hovering
		onTransitionStart: function(){},// Executes on transition start
		onTransitionComplete: function(){} // Executes on transition completion
	},
	initialize: function(options){
		this.setOptions(options);
        	this.itemFXs = [];
       	this.outDelay = 0;
        	this.inDelay = 0;
		this.started = false;
		this.currentitem = this.options.firstitem;
		if(this.options.pause!=-1)
			this.loop = true;
		else{
			this.loop = false;
			this.options.pause =2;	
		}
		this.previousitem=-1;
		if (typeof(this.options.trans) == "string") this.options.trans = {'tin':this.options.trans, 'tout':this.options.trans};
		
		window.addEvent('domready', function() {
			//get all mooqueeItems
			
			this.items = $$('#' + this.options.element + ' .' + this.options.cssitem);
			this.totalitems = this.items.length;
			if($(this.options.element).style.overflow != 'hidden')
				$(this.options.element).style.overflow = 'hidden';
			if($(this.options.element).style.position != 'relative')
				$(this.options.element).style.position = 'relative'; 

			this.setMooqueeFXs();
			this.setTrans(this.options.trans);//has setMooqueeItems in it

			if(this.options.startOnLoad)
				this.loopTimer = this.mooveAll.delay(this.options.pause*1000 ,this);
			if(this.options.pauseOnHover){
				$(this.options.element).addEvent('mouseover',function(){this.pauseMooquee()}.bind(this));
				$(this.options.element).addEvent('mouseout',function(){this.resumeMooquee()}.bind(this));
			}
		}.bind(this));
		
		
	},
	setMooqueeItems: function(){
		this.resetting =true;
		var i=0;
		
		this.items.each(function (element){
			if($(element).style.position != 'absolute')
				$(element).style.position = 'absolute';
			$(element).style.width = $(this.options.element).clientWidth + 'px';
			$(element).style.overflow = this.options.overflow;

			if(i == this.currentitem)
				this.itemFXs[i].set(this.resetStyle).set(this.inStyle);
			else
				this.itemFXs[i].set(this.resetStyle).set(this.startStyle);
           
			i++;
		}.bind(this));

		this.resetting =false;
	},
	setMooqueeFXs: function(){
		var i=0;
		this.items.each(function (element){
			this.itemFXs[i] = new Fx.Morph(element,{duration:(this.options.duration*1000)});
			i++;
		}.bind(this));
	},
	mooveAll: function(){
		if((this.currentitem + 1) == this.totalitems)
			citem = 0;
		else
			citem = this.currentitem + 1;
		this.moove(citem);

	},
	moove: function(itemnumber){
		if(itemnumber < this.totalitems)
		if(!this.mousedOver){
		if(itemnumber != this.currentitem){
			
			$clear(this.loopTimer);
			
			if(this.previousitem != -1){
				this.itemFXs[this.previousitem].cancel().set(this.resetStyle).set(this.startStyle);
				this.itemFXs[this.currentitem].cancel().set(this.resetStyle).set(this.inStyle);
				this.previousitem=-1;
			}

			this.returnpreviousitem = this.previousitem = this.currentitem;
			this.returncurrentitem = this.currentitem = itemnumber;
			this.options.onTransitionStart(this.returncurrentitem,this.returnpreviousitem);

				this.itemFXs[this.previousitem].start(this.outStyle).chain(function(){
					if(!this.resetting){
						this.itemFXs[this.previousitem].set(this.resetStyle).set(this.startStyle);
						this.previousitem=-1;
					}
				}.bind(this));

				(function(){ 
					this.itemFXs[this.currentitem].start(this.inStyle).chain(function(){
						this.options.onTransitionComplete(this.returncurrentitem,this.returnpreviousitem);
						if(this.loop == true)
							this.loopTimer = this.mooveAll.delay(this.options.pause*1000 ,this);
					}.bind(this));
				}).delay(this.inDelay*this.options.pause*1000 ,this);
			
		}
		}else{
			this.moove.delay(50 ,this,itemnumber);	
		}
		
	},
    setTrans: function(newTrans){
        this.startStyle = {}
        this.inStyle = {};
        this.outStyle = {};
        this.resetStyle = {};
        this.inDelay = 0;
        switch(newTrans.tin){
                case 'up':
                    this.startStyle = {'top': $(this.options.element).clientHeight};
                    this.inStyle = {'top': 0};
                break;
                case 'down':
                    this.startStyle = {'top': $(this.options.element).clientHeight * -1};
                    this.inStyle = {'top': 0};
                break;
                case 'left':
                    this.startStyle = {'left': $(this.options.element).clientWidth};
                    this.inStyle = {'left': 0};
                break;
                case 'right':
                    this.startStyle = {'left': $(this.options.element).clientWidth * -1};
                    this.inStyle = {'left': 0};
                break;
                case 'fade':
                    this.startStyle = {'opacity': 0};
                    this.inStyle = {'opacity': 1};
                break;
        }
        switch(newTrans.tout){
                case 'up':
                    this.outStyle = {'top': $(this.options.element).clientHeight * -1};
                    this.resetStyle = {'top': 0};
                break;
                case 'down':
                    this.outStyle = {'top': $(this.options.element).clientHeight};
                    this.resetStyle = {'top': 0};
                break;
                case 'left':
                    this.outStyle = {'left': $(this.options.element).clientWidth * -1};
                    this.resetStyle = {'left': 0};
                break;
                case 'right':
                    this.outStyle = {'left': $(this.options.element).clientWidth};
                    this.resetStyle = {'left': 0};
                break;
                case 'fade':
                    this.outStyle = {'opacity': 0};
                    this.resetStyle = {'opacity': 1};
                    this.inDelay = .5;
                break;
        }
        this.setMooqueeItems();
    },
	pauseMooquee: function(){
		if(this.previousitem != -1){
			this.itemFXs[this.previousitem].pause();
			this.itemFXs[this.currentitem].pause();
		}
		this.mousedOver = true;
	},
	resumeMooquee: function(){
		if(this.previousitem != -1){
			this.itemFXs[this.previousitem].resume();
			this.itemFXs[this.currentitem].resume();
		}
		this.mousedOver = false;
	},
	stopMooqueeLoop: function(){
		this.loop = false;
		this.options.pause = 2;
	}
});

mookieHeader = new Mooquee({'trans':'right','pause': 4});

window.addEvent('domready', function() {
	if ($('homegallery')) {	
		new smallGallery('homegallery', {
			size: 120,
			images: [
				'photos/IMG_0079.jpg',
				'photos/IMG_0080.jpg',
				'photos/IMG_0084.jpg',
				'photos/IMG_0087.jpg',
				'photos/IMG_0088.jpg',
				'photos/IMG_0089.jpg',
				'photos/IMG_0090.jpg',
				'photos/IMG_0091.jpg',
				'photos/IMG_0093.jpg',
				'photos/IMG_0094.jpg',
				'photos/IMG_0095.jpg',
				'photos/IMG_0096.jpg',
				'photos/IMG_0099.jpg',
				'photos/IMG_0100.jpg',
				'photos/IMG_0101.jpg',
				'photos/IMG_0102.jpg',
				'photos/IMG_0103.jpg',
				'photos/IMG_0104.jpg',
				'photos/IMG_0105.jpg',
				'photos/IMG_0107.jpg',
				'photos/IMG_0110.jpg',
				'photos/IMG_0111.jpg',
				'photos/IMG_0112.jpg',
				'photos/IMG_0113.jpg',
				'photos/IMG_0117.jpg',
				'photos/IMG_0118.jpg',
				'photos/IMG_0125.jpg',
				'photos/IMG_0126.jpg',
				'photos/IMG_0129.jpg',
				'photos/IMG_0130.jpg',
				'photos/IMG_0131.jpg',
				'photos/IMG_0145.jpg',
				'photos/IMG_0144.jpg',
				'photos/IMG_0148.jpg'

			]
		});
	};

	if ($('oigear')) {	
		new smallGallery('oigear', {
			size: 80,
			images: [
				'photos/IMG_0239.jpg',
				'photos/IMG_0238.jpg',
				'photos/IMG_0138.jpg',
				'photos/rockstar2.jpg',
				'photos/IMG_0139.jpg',
				'photos/rockstar3.jpg',
				'photos/IMG_0141.jpg',
				'photos/rockstar1.jpg',
				'photos/IMG_0142.jpg'
			]
		});
	};

	if ($('bikes')) {
		new ImageFade('bikes','official-dealer', {
			bikes: [
			
			['images/bikes/grizzly350.png','images/official-dealer.png'],
			['images/bikes/2010raider.png','images/official-dealer.png'],
			['images/bikes/grizzly450.png','images/official-dealer.png'],
			['images/bikes/2011apex.png','images/official-dealer.png'],
			['images/bikes/grizzly700.png','images/official-dealer.png'],
			['images/bikes/raptor125.png','images/official-dealer.png'],
			['images/bikes/2009rhino.png','images/official-dealer.png'],
			['images/bikes/raptor250r.png','images/official-dealer.png'],
			['images/bikes/raptor700RSE.png','images/official-dealer.png']
			/*
				['images/bikes/2010yz450f.png','images/official-dealer.png'],
				
				['images/bikes/2010grizzly.png','images/official-dealer.png'],
				
				
				*/
			]
		});
	};

	$$('.lavishmenu ul').lavishmenu();
});

