$(document).ready(function(){

$('#top-nav > li:nth-child(2)').addClass('second');
$('#top-nav > li:last-child').addClass('last');

	$("#top-nav li:has(ul)").addClass("root").find("a:first").addClass("sub");
	
	$("#top-nav li.root").hover(function () {
		$(this).children('ul:hidden').css({'width': $(this).width(), overflow: 'hidden'}).slideDown(500); 
	
		},function(){
			$(this).children('ul:visible').slideUp(500);
    	}
    );
	
$('#slider').waitForImages(function() {

   $("#slidetabs").tabs("#slider .images > div.item", {rotate: true}).slideshow({autoplay: true, clickable: false, interval: 5000});
   tabsettings = $('#slidetabs').data("tabs");
   if (tabsettings) {
      tabapi = tabsettings.getConf();
      tabapi.effect = "fade";
      tabapi.fadeInSpeed = "slow";
      tabapi.fadeOutSpeed = "slow";
   };
   
});

$("#clients .more").fancybox();
	
$('#box-4 input[name=email]').bind('change', function() {
if ($(this).val()) {
$('#hidden-form input[name=email]').val($(this).val()).removeClass('watermark');
} else {
$('#hidden-form input[name=email]').val($('#hidden-form input[name=email]').attr('title')).addClass('watermark');
}
});


$("#hidden-form FORM").validate();
$("#box-4 .quote-1 FORM").validate();
$("#request-form FORM").validate();

$.validator.addMethod("defaultInvalid", function(val, el) {
if (el.value == el.title) {
return false;
}
return true;
});


$(function()
{
	$('.scroll-pane').closest('.item').show();
	$('.scroll-pane').jScrollPane();
	$('.scroll-pane').closest('.item').hide();
});


	$('input[type="text"]').focus(function() {
        if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
    });
    $('input[type="text"]').blur(function() {
        if (this.value == ''){
        	this.value = this.defaultValue;
    	}
    });
	

	$("#box-2 .tabs").tabs("#box-2 .panes > .item");
	
	$("#steps .pop").fancybox();
	
$("#box-4 .more").click(function() {
	$('#hidden-form').show();
  });

$("#hidden-form .close").click(function() {
	$('#hidden-form').hide();
  });
	
$("#portfolio-slider-items DIV").click(function() {
	$("#portfolio-slider-items DIV").removeClass("current");
	$(this).addClass("current");
    var image = $(this).attr("rel");
	var name = $(this).attr("alt");
    $('#big-image IMG').fadeTo("medium", 0.8).attr('src',image).fadeTo("fast", 1);
	$('#big-image SPAN').html(name); 	
    return false;
  }).filter(":first").click();
  
var $scrollables = $('#portfolio-slider-panes ').scrollable({
onSeek: function(e, index) {
        var items = this.getItems();
        items.removeClass('current');
        items.eq(index).addClass('current');
		items.eq(index).trigger('click');
},circular: true
});

$scrollables.each(function() {
	var $itemsToClone = $(this).scrollable().getItems().slice(1);
	var $wrap = $(this).scrollable().getItemWrap();
	var clonedClass = $(this).scrollable().getConf().clonedClass;
	$itemsToClone.each(function() {
		$(this).clone(true).appendTo($wrap)
			.addClass(clonedClass + ' hacked-' + clonedClass);
	})
});

$('.wpcf7-form').submit(function() {
  setTimeout(function() {
    checkResponse();
  }, 1000);
});
});

function checkResponse() {
  if ($('.wpcf7-response-output').text().length) {
    setTimeout( function() {
      $('.wpcf7-response-output').html('').addClass('wpcf7-display-none').css('display', 'none');
    }, 5000);
  } else {
    setTimeout(function() {
      checkResponse();
    }, 1000);
  }
};


