// let's preload images
if (document.images) {
	img1 = new Image();
	img2 = new Image();
	img3 = new Image();
	img4 = new Image();
	img5 = new Image();
	img6 = new Image();
	img7 = new Image();
	img8 = new Image();
	img1.src = "/_img/projects-next.jpg";
	img2.src = "/_img/projects-next-hover.jpg";
	img3.src = "/_img/projects-previous.jpg";
	img4.src = "/_img/projects-previous-hover.jpg";
	img5.src = "/_img/buttons.png";
	img6.src = "/_img/project-item.gif";
	img7.src = "/_img/project-item-active.gif";
	img8.src = "/_img/project-itme-hover.gif";
}

// the Sliding Tabs mootools plugin is a creation of Jenna “Blueberry” Fox!
// Documentation: http://creativepony.com/journal/scripts/sliding-tabs/
// version: 1.6.1

var SlidingTabs = new Class({
	options: {
		startingSlide: false, // sets the slide to start on, either an element or an id 
		activeButtonClass: 'active', // class to add to selected button
		activationEvent: 'click', // you can set this to ‘mouseover’ or whatever you like
		wrap: true, // calls to previous() and next() should wrap around?
		slideEffect: { // options for effect used to animate the sliding, see Fx.Base in mootools docs
			duration: 400 // half a second
		},
		animateHeight: true, // animate height of container
		rightOversized: 0 // how much of the next pane to show to the right of the current pane
	},
	current: null, // zero based current pane number, read only
	buttons: false,
	outerSlidesBox: null,
	innerSlidesBox: null,
	panes: null,
	fx: null, // this one animates the scrolling inside
	heightFx: null, // this one animates the height
	
	
	initialize: function(buttonContainer, slideContainer, options) {
		if (buttonContainer) { this.buttons = $(buttonContainer).getChildren(); }
		this.outerSlidesBox = $(slideContainer);
		this.innerSlidesBox = this.outerSlidesBox.getFirst();
		this.panes = this.innerSlidesBox.getChildren();
		
		this.setOptions(options);
		
		this.fx = new Fx.Scroll(this.outerSlidesBox, this.options.slideEffect);
		this.heightFx = this.outerSlidesBox.effect('height', this.options.slideEffect);
		
		// set up button highlight
		this.current = this.options.startingSlide ? this.panes.indexOf($(this.options.startingSlide)) : 0;
		if (this.buttons) { this.buttons[this.current].addClass(this.options.activeButtonClass); }
		
		// add needed stylings
		this.outerSlidesBox.setStyle('overflow', 'hidden');
		this.panes.each(function(pane, index) {
			pane.setStyles({
			 'float': 'left',
			 'width': this.outerSlidesBox.offsetWidth.toInt() - this.options.rightOversized + 'px',
			 'overflow': 'hidden'
		  });
		}.bind(this));
		
		// stupidness to make IE work - it boggles the mind why this has any effect
		// maybe it's something to do with giving it layout?
		this.innerSlidesBox.setStyle('float', 'left');
		
		this.innerSlidesBox.setStyle(
			'width', (this.outerSlidesBox.offsetWidth.toInt() * this.panes.length) + 'px'
		);
		
		if (this.options.startingSlide) this.fx.toElement(this.options.startingSlide);
		
		// add events to the buttons
		if (this.buttons) this.buttons.each( function(button) {
		  button.addEvent(this.options.activationEvent, this.buttonEventHandler.bindWithEvent(this, button));
		}.bind(this));
		
		if (this.options.animateHeight)
		  this.heightFx.set(this.panes[this.current].offsetHeight);
	},
	
	
	changeTo: function(element) {
		var event = { cancel: false, target: $(element) };
		this.fireEvent('change', event);
		if (event.cancel == true) { return; };
		
		if (this.buttons) { this.buttons[this.current].removeClass(this.options.activeButtonClass); };
		this.current = this.panes.indexOf($(event.target));
		if (this.buttons) { this.buttons[this.current].addClass(this.options.activeButtonClass); };
		this.fx.stop();
		this.fx.toElement(event.target);
		if (this.options.animateHeight)
		  this.heightFx.start(this.panes[this.current].offsetHeight);
	},
	
	// Handles a click
	buttonEventHandler: function(event, button) {
		if (event.target == this.buttons[this.current]) return;
		this.changeTo(this.panes[this.buttons.indexOf($(button))]);
	},
	
	next: function() {
		var next = this.current + 1;
		if (next == this.panes.length) {
			if (this.options.wrap == true) { next = 0 } else { return }
		}
		
		this.changeTo(this.panes[next]);
	},
	
	previous: function() {
		var prev = this.current - 1
		if (prev < 0) {
			if (this.options.wrap == true) { prev = this.panes.length - 1 } else { return }
		}
		
		this.changeTo(this.panes[prev]);
	}
});

SlidingTabs.implement(new Options, new Events);

//	tips - popup information for services in footer menu
window.addEvent('domready', function(){
	/* Tips 1 */
	var Tips1 = new Tips($$('.Tips1'));	 
	/* Tips 2 */
	var Tips2 = new Tips($$('.Tips2'), {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});	 
	/* Tips 3 */
	var Tips3 = new Tips($$('.Tips3'), {
		showDelay: 400,
		hideDelay: 400,
		fixed: true
	});	 
	/* Tips 4 */
	var Tips4 = new Tips($$('.Tips4'), {
		className: 'custom'
	});
});

function includeCheck() {
	if (document.getElementById('include_yes').checked) {
		document.getElementById('provide_name').style.display = '';
	} else {
		document.getElementById('provide_name').style.display = 'none';
	}
}
/* validate logo form */
function validLogo( form ) {
	
	// all requireds
	if (form.full_name.value == '') {
		alert('Your full name is required.');
		return false;
	}
	if (form.email_address.value == '') {
		alert('A valid Email Address is required so we can get in touch with you.');
		return false;
	}
	if (form.company_name.value == '') {
		alert('The company is required.');
		return false;
	}
	if (form.business_does.value == '') {
		alert('Please let us know what your business does - it will help us when designing / researching.');
		return false;
	}
	if (form.logo_message.value == '') {
		alert('Please let us know what message your logo should convey.  That way, we know what to design... metaphysically.');
		return false;
	}
	if (form.yes_logos.value == '') {
		alert('Please give us at least one logo you have liked.  Information like this helps us know a good starting point.');
		return false;
	}
	if (form.captcha_code.value == '') {
		alert('Please provide the random letters in the image.  This is how we know you are not a Spam Bot.  If you are a Span Bot, keep trying, you will not get by.');
		return false;
	}
	
	// only if they want to
	if (document.getElementById('include_yes').checked) {
		if (form.include_this_name.value == '') {
			alert('Since you have requested to include a name/initials in the logo, please provide what name or which initials.');
			return false;
		}
	}
	
	// email and verify email address must match
	if (form.email_address.value != form.verify_email_address.value) {
		alert('Your Email Address and Verify Email Address do not match.');
		return false;
	}
	
	// email address must be a valid email address format (taken up from (xt) signup.js)
	var emailRegExp = /^.+@.+\..{2,3}$/;
	var emailAddress = form.email_address.value;
	if ((!(emailRegExp.test(emailAddress))) || (emailAddress == '')) {
		newHtml = "Please provide a valid Email Address.";
		alert(newHtml);
		return false;	
	}
	var emailBadChar = /[\(\)\<\>\,\;\:\\\"\[\]]/;
	if (emailAddress.match(emailBadChar)) {
		newHtml = "Please provide a valid Email Address (no crazy, illegal characters... please).";
		alert(newHtml);
		return false;	
	}
	
}