// JavaScript Document

var empty = /^\s*$/;
var email_format = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
var number_format = /^\d+$/;
var cur_type = '';
var carousel = 0;
var carouse_count = 0;


/***************************************** Form Validation ********************************************/

// form validator
function validate_form(the_id) {
	msg = jQuery("#info-msg").html("");
	
	jQuery('#' + the_id + ' .required').each(function() {
		// vars
		if(jQuery(this).attr("name") != null) {
			id = jQuery(this).attr("id");
			if(empty.test(jQuery(this).val())) {
				jQuery("#info-msg").html('<div class="info-msg">' + jQuery(this).attr("title") + '</div>');
				return false;
			}
			
			if(jQuery(this).hasClass("email") && !email_format.test(jQuery(this).val())) {
				jQuery("#info-msg").html('<div class="info-msg">' + jQuery(this).attr("title") + '</div>');
				return false;
			}
			
			if(jQuery(this).hasClass("phone")  && !number_format.test(jQuery(this).val())) {
				jQuery("#info-msg").html('<div class="info-msg">' + jQuery(this).attr("title") + '</div>');
				return false;
			}
			
			var checked  = $('#' + the_id + ' input[name="s3capcha"]:checked').length;
			var itemval  = $('#' + the_id + ' input[name="s3capcha"]:checked').val();
			
			if(checked<1){
				jQuery("#info-msg").html('<div class="info-msg"> Please select the right fruit. </div>');
				return false;
			}
			// for captcha
			/*jQuery('.captcha').each(function() {
				if(jQuery('#captcha').val() != jQuery('#verify').val()) {
					jQuery("#info-msg").html('<div class="info-msg">Security code does not match.</div>');
					return false;
				}
			});*/
		}
		
		
		
	});
	
	
	cur_msg = jQuery("#info-msg").html();
	
	if(cur_msg != '') {
		return false;
	} else {
		return true;
	}
}

/***************************************** Form Validation ###################################*******/

jQuery(function() {
	jQuery(".product-link").click(function() {
		//alert("test");
		the_pos = jQuery(this).attr("rel");
		the_id = jQuery(this).attr("id");
		jQuery("#product-pointer").animate({top : the_pos + 'px'}, 300, function() {
			jQuery(".product-link").removeClass("selected");
			jQuery(".product-link-details").hide();
			jQuery("#" + the_id + "-details").fadeIn();
			jQuery("#" + the_id).addClass("selected");
			//alert('this is a test');
		});
		current_pos = the_pos;
		return false;
	});
	
	/*********************** FAQ *****************************/
	
	jQuery(".faq-link").click(function() {
		jQuery(".faq-details").slideUp();
		jQuery(".faq-link").removeClass("selected");
		jQuery("#" + jQuery(this).attr("id")).addClass("selected");
		jQuery("#" + jQuery(this).attr("id") + "-details").slideDown();
		return false;
	});
	
	/*********************** FAQ *****************************/
	
	
	/******************** Deep Link ***************************/
	// Initialize history plugin.
	jQuery.history.init(deeplink_content);
	// deep linking
	jQuery(".deeplink").live("click", function() {
		var hash = jQuery(this).attr("href");
		jQuery.history.load(hash);
		return false;
	});
	// deep linking
	/******************** Deep Link **************************/
	
	
	/******************** Media **************************/
	
	if(cur_page == 'media') {
		jQuery('#prev').addClass("transparent");
		carousel_count = Math.ceil((jQuery(".play-btn").length) / 4);
	}
	
	jQuery("#prev").click(function() {
		if(carousel >= 1) {
			jQuery(".youtube-thumbs-overflow").animate({left: '+=568'}, 800, function() {
				// Animation complete.
				jQuery('#next').removeClass("transparent");
				
				if(carousel == 0) {
					jQuery('#prev').addClass("transparent");
				}
			});
			carousel--;
		}
		return false;
	});
	
	jQuery("#next").click(function() {
		if(carousel < carousel_count - 1) {
			jQuery(".youtube-thumbs-overflow").animate({left: '-=568'}, 800, function() {
				// Animation complete.
				jQuery('#prev').removeClass("transparent");
				
				if(carousel == carousel_count - 1) {
					jQuery('#next').addClass("transparent");
				} else {
					jQuery('#next').removeClass("transparent");
				}
			});
			carousel++;
		}
		return false;
	});
	
	if(cur_page == 'home' && jQuery("#mashead-flash").html().indexOf(".swf") < 0) {
		//slideshow
		jQuery("#portfolio").innerfade({ 
				speed: 'slow', 
				timeout: 8000, 
				type: 'sequence', 
				containerheight: '220px', 
				slide_nav_id: 'slideshow-nav',
				slide_ui_parent: 'portfolio'
		   }); 
			
		  jQuery.setOptionsButtonEvent();	
		
		jQuery(".circle-nav").hover(function() {
			var current = jQuery(this).attr("id")
			var content = jQuery("#portfolio").html();
			var settings = {
				'animationtype':    'fade',
				'speed':            'normal',
				'type':             'sequence',
				'timeout':          8000,
				'containerheight':  'auto',
				'runningclass':     'innerfade',
				'children':         null
			};
			current = current.replace("circle-", "");
			//jQuery.innerfade.next(jQuery("#portfolio"), settings, current, 0);
		}); 
	}
	//form validations 
	
	/******************** Media **************************/
});

/******************************************* Deep Linking ****************************************************/

function deeplink_content(hash) {
	// ajax post here
	if(hash != '') {
		// split hash
		arr = hash.split('/');
		
		// this is for static pages
		if(cur_page == 'about_us') {
			process_static_deeplink(arr);
		} else if(cur_page == 'careers') {
			process_careers_deeplink(arr);
		} else {			
			if(arr[1] == null) {
				//jQuery("#cont-holder").html('<img src="' + base_url + 'images/loader.gif" />&nbsp;<small>Please wait...</small>');
			}
			
			if(cur_page == 'products') {
				
				switch(hash) {
					case 'body-bar':
						product_link = 'product-link-1';
						
						break;
					case 'lotion':
						product_link = 'product-link-2';
						break;
					case 'face-wash':
						product_link = 'product-link-3';
						break;
					case 'toner':
						product_link = 'product-link-4';
						break;
					case 'vitamin-cream':
						product_link = 'product-link-5';
						break;
					default:
						product_link = 'product-link-1';
						break;
					
				}
				the_pos = jQuery("#" + product_link).attr("rel");
				jQuery("#product-pointer").animate({top : the_pos + 'px'}, 300, function() {
				});
				jQuery(".product-link").removeClass("selected");
				jQuery("#" + product_link).addClass("selected");
				jQuery(".product-link-details").hide();
				jQuery("#" + product_link + "-details").fadeIn();
				
				//params = {'arr' : arr}
				//jQuery.post(site_url + 'products/display_products_by_category', params, function(data) {
					//jQuery("#cont-holder").html(data);
				//});
			}
						
			jQuery("#cont-holder").stop(true, true).fadeIn(500);
	
			window.scrollTo(0, 0);
		}
	}
}

/******************************************* Deep Linking ****************************************************/




