
$(document).bind("ready", function(){
				   
	$('body').addClass("javascript");

	$('#search input').each(function(){
									 
		$(this).attr("revert", $(this).attr("title"));
		
		$(this).bind("focus", function(){
			if($(this).val() == $(this).attr("revert")){
				$(this).val("");
			}
			
			$(this).addClass("filled");
		});
		
		$(this).bind("blur", function(){
			if($(this).val() == ""){
				$(this).val($(this).attr("revert")).removeClass("filled");
			}
		});
		
		$(this).blur();
		
	});
	
	if(jQuery.fn.lightBox){
		$('a[rel=lightbox]').lightBox();
	}
	
	$("div.tiles div.section").hover(function(){
		$(this).addClass("hover");
	}, function(){
		$(this).removeClass("hover");
	});

	jQuery.fn.ticker2 = function(){
		
		if($(this).length <= 0) return;
		
		if(!$.tickerItem){
			$.tickerInit = true;
			$.tickerFirst = true;
			$.tickerItem = this;
		}
		
		$(this).css("width", 5000);
		$(this).append("<span>marker</span>");
		
		length = $("span", this).position();
		length = length.left + 20;
		
		$(this).attr("length", length);

		$("span", this).remove();
		
		$(this).css({width: length, left: length-960+'px' });
		
		if($.tickerInit){
			setTimeout(function(){
				$($.tickerItem).clone().insertBefore($.tickerItem);
				$($.tickerItem).parent().find("div:first").ticker();
			}, length*7);
		}
		
		interval = function(me){
			length = parseFloat($(me).attr("length"));
			rlength = length.reverse();

			$(me).css("left", length-960+'px');
	
			if($.tickerFirst){
				$(me).css("left", "0px");
				ratio = length/960;
				$.tickerFirst = false;
			}else{
				ratio = 1;
			}

			$(me).animate({ left: rlength + 'px' }, (length*14)/ratio, 'linear', function(){ interval(this); });
		};
		
		$.tickerInit = false;
		interval(this);

	}
	
	me = $('#ticker div');


	jQuery.fn.extend({
		getCurrentAndNext: function(filter){
			current = $(me).find(filter + "[current]");
			
			len  = $(me).find(filter + "[current]").next(filter).length;
			if(len >= 1){
				next = $(me).find(filter + "[current]").next(filter);
			}else{
				next = $(me).find(filter + ":first");
			}
			
			$(current).removeAttr("current");
			$(next).attr("current", "true");
			
			return [current, next];
		}
	});
	
	$(me).find('a:not(:first)').css({ top: '-20px' });
	$(me).find('a:first').attr("current", "true");
	
	setInterval(function(){
		if($(me).find("a").length == 1) return;
		nextCurrent = $(me).getCurrentAndNext("a");
		
		current = nextCurrent[0];
		next	= nextCurrent[1];
		
		$(current).animate({ top: '50px' }, 400, function(){ $(this).css({ top: '-20px' }); });
		$(next).css({ top: '-20px' }).animate({ top: '10px' }, 400);
	}, 3000);

	
});
