// JavaScript Document

window.slide=0;
time_delay=5000;
change_slide=1;
$(function(){
	$('.slider-pager A').click(function(){
		$('.slider-pager A').removeClass('active');
		$(this).addClass('active');
		$('.slider-holder>div.slide').fadeOut('slow');
		$('#slide'+$(this).html()).fadeIn('slow');
		window.slide=parseInt($(this).html())-1;
		change_slide=0;
	});

	window.setTimeout(next_slide,time_delay);
});

function next_slide(){
	var n=$('.slider-pager A').size();
	var i=parseInt(window.slide)+1;
	if(i>=n){ i=0;}
	if (change_slide==1){
		$('.slider-pager A').eq(i).click();
	};
	window.setTimeout(next_slide,time_delay);
}


jQuery.fn.extend({
	autotip: function(options) {
		return this.each(function() {
			new jQuery.AutoTip(this, options);
		});
	}
});


jQuery.AutoTip = function(container, options) {

	var settings = {
	text: 'Enter a value',
	color: '#ccc',
	style: 'italic'
	};

if(options) $.extend(settings, options);
	
	$(container).focus(function(){
		if($(this).val()==settings['text']){
			$(this).val('');
		}
		$(this).css('color','#000');
		$(this).css('style','none');
	});

	$(container).blur(function(){
		if($(this).val()==''){
			$(this).val(settings['text']);
			$(this).css('color',settings['color']);
			$(this).css('font-style',settings['style']);
		}
	});
	
	$(container).blur();
};

$(function(){

	$('acronym').each(function(){
		var text=$(this).attr('title');
		var abbr_replacement='<span class="abbr">'+$(this).html()+'<span class="abbr_description"><big>'+text.split('|')[0]+'</big><small>'+text.split('|')[1]+'</small></span></span>';
		$(this).replaceWith(abbr_replacement);		
	})
	
	$('.abbr').hover(function(){$('span.abbr_description',this).show();},	function(){	$('span.abbr_description').hide();});
	
	
	$('.header form :text').autotip({text:'Email address'});
	$('.header form :password').autotip({text:'password'});
	
	
	var form_inputs = $('.row input, .row select, .row textarea');
	
	form_inputs.change(function()
	{
		if($.trim($(this).val()) == ''){
			$(this).parents('.row').removeClass('changed');
		} else {
			$(this).parents('.row').addClass('changed');
		}
	});
	
	form_inputs.change();
	
	form_inputs.keyup(function()
	{
		$(this).change();
	});
	
	form_inputs.focus(function()
	{
		if($(this).attr('type') == 'radio'){
			return;
		}
		$(this).parents('.row').addClass('focused');
	});
	
	form_inputs.blur(function()
	{
		$(this).parents('.row').removeClass('focused');
		$(this).change();
	});
	
	$('.customers-box ul.customers-info li').hover(function()
	{
		$(this).siblings().removeClass('current');
		$(this).addClass('current');
	});
	
});

