// 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,.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){
function DefaultValue (field, text) {
  
  return field.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($("#awf_field-30673055-first").length){
		DefaultValue($("#awf_field-30673055-first"), "First Name");
	}
  if($("#awf_field-30673055-last").length){
  	DefaultValue($("#awf_field-30673055-last"), "Last Name");
  }
  if($("#awf_field-30673056").length){
  	DefaultValue($("#awf_field-30673056"), "Company Name");
  }
  if($("#awf_field-30673057").length){
  	DefaultValue($("#awf_field-30673057"), "Email");
  }
  if($("#awf_field-30673058").length){
  	DefaultValue($("#awf_field-30673058"), "Phone Number");
  }
  if($("#awf_field-30673059").length){
  	DefaultValue($("#awf_field-30673059"), "Comments");
  }  
  
  if ($("#yourName").length) {
    DefaultValue($("#yourName"), "Your Name");
  }
  if ($("#phoneNumber").length) {
    DefaultValue($("#phoneNumber"), "Phone Number");
  }
  if ($("#emailAddress").length) {
    DefaultValue($("#emailAddress"), "Email Address");
  }
  
});

//Case study thumbnail hover
$(function(){
	$("a[rel='prettyPhoto'], a[rel='prettyPhoto[gallery]']").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(){
	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")').parent().css('display', 'none');;
});

$(document).ready(function() {
	var colHeight = $('#facebookActivity').height();
	colHeight += 313;
	
	$('#homepageColRight').css({height:colHeight});
});

// Top Designs Gallery               
$(function() {
   
  // Check if the adGallery is present
  if (typeof $.fn.adGallery == 'function') {      
    var galleries = $('.ad-gallery').adGallery({
      loader_image: '/sites/all/themes/acro/graphics/gallery/loader.gif',
      description_wrapper: false
    });
    $('#switch-effect').change(
      function() {
        galleries[0].settings.effect = $(this).val();
        return false;
      }
    );
    $('#toggle-slideshow').click(
      function() {
        galleries[0].slideshow.toggle();
        return false;
      }
    );  
  }
});


function togglePasswordReset() {
  $('#forgotPasswordCont').show();
}

