﻿/* ------------------ON LOAD ----------- */
$(document).ready(function() {
    $("#fbIframe").attr('allowTransparency', 'true');
    //Fade effect on links : no custom .js, plain jquery
    $(".fadehover").mouseover(function() {
        $(this).stop().animate({ "opacity": ".25" }, 0);
        $(this).attr("src", $(this).attr("src").replace("-off.", "-on."));
        $(this).stop().animate({ "opacity": "1" }, "slow");
    }).mouseout(function() {
        $(this).attr("src", $(this).attr("src").replace("-on.", "-off."));
    });

    //rollover effect on links : no custom .js, plain jquery
    $(".simplehover").mouseover(function() {
        $(this).attr("src", $(this).attr("src").replace("-off.", "-on."));
    }).mouseout(function() {
        $(this).attr("src", $(this).attr("src").replace("-on.", "-off."));
    });
	
	$(".toHide").hide();

    //Tooltips : tools.tooltip-1.1.3.min.js & tools.tooltip.slide-1.0.0.min.js
    $(".tooltip[title]").tooltip({ tip: '#tooltip', effect: 'slide', offset: [10, 0] });

    //Expose : tools.expose-1.0.5.min.js
    $("form.expose").bind("click keydown", function() {
        $(this).expose({
            maskId: 'expose',
            api: true
        }).load();
    });

    //The 3 big boxes
    $(".boxslidedown").mouseenter(function() {
        $(this)
            .css({ background: $(this).css("background-image").replace("-off.", "-on.") + ' no-repeat' })
            .stop().animate({ "top": "+=5px" }, 200);
    }).mouseleave(function() {
        $(this)
            .css({ background: $(this).css("background-image").replace("-on.", "-off.") + ' no-repeat' })
            .stop().animate({ "top": "0px" }, 100);
    });


    //Load client ribbon carousel : jquery.jcarousel.pack.js
    jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) { if ((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b; } else if (t < (2 / 2.75)) { return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b; } else if (t < (2.5 / 2.75)) { return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b; } else { return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b; } };
    $('#ribboncarousel').jcarousel({ auto: 5, easing: 'BounceEaseOut', animation: 1000, wrap: 'last' });


    //Banners slideshow
    $('#slideshow').cycle({ timeout: 10000, next: '#slideshow-next' });
    $('#slideshowtop').cycle({ timeout: 10000, next: '#slideshow-next' });

    $("#slideshow-play").hide();
    $('#slideshow-play').click(function() { $("#slideshow").cycle('resume'); $("#slideshowtop").cycle('resume'); $("#slideshow-play").hide(); $("#slideshow-pause").show(); })
    $('#slideshow-pause').click(function() { $("#slideshow").cycle('pause'); $("#slideshowtop").cycle('pause'); $("#slideshow-pause").hide(); $("#slideshow-play").show(); })


    //Highlight textboxes on focus
    $(".textbox").focusin(function() { $(this).addClass("textbox-on"); });
    $(".textbox").focusout(function() { $(this).removeClass("textbox-on"); });


    //Pulsate Thank you after submit form
    $("#ctl00_divSent").effect("pulsate", { times: 2 }, 700);

    //This is to confuse Form Bots. we apply new class 'jqueryttrraappme' with hide the traping textbox.
    $(".jquerytrapme").addClass("jqueryttrraappme");


    $(".socialboxes").corner();

});




/* ------------------------------------- FUNCTIONS ----------- */
//Load the form popup when requested
function formpopup(detailed) {

    if (detailed) {
        $("#form-detailed").attr('style', 'display:block;');
        $(".txtNotesPopup").attr('style', 'height:100px;');
        $(".txtHidden").attr('value','Quote Request');
    }
    else {
        $("#form-detailed").attr('style', 'display:none;');
        $(".txtNotesPopup").attr('style', 'height:220px;');
        $(".txtHidden").attr('value', 'Simple Request');
    }
    
    
    $("#form-popup").modal({
        onOpen: function(dialog) {
            dialog.overlay.fadeIn('slow', function() {
                dialog.data.hide(); 
                dialog.container.fadeIn('slow', function() {
                    dialog.data.slideDown('slow');
                });
            });
        },
        overlayClose: true,
        containerId:'form-popup',
        appendTo:'form'
    });


}


//List controls to be validated here for the popup form
function ValidatePopupForm() {
    isValid = true;

    if (!ValidateField($("#ctl00_ucPopupForm_txtName"))) {isValid = false;}
    if (!ValidateField($("#ctl00_ucPopupForm_txtEmail"))) { isValid = false; }

    if (isValid) { DisableSubmit($("#ctl00_ucPopupForm_btnSubmit")); }
    LogSubmitInAnalytics(isValid, 'Popup: ' + $(".txtHidden").val());
    
    return isValid;
}

//List controls to be validated here for the contact us page form
function ValidateForm() {
    isValid = true;

    if (!ValidateField($("#ctl00_cphMain_ucContactForm_txtName"))) { isValid = false; }
    if (!ValidateField($("#ctl00_cphMain_ucContactForm_txtEmail"))) { isValid = false; }

    if (isValid) { DisableSubmit($("#ctl00_cphMain_ucContactForm_btnSubmit")); }
    LogSubmitInAnalytics(isValid, 'Form');
    
    return isValid;
}


function ValidateField(obj) {
    if (obj.val().length > 1) {
        obj.removeClass("textbox-error");
        return true;
    }
    else {
        obj.addClass("textbox-error");
        return false;
    }
}

function DisableSubmit(obj) {
    obj.attr("src", obj.attr("src").replace("submit-on.png", "wait.png"));
    obj.attr("src", obj.attr("src").replace("submit-off.png", "wait.png"));
}

function LogSubmitInAnalytics(isValid, sName) {
    if (isValid) { 
		
		//pageTracker._trackEvent('Forms', 'Submit', sName); 
		_gaq.push(['_trackEvent', 'Forms', 'Submit', sName]);
		//alert('Forms + Submit :' + sName);
	}
    else { }
}
