

(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);




$(function () {



    //FONT REPLACE INITILIZATION


    Cufon.set('fontFamily', 'Interstate').replace('li a');
    Cufon.set('fontFamily', 'Interstate').replace('h2');
    Cufon.set('fontFamily', 'Interstate').replace('h3');
    Cufon.set('fontFamily', 'Interstate').replace('.title');
    Cufon.set('fontFamily', 'Interstate').replace('label');
    Cufon.set('fontFamily', 'Interstate').replace('.contactform ul');
    Cufon.set('fontFamily', 'Interstate').replace('h5');



    //LOAD FEATURED STORY FROM PRESS
    $("#hello .news span").load("news/index.php?p=2", function () { Cufon.refresh("h2"); });


    //CONTACT FORM



    var contactconfig1 = {
        sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)
        interval: 150, // number = milliseconds for onMouseOver polling interval
        over: showContact, // function = onMouseOver callback (REQUIRED)
        timeout: 250, // number = milliseconds delay before onMouseOut
        out: nothing // function = onMouseOut callback (REQUIRED)
    };

    var contactconfig2 = {
        sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)
        interval: 1, // number = milliseconds for onMouseOver polling interval
        over: showContact, // function = onMouseOver callback (REQUIRED)
        timeout: 250, // number = milliseconds delay before onMouseOut
        out: hideContact // function = onMouseOut callback (REQUIRED)
    };



    $("#Subject").hoverIntent(contactconfig1);
    $(".contactform ul").hoverIntent(contactconfig2);



    $("#Subject").focus(function () {
        showContact();
    });




    $(".contactform li").click(function () {

        var theSubject = $(this).text();
        $("#Subject").attr("value", theSubject);
        $(".contactform ul").slideUp();

    })


    $("#subscribe").click(function () {
		
		/*$('#sub .login').html("<h5>Your subscription has been confirmed. You've been added 			to our list and will hear from us soon.</h5>");
        Cufon.refresh("h5");
		
		return false;*/
		
        var Name = $("input[name='cm-name']").val();
        if (Name == "") {
            alert("Please enter your name");
            $("input[name='cm-name']").focus();
            return false;
        }

        var email = $("input[name='cm-ctijui-ctijui']").val();
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

        if (email == "") {
            alert("Please enter a valid email address");
            $("input[name='cm-ctijui-ctijui']").focus();
            return false;
        }
        else if (!emailReg.test(email)) {
            alert("Please enter a valid email address");
            $("input[name='cm-ctijui-ctijui']").focus();
            return false;
        }
        //var dataString = 'cm-name=' + Name + '&cm-ctijui-ctijui=' + email;
		var dataString = $("#subForm").serialize();
        //alert($("#subForm").serialize());
        //return false;
        $.ajax({
            type: "POST",
            url: "../cm-ajax.php",
            data: dataString,
            success: function (data) {
                //$('.contactform').html("<h5>Thank you for your submission.<br/>We will be in touch shortly.</h5>");
                //Cufon.refresh("h5");
                //"Your subscription has been confirmed. You've been added to our list and will hear from us soon.";
                if ($.trim(data) == 'SUCCESS') {
                    $('#subForm').parent().html("<h5>Your subscription has been confirmed. You've been added 			to our list and will hear from us soon.</h5>");
                    Cufon.refresh("h5");
                }
                else {
                    alert(data);
                }
            }
        });

        return false;
    });

    $("#submitButton").click(function () {
		
		/*$('.contactform').html("<h5>Thank you for your submission.<br/>We will be in touch shortly.</h5>");
                Cufon.refresh("h5");
		return false;*/
		
        // validate and process form
        // first hide any error messages

        var Name = $("input#Name").val();
        if (Name == "") {
            alert("Please enter your name");
            $("input#Name").focus();
            return false;
        }

        var email = $("input#email").val();
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

        if (email == "") {
            alert("Please enter a valid email address");
            $("input#email").focus();
            return false;
        }

        else if (!emailReg.test(email)) {
            alert("Please enter a valid email address");
            $("input#email").focus();
            return false;

        }

        var phone = $("input#Phone").val();

        var company = $("input#company").val();


        var Subject = $("input#Subject").val();
        if (Subject == "") {
            alert("Please choose a subject");
            $("input#Subject").focus();
            return false;
        }

        var Message = $("textarea#Message").val();
        if (Message == "") {
            alert("Please enter a message");
            $("textarea#Message").focus();
            return false;
        }

        var dataString = 'name=' + Name + '&email=' + email + '&company=' + company + '&phone=' + phone + '&Subject=' + Subject + '&Message=' + Message;
        //alert (dataString);return false;

        $.ajax({
            type: "POST",
            url: "js/process.php",
            data: dataString,
            success: function () {
                $('.contactform').html("<h5>Thank you for your submission.<br/>We will be in touch shortly.</h5>");
                Cufon.refresh("h5");
            }
        });
        return false;
    });









    //NAV HOVER CONFIGURATION BEGIN

    var workconfig = {
        sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)
        interval: 1, // number = milliseconds for onMouseOver polling interval
        over: showWork, // function = onMouseOver callback (REQUIRED)
        timeout: 250, // number = milliseconds delay before onMouseOut
        out: nothing // function = onMouseOut callback (REQUIRED)
    };




    //$("#work").hoverIntent(workconfig);




    var bioconfig = {
        sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)
        interval: 1, // number = milliseconds for onMouseOver polling interval
        over: showBios, // function = onMouseOver callback (REQUIRED)
        timeout: 250, // number = milliseconds delay before onMouseOut
        out: nothing // function = onMouseOut callback (REQUIRED)
    };



    //$("#bios").hoverIntent(bioconfig);



    var hideSubNavconfig = {
        sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)
        interval: 250, // number = milliseconds for onMouseOver polling interval
        over: hideSubNav, // function = onMouseOver callback (REQUIRED)
        timeout: 250, // number = milliseconds delay before onMouseOut
        out: nothing // function = onMouseOut callback (REQUIRED)
    };

    /*$("#hello").hoverIntent(hideSubNavconfig);*/
    /*$("#contact").hoverIntent(hideSubNavconfig);*/



    var showSubNavconfig = {
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
        interval: 1, // number = milliseconds for onMouseOver polling interval
        over: showThis, // function = onMouseOver callback (REQUIRED)
        timeout: 250, // number = milliseconds delay before onMouseOut
        out: nothing // function = onMouseOut callback (REQUIRED)
    };


   /* $(".subnavContainer").hoverIntent(showSubNavconfig);*/




    //PERMALINK HASHTAG CODE
	/*
    var hash = window.location.hash.substr(1);
    if (hash != "") {
        var qu = hash;
        var an = "#" + hash;


        $("#wrapper").scrollTo(an, { duration: 1000, axis: "xy", offset: { top: -10, left: 0} });

        $(".subnav a").each(function () {

            var whatisit = $(this).attr('href');
            if (whatisit == an) {
                $(".subnav li a").removeClass("selected");
                $(this).addClass("selected");
                Cufon.refresh("li a");
            }
        });
		


    }*/




    //NAV SCROLL COMMANDS
	
	
    $("#nav a").click( function (event) {
		
        if ( $(this).hasClass("press") ) { }
        else {
			
            var thehash = $(this).attr('href');
            /*event.preventDefault();*/
            $(".subnavContainer").css({ position: "absolute", margin: "0" });
            var qu = $(this).attr("href");
            var an = "#" + qu.replace("q", "a");
			
            $("#wrapper").scrollTo(an, { duration: 1000, axis: "xy", offset: { top: -10, left: 0} });
			
            $(".subnav li a").removeClass("selected");
			
            if ($(this).hasClass("bionav")) {
                $(".biossubnavContainer").animate({ top: "10px" });
                $(".worksubnavContainer").animate({ top: "-480px" });
                $(".biossubnavContainer ul li a:first").addClass("selected");
                Cufon.refresh("li a");
            }

            else if ($(this).hasClass("worknav")) {
                $(".biossubnavContainer").animate({ top: "-480px" });
                $(".worksubnavContainer").animate({ top: "10px" });
                $(".worksubnavContainer ul li a:first").addClass("selected");
                Cufon.refresh("li a");

            }

            else {
				
                $(".biossubnavContainer").animate({ top: "-480px" });
                $(".worksubnavContainer").animate({ top: "-480px" });
            }

            Cufon.refresh("li a");
            window.location.hash = thehash;
        }
		

    });


	
    $(".title h2 a").click(function (event) {

        if ($(this).hasClass("press")) { }
        else {
            /*var thehash = $(this).attr('href');
            event.preventDefault();
            $(".subnavContainer").css({ position: "absolute", margin: "0" });
            var qu = $(this).attr("href");
            var an = "#" + qu.replace("q", "a");
            $("#wrapper").scrollTo(an, { duration: 1000, axis: "xy", offset: { top: -10, left: 0} });*/
            $(".subnav li a").removeClass("selected");/*
            $(qu + " .subnavContainer li a:first").addClass("selected");
            Cufon.refresh("li a");
            window.location.hash = thehash;*/
        }
    });




    $(".news a").click(function (event) {
        event.preventDefault();/*
        $(".subnavContainer").css({ position: "absolute", margin: "0" });
        var qu = $(this).attr("href");
        var an = "#" + qu.replace("q", "a");
        $("#wrapper").scrollTo(an, { duration: 1000, axis: "xy", offset: { top: -10, left: 0} });*/
        $(".subnav li a").removeClass("selected");/*
        $(qu + " .subnavContainer li a:first").addClass("selected");
        Cufon.refresh("li a");*/
    });



    $(".worksubnavContainer a").click(function (event) {
        var thehash = $(this).attr('href');
        /*event.preventDefault();*/
        $(".subnav a").removeClass("selected");
        $(this).addClass("selected");
        Cufon.refresh("li a");
        var qu = $(this).attr("href");
        var an = "#" + qu.replace("q", "a");
        /*$("#wrapper").scrollTo(an, { duration: 1000, axis: "xy", offset: { top: -10, left: 0} });*/
        window.location.hash = thehash;

    });



    $(".biossubnavContainer a").click(function (event) {
        var thehash = $(this).attr('href');
        event.preventDefault();
        $("#bios .subnavContainer").css({ position: "fixed", margin: "10px 0 0 0" })
        $(".subnav a").removeClass("selected");
        $(this).addClass("selected");
        Cufon.refresh("li a");
        var qu = $(this).attr("href");
        var an = "#" + qu.replace("q", "a");
        /*$("#wrapper").scrollTo(an, { duration: 1000, axis: "xy", offset: { top: -10, left: 0} });*/
        window.location.hash = thehash;
    });




});


	//SUBNAV ANIMATION
	function showWork() {
        $(".biossubnavContainer").animate({top:"-480px"});
        $(".worksubnavContainer").animate({top:"10px"});
	}
	
	function showBios() {
	    $(".biossubnavContainer").animate({top:"10px"});
        $(".worksubnavContainer").animate({top:"-480px"});
	}
	
	function hideSubNav() { 
        $(".biossubnavContainer").animate({top:"-480px"});
        $(".worksubnavContainer").animate({top:"-480px"});
	}
	
	function nothing() {} //do not delete
	
	function showThis() { 
		$(this).css("top","10px");
		showing = "true";
	}
	
	function showContact() {
        $(".contactform ul").slideDown("fast");
	}
	
	function hideContact() {
        $(".contactform ul").slideUp("fast");
	}	
