// Fakes the www.orangeslyce.com URL for Dev and Staging
Arkayne.token = '3322-MkRUBmO4HBWSt0zGDdhS';
Arkayne.get_url = function(url) {
  return url.replace('www.staging.', 'www.').replace('127.0.0.1:3000', 'www.orangeslyce.com');
};

jQuery(document).ready(function($){

  // Delayed hiding of flash messages
  (function() {$('#flash').slideUp('slow')}).delay(6);
  
  $('input[type="text"], textarea').each(function() {
    $(this).focus(function () { $(this).parent('dd').children('.help:first').fadeIn('fast'); });
    $(this).blur(function () { $(this).parent('dd').children('.help:first').fadeOut('fast'); });
  });
  
  $('form:first input:visible:first').focus();

  $('input[id^=student_profile_school_name]').autocomplete('/schools', { delay: 0} );
  $('input[id^=student_profile_skills_attributes][id$=name]').autocomplete('/skills', { delay: 0} );
  $('input[id^=student_profile_majors_attributes][id$=name]').autocomplete('/majors', { delay: 0} );
  
  $('input[name=Skill]').autocomplete('/skills');
  $('input[name=Major]').autocomplete('/majors');

  $('#search-bar input[type="text"]').example('logo design, website design, twitter background, etc.');

  $('a[rel*="fancybox"]').fancybox({ 'padding' : 20, 'showNavArrows' : false, 'titleShow' : false }); 
  $('a[rel*="fancybox-page"]').fancybox({ 'padding' : 20, 'showNavArrows' : false, 'titleShow' : false, 'autoDimensions' : false, 'width' : 750, 'height' : 600 }); 
  $('a.portfolio-image').fancybox({ 'padding' : 20, 'titleShow' : false, 'type' : 'image' }); 
  
  // Bind click events to New Project Step 3
  $("a#login-switch").click(function(){
    $('#new_user').val('0'); 
    $('#register-form').slideToggle(); 
    $('#signin-form').slideToggle();
    return false; 
  }); 
  
  $("a#register-switch").click(function(){
    $('#new_user').val('1'); 
    $('#register-form').slideToggle(); 
    $('#signin-form').slideToggle();
    return false; 
  }); 
  
  // Bind the coupon code show link in Step 4
  $("a#coupon-code-link").click(function(){
    $('#coupon-code').slideToggle();
    return false;
  });
});

// Applies a selected style to the selected category
function select_category(category_label) {
  // First removes the selected class on other labels
  jQuery(".selected").each( function() { jQuery(this).removeClass('selected'); } );
  jQuery(category_label).addClass('selected');
}

jQuery.nano = function(template, data){
  return template.replace(/\{([\w\.]*)}/g, function(str, key){
    var keys = key.split("."), value = data[keys.shift()]
    jQuery.each(keys, function(){ value = value[this] })
    return value
  })
}
