// iCarousel 

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('q Z=C z({5:{7:{i:"1x",D:"18",s:1,r:13.12.1I.14,u:1K,l:{i:"1J",R:1X,1z:"G"}},j:{W:"j",p:1T},P:"1Y",S:"1H",T:"21",1d:z.H,1b:z.H,1F:z.H,1t:z.H,1A:z.H},1L:8(1i,1k){4.1N(1k);4.m=$(1i);4.9=$A($$("."+4.5.j.W));4.x=U;d(4.5.P!="10"&&$(4.5.P)){$(4.5.P).17("11",8(1o){C 1a(1o).G();4.1B();4.J("1d",4,20)}.h(4))}d(4.5.S!="10"&&$(4.5.S)){$(4.5.S).17("11",8(1g){C 1a(1g).G();4.15();4.J("1b",4,20)}.h(4))}d(4.5.T!="10"&&$(4.5.T)){$(4.5.T).17("11",8(1e){C 1a(1e).G();4.1r()}.h(4))}q w=4.5.7;K(4.5.7.i.N()){t"L":4.9.Y(8(E){E.e=E.19("B",{u:w.u,r:w.r});E.O("B",0);E.1l({"1n":8(){4.x=1m;d(4.5.7.l.i=="I"){4.v=$1h(4.v)}}.h(4),"1c":8(){4.x=U;d(4.5.7.l.i=="I"){4.v=4.V.X(4.5.7.l.R,4)}}.h(4)})}.h(4));4.y=4.m.1p("y").1q();4.6=0;4.o(4.6);k;M:(2).1R(8(){4.9.Y(8(1f){1f.1V().1U(4.m)}.h(4))}.h(4));4.9=$A($$("."+4.5.j.W));4.9.Y(8(1j){1j.1l({"1n":8(){4.x=1m;d(4.5.7.l.i=="I"){4.v=$1h(4.v)}}.h(4),"1c":8(){4.x=U;d(4.5.7.l.i=="I"){4.v=4.V.X(4.5.7.l.R,4)}}.h(4)})}.h(4));4.e=4.m.1S({u:w.u,r:w.r,1Z:U});4.6=4.9.g/3;4.m.O(w.D,-4.6*4.5.j.p);k}d(4.5.7.l.i=="I"){4.v=4.V.X(4.5.7.l.R,4)}},1P:8(n){K(4.5.7.i.N()){t"L":q 1D=4.6;4.6=1E.1C(n%(4.9.g/3));4.o(4.6,1D);k;M:4.6=1E.1C(n%(4.9.g/3));4.6+=4.9.g/3;4.o(4.6);k}4.J("1A",4,20)},1B:8(){K(4.5.7.i.N()){t"L":q 1G=4.6;4.6-=4.5.7.s;d(4.6<0){4.6=(4.9.g-1)}4.o(4.6,1G);k;M:4.6-=4.5.7.s;d(4.6<4.9.g/3){4.m.O(4.5.7.D,-4.5.j.p*4.9.g*2/3);4.6=4.9.g*2/3-4.5.7.s}4.o(4.6);k}4.J("1F",4,20)},15:8(){K(4.5.7.i.N()){t"L":q 1s=4.6;4.6+=4.5.7.s;d(4.6>=4.9.g){4.6=0}4.o(4.6,1s);k;M:4.6+=4.5.7.s;d(4.6>4.9.g*2/3){4.m.O(4.5.7.D,-4.5.j.p*4.9.g/3);4.6=4.9.g/3+4.5.7.s}4.o(4.6);k}4.J("1t",4,20)},1r:8(){(4.m.1p("y").1q()==0)?4.m.19("y",{u:1u,r:13.12.1y.14}).f(4.y):4.m.19("y",{u:1u,r:13.12.1y.14}).f(0)},V:8(){d(4.5.7.l.1z=="G"&&!4.x){4.15()}},o:8(a,b){K(4.5.7.i){t"L":d($1W(b)){4.9[b].e.f(0).F(8(){4.9[a].e.f(1)}.h(4))}16{4.9[a].e.f(1)}k;t"1Q":q c=4;d(c.5.7.D=="Q"){c.e.f({"Q":-a*c.5.j.p})}16{c.e.f({"18":-a*c.5.j.p})}k;t"1x":q c=4;d(c.5.7.D=="Q"){c.e.f({"B":0.1v}).F(8(){c.e.f({"Q":-a*c.5.j.p}).F(8(){c.e.f({"B":1})})})}16{c.e.f({"B":0.1v}).F(8(){c.e.f({"18":-a*c.5.j.p}).F(8(){c.e.f({"B":1})})})}k}}});Z.1w(C 1O);Z.1w(C 1M);',62,126,'||||this|options|atScreen|animation|function|aItems|||_10|if|fx|start|length|bind|type|item|break|rotate|container||_animate|size|var|transition|amount|case|duration|timer|_6|isMouseOver|height|Class||opacity|new|direction|_7|chain|stop|empty|auto|fireEvent|switch|fade|default|toLowerCase|setStyle|idPrevious|top|interval|idNext|idToggle|false|_autoRotate|klass|periodical|each|iCarousel|undefined|click|Transitions|Fx|easeInOut|_next|else|addEvent|left|effect|Event|onClickNext|mouseleave|onClickPrevious|_5|_8|_4|clear|_1|_9|_2|addEvents|true|mouseenter|_3|getStyle|toInt|_toggle|_d|onNext|1000|75|implement|fadeNscroll|Sine|onMouseOver|onGoTo|_previous|abs|_b|Math|onPrevious|_c|next|Cubic|manual|500|initialize|Options|setOptions|Events|goTo|scroll|times|effects|100|injectInside|clone|defined|5000|previous|wait||toggle'.split('|'),0,{}))




/*
 * footer form validation functions
 * 
 */

// check multi checkboxes based on the name passed in.
	function CheckMultiple(name) 
	{
		theFrm = document.oemProSubscription;
		for (var i=0; i < theFrm.length; i++) 
		{
			fldObj = theFrm.elements[i];
			var fieldnamecheck=fldObj.name.indexOf(name);
			if (fieldnamecheck != -1) {
				if (fldObj.checked) {
					return true;
				}
			}
		}
		return false;
	}
	
	
	function CheckSS()
	{
		theFrm = document.oemProSubscription;
	
		hasDot = theFrm.FormValue_Email.value.indexOf(".");
		hasAt = theFrm.FormValue_Email.value.indexOf("@");
		
		if (hasDot == -1 || hasAt == -1)
		{
			alert("Please enter a valid email address.");
			theFrm.FormValue_Email.focus();
			theFrm.FormValue_Email.select();
			return false;
		}
	
		
		return true;
	}





// Campbell Salgado Gallery

	var fx											= [];
	var CurrentImage						= '';
	var GalleryStateOpen				= 0;
	var CurrentGallery					= 'OriginalPortraits';
	var ViewedImages						= [];
	var FeatureMaskOpacity 			= 1;
	var FeatureAreaCollapsed		=	256;
	var FeatureAreaExpanded			=	374;


function InsertThumbsHTML(Gallery) {

	GallertyThumbs = $('gallerythumbs');

	GallertyThumbs.empty();
	
	URL				=	'http://photos.campbellsalgado.com/photos/';
	
	ThumbArrayLength = ThumbArray[Gallery].length;
	ThumbWrapperWidth = ThumbArrayLength * 47 +5;

	ThumbArray[Gallery].each(function(el) { 
		var styleclasses	= { 'class': 'ViewedImage'};

		var ThumbItem		= new Element('li', {
				'styles': { 'background-image': 'url(\''+URL+el+'-Ti.jpg\')' }
			}).adopt(new Element('a', {
							'href'	:	'#',
						 'events': {
								'click': function(evnt) { 
										new Event(evnt).stop(); 
										DisplayImage(el,this);
								}
							}
					})
			);

		if(ViewedImages.contains(el)) {
			ThumbItem.addClass('ViewedImage');
		}
		$('thumbwrapper').setStyle('width', ThumbWrapperWidth+'px');
		GallertyThumbs.adopt(ThumbItem);
	
	});

}




function EnableFeatureMask() { 
	if($('featuremask').getStyle('opacity') == '0') {
		Fader['FeatureMask'].start.pass([0,FeatureMaskOpacity],Fader['FeatureMask']).delay(200);
	}
	Cookie.set('FeatureMask', 1,{path:'/',duration:1});
}





function DisableFeatureMask() {
	CurrentMaskOpacity = $('featuremask').getStyle('opacity');
	if(CurrentMaskOpacity != '0') {
		Fader['FeatureMask'].start(CurrentMaskOpacity,0);
	}
	Cookie.set('FeatureMask', 0, {path:'/',duration:1});

}



function SetGalleryImage(imgID) {

	GalleryImage = $('galleryimage');
	
	GalleryImage.empty();
	
	GalleryImage.adopt(new Element('img', {
			 'src': 'http://photos.campbellsalgado.com/photos/'+imgID+'-S.jpg'
		}));

}




function OpenGalleryImage(imgID) {

	SetGalleryImage(imgID);
	
	var CurrentOpacity = $('galleryimage').getStyle('opacity');

	if(CurrentOpacity == '0') {
		Fader['GalleryImage'].start(CurrentOpacity,1);
	}

	Cookie.set('CurrentImage', imgID, {path:'/',duration:1});

	
}



function CloseGalleryImage() {
	CurrentOpacity = $('galleryimage').getStyle('opacity');

	if(CurrentOpacity != 0) {
		Fader['GalleryImage'].start(CurrentOpacity,0);
	}
	Cookie.set('CurrentImage', 0, {path:'/',duration:1});
}









function OpenGallery(Gallery) {
	
	if(Cookie.get('GalleryStateOpen') == 1) { 
		SwitchGallery(Gallery); 
		//$('gallerycontrols').setStyle('display', 'block');
	}
	else {

		GalleryControls = $('gallerycontrols');

		InsertThumbsHTML(Gallery);
	
		$('NavPortfolio').addClass('NavStateOpen');
		
		if(window.scrollY != 0) {
			GalleryScroller				= new Fx.Scroll(window,	{duration: 900, fps:35}	);
			
			GalleryScroller.scrollTo(0,0).chain(
			function() {
				FeatureAreaSlider.chain(
																function(){
				GalleryControls.setStyle('display', 'block');
				Fader['GalleryControl'].start(0,1);
																	}
																).start(FeatureAreaCollapsed,FeatureAreaExpanded);
				}
			);
		}
		else {
			FeatureAreaSlider.chain(
															function(){
				GalleryControls.setStyle('display', 'block');
				Fader['GalleryControl'].start(0,1);
																}
															).start(FeatureAreaCollapsed, FeatureAreaExpanded);
		}

	}
		Cookie.set('GalleryStateOpen', 1, {path:'/',duration:1});
		Cookie.set('CurrentGallery', Gallery, {path:'/',duration:1});

}





function CloseGallery() {

		CloseGalleryImage();
		
		TempMaskFader		=	DisableFeatureMask;

		Fader['GalleryControl'].start(1,0).chain(
				function(){
					$('gallerycontrols').setStyle('display', 'none');
					DisableFeatureMask();
//					TempMaskFader.pass(TempMaskFader).delay(300);
					FeatureAreaSlider.start(FeatureAreaExpanded,FeatureAreaCollapsed);
				}
			);

		$('NavPortfolio').removeClass('NavStateOpen');
		
		Cookie.set('GalleryStateOpen', 0, {path:'/',duration:1});
		Cookie.set('CurrentImage', 0, {path:'/',duration:1});


}



function ToggleGallery() {	

	if($('featurearea').getStyle('height') == FeatureAreaExpanded+'px') {

		CloseGallery();		


	}
	else {
		OpenGallery(CurrentGallery); 	
	} //end else

}





function SwitchGallery(Gallery) {

	if(CurrentGallery != Gallery) {

		ThumbScroller.scrollTo(0,0);

		CloseGalleryImage();

		Fader['FeatureMask'].start($('featuremask').getStyle('opacity'),1).chain(
			function() {
//				DisableFeatureMask();
				InsertThumbsHTML(Gallery);
				Cookie.set('CurrentGallery', Gallery, {path:'/',duration:1});
				CurrentGallery = Gallery;
			});
	}

}







function DisplayImage(imgID,ElementToShade) {

	var ReplacementImage = imgID;

	if(ReplacementImage != CurrentImage) {
		EnableFeatureMask();
		CurrentImage = imgID;

		GalleryImage = $('galleryimage');

		if(GalleryImage.getStyle('opacity') != 0) {
			Fader['GalleryImage'].start(GalleryImage.getStyle('opacity'),0).chain(
				function(){
					OpenGalleryImage(CurrentImage);
				}
			);
		}
		else {
			OpenGalleryImage(CurrentImage);
		}
	}
	
 	$(ElementToShade).getParent().addClass('ViewedImage');

	Cookie.set('ViewedImages', ViewedImages.include(imgID), {path:'/',duration:1});

}



function init() {

//
///////////    Effects Animation / Behaviors
//

	// Create Effects Objects
	FeatureAreaSlider = new Fx.Style('featurearea', 		'height', 	{transition:Fx.Transitions.Quad.easeInOut, 
																			 																		duration: 1200,		fps:30}				        );		
	Fader = {
		GalleryControl	: 	new Fx.Style('gallerycontrols', 'opacity',	{transition:Fx.Transitions.Quad.easeInOut, 
																																							duration: 800,		fps:20,	wait: 1}			),
		GalleryImage		: 	new Fx.Style('galleryimage', 		'opacity',	{transition:Fx.Transitions.Quart.easeInOut, 
																																						duration: 1200,	fps:30}								),
		FeatureMask			:		new Fx.Style('featuremask', 		'opacity',	{transition:Fx.Transitions.Quad.easeInOut, 
																																						duration: 1200,	fps:25,	wait: 1} )
	}


	// Create scroller for when viewport is not completely visible before gallery click
	ThumbScroller				= new Fx.Scroll('thumbviewport', {duration:800});


//
////    End Effects Setup
//




//
/////			Event Setup
//

	//Function for up click events for  gallery left and right scrollers
	function SetArrowEvent(Arrow,Offset,ScrollEffect) {
		$(Arrow).addEvent('click', 
			function(event) {
				event = new Event(event).stop();
				CurrentCoordinates = $('thumbviewport').getSize();
				ScrollEffect.scrollTo(CurrentCoordinates['scroll']['x'] + Offset);
			});
	}

	// Set up thumbnail advance / return controls for gallery
	SetArrowEvent('leftarrow', -156,ThumbScroller);
	SetArrowEvent('rightarrow', 156,ThumbScroller);


	// Add click events for for "help" definition lists (products, packages, FAQs
	// Selector graps all links within definition terms
	$$('.main dt a').each(function(el,i) {
		// get the parent of the link (the definition term), and the next definition data (should follow the definition term)
		elem = el.getParent().getNext();
		//for the current link element, store the slider effect in an array, immediately hide
		fx[i] = new Fx.Slide(elem, {wait:false, duration:500}).hide();
		//add the event to toggle display
		el.addEvent('click', function(el) {
			new Event(el).stop();														
			fx[i].toggle();
			this.toggleClass('ListArrowActive');
		});
	});


	// 
	// 

	// Add Click Events for links with gallery control anchors
	// Selector searches for anchor tags containing 'Portfolio'
	$$('a[href*="#Portfolio"]').each(function(el) {
		//Call method once and store value
		LinkHREF = el.getProperty('href');
		//Create function to add event, based on later conditional
		function TriggerAdd(func) {
			el.addEvent('click', function(evnt) { 
				new Event(evnt).stop();
				//execute passed-in function
				func();
			});
		}

		//Determine which gallery to open based on contents of anchor tag, create callback function
		switch(true) {
			case LinkHREF.contains('#Portfolio/OriginalPortraits'):
				GallTrigger = function(){ OpenGallery('OriginalPortraits'); };
				break;
			case LinkHREF.contains('#Portfolio/Vignettes'):
				GallTrigger = function(){ OpenGallery('Vignettes'); };
				break;
			default: 
				GallTrigger = function(){ ToggleGallery() };
				break;
		}
		//Add the event
		TriggerAdd(GallTrigger);

	});

///
/////////////////// End Behaviors
///




///
/////////////////// VIEW STATES
///
	if(Cookie.get('CurrentGallery')) {
		CurrentGallery = Cookie.get('CurrentGallery');		
	}

	if(Cookie.get('GalleryStateOpen') == 1) {
		InsertThumbsHTML(CurrentGallery);
		FeatureAreaSlider.set(FeatureAreaExpanded);
		$('gallerycontrols').setStyle('display', 'block');
	 	Fader['GalleryControl'].set(1);

		$('NavPortfolio').addClass('NavStateOpen');		
	}
	else {
		FeatureAreaSlider.set(FeatureAreaCollapsed);
		$('gallerycontrols').setStyle('display', 'none');
		Fader['GalleryControl'].set(0);																			
	}


	if(Cookie.get('CurrentImage') != 0) {
			SetGalleryImage(Cookie.get('CurrentImage'));
			Fader['GalleryImage'].set(1);
	}
	else {
			Fader['GalleryImage'].set(0);
	}


	if(Cookie.get('FeatureMask') == 1 ) {
		 Fader['FeatureMask'].set(FeatureMaskOpacity);					
	}
	else {
		Fader['FeatureMask'].set(0);																					
	}
	

	
	///
	/// END VIEW STATES
	///



	var AffiliatesCarousel = new iCarousel("carousel", {

		animation: {			
			type: 			"fade",  
			duration: 	700,
			rotate: { 
				type: "auto",			
				interval: 13500
			}
		}

	}); 



}



// redirect the page if it contains an old link with a #ID in it
PageURL 	= window.location.href;
urlRegEx	=	/\/blog\/\#([0-9].*)/;

if(result		=	urlRegEx.exec(PageURL)) {
	window.location.href = '/blog/' + result[1];
} else {

	//initialize the code
	window.addEvent('domready', init);

}




