Array.prototype.sum = function(){
       for (var i=0, sum=0; i < this.length; sum += this[i++]);
       return sum;
}
jQuery(function($){
	var options = $('#more-options');
	var optionsButtons = $('#more-options-button');
	var closedStateColor = '#dddddd';
	var openedStateColor = '#f5f5f5';
	menuResize();
	
	
	function getCallbackFunction() {
		var isIE;
		if ($.browser.msie) {
			isIE = (parseInt($.browser.version) < 8);
		} else {
			isIE = false;
		}
		
		if (isIE) {
			return function(){
				$('#more-options-button').css({borderLeft : 'solid 1px #acacac'});
			};
		} else {
			return function(){};
		}
	}
	
	
	/*hide show-more1 link*/
	options.find('.show-more1:first')
	.find('span').css({color:closedStateColor})
	.end().animate({opacity : 'hide'}, 1);
	
	/*handle show-more link click (show additional options)*/
	optionsButtons.find('a.show-more:first').click(function(e){
		e.preventDefault();
		optionsButtons.find('.show-more1:first').animate({opacity : 'show'}, 500)
		.find('span').animate({color:'#000000'}, 500);
		
		optionsButtons.find('.show-more1:first').animate({opacity : 'show'}, 500);
		
		/*hide show-more link*/
		$(this).animate({opacity:'hide'}, 500)
		.find('span').animate({color:openedStateColor}, 500)
		.end().find('img').animate({opacity:0}, 500);
		
		//$(this).animate({opacity:'hide'}, 500);
		
		/*show more options*/
		options.slideDown(500);
		
		/*change bgcolor of buttons panel*/
		optionsButtons.animate({backgroundColor:openedStateColor}, {duration:500, complete:getCallbackFunction() });
		
	}).click();
	
	/*handle show-more1 link click (hide additional options)*/
	optionsButtons.find('a.show-more1:first').click(function(e){
		e.preventDefault();
		$(this).animate({opacity : 'hide'}, 500)
		.find('span').animate({color:closedStateColor}, 500);
		
		/*show show-more link*/
		optionsButtons.find('a.show-more:first').animate({opacity:'show'}, 500)
		.find('span').animate({color:'#000000'}, 500)
		.end().find('img').animate({opacity:1}, 500);
		
		/*hide options*/
		options.slideUp(500);
		
		/*change bgcolor of buttons panel*/
		optionsButtons.animate({backgroundColor:closedStateColor}, 500);
		$('#more-options-button').css({borderLeft : '0'});
	});
	
	/*search form*/
	$('#with-submit').click(function(e){
		e.preventDefault()
		$('#srchForm').submit();
	});
	
	/*login form*/
	$('#showLoginForm').fancybox({
		'hideOnContentClick': false
		,'frameWidth' : 240	 
		,'frameHeight' : 140
	});

	var rEx = /\([0-9a-z_A-Z\-]*\)/;
	$('.replace').each(function(){
		var toReplace = $(this).html();
		$(this).html( toReplace.replace(rEx, '') );
	});
	
	/*submit form*/
	$('.form-submit').click(function(e){
		e.preventDefault();
		$(this).parents('form:first').submit();
	});
	
	/*prevent clicking a link*/
	$('.inactive').click(function(e){
		e.preventDefault();
	});
	
	/*take title values from each div with class "date"*/
	$('div.date').each(function(){
		var title = $(this).attr('title');
		$(this).prepend(title);
	});
	

});


function number_format( number, decimals, dec_point, thousands_sep ) {
	// *     example 1: number_format(1234.5678, 2, '.', '');
	// *     returns 1: 1234.57
	var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
	var d = dec_point == undefined ? "," : dec_point;
	var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
	var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

function menuResize()
{
    var arrW=new Array();
$('#mainnav>*').each(function(i){
arrW[i]=$(this).outerWidth();
 });
var sum = 1003-arrW.sum();
$('#mainnav *:last-child').css('padding-left',22+sum);
}


