$(function () {
    // primary nav //
    var timeout = 1000;
    var closetimer = 0;
    var ddmenuitem = 0;

    function jsddm_open() {
        jsddm_canceltimer();
        jsddm_close();
        ddmenuitem = $(this).find('.dropdown').css('visibility', 'visible');
    }
    function jsddm_close() {
        if (ddmenuitem) {
            ddmenuitem.css('visibility', 'hidden');
        }
    }
    function jsddm_timer() {
        closetimer = window.setTimeout(jsddm_close, timeout);
    }
    function jsddm_canceltimer() {
        if (closetimer) {
            window.clearTimeout(closetimer);
            closetimer = null;
        }
    }
    $('header nav > ul > li').hover(jsddm_open, jsddm_timer);
    document.onclick = jsddm_close;

    // image slider	
    $('#coda-slider-1').codaSlider({
        autoSlideInterval: 4000
    });

    //Copyright on master page now given current year dynamically
    var currentyear = new Date
    currentyear = currentyear.getFullYear().toString()
    $('.copyright').html('All content &copy;Domainbox ' + currentyear);

    //Populate header strap with content.
    $('#strap').append($('#strapcontent'));

    //Populate the 'admin portal login' link.
    if ($('.admin-populate').html() != null) {
        $('.admin-populate').html($(".admin-populate").html().replace("-", "admin portal login"));
    }

    //Populate the 'Read more' link.
    $('.more').html('<a href="/testimonials/">Read more >></a>');
    
    //Populate the 'Sign up now' links.
    if ($('.sign').html() != null) {
        $('.sign').html($(".sign").html().replace("-", "Sign up now"));
    }

    //Populate the 'Sign up now' links.
    if ($('.sign-up').html() != null) {
        $('.sign-up').html($(".sign-up").html().replace("-", "Sign up now"));
    }

    //Populate the 'Sign up now' links.
    if ($('.signup').html() != null) {
        $('.signup').html($(".signup").html().replace("-", "Sign up now"));
    }

    // homepage "what's in the box" selector
    var item = "#in-the-box ul li";
    $('#domain-reseller a').hover(
		function () {
		    $(item).removeClass('active');
		    $('#domain-reseller').addClass('active');
		    $('#in-the-box').css('height', 380);
		});
    $('#custom-storefront a').hover(
		function () {
		    $(item).removeClass('active');
		    $('#custom-storefront').addClass('active');
		    $('#in-the-box').css('height', 380);
		});
    $('#soap-api a').hover(
		function () {
		    $(item).removeClass('active');
		    $('#soap-api').addClass('active');
		    $('#in-the-box').css('height', 380);
		});
    $('#admin-portal a').hover(
		function () {
		    $(item).removeClass('active');
		    $('#admin-portal').addClass('active');
		    $('#in-the-box').css('height', 380);
		});
    $('#green-box a').hover(
		function () {
		    $(item).removeClass('active');
		    $('#green-box').addClass('active');
		    $('#in-the-box').css('height', 560);
		});

    // fancybox call
    $('a.iframe').fancybox({
        'width': 650,
        'height': 450
    });

    $('a.inlinePop').fancybox({
        'width': 650,
        'height': 450
    });

    // footer testimonials slider	
    $('#footer-quotes').codaSlider({
        autoSlideInterval: 5000
    });

    //converts email addresses to mailtos using JS in an attempt to fool spam bots
    HumansNotBots("dom", "AT", "DOT");

});
	//Pricing page checkbox switcher
	function pricingCheck(){
		var columns=1;
		if ($('#checkboxRenewal:checked').val() !== undefined) {
			columns++;
			$('.priceRenewal').show();
		}else{
			$('.priceRenewal').hide();
		}
		if ($('#checkboxTransfer:checked').val() !== undefined) {
			columns++;
			$('.priceTransfer').show();
		}else{
			$('.priceTransfer').hide();
		}
		$('.tier1heading').attr('colspan',columns);
		$('.tier2heading').attr('colspan',columns);
		$('.tier3heading').attr('colspan',columns);
	}
	$(document).ready(function() {	
		pricingCheck()
});

//This function will hardcode the links in the menu to look at live domainbox http.
//Currently used to fix 'https' issue from 'sign me up' page.
//can be called again from any page where you need to hardcode links.
function hardCodeLinks() {
    //In The Box
    //Domain Reseller Package
    $(".reseller ul").html($(".reseller ul").html().replace("/reseller/domain-names/", "http://www.domainbox.com/reseller/domain-names/"));
    $(".reseller ul").html($(".reseller ul").html().replace("/reseller/dns/", "http://www.domainbox.com/reseller/dns/"));
    $(".reseller ul").html($(".reseller ul").html().replace("/reseller/email/", "http://www.domainbox.com/reseller/email/"));
    $(".reseller ul").html($(".reseller ul").html().replace("/reseller/ssl/", "http://www.domainbox.com/reseller/ssl/"));

    //Storefront, soap based api, admin portal.
    $(".reseller").html($(".reseller").html().replace("/reseller/", "http://www.domainbox.com/reseller/"));
    $(".soapapi").html($(".soapapi").html().replace("/domain-api/", "http://www.domainbox.com/domain-api/"));
    $(".storefront").html($(".storefront").html().replace("/reseller/website/", "http://www.domainbox.com/reseller/website/"));
    $(".admin").html($(".admin").html().replace("/admin-portal/", "http://www.domainbox.com/admin-portal/"));

    //Why Us?
    $(".benefits").html($(".benefits").html().replace("/benefits/", "http://www.domainbox.com/benefits/"));
    $(".features").html($(".features").html().replace("/features/", "http://www.domainbox.com/features/"));
    $(".pricing").html($(".pricing").html().replace("/pricing/", "http://www.domainbox.com/pricing/"));
    $(".testimonials").html($(".testimonials").html().replace("/testimonials/", "http://www.domainbox.com/testimonials/"));

    //Contact Us
    $(".about").html($(".about").html().replace("/about-us/", "http://www.domainbox.com/about-us/"));
    $(".team").html($(".team").html().replace("/team/", "http://www.domainbox.com/team/"));
    $(".careers").html($(".careers").html().replace("/careers/", "http://www.domainbox.com/careers/"));
    $(".contact").html($(".contact").html().replace("/contact-us/", "http://www.domainbox.com/contact-us/"));

    //Sign me up!
}
