var site = function(){
	this.navLi = $('#nav > li').children('ul').hide().end();
	this.init();	
};

site.prototype = {
	init : function() {
		this.setMenu();
		this.setSearch();
	},
	setMenu : function() {
		this.navLi.hover(function(){
			$(this).find('> ul').stop(true, true).slideDown(200);
		}, function() {
			$(this).find('> ul').stop(true, true).fadeOut(100);
		});
	},
	setSearch : function() {
		$('#search').focusin(function(){
			$('#search').attr('value', '');
		});
	}
	
}

new site();

$(document).ready(function() {

// slide jobs


	$('.dealer.first').each(function(){ 
    	var $this = $(this); 
    	$this 
       .add( $this.next('.dealer.last') ) 
       .wrapAll('<div class="option_wrap" />'); 
	}); 

	$('.team.first').each(function(){ 
    	var $this = $(this); 
    	$this 
       .add( $this.next('.team.last') ) 
       .wrapAll('<div class="team_wrap" />'); 
	}); 

	var tallest = 0;

$('.option_wrap').each(function() {

	var firstHeight = $(this).children('.dealer.first').height();
	var lastHeight = $(this).children('.dealer.last').height();
	if (firstHeight > lastHeight) {
		tallest = firstHeight;
	} else {
		tallest = lastHeight;
	}

$(this).children('.dealer').height(tallest);
})

$('.team_wrap').each(function() {

	var firstHeight = $(this).children('.team.first').height();
	var lastHeight = $(this).children('.team.last').height();
	if (firstHeight > lastHeight) {
		tallest = firstHeight;
	} else {
		tallest = lastHeight;
	}

$(this).children('.team').height(tallest);
})

});

function clear_form_elements(ele) {

    $(ele).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });

}

// list splitter

/*
 *  easyListSplitter 1.0.2 - jQuery Plugin
 *  written by Andrea Cima Serniotti    
 *  http://www.madeincima.eu
 *
 *  Copyright (c) 2010 Andrea Cima Serniotti (http://www.madeincima.eu)
 *  Dual licensed under the MIT (MIT-LICENSE.txt)
 *  and GPL (GPL-LICENSE.txt) licenses.
 *
 *  Built for jQuery library
 *  http://jquery.com
 *
 */
  
 /*
    To activate the plugin add the following code to your own js file:
     
    $('.your-list-class-name').easyListSplitter({ 
            colNumber: 3,
            direction: 'horizontal'
    });
     
 */
 
var j = 1;
  
(function(jQuery) {
    jQuery.fn.easyListSplitter = function(options) {
     
    var defaults = {            
        colNumber: 2, // Insert here the number of columns you want. Consider that the plugin will create the number of cols requested only if there are enough items in the list.
        direction: 'vertical'
    };
             
    this.each(function() {
         
        var obj = jQuery(this);
        var settings = jQuery.extend(defaults, options);
        var totalListElements = jQuery(this).children('li').size();
        var baseColItems = Math.ceil(totalListElements / settings.colNumber);
        var listClass = jQuery(this).attr('class');
         
        // -------- Create List Elements given colNumber ------------------------------------------------------------------------------
         
        for (i=1;i<=settings.colNumber;i++)
        {   
            if(i==1){
                jQuery(this).addClass('listCol1').wrap('<div class="listContainer'+j+'"></div>');
            } else if(jQuery(this).is('ul')){ // Check whether the list is ordered or unordered
                jQuery(this).parents('.listContainer'+j).append('<ul class="listCol'+i+'"></ul>');
            } else{
                jQuery(this).parents('.listContainer'+j).append('<ol class="listCol'+i+'"></ol>');
            }
                jQuery('.listContainer'+j+' > ul,.listContainer'+j+' > ol').addClass(listClass);
        }
         
        var listItem = 0;
        var k = 1;
        var l = 0;  
         
        if(settings.direction == 'vertical'){ // -------- Append List Elements to the respective listCol  - Vertical -------------------------------
             
            jQuery(this).children('li').each(function(){
                listItem = listItem+1;
                if (listItem > baseColItems*(settings.colNumber-1) ){
                    jQuery(this).parents('.listContainer'+j).find('.listCol'+settings.colNumber).append(this);
                } 
                else {
                    if(listItem<=(baseColItems*k)){
                        jQuery(this).parents('.listContainer'+j).find('.listCol'+k).append(this);
                    } 
                    else{
                        jQuery(this).parents('.listContainer'+j).find('.listCol'+(k+1)).append(this);
                        k = k+1;
                    }
                }
            });
             
            jQuery('.listContainer'+j).find('ol,ul').each(function(){
                if(jQuery(this).children().size() == 0) {
                jQuery(this).remove();
                }
            }); 
             
        } else{  // -------- Append List Elements to the respective listCol  - Horizontal ----------------------------------------------------------
             
            jQuery(this).children('li').each(function(){
                l = l+1;
 
                if(l <= settings.colNumber){
                    jQuery(this).parents('.listContainer'+j).find('.listCol'+l).append(this);
                     
                } else {
                    l = 1;
                    jQuery(this).parents('.listContainer'+j).find('.listCol'+l).append(this);
                }               
            });
        }
         
        jQuery('.listContainer'+j).find('ol:last,ul:last').addClass('last'); // Set class last on the last UL or OL 
        j = j+1;
         
    });
    };
})(jQuery);

     
    $('.dealer_nav').easyListSplitter({ 
            colNumber: 2,
            direction: 'horizontal'
    });

$('.careers .listCol1.dealer_nav').css('margin', 0);
$('.careers .listCol2.dealer_nav li').first().addClass('first');

$('.careers .job_posting').height(200).css({'overflow' : 'hidden', 'margin-bottom': 18}).after( '<p><a class="more_link" href="#">More</a></p>' ).next().click(function(event) {
  event.preventDefault();
 $(this).prev().height('auto');
 $(this).hide();
});

