; (function($) {

    $.columnize = {
        columns: 3
    }

    $.fn.extend({

        columnize: function(options) {

            var options = $.extend($.columnize, options);


            return this.each(function() {
                var obj = $(this);
                var item_count = obj.find('li').length;
                var per_column = Math.ceil(item_count / options.columns);

                for (var i = 0; i < options.columns; i++) {
                    obj.before($('<ul></ul>'));
                    var column = obj.prev();

                    items = obj.find('li').slice(0, per_column);
                    column.append(items);
                }
                obj.remove();

            }); // end return
        } // end function
    }); // end extend
})(jQuery);


; (function($) {

    $.inputclear = {
}

$.fn.extend({

    inputclear: function(options) {

        var options = $.extend($.slidenstop, options);


        return this.each(function() {
            var obj = $(this);

            if (obj.is('input:text, textarea')) {
                obj.focus(function() {
                    if (!$(this).hasClass('activated')) {
                        $(this).addClass('activated');
                        $(this).data("initVal", $(this).val());
                        $(this).val('');
                    }
                });
                obj.blur(function() {
                    if (jQuery.trim($(this).val()) == '') {
                        $(this).val($(this).data('initVal'));
                        $(this).removeClass('activated');
                    }
                })
            }
        }); // end return
    } // end function
}); // end extend
})(jQuery);

; (function($) {

    var select_obj, target_obj, options;

    $.select_mod = {
        hilight_class: 'hilight',
        hilight_color: '#ffffff',
        default_color: '#092e4b',
        hover_color: '#f67b01'
    }

    $.fn.extend({

        select_mod: function(_target, _options) {

            options = $.extend($.select_mod, _options);
            target_obj = _target;

            return this.each(function() {
                select_obj = $(this);

                doHighlight();

                select_obj.change(function() {
                    doHighlight();
                }) // change

            }); // end return
        } // end function
    }); // end extend


    function doHighlight() {
        var selected_class = '';

        select_obj.find('option:selected').each(function() {
            selected_class = $(this).val();

            target_obj.each(function() {
                $(this).find('li').each(function() {
                    $(this).removeClass(options.hilight_class);

                    if ($(this).hasClass(selected_class) || selected_class == 'all') {
                        $(this).addClass(options.hilight_class);
                        //$(this).find('a').css('color', options.hilight_color);
                        $(this).find('a').animate({ color: options.hilight_color }, 300);
                    } else {
                        //$(this).find('a').css('color', options.default_color);
                        $(this).find('a').animate({ color: options.default_color }, 300);
                    }

                }) // each
            }) // each
        }) // each 
    }

})(jQuery);
;(function($) {

	var feature_obj, nav, items, timeout;
	
	$.feature = {		
		defaults: {
			delay: 5000,
			animtime: 1200,
			mode: 'slide'
		}	
	};

	$.fn.extend({
		
		feature: function(options) {
	
			options = $.extend({}, $.feature.defaults, options);
		
			return this.each(function() {
				feature_obj = $(this);
				nav = feature_obj.find('ul.nav');
				items = feature_obj.find('ul.items');
				
				$.data(feature_obj, "feature", options);

				create_pagination();
				create_pagination_actions();	
			
				init_items();		
				feature_action(0);										
				
				start_timeout();			
			})
									
		} // end function
	});
	
	function settings(element) {
		return $.data(element, "feature");
	}
	
	function create_pagination() {
		var news_count = items.find('li').length;

		nav.empty();
				
		for(i=1; i < (news_count + 1); i++) {
			nav.append('<li><a href="#news_'+ i +'" title="Read this news item">'+ i +'</a></li>');
		}		
	}

	function create_pagination_actions() {
		var nav_anchors = nav.find('li a');
		var width = feature_obj.width();
		
		nav_anchors.click(function() {
			var index = $(this).text() - 1;
			
			clearInterval(timeout);
			feature_action(index);				
		});
	}
		
	function init_items() {	
		switch(settings(feature_obj).mode) {
			case "slide":		
				var item_count = items.find('li').length;
				var width = items.find('li').outerWidth();
				
				items.width(item_count * width);		
				
				break;
			case "fade":
				items.find('li').each(function(i) {
					$(this).css({
						position: 'absolute',
						top:      0,
						left:     0,
						opacity:  0
					});
				})
				items.find('li:first').css({
					opacity: 1
				});
				break;
			default:		
		}
	}
	
	function feature_action(index) {
		switch(settings(feature_obj).mode) {
			case "slide":
				var width = items.find('li').outerWidth();
				var pos = index * width * -1;
				
				items.animate({
					left: pos
				}, settings(feature_obj).animtime, 'swing');	
				
				
				
				break;
			case "fade":
				var current_index  = (nav.find('li.selected a').length > 0) ?  nav.find('li.selected a').text() - 1 : nav.find('li').length - 1;
				var move_to_index  = index;
												
				//items.find('li:eq('+ index +')').css({ opacity: 1, zIndex: index });
				items.find('li:eq('+ move_to_index  +')').show().css({ zIndex: index + 1 }).animate({ opacity: 1 }, settings(feature_obj).animtime / 2, 'swing');				
				items.find('li:eq('+ current_index  +')').css({ zIndex: index }).animate({ opacity: 0 }, settings(feature_obj).animtime, 'linear', function() { $(this).hide(); });				
				
				break;
			default:
		}
		
		nav.find('li').removeClass('selected');
		nav.find('li:eq('+ index +')').addClass('selected');
	}
	
	function start_timeout() {
		timeout = setInterval(function() {
			var current_index = nav.find('li.selected a').text();
			var item_count    = nav.find('li').length;
			var new_index;
			
			if (current_index < item_count) {
				new_index = current_index++;
			} else {
				new_index = 0;
			}
			feature_action(new_index);
			
		}, settings(feature_obj).delay);
	}

})(jQuery);
