/*******************************************************************************

	CSS on Sails Framework
	Title: Studio MSV
	Author: XHTMLized (http://www.xhtmlized.com/)
	Date: February 2011

*******************************************************************************/


function validateForm(formData, jqForm, options){
	var flag = true;
	var form = jqForm[0];
		//.c-field 
		$('.c-field input:text', form).each(function(i){
			
			if ($(this).next().hasClass('require')){
			 $(this).next().remove();
			}
			if ($(this).val() == ''){
				flag = false;
				$(this).after('<span class="require">*</span>');
			}
		});
		
		

		//select
		$('.custom-select', form).each(function(){
			if ($(this).next().hasClass('require')){
				 $(this).next().remove();
			}
			if ($(this).children('strong').html() == ''){
				flag = false;
				$(this).after('<span class="require">*</span>');
			}
		});
		

		//other-referrer
		var other_text = $('.other-referrer input:text', form);
		if (other_text.parent('.field').is(':visible')){
			if (other_text.next().hasClass('require')){
				 other_text.next().remove();
			}
			if (ther_text.val() == ''){
				flag = false;
				ther_text.after('<span class="require">*</span>');
			} 
		}
		

		//shoot-type
		$(' .shoot-type input:text, .shoot-type textarea', form).each(function(){
			if ($(this).parents('.shoot-type').is(':visible')){
				if ($(this).next().hasClass('require')){
				 $(this).next().remove();
				}
				if ($(this).val() == ''){
					flag = false;
					$(this).after('<span class="require">*</span>');
				}
			}
			
		});
		
		return flag;
}

function  showResponse(responseText, statusText, xhr, $form){
	$('.contact-form').html(responseText);
}


function contactForm(){
	var options = { 
        target:        '.contact-form',   // target element(s) to be updated with server response 
        beforeSubmit:  validateForm,  // pre-submit callback 
        success:  showResponse  // post-submit callback 
    }; 
 
	$('.contact-form form').submit(function(){
		$(this).ajaxSubmit(options);
		return false;
	
		
	})
}

$(document).ready(function() {

	$('.social').click(function() {
	stopVideo();
	});

  /* Scrollable */
  $('.scrollable').scrollable({ circular: true }).navigator('#navigation ul.navi');
  $('.browse').click(function() {
	return false;
	});
	
	var url = window.location.href;

 	if (1 > 0) {
  	$('.li_2 a').click();
  }
  
  if (url.indexOf('demo') > 0) {
  	$('.li_2 a').click();
  }
  
  if (url.indexOf('about') > 0) {
  	$('.li_3 a').click();
  }
  
  if (url.indexOf('press') > 0) {
  	$('.li_4 a').click();
  }
  
  if (url.indexOf('blog') > 0) {
  	$('.li_5 a').click();
  }
  
  if (url.indexOf('contact') > 0) {
  	$('.li_6 a').click();
  }
  
  if ($('.contact-form').length){
  	x_customForm.Form.setup();
  	contactForm();
  	
  }
  




});

