// FORM VALIDATION

$(document).ready(function(){
    // binds form submission and fields to the validation engine
    $("#estimate-form").validationEngine();
});

/**
 *
 * @param {jqObject} the field where the validation applies
 * @param {Array[String]} validation rules for this field
 * @param {int} rule index
 * @param {Map} form options
 * @return an error string if validation failed
 */
function checkHELLO(field, rules, i, options){
    if (field.val() != "HELLO") {
        // this allows to use i18 for the error msgs
        return options.allrules.validate2fields.alertText;
    }
}

$(document).ready(function(){
    // binds form submission and fields to the validation engine
    $("#claim-form-wrap").validationEngine();
});

/**
 *
 * @param {jqObject} the field where the validation applies
 * @param {Array[String]} validation rules for this field
 * @param {int} rule index
 * @param {Map} form options
 * @return an error string if validation failed
 */
function checkHELLO(field, rules, i, options){
    if (field.val() != "HELLO") {
        // this allows to use i18 for the error msgs
        return options.allrules.validate2fields.alertText;
    }
}

$(document).ready(function(){
    // binds form submission and fields to the validation engine
    $("#contact-form").validationEngine();
});

/**
 *
 * @param {jqObject} the field where the validation applies
 * @param {Array[String]} validation rules for this field
 * @param {int} rule index
 * @param {Map} form options
 * @return an error string if validation failed
 */
function checkHELLO(field, rules, i, options){
    if (field.val() != "HELLO") {
        // this allows to use i18 for the error msgs
        return options.allrules.validate2fields.alertText;
    }
}


// MOVE CALENDAR TABS

$(document).ready(function() {
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});


// TWITTER FEED
    
$(function() {    
    $.getJSON('http://twitter.com/status/user_timeline/DircksMoving.json?count=2&callback=?', function(data){
            $.each(data, function(index, item){
                    $('#twitter-feed').append('<div class="tweet"><li>' + item.text.linkify() + '  <span><strong>' + relative_time(item.created_at) + '</strong></span></li></div>');
            });
    
    });   
    
    function relative_time(time_value) {
      var values = time_value.split(" ");
      time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
      var parsed_date = Date.parse(time_value);
      var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
      var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
      delta = delta + (relative_to.getTimezoneOffset() * 60);
      
      var r = '';
      if (delta < 60) {
            r = 'a minute ago';
      } else if(delta < 120) {
            r = 'couple of minutes ago';
      } else if(delta < (45*60)) {
            r = (parseInt(delta / 60)).toString() + ' minutes ago';
      } else if(delta < (90*60)) {
            r = 'an hour ago';
      } else if(delta < (24*60*60)) {
            r = '' + (parseInt(delta / 3600)).toString() + ' hours ago';
      } else if(delta < (48*60*60)) {
            r = '1 day ago';
      } else {
            r = (parseInt(delta / 86400)).toString() + ' days ago';
      }
      
      return r;
    }
    
    String.prototype.linkify = function() {
            return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
                    return m.link(m);
            });
    };
    
});

// MAIN NAV SLIDE DOWN

$(document).ready(function (){  
  $("#main-nav ul li").menu({
  	autohide: 0,
	autostartSpeed: 0
  });
});


// FORM FOCUS

$(document).ready(function(){
        $("input, select, textarea").focus(function() {
                $(this).parent().addClass("curFocus")
        });
        $("input, select, textarea").blur(function() {
                $(this).parent().removeClass("curFocus")
        });
});

// BUBBLE POPUP ON STORAGE FACILITY IMAGE

$(document).ready(function(){
	// create bubble popups
	$('.popup').CreateBubblePopup({
					innerHtmlStyle: {
										color:'#FFFFFF', 
										'text-align':'center',
										'font-size' :'1em'
									},						
					themeName: 	'all-black',
					themePath: 	'http://dircks.santysandbox.com/images/jquerybubblepopup-theme'
			});		
	$('#popup1').SetBubblePopupInnerHtml('200,000 total sq.ft.');
	$('#popup2').SetBubblePopupInnerHtml('2,500 sq.ft. of air conditioned storage');
	$('#popup3').SetBubblePopupInnerHtml('34 ft. clear height ceilings');		
	$('#popup4').SetBubblePopupInnerHtml('12 overhead doors w/ ramps');
	$('#popup5').SetBubblePopupInnerHtml('80 ft. long, 200,000 lb. capacity public scale');
	$('#popup6').SetBubblePopupInnerHtml('Parking for 50 trucks');
});




