$(document).ready(function () {
    //--  create and initiate the Project thumbs and the About Us section

    //init fade variables
    var fadeSpeed = 1000;
    var fadeDelay = 500;

    //initial thumbnail state
    $('.project').each(function () {
        //$(this).children('a').children('.projectInfo').delay(fadeDelay).fadeTo(fadeSpeed,.08);
        $(this).children('a').children('.projectInfo').delay(fadeDelay).animate({ color: "#393937" }, fadeSpeed);
        $(this).children('a').children('.projectImage').children('.projectImageHover').delay(fadeDelay).fadeTo(fadeSpeed, .08);
    });

    //initial 'about us' state
    $('.fader, .faderCareer, .careerAnchorTitle, #careersHeader').each(function () {
        $(this).delay(700).animate({ color: "#393937" }, fadeSpeed);
        fadeDelay += 100;
    });
    $('.contourField').addClass("faderCareer");

    $("#accordion").accordion({ autoHeight: false, active: false, collapsible: true });    
    
    mCustomScrollbars();

    //initial 'careers' state

    $('#careersContainer').hide();
    $('#careersCollapseBtn').click(function () {
        $('#careersContainer').slideToggle('slow');
        if ($('#careersContainer').css('display') == 'block') {
            var $elem = $('body');
            $('html, body').animate({ scrollTop: $elem.height() }, 1000);

        }
    });

    $('.contourError').click(function () {
        $(this).css('display', 'none');
    });

    $('#contour .contourError').append("<span class='dismissX'>X</span>");

    //accordion scrollbar initialising
    $('.careerAnchorTitle').click(function () {
        setTimeout(function () {
            $("#mcs_container").mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "auto", "yes", "yes", 10);
            $("#mcs1_container").mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "auto", "yes", "yes", 10);
            $("#mcs2_container").mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "auto", "yes", "yes", 10);
        }, 300);
    });

    setupThumbs();
    setupAboutUs();
    setupCareers();

    $('#footer ul li').first().css('margin-left', '0');

    $(this).find(":submit").attr('value', 'Shoot');

});  

//-------------------------------------------------------------------------
//-------------------------------------------- PROJECT THUMBS -------------
//-------------------------------------------------------------------------
function setupThumbs(){
  //for each thumbnail
  $('.project').each(function() {
    
    //add the mouse events
    $(this).mouseenter(function() {
      $(this).children('a').children('.projectImage').children('.projectImageHover').stop(true,true).fadeTo(500,1);
      $(this).children('a').children('.projectInfo').stop(true,true).animate({color: "#fff"});
    }).mouseleave(function() {
      // on mouse out, check if the thumb is already active
      // if it is active, do nothing to the thumb
      if ($(this).hasClass('active'))
      {
        // this will do nothing when on home page
      } 
      // if its not active, fade it out
      else 
      { 
        $(this).children('a').children('.projectImage').children('.projectImageHover').stop(true,true).fadeTo(500,.08);
        $(this).children('a').children('.projectInfo').stop(true,true).animate({color: "#393937"});
      }
    });
  });
}  

//-------------------------------------------------------------------------
//-------------------------------------------- ABOUT US ROW ---------------
//-------------------------------------------------------------------------
function setupAboutUs(){
  //for each thumbnail
  $('.fader').each(function() {
    
    //add the mouse events
    $(this).mouseenter(function() {
      $(this).stop(true,true).animate({color: "#fff"});
      
    }).mouseleave(function() {
      $(this).stop(true,true).animate({color: "#393937"});
    });

});
}

//-------------------------------------------------------------------------
//-------------------------------- CAREER CUSTOM SCROLLBARS ---------------
//-------------------------------------------------------------------------

function mCustomScrollbars() {
      /*
      malihu custom scrollbar function parameters:
      1) scroll type (values: "vertical" or "horizontal")
      2) scroll easing amount (0 for no easing)
      3) scroll easing type
      4) extra bottom scrolling space for vertical scroll type only (minimum value: 1)
      5) scrollbar height/width adjustment (values: "auto" or "fixed")
      6) mouse-wheel support (values: "yes" or "no")
      7) scrolling via buttons support (values: "yes" or "no")
      8) buttons scrolling speed (values: 1-20, 1 being the slowest)
      */
      $("#mcs_container").mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "auto", "yes", "yes", 10);
      $("#mcs1_container").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"auto","yes","yes",10);
      $("#mcs2_container").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"auto","yes","yes",10);
      //$("#mcs3_container").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"auto","yes","yes",10);  

      $('#accordion').each(function () {
          //add the mouse events

          $(this).mouseenter(function () {
              $('#accordion #mcs_container, #mcs_container .customScrollBox p, #mcs1_container .customScrollBox p, #mcs2_container .customScrollBox p, .careerAnchorTitle').stop(true, true).animate({ color: "#fff", borderColor: "#fff" });             
          }).mouseleave(function () {
              $('#mcs_container, #mcs_container .customScrollBox p, #mcs1_container .customScrollBox p, #mcs2_container .customScrollBox p, .careerAnchorTitle').stop(true, true).animate({ color: "#393937", borderColor: "#393937" });
             
          });

      });          
}

/* function to fix the -10000 pixel limit of jquery.animate */
$.fx.prototype.cur = function () {
    if ((this.elem[this.prop] != null) && (!this.elem.style || this.elem.style[this.prop] == null)) {
    return this.elem[this.prop];
    }
    var r = parseFloat(jQuery.css(this.elem, this.prop));
    return typeof r == 'undefined' ? 0 : r;
}

/* function to load new content dynamically */
function LoadNewContent(id, file) {
    $("#" + id + " .customScrollBox .content").load(file, function () {
        mCustomScrollbars();
    });
}

function setupCareers() {

 $('#careers').each(function () {
        //add the mouse events

        $(this).mouseenter(function () {
            $('#careersHeader').stop(true, true).animate({ color: "#fff", border: "#fff" });           
        }).mouseleave(function () {
            $('#careersHeader').stop(true, true).animate({ color: "#393937", border: "#393937" });
        });                
    });

    $('#careersapplyForm').each(function () {
        //add the mouse events

        $(this).mouseenter(function () {
            $('#careersapplyForm h2, .faderCareer, #contour .contourButton, #contour textarea, .contourFieldSet, #contour label, .contourFieldSet small').stop(true, true).animate({ color: "#fff", border: "#fff" });
            $('#contour input.fileupload').stop(true, true).animate({ color: "#E2B200" });
        }).mouseleave(function () {
            $('#careersapplyForm h2, .faderCareer, #contour .contourButton, #contour textarea, .contourFieldSet, #contour label, .contourFieldSet small').stop(true, true).animate({ color: "#393937", border: "#393937" });
            $('#contour input.fileupload').stop(true, true).animate({ color: "#8b6e02" });
        });                
    });

    $(function () {
        $('input#ContentPlaceHolderDefault_ctl15_RenderForm_4_rpFieldsets_rpFields_0_477388c7_6ada_4cab_a752_8ce2df88db5f_3').wheelColorPicker({ dir: '.' });
        $('input#ContentPlaceHolderDefault_ctl15_RenderForm_4_rpFieldsets_rpFields_0_477388c7_6ada_4cab_a752_8ce2df88db5f_3').val("#");
    });

}

