$(document).ready(function() {	
	/* Send External Links to New Window */
	$("a[rel=external]").attr("target","_blank");
	$('a.chat').click(function(){
    window.open(this.href,'','height=600, width=300,scrollbars=no');
    return false;
  });
	
	/* Font Replacement */
	Cufon.replace("ul#navigation h2 a, #main-column h3, #main-column .keypoint h4");
	
	/* Sidebar Default Form Value */
	$("form#sign-up-for-updates label").hide();
	$("form#retrieve-quote label").hide();
	$("form#save-quote label").hide();
	$("input#newsletter-name").defaultValue("Name");
	$("input#newsletter-email").defaultValue("Email");
	$("input#newsletter-company").defaultValue("Company");
	$("input#save-email-input").defaultValue("Email");
	$("input#retrieve-email-input").defaultValue("Email");
	$("input#retrieve-quote-input").defaultValue("Quote Number");
	
	/* Home Slideshow */
  $("ul#slideshow") 
    .before("<ul id='slideshow-controls'>") 
    .cycle({ 
      fx: "fade",
      timeout: 8000,
      pager: "#slideshow-controls",
      pagerAnchorBuilder: function(idx, slide) { 
        return '<li class="'+$(slide).attr('class')+'"><a href="#">'+(idx+1)+'</a></li>';
    }
  });
  $("ul#slideshow-controls li.one a").html("Experience");
  $("ul#slideshow-controls li.two a").html("Customer Service");
  $("ul#slideshow-controls li.three a").html("Printing Options");
	
	/* FAQ Toogles */
	$(".faq").children("p, ul").hide();
	$(".faq h4 a").addClass("closed");
  $(".faq h4 a").click(function() {
    $(this).parent().nextAll("p, ul").slideToggle("fast");
    $(this).toggleClass("closed");
    return false;
  });
  
  /* Team Toogles */
	$(".team").children("p").hide();
	$(".team").append("<p class='toggle'><a href='#'>Bio</a></p>");
  $(".team p.toggle a").toggle(function() {
			$(this).html("Close");
			$(this).addClass("close");
			$(this).parent().parent().children("p").not("p.toggle").slideDown("fast");
				}, function () {
			$(this).html("Bio");
			$(this).removeClass("close");
			$(this).parent().parent().children("p").not("p.toggle").slideUp("fast");
			return false;
	});
  
  /* Images Lightbox */
	$("a.image-zoom").fancybox({
    'overlayShow': false,
    'centerOnScroll': false
	});
	
	/* Contact Map Lightbox */
	$("a.iframe").fancybox({
    'overlayShow': false,
    'centerOnScroll': false,
		'width': 800,
    'height': 500
	});
  
  /* File Uploader */
  $("#upload-file-input").uploadify({
		'uploader'       : '/media/scripts/uploadify.swf',
		'script'         : '/media/scripts/uploadify.php',
		'folder'         : '/media/images/quotes/uploads',
		'buttonImg'      : '/media/images/quotes/button.png',
		'width'          : 86,
		'height'         : 34,
		'queueID'        : 'upload-progress',
		'buttonText'     : 'Choose File',
		'auto'           : false,
		'multi'          : false
	});
	
	/* Hide Sections */
	$(".billing-section").hide();
  $(".payment-section").hide();
  $(".shipping-section").hide();
  
	/* Billing Section Toggle */
  if ($("input.billing-radio:checked").val() == "united-states-canada-mexico") {
    $(".billing-section:first").show();
  }
  if ($("input.billing-radio:checked").val() == "other") {
    $(".billing-section:last").show();
    $(".shipping-section:visible").hide();
    $(".shipping-section:last").show();
    $("#shipping-checkbox").hide();
    $("input#shipping-different-billing-input").attr("checked", false);
  }
  $("input.billing-radio").click(function() {
    if ($("input.billing-radio:checked").val() == "other") {
        $(".billing-section:first").slideUp("fast");
        $(".billing-section:last").slideDown("fast");
        $(".shipping-section:visible").slideUp("fast");
        $(".shipping-section:last").slideDown("fast");
        $("#shipping-checkbox").slideUp("fast");
        $("input#shipping-different-billing-input").attr("checked", false);
    }
    else {
        $(".billing-section:first").slideDown("fast");
        $(".billing-section:last").slideUp("fast");
        $(".shipping-section:last").slideUp("fast");
        $("#shipping-checkbox").slideDown("fast");
    }
  });
  
  /* Payment Section Toggle */
  if ($("input.payment-radio:checked").val() == "credit-card") {
    $(".payment-section").show();
  }
  $("input.payment-radio").click(function() {
    if ($("input.payment-radio:checked").val() == "credit-card") {
        $(".payment-section").slideDown("fast");
    }
    else {
        $(".payment-section").slideUp("fast");
    }
  });
  
  /* Shipping Section Toggle */
  if ($("input#shipping-different-billing-input:checked").val() == "shipping-different") {
    $(".shipping-section:first").show();
  }
  $("input#shipping-different-billing-input").click(function() {
    if ($(this).is(":checked")) {
      $(".shipping-section:first").slideDown("fast");
    }
    else {
      $(".shipping-section:first").slideUp("fast");
    }
  });
  
  /* Forgot Password Toggle */
  $("#my-account-forgot-password").hide();
  $("a#forgot-password").click(function() {
    $("#my-account-forgot-password").slideToggle("fast");
    return false;
  });
  
});
