
/*		CONTACT FORM PLUGIN		*/
$(document).ready(function(){
        $('#send_message').click(function(e){
            
            //stop the form from being submitted
            e.preventDefault();
            
            /* declare the variables, var error is the variable that we use on the end
            to determine if there was an error or not */
            var error = false;
            var name = $('#name').val();
            var email = $('#email').val();
            var subject = $('#subject').val();
            var message = $('#message').val();
            
            /* in the next section we do the checking by using VARIABLE.length
            where VARIABLE is the variable we are checking (like name, email),
            length is a javascript function to get the number of characters.
            And as you can see if the num of characters is 0 we set the error
            variable to true and show the name_error div with the fadeIn effect. 
            if it's not 0 then we fadeOut the div( that's if the div is shown and
            the error is fixed it fadesOut. 
            
            The only difference from these checks is the email checking, we have
            email.indexOf('@') which checks if there is @ in the email input field.
            This javascript function will return -1 if no occurence have been found.*/
            if(name.length == 0){
                error = true;
                $('#name_error').fadeIn(500);
            }else{
                $('#name_error').fadeOut(500);
            }
            if(email.length == 0 || email.indexOf('@') == '-1'){
                error = true;
                $('#email_error').fadeIn(500);
            }else{
                $('#email_error').fadeOut(500);
            }
            if(subject.length == 0){
                error = true;
                $('#subject_error').fadeIn(500);
            }else{
                $('#subject_error').fadeOut(500);
            }
            if(message.length == 0){
                error = true;
                $('#message_error').fadeIn(500);
            }else{
                $('#message_error').fadeOut(500);
            }
            
            //now when the validation is done we check if the error variable is false (no errors)
            if(error == false){
                //disable the submit button to avoid spamming
                //and change the button text to Sending...
                $('#send_message').attr({'disabled' : 'true', 'value' : 'Sending...' });
                
                /* using the jquery's post(ajax) function and a lifesaver
                function serialize() which gets all the data from the form
                we submit it to send_email.php */
                var contactformurl = mysiteurl+"/js/send_email.php";
                $.post(contactformurl, $("#contact_form").serialize(),function(result){
                    //and after the ajax request ends we check the text returned
                    if(result == 'sent'){
                        //if the mail is sent remove the submit paragraph
                         $('#cf_submit_p').remove();
                        //and show the mail success div with fadeIn
                        $('#mail_success').fadeIn(500);
                    }else{
                        //show the mail failed div
                        $('#mail_fail').fadeIn(500);
                        //reenable the submit button by removing attribute disabled and change the text back to Send The Message
                        $('#send_message').removeAttr('disabled').attr('value', 'Send The Message');
                    }
                });
            }
        });    
    });



/*
Image zoom
--------------------------------*/
function img(){
$("a.image_zoom img,a.image_video img").mouseover(function(){
	$(this).stop(true,true);
	$(this).fadeTo(300, 0.6);
});

$("a.image_zoom img,a.image_video img").mouseout(function(){
	$(this).fadeTo(400, 1.0);
});

}

function query(){
var user= $('li.myroundabout').find('img').attr('alt');
	$('#description').html(user).hide(200).toggle(200);

$('li.myroundabout').focus(function() {
	var user= $(this).find('img').attr('alt');
	$('#description').html(user).hide(200).toggle(200);
});
}


function query(){
var user= $('li.myroundabout').find('img').attr('alt');
if(user!=null){
$('#description').html(user).hide(200).toggle(200);
$('li.myroundabout').focus(function() {
var user= $(this).find('img').attr('alt');
$('#description').html(user).hide(200).toggle(200);
});
}
}


/**************************************
blog social button
***************************************/
 
// this tells jquery to run the function below once the DOM is ready
$(document).ready(function() {
 
// choose text for the show/hide link - can contain HTML (e.g. an image)
var showText='Show';
var hideText='Hide';
 
// initialise the visibility check
var is_visible = false;
 
// append show/hide links to the element directly preceding the element with a class of "toggle"
$('.togglediv').append('<a href="#" class="toggleLink">'+showText+'</a>');
 
// hide all of the elements with a class of 'toggle'
$('.toggle').hide();
 
// capture clicks on the toggle links
$('a.toggleLink').click(function() {
 
// switch visibility
is_visible = !is_visible;
 
// change the link depending on whether the element is shown or hidden
$(this).html( (!is_visible) ? showText : hideText);
 
// toggle the display - uncomment the next line for a basic "accordion" style
//$('.toggle').hide();$('a.toggleLink').html(showText);
$(this).parent().next('.toggle').toggle('slow');
 
// return false so any link destination is not followed
return false;
 
});
});

jQuery(function($){


$(".social ul li:last-child").addClass("last");

img();

query();

$("a[rel^='prettyPhoto']").prettyPhoto({
show_title:false
});


/*
Toggles
-------------------------------*/

$(".toggle_container").hide(); 

$(".toggle_trigger").click(function(){
	$(this).toggleClass("toggle_active").next().slideToggle("fast");
	return false;
});



/*###################
Auto clear for input
#####################*/

$('.autoclear').click(
function() {
if ( this.value == this.defaultValue ) {
this.value = '';
} 
});

$('.autoclear').blur(
function() {
if (this.value == '') {
this.value = this.defaultValue;
}
}
);


/*
Sidebar Tabs
------------------------------------*/


$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab

$(".tab_content").filter(':first').show(); //Show first tab content


$("ul.tabs li").click(function() {

	$("ul.tabs li").removeClass("active"); //Remove any "active" class
	$(this).addClass("active"); //Add "active" class to selected tab
	$(".tab_content").hide(); //Hide all tab content

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


/*
cufon 
---------------------------------
	*/



	
/*
Disable all the A links
---------------------------------------*/

$('a').click(function(){
	var h = $(this).attr('href');
	if (h=='#')
	{
		return false;
	}

});
			
	
	
	
	
/*
Social tips and hover 
-----------------------------------*/

	$('.social_footer img').tipsy({
			delayIn :200,
			delayOut :200,
			fade : false,
			gravity: 's',
			title : 'alt'
	
	});
	
			
	$('.social_footer img').css({opacity : 0.6});
	$('.social_footer img').hover(function(){
		$(this).stop().animate({
		opacity : 1
		},400);
	
	},function(){
	$(this).stop().animate({
		opacity : 0.5
		},300);
	
	});
	
	
/****************
tipsy jquery for shortcodes
****************/

$('a.toll img,a.toll').tipsy({
			delayIn :200,
			delayOut :200,
			fade : false,
			gravity: 's',
			title : 'alt'
	
	});
	
	
	
/*
Wslider :Why transforms 
-------------------------------------------*/

$('#navigation ul li a,#tab-menu li a').hover(function(){
	$(this).animate({
		paddingLeft : '17px'
	},200);
		
},function(){
	$(this).animate({
		paddingLeft : '12px'
	},200);
	
},200);






	
/*
quick sand jquery 
-----------------------------------*/

// Custom sorting plugin
	// bind radiobuttons in the form
	var $filterType = jQuery('#filter a');
	// get the first collection
	var $list = jQuery('#portfolio-sorting');
	// clone applications to get a second collection
	var $data = $list.clone();

	$filterType.click(function(event) {

		if (jQuery(this).attr('rel') == 'everyone') {
		  var $sortedData = $data.find('li');
		} else {
			var $sortedData = $data.find('.'+ jQuery(this).attr('rel'));
		}

		jQuery('#filter a').removeClass('current_link');
		jQuery(this).addClass('current_link');
			
		$list.quicksand($sortedData, {
		  attribute: 'id',
		  duration: 800,
		  easing: 'easeInOutQuad',
		  useScaling: 'false',
		   adjustHeight: 'auto'
		   },function(){
		   
		   img(),
  $("a[rel^='prettyPhoto']").prettyPhoto({
show_title:false
});

		   });

		   return false;

		});
});

/******************************
Services  page 
******************************/

 $(function(){	
	$('.tab-content div.tab:first-child').addClass('show');

  //Get all the LI from the #tabMenu UL
  $('#tab-menu> ul> li>a').click(function(){
    //remove the selected class from all LI    
    $('#tab-menu >ul>li>a').removeClass('selected');
    //Reassign the LI
    $(this).addClass('selected');
    //Hide all the DIV in .tab-content
    $('div.tab').slideUp('slow');
    //Look for the right DIV in boxBody according to the Navigation UL index, therefore, the arrangement is very important.
    $('div.tab:eq(' + $('#tab-menu >ul> li >a').index(this) + ')').slideDown('slow');
  }).mouseover(function() {
    //Add and remove class, Personally I dont think this is the right way to do it, anyone please suggest    
    $(this).addClass('mouseover');
    $(this).removeClass('mouseout');   
  }).mouseout(function() {
    //Add and remove class
    $(this).addClass('mouseout');
    $(this).removeClass('mouseover');    
  });
  
});

/*************************************
Default Home 
*************************************/

$(function(){
	//why transforms section
	$("#w_slides").wslide({
		width:620,
		height:280,
		horiz: true,
		autolink: false,
		effect: 'easeOutBounce',
		duration :1500
	}); 
	
	
	$('#clients').wslide({
	width: 350,
	height: 170,
	horiz: true
	});
		
	//recent project section
	$('#carusol ul').bxSlider({
	controls: true,
	displaySlideQty: 4,
	moveSlideQty: 1, 
	auto: false,
	onAfterSlide: function(){
  $("a[rel^='prettyPhoto']").prettyPhoto({
show_title:false
});
		img();
	Cufon.replace('h1,h2,h3,h4,h6,.bigbutton span'); 
		}  
	
	});

	
	//testimonial section
	$('#testimonial ul').bxSlider({
			mode: 'fade',
			auto: true,
			controls: false
	});
	
	
	//round about  Client section
	$('#featured ul').roundabout({ 
		easing: 'easeOutInCirc',
		duration: 600,
		btnNext : '#next',
		btnPrev: '#previous',
		easing: 'easeOutExpo'
	});
	
});

