// main js

$(document).ready(function(){
	
	//input focus and blur
	$('input[type="text"]').focus(function(){
		if($(this).val()==$(this).attr('title')) $(this).val('');
	});
	$('input[type="text"]').blur(function(){
		if($(this).val()=='' || $(this).val()==$(this).attr('title')) $(this).val($(this).attr('title'));
	});		
	
	
	$('textarea').focus(function(){
		if($(this).val()==$(this).attr('title')) $(this).val('');
	});
	$('textarea').blur(function(){
		if($(this).val()=='' || $(this).val()==$(this).attr('title')) $(this).val($(this).attr('title'));
	});	
	
	// Submenu
	$("section.termsConditions h2 a").click(function(){
		if ($('.termsText').is(":hidden")) {
			$('.termsText').slideDown("slow");
			$('.termsText').addClass("open");
		} else {
			$('.termsText').slideUp(1000);
			$('.termsText').removeClass("open");
		}
		return false;
	});	
	
  
   
	function mySideChange(front) {
		$(this).parent().find('a.a1').hide();
        $(this).parent().find('a.a2').show();
	}
	function mySideChange2(front) {
		$(this).parent().find('a.a1').show();
        $(this).parent().find('a.a2').hide();
	}
	
 
	$('.brand1 .a1, .brand2 .a1, .brand3 .a1, .brand4 .a1, .brand5 .a1, .brand6 .a1, .brand7 .a1, .brand8 .a1, .brand9 .a1').click(function () {
   		$(this).rotate3Di('toggle', 250, {direction: 'clockwise', sideChange: mySideChange});
   		return false;
	});
	
	
	$('.brand1 .a2, .brand2 .a2, .brand3 .a2, .brand4 .a2, .brand5 .a2, .brand6 .a2, .brand7 .a2, .brand8 .a2, .brand9 .a2').click(function () {
		$(this).rotate3Di('toggle', 500, {direction: 'clockwise', sideChange: mySideChange2});
		return false;
	});	
	
	// video tabs
	//When page loads...
		
	$("#ideas .video2").hide(); //Hide all content
	$("#ideas #ideasList li:first").addClass("active").show(); //Activate first tab
	$("#ideas .video2:first").show(); //Show first tab content

	//On Click Event
	$("#ideas #ideasList li").click(function() {

		$("#ideas #ideasList li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$("#ideas .video2").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).show(); //Fade in the active ID content
		$(document).scrollTo(activeTab,0);
		return false;
	});
	
	
});

$(function()
{
	$('.scroll-pane').jScrollPane({showArrows: true});
});


function contact() {

	//eror
	var error='';


	// start
	// jQuery('.cbut2').addClass('loading');

	// info
	ver_name = 'Name and surname';
	ver_email = 'Email';
	ver_message = 'Your message';
	
	var name = jQuery('#name').val();
	var email = jQuery('#email').val();
	var message = jQuery('#message').val();

	// check
	if(name==ver_name || name==' ') error += 'Name and surname field is empty <br />';
	if(email==ver_email || email==' ') error += 'Email field is empty <br />';
	
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(reg.test(email) == false) error += 'Invalid email<br />';
	

	if(message==ver_message || message==' ') error += 'Message field is empty <br />';

	if(error.length==0) {

		jQuery('.flerror2').slideUp('slow');

		// post
		jQuery.post('ajax.php?a=contact',
			{

				name: name,
				email: email,
				
				message: message

			},
				function(data)
					{

						// afisare ok
						jQuery('.flerror').fadeIn('fast');
						jQuery('#name').val(ver_name);
						jQuery('#email').val(ver_email);
						jQuery('#message').val(ver_message);
						// stop
						// jQuery('.cbut2').removeClass('loading');

					}
		);

	} else {
		 // jQuery('.cbut2').removeClass('loading');
		jQuery('.flerror2 p').html(error);
		jQuery('.flerror2').slideDown('slow');
	}

}

