var COLLINS_APP = {};

/*    
	Text refill
*/
COLLINS_APP.refillText = {

    initValues : new Array(),

    init: function() {
        var iv = new Array();
        $('input.input-refill').each( function() {
            $i = $(this);
            iv[$i.attr('id')] = $i.val();
            COLLINS_APP.refillText.watchFieldEvent(this);
        });
        this.initValues = iv;
    },
   
    watchFieldEvent: function(field) {
        var $field = $(field);
        $field.focus( function() {
            var v = $field.val();
            var id = $field.attr('id');
            if ( COLLINS_APP.refillText.initValues[id] == v ) {
                $field.val('');
            }
        });
        $field.blur( function() {
            if ( $field.val() == '' ) {
                $field.val( COLLINS_APP.refillText.initValues[$field.attr('id')] );
            }
        });
    }
   
};


/*    Match Columns
	-------------
	This function loops through a result set and for each result,
	it matches the height of the longest result.
*/
$.fn.matchColumns = function() {
	var height_tar = 0, height_obj, pad_top, pad_bot, bor_top, bor_bot, offset;

	this.each(function() {
		height_obj = $(this).outerHeight();
		height_tar = Math.max(height_tar, height_obj);
	});

	this.each(function() {
		pad_top = parseInt($(this).css("padding-top"), 10),
		pad_bot = parseInt($(this).css("padding-bottom"), 10),
		offset  = pad_top + pad_bot;

		// fix for ie6
		if ($.browser.msie && $.browser.version == 6) {
			$(this).css("height", (height_tar - offset) + "px");
		} else {
			$(this).css("min-height", (height_tar - offset) + "px");
		}

	});

}

	

$(document).ready(function(){

	//Superfish menu
	$("ul.sf-menu").supersubs().superfish(
	{
				delay:       1000,                            // one second delay on mouseout
				animation:   {opacity:'show'},  // fade-in and slide-down animation
				speed:       'normal',                          // faster animation speed
				autoArrows:  false,                           // disable generation of arrow mark-up
				dropShadows: false                            // disable drop shadows
			}
	);
	
	//Toggle functions
	 $("#toggle-all").toggle(
						function(){
							 $(".excerpt").hide('slow');
				 $("#toggle").attr("class","show-all");
						}, function() {
							 $(".excerpt").show('slow');
				 $("#toggle").attr("class","hide-all");
						});
	
	$(".hide-excerpt").click(function (event) {
		event.preventDefault();
		  $(this).parents(".excerpt").hide("normal");
		});
	
	$(".view-excerpt").click(function (event) {
		event.preventDefault();
		  $(this).parents(".headline").next(".excerpt").toggle("normal");
		});
	
	//$("#widget-articles .inner, #left").matchColumns();
	
	if( !$(".home-content").length ) {
		$(window).load( function() {
			$(".widget-border, #left").matchColumns();
		});
	} else {
		$(window).load( function() {
			$("#widget-home-kickers .widget-border, #left .single_content").matchColumns();
		});
	}
	
	// handle text field replacement
	COLLINS_APP.refillText.init();

 });

