
var latest_news = [];
var latest_news_index = -1; 
var latest_news_delay = 5000;
var latest_news_effect = 1000;
var scrollable = 1;

function scroll_ticker()
{
	if(scrollable++%2) return;
	$("#news .scroll:first").insertAfter($("#news .scroll").eq(1)).css("left", parseInt($(".scroll").width())+"px");

	$("#news .scroll").animate(
			{'left':"-="+$(".scroll").width()+"px"},
			parseInt($(".scroll").width()*20),
			"linear",
			scroll_ticker
		);
}

jQuery(document).ready( function(){
//	var pos = findPos($("#news").get(0));
	if($("#news .scroll").size()>0) {
	$(".scroll").clone(true).insertAfter(".scroll");
	$(".scroll").css("position", "absolute").css("white-space", "nowrap");
	$(".scroll").each(function(k,v){
		$(this).css("left", parseInt(k*$(".scroll").width())+"px");
	})
	$("#news .scroll").animate(
			{'left':"-="+$(".scroll").width()+"px"},
			parseInt($(".scroll").width()*25),
			"linear",
			scroll_ticker
		);
	}
	// init box slider
	$("#text ul li").css('margin', '60px 0 0 0');
	if ( $('#latest-news') ){
		latest_news = $('#text li');
		//latest_news.each( function(i){ $(this).css('visibility', 'hidden') } );
		if ( latest_news.length > 0 )
			toggleNews();
	}

	if ( $('#block-1') ){
	  var heightArray = new Array(3);
	  heightArray[0] = $('#block-1 .bottom').height();
	  heightArray[1] = $('#block-2 .bottom').height();
	  heightArray[2] = $('#block-3 .bottom').height();
    heightArray.sort();
		$('#block-1 .bottom').css("height", heightArray[2]);
		$('#block-2 .bottom').css("height", heightArray[2]);
		$('#block-3 .bottom').css("height", heightArray[2]);
	}
});


function startToggleNews(){
	setTimeout("toggleNews();", latest_news_delay);
}

function toggleNews(){
  var item = latest_news[latest_news_index];
  var cur_height = $(item).height();
  var margin_top = ( (78 - cur_height)/2 ) - 10;
//	var margin = margin_top + 'px 0 0 0';
	
	if ( latest_news_index == -1 ){
		var item = latest_news[++latest_news_index];
		cur_height = $(item).height();
  		margin_top = ( (78 - cur_height)/2 ) - 10;
//		margin = margin_top + 'px 0 0 0';
 
		$(item).css({'opacity':0, 'display':'block'});
		$(item).animate(
			{'opacity':1, 'marginTop':"20px"},
			latest_news_effect,
			null,
			function(){ startToggleNews(); }
		);
		return;
	}

	var item = latest_news[latest_news_index++];
	$(item).animate({'opacity':0, 'marginTop':0}, latest_news_effect, null, function(){
		$(this).css('display', 'none');
  	$(this).css('margin-top', '50px');
		if ( latest_news_index == latest_news.length ){
			latest_news_index = 0;
		}
		var item = latest_news[latest_news_index];
		$(item).css({'opacity':0, 'display':'block'});
		$(item).animate({'opacity':1, 'marginTop':margin_top}, latest_news_effect, null, function(){ startToggleNews(); });
	});
	
}

// init login form
$(document).ready(function(){
//	if(!document.getElementById("login_form")) return;

	$("form input").each( function(i){
		if( ($(this).attr("type") == "text" || $(this).attr("type") == "password") && $(this).attr("alt") != ""){
			var parts = String($(this).attr("alt")).split(':');
			$(this).attr('default_value', jQuery.trim(parts[1]));
			$(this).focus( function(e){
				if(jQuery.trim($(this).val().toLowerCase()) == jQuery.trim($(this).attr('default_value').toLowerCase())){
					$(this).val('');
				}
			});
			$(this).blur( function(e){
				if(this.value == ''){
					$(this).val($(this).attr('default_value'));
				}
			});
		}
	});
});
 
