// Copyright Acro Media Inc. 1998-2009, www.acromediainc.com

// copyright year
$(function(){
  $('#insertYear').html(new Date().getFullYear());
});

// pri nav fade
$(function() {
	// set opacity to 0 on page load
	$("#priNav a").css("opacity","0");
	$("#priNav a").show();

	// set opacity to 1 for active on page load
	$("#priNav a.active, #priNav li.active-trail a").css("opacity","1");

	// on mouse over
	$("#priNav a").each(function () {
		parentItem = $(this).parent();
		if($(this).hasClass('active') == false && parentItem.hasClass('active-trail') == false ){
			$(this).hover(function () {
				// animate opacity to full
				$(this).stop().animate({
					opacity: 1
				}, "normal");
			},

			// on mouse out
			function () {
				$(this).stop().animate({
					opacity: 0
				}, "normal");
			});
		}
	});
});

// external links
$(function(){
    $("a[href^='http']").each(function(){
        var re_matches = /https?:\/\/([^\/]*)/.exec($(this).attr('href'));
        if(re_matches[1] && re_matches[1] != location.hostname){
            $(this).attr('target', '_blank');
        }
    });
});

/// add hovers
$(function(){
  $('.form-submit').hover(function(){
    $(this).toggleClass('hover');
  }, function(){
    $(this).toggleClass('hover');
  });
});

/* Acro Search  */
$(function(){
  $("#acroSearch").mouseover(function() {
		if (!$("#acroSearchWrapper").hasClass("swingOut")) {
			$("#acroSearchWrapper").animate({"left": "+=110px"}, "normal");
			$("#acroSearchWrapper").addClass("swingOut");
      $("#acroSearchSubmit").show();
		}
	});
});

$(function() {
  $("#bAcroSearchClose").click( function() {
		$("#acroSearchWrapper").animate({"left": "-=110px"}, "normal");
		$("#acroSearchWrapper").removeClass("swingOut");
    $("#acroSearchSubmit").hide();
    return false;
  });
});

function submitAcroSearchForm() {
  $("#acro-search-form").submit();
  return false;
 }

$(function() {
	$(".view-portfolio li:nth-child(3n+1)").addClass("noMargin");
});


// footer menu fade
$(function() {
	// set opacity to 0 on page load
	$("#footerNav a").css("opacity","0");
	$("#footerNav a").show();

	// on mouse over
	$("#footerNav a").each(function () {
			$(this).hover(function () {
				// animate opacity to full
				$(this).stop().animate({
					opacity: 1
				}, "normal");
			},

			// on mouse out
			function () {
				$(this).stop().animate({
					opacity: 0
				}, "normal");
			});
	});
});

// default input text
jQuery.fn.DefaultValue = function(text){
    return this.each(function(){
    //Make sure we're dealing with text-based form fields
    if(this.type != 'text' && this.type != 'password' && this.type != 'textarea')
      return;

    //Store field reference
    var fld_current=this;

    //Set value initially if none are specified
        if(this.value=='' || this.value == text) {
      this.value=text;
    } else {
      //Other value exists - ignore
      return;
    }

    //Remove values on focus
    $(this).focus(function() {
      if(this.value==text || this.value=='')
        this.value='';
    });

    //Place values back on blur
    $(this).blur(function() {
      if(this.value==text || this.value=='')
        this.value=text;
    });

    //Capture parent form submission
    //Remove field values that are still default
    $(this).parents("form").each(function() {
      //Bind parent form submit
      $(this).submit(function() {
        if(fld_current.value==text) {
          fld_current.value='';
        }
      });
    });
    });
};
//Set values
$(document).ready(function() {
	if($("#edit-submitted-first-name").length){
		$("#edit-submitted-first-name").DefaultValue("First name");
	}
  if($("#edit-submitted-last-name").length){
  	$("#edit-submitted-last-name").DefaultValue("Last name");
  }
  if($("#edit-submitted-company-name").length){
  	$("#edit-submitted-company-name").DefaultValue("Company name");
  }
  if($("#edit-submitted-email-address").length){
  	$("#edit-submitted-email-address").DefaultValue("Email address");
  }
  if($("#edit-submitted-phone-number").length){
  	$("#edit-submitted-phone-number").DefaultValue("Phone number");
  }
});

//Case study thumbnail hover
$(function(){
	$("a[rel='prettyPhoto']").hover(
	function() {
		$(".thumbOverlay", this).fadeIn("normal");
	},
	function() {
		$(".thumbOverlay", this).fadeOut("normal");
	});
});

//Portfolio pageination
$(function(){
	$('.pager-current').prepend('Page&nbsp;');
	$('.pager-previous a').text('< previous page');
	$('.pager-next a').text('next page >');
});

function acro_contact_form(){
	$.ajax({
		url: '/acro_contact_form',
		type: 'POST',
		data: ({name : $('#yourName').val(), phone_number : $('#phoneNumber').val(), email : $('#emailAddress').val() }),
		dataType: 'html',
		success: function(data) {
			$('#welcomeBackCont').hide();
			$('#thankYouCont').fadeIn('slow');
			pageTracker._trackPageview("/home-thank-you");
		}

	});

	return false;
}

$(function(){
	if ($.browser.msie && $.browser.version.substring(0,1) === '6' || $.browser.version.substring(0,1) === '7') {
		$('#acroTagCont').css('left','20px');
	}
});

// Hide Thank You Page From Sitemap
$(function() {
   $('#site-map .leaf a:contains("Thank you")').css('display', 'none');;
});





