$(document).ready( function() {
   
  // open external link in new tab/window
  $("a[href*='http://']:not([href*='"+location.hostname+"'])").click(function(){
    this.target = "_blank";
  });

	//remove default value
	$('input[alt]').focus(function () {
        if ($(this).attr("value") == $(this).attr("defaultValue")) {
                $(this).attr("value", '');
        }		
	});
	$('input[alt]').blur(function () {
        if ($(this).attr("value") == '') {
      	$(this).attr("value", $(this).attr("defaultValue"));
      }
	});

	
	//hide and show search form
	
	$('#keyword').hide();
	$('#search').mouseenter(function() {
		$(this).addClass('show').stop(true, true).animate({width: '220px'}, 200);
		$('#keyword').show();
	});
	$('#search').mouseleave(function() {
		
		if($('#keyword').val() == ''){
			$(this).stop(true, true).animate({width: '32px'}, 200, function(){
				$(this).removeClass('show')
			});
			$('#keyword').hide();
		}
	});
	
	// HIDE AND SHOW FOR CONTACT PAGE FORMS
	
	$('.form:not(#form-general)').hide();
	$('#contact-page.thankyou .form').hide();
	
	$('#contact-page #secondary-nav li a').click(function() {
		$('#contact-page #secondary-nav li a').removeClass('active');
		$(this).addClass('active');
		//getting id of clicked a
		var id = $(this).attr('id');
		$('.form').hide();
		$('#thanks').hide();
		//adding the id of clicked a and show this form
		$('#form-' + id).fadeIn();
		return false;
	});
	
	
	// CONTACT FORM VALIDATION
	
	$('#form-general').validate();	
	$('#form-business').validate();	
	$('#form-careers').validate();	
	
	
	// WORK INNER PAGE CYCLE CAROUSEL
	
	$('#cycle-carousel').cycle({ 
    fx:     'fade', 
    speed:  400, 
    timeout: 0, 
    pager:  '#pager',
    next: '#next',
    prev: '#prev'
	});	   
	
	// TWITTER FEED
	
	/*$("#twitter-feed").tweet({
	  username: "hardhatdigital",
	  join_text: "auto",
	  avatar_size: 0,
	  count: 1,
	  auto_join_text_default: "",
	  auto_join_text_ed: "",
	  auto_join_text_ing: "",
	  auto_join_text_reply: "",
	  auto_join_text_url: "",
	  loading_text: "Sit tight, we're loading tweets..."
	});*/
	
	// RSS FEED
	
	$('#feed a').gFeed({ target: '#feed', max: 2 }); 
	
	//HOME PAGE CYCLE
	
	$("#featured").cycle({ 
    fx:     'fade', 
    speed:  400, 
    timeout: 7000, 
    pager:  '#pager',
    next: '#next',
    prev: '#prev'
	});
	
});
