﻿/***************************/
//@Author for portions of this: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

$(document).ready(function(){
	$(".menutab > li").click(function(e){
		switch(e.target.id){
			case "tab1":
				//change status & style menutab
				$("#tab1").addClass("active");
				$("#tab2").removeClass("active");
				$("#links").removeClass("active");
				//display selected division, hide others
				$("div.tab1").fadeIn();
				$("div.tab2").css("display", "none");
				$("div.links").css("display", "none");
			break;
			case "tab2":
				//change status & style menutab
				$("#tab1").removeClass("active");
				$("#tab2").addClass("active");
				$("#links").removeClass("active");
				//display selected division, hide others
				$("div.tab2").fadeIn();
				$("div.tab1").css("display", "none");
				$("div.links").css("display", "none");
			break;
			case "links":
				//change status & style menutab
				$("#tab1").removeClass("active");
				$("#tab2").removeClass("active");
				$("#links").addClass("active");
				//display selected division, hide others
				$("div.links").fadeIn();
				$("div.tab1").css("display", "none");
				$("div.tab2").css("display", "none");
			break;
		}
		//alert(e.target.id);
		return false;
	});
	var $oe_menu = $('#oe_menu');
	var $oe_menu_items	= $oe_menu.children('li');
	var $oe_overlay		= $('#oe_overlay');
 
	$oe_menu_items.bind('mouseenter',function(){
		var $this = $(this);
		$this.addClass('slided selected');
		$this.children('div').css('z-index','9999').stop(true,true).slideDown(200,function(){
			$oe_menu_items.not('.slided').children('div').hide();
			$this.removeClass('slided');
		});
	}).bind('mouseleave',function(){
		var $this = $(this);
		$this.removeClass('selected').children('div').css('z-index','0');
	});
 
	$oe_menu.bind('mouseenter',function(){
		var $this = $(this);
		$oe_overlay.stop(true,true).fadeTo(200, 0.6);
		$this.addClass('hovered');
	}).bind('mouseleave',function(){
		var $this = $(this);
		$this.removeClass('hovered');
		$oe_overlay.stop(true,true).fadeTo(200, 0);
		$oe_menu_items.children('div').hide();
		$oe_overlay.hide();
	})
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","auto");
		});
	}
	$('.bgChanger').bind('click', function(){
		var newBg = $(this).attr('data-bg');
		var changeDiv = $(this).attr('data-changeDiv');
		if(newBg != undefined){
			$('#'+changeDiv).fadeTo('2000', 0, function()
			{
				$(this).css('background', 'url('+newBg+') no-repeat center center fixed');
				$(this).css('background-size', 'cover');
			}).fadeTo('2000', 1);
		}
	});
	if($('#container').attr('data-bg') != undefined){
		$('#container').fadeTo('2000', 0, function()
		{
			var newBg = $('#container').attr('data-bg');
			$(this).css('background', 'url('+newBg+') no-repeat center center fixed');
			$(this).css('background-size', 'cover');
		}).fadeTo('2000', 1);
	}


$('#boutiqueForm').submit(function(e) {
	var first = $('#firstName').val();
	var last = $('#lastName').val();
	var email = $('#email').val();
	var prod = $('#prod').val();
	var quan = $('#quan').val();
	var comm = $('#Comments').val();
	var errArray = new Array();
	var numex = /\d/g;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if(first == '') {
		errArray.unshift['Please enter your first name'];
	}
	else if(numex.test(first)) {
		errArray.unshift('Your first name contained numbers');
	}
	if(last == '') {
		errArray.unshift('Please enter your last name');
	}
	else if(numex.test(last)) {
		errArray.unshift('Your last name contained numbers');
	}
	if(filter.test(email)) {}
	else {
		errArray.unshift('Please enter a valid email');
	}
	if(prod == 'select') {
		errArray.unshift('Please select a product');
	}
	if(quan == '0') {
		errArray.unshift('Please select a quantity');
	}
	if(errArray.length == 0) {
    
  }
	else {
		e.preventDefault();
		$('#errBox').remove();
		$('body').append('<div id="errBox"></div>');
		$('#errBox').append('<div id="dotted"><h2>Form Error</h2><p>Please note the following errors:</p><span id="errList"></span><button id="errOk">Ok</button><div class="clear"></div></div>');
		for(a=0; a<errArray.length; a++) {
			$('#errList').append(errArray[a]+'<br />');
		}
	}
	$('#errOk').click(function(){
		$('#errBox').remove();
	})
});
});
