$(window).load(function() {
	$('#slider').nivoSlider({effect: 'boxRainGrow'});
	// add a last class to the 3rd item from each row
	$("#latest_work li:nth-child(3n), #portfolio_items li:nth-child(3n)").addClass("last");
	
	var lis = $("#latest_work li");
	$("#latest_work li").hover(
	  function () {
		$(this).find('.description-overlay').animate({top:'20px'}, 300, 'easeOutExpo');
	  },
	  function () {
		$(this).find('.description-overlay').animate({top:'140px'}, 200, 'easeOutExpo');
	  }
	);
	
	// portfolio item animation
	var portfolio_items = $("#portfolio_items .tab_content li");
	var portfolio_items_height = $("#portfolio_items .tab_content li").css('height');

	portfolio_items.each(function(el){
		$(this).find('.description-overlay').css({'height':portfolio_items_height,'top':portfolio_items_height});
	})
	
	portfolio_items.hover(
	  function () {
		$(this).find('.description-overlay').animate({top:0}, 300, 'easeOutExpo');
	  },
	  function () {
		$(this).find('.description-overlay').animate({top: portfolio_items_height}, 200, 'easeOutExpo');
	  }
	);
	
	// add a plus to the services & clients lists
	$('#mainbottom li, #sidebar ul.menu li').prepend("<span>+</span>");
	
	// display random testimonial
	var list = $(".testimonials ul li").toArray();
	var elemlength = list.length; 
	var randomnum = Math.floor(Math.random()*elemlength);
	var randomitem = list[randomnum];
	$(randomitem).css("display", "block");

	//initialize the menu
	$(function($){ $("ul.sf-menu").supersubs({minWidth:13, maxWidth:30, extraWidth:0}).superfish({hoverClass:'sfHover', pathClass:'sf-active', pathLevels:0, delay:500, animation:{height:'show'}, speed:'def', autoArrows:1, dropShadows:0}) });

	// init colorbox
	$("a[rel='colorbox']").colorbox();
	$(".video").livequery(function(){
		$(this).colorbox({iframe:true, width:650, height:550}); 
	});
	
	// init infield labels
	$("#newsletter-form label, .searchbox label, #commentform label, #contact-form label ").inFieldLabels();
	
	// FAQ Code
	$('#faqs h3').each(function() {
		var tis = $(this), state = false, answer = tis.next('div').hide().css('height','auto').slideUp();
		tis.prepend("<span>+</span> ")
		tis.click(function() {
		  state = !state;
		  answer.slideToggle(state);
		  tis.toggleClass('active',state);
		  if(tis.hasClass('active')) {
			  tis.find('span').text('â†’');
		  } else {
			  tis.find('span').text('+');
		  }
		});
	}); // end each faqs
	
	
	
	
});
$(document).ready( function (){
	var $selections = 0;

	$('#contact-form').submit(submitForm);
	$('#patterns div').click(function (){
		$('#patterns div').removeClass('selected');
		$(this).addClass('selected');
		$('#pattern').attr('value', $(this).find('img').attr('title'));
	});
	$('#parallax li').parallax(
    {mouseport: $('#parallax')}, {xparallax: '100px', yparallax: '30px'}, {xparallax: '300px', yparallax: '50px'}, {xparallax: '150px', yparallax: '30px'}, {xparallax: '250px', yparallax: '70px'});
  
                $('#swatch').slideUp();
                
               $('.tone').hover(function(e){$(this).stop().animate({opacity: 0.3}, 'slow');},function(e){$(this).stop().animate({opacity: 1}, 'fast'); }); 
               
               $('input[name*= color]').focus(function(){
               	$selection=$(this).attr('name');
               	$('#swatch').slideDown(); });
                $('.tone').click(function(){
                       $('input[name='+$selection+']').attr('value',$(this).attr('title'));
                       $(this).remove();
                       if($('input[name='+$selection+']').attr('value')!="")
                       $selections++;	
                       
                       $('#swatch').slideUp();
                       if($selections==1){
                       	$('#color2').css('visibility','visible');
                       }
                       if($selections>=2){
                       	$('#color3').css('visibility','visible');
                       	$('#HP').css('visibility','visible');
                       	$('#VP').css('visibility','visible');
                       }
               });
            $('#swatch').jScrollPane({showArrows: false, autoReinitialise:true}).data('jsp'); 
            
});

function showResult(data){
	$('#success').empty().removeAttr('class');
	if(data == 'success')
	   $('#success').addClass('success').html("Your message has been sent");
	if (data=='warning')
	   $('#success').addClass('warning').html("Please verify the information provided and try again");
	if (data=='error')
	   $('#success').addClass('error').html("The messaging service is temporarily unavailable, please try again later");
	   
}
function submitForm(){
		var $data = $(this).serialize();
		var $action = $(this).attr('action');
		$.post($action, $data, showResult);
		return false;
	}

