/*
 * Author	: Reza
 * Date		: 2 JUNE 2011
 */

jQuery(document).ready(function($){
	
	$('.blueBox ul.fadeBox').esaFader({
		speed: 1000,
		pause: 2000
	});
	
	$('.box_1 ul.fadeBox').esaFader({
		speed: 1000,
		pause: 2900
	});
	
	$('.box_4 ul.fadeBox').esaFader({
		speed: 800,
		pause: 3200
	});
	
	$('.box_6 ul.fadeBox').esaFader({
		speed: 700,
		pause: 2200,
		start: 0,
		mousePause: true
	});
	
	$('ul.zoomBox').hover(
		function(){
			$(this).css('z-index','100').children().stop(true,true).filter(':first').fadeOut('slow').next().fadeIn('slow');
		},
		function(){
			$(this).css('z-index','').children(':first').fadeIn('slow').next().fadeOut('slow');
		}
	);
	
	$('div.logoBox').hover(
		function(){
			$(this).children().stop(true,true).filter('img:first').fadeOut('slow').next('div.clientIn').fadeIn('slow');
		},
		function(){
			$(this).children('div.clientIn').fadeOut('slow').prev('img').fadeIn('slow');
		}
	);
});




(function($){
$.fn.esaFader = function(options) {
	var defaults = {
		speed: 1000,
		pause: 3000,
		start: 0,
		mousePause: true,
		isPaused: false
	};
	
	var options = $.extend(defaults, options);
	//console.log('>>>>>>>'+options.speed);
	
	animator = function(obj, kids){
		if(options.isPaused)
			return;
		
		kids.curKid = ( kids.curKid >= (kids.total-1) || kids.curKid < 0 )? 0 : kids.curKid+1;
		obj.children('li').stop(true,true).fadeOut(options.speed).eq(kids.curKid).fadeIn(options.speed);
	};
	
	return this.each(function(i,o) {
		var obj = $(this), kids={curKid:options.start,total:obj.children().length};//new Object();
		//obj.css({overflow: 'hidden', position: 'relative'}).children('li').css({position: 'absolute', left: 0, top: 0});
		
    	this.temp = setInterval(function(){ animator(obj, kids); }, options.pause);
		
		if(options.mousePause){
			obj.bind("mouseenter",function(){options.isPaused = true})
				.bind("mouseleave",function(){options.isPaused = false});
		}
	});
};
})(jQuery);

String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g,'')};

 function validate_this_form(){
		if( jQuery('#userName').val().trim()=='' || jQuery('#userName').val()=='name' ){
			alert('Enter your Name.');
			jQuery('#userName').focus();
			return false;
		}else if( jQuery('#txtEmail').val().trim()=='' || jQuery('#txtEmail').val()=='email' ){
			alert('Choose an Email.');
			jQuery('#txtEmail').focus();
			return false;
		}else if( jQuery('#txtMessage').val().trim()=='' ){
			alert('Insert Message.');
			jQuery('#txtMessage').focus();
			return false;
		}
		if( !checkEmail(jQuery('#txtEmail').val().trim()) ) {
			alert('Email is not valid');
			jQuery('#txtEmail').focus();
			return false;
		}
	}

function checkEmail(emial){
        var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        return filter.test(emial);
}
