(function($) {
    $(document).ready(function() {
        
        
        // search default value
        $.fn.search = function()
        {
            // nothing is entered by default
            if (!this.hasClass('entered'))
            {
                return this.focus(function()
                {
                    if( this.value == this.defaultValue )
                    {
                        this.value = "";
                    }
                }).blur(function() {
                    if( !this.value.length )
                    {
                        this.value = this.defaultValue;
                    }
                });

            }
        };

        $("#searchFormQuery").search();
        
        
        
        $('.fancy').each(function()
        {
            var urlParts = $(this).attr('id').split('_');
            
            $(this).attr('href', $(this).attr('href') + '?block=' + urlParts[0]);
            
            if (typeof urlParts[1] != 'undefined')
            {
                $(this).attr('href', $(this).attr('href') + '&id=' + urlParts[1]);
            }
        })
        
        .fancybox({
            overlayOpacity : 0.5,
            overlayColor : '#000000',
            hideOnOverlayClick : false,
            enableEscapeButton : false,
            showNavArrows : (typeof hideArrows != 'undefined' ? false : ($.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest ? false : true)),
            titleShow: false,
			onComplete : function() {$("#fancybox-wrap").unbind('mousewheel.fb'); $('#fancybox-content').width($('.itemContent').width() + 20); $('#fancybox-wrap').width($('.itemContent').width() + 58); $.fancybox.center(true); $("#fancybox-wrap").fadeIn(200);}
        });
        
        
        $('.fancybox').fancybox({
            overlayOpacity : 0.5,
            overlayColor : '#000000',
            hideOnOverlayClick : false,
            enableEscapeButton : false,
			scrolling : 'no',
            showNavArrows : (typeof hideArrows != 'undefined' ? false : ($.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest ? false : true)),
            titleShow: false,
			onComplete : function() {$("#fancybox-wrap").unbind('mousewheel.fb'); $('#fancybox-content').width($('.itemContent').width() + 20); $('#fancybox-wrap').width($('.itemContent').width() + 58); $.fancybox.center(true);}
        });
        				
				
        $('.trigger').trigger('click');

    }) // document
})(jQuery)

function trim(str, charlist)
{
    var whitespace, l = 0,
    i = 0;
    str += '';

    if (!charlist)
    {
        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    }
    else
    {
        charlist += '';
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
    }

    l = str.length;
    for (i = 0; i < l; i++)
    {
        if (whitespace.indexOf(str.charAt(i)) === -1)
        {
            str = str.substring(i);
            break;
        }
    }

    l = str.length;
    for (i = l - 1; i >= 0; i--)
    {
        if (whitespace.indexOf(str.charAt(i)) === -1)
        {
            str = str.substring(0, i + 1);
            break;
        }
    }

    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}


// function to vertically align content in container - cross-browser
// calculates parent height, and sets appropriate margin to child element

(function ($) {
    $.fn.vAlign = function(container) {
        return this.each(function(i){
	   if(container == null) {
	      container = 'div';
	   }
	   var paddingPx = 0; //change this value as you need (It is the extra height for the parent element)
	   $(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
	   var el = $(this).children(container + ":first");
	   var elh = $(el).height(); //new element height
	   var ph = $(this).height(); //parent height
       
       //if new element height is larger apply this to parent
	   /*
       if (elh > ph)
       { 
	       $(this).height(elh + paddingPx);
	       ph = elh + paddingPx;
	   }
       */
	   var nh = (ph - elh) / 2; //new margin to apply
	   $(el).css('margin-top', nh);
        });
     };
})(jQuery);
