$(function() {
	$('.field').focus(function() {
        if(this.title==this.value) {
            this.value = '';
        }
    }).blur(function(){
        if(this.value=='') {
            this.value = this.title;
        }
    });
});

var animationOn = false;
var slideID = 1;
var currentslideID = 1;

function pageLoaded() {

	$('.aktt_tweet_time').remove();

	var sitemapColumns = $('#primaryNav').find('li:first-child').size();
	sitemapColumns = sitemapColumns + 1;
	$('#primaryNav').addClass('col'+sitemapColumns);
	
	$('.box .post-short:last-child').addClass('post-last');
	$('.box .post-short').each(function() {
		$(this).append('<div class="cl">&nbsp;</div>');
	});
	
	$('.post.news').each(function() {
		$(this).addClass('post-news');
	});
	
	$('.post.blog').each(function() {
		$(this).addClass('post-blog');
	});

	$('#slider .slides li').not('#slide-1').css({'opacity':0},0);
	
	$('.custom-nav a').click(function(){
	
		if (animationOn == false){
			
			temp_slideID = $(this).attr('rel');
			if (temp_slideID != currentslideID){
		
				animationOn = true;
				$(this).addClass('active');
				$('.custom-nav a').not(this).removeClass('active');
				
				currentslideID = slideID;
				slideID = $(this).attr('rel');
	
				if (currentslideID < slideID){
					$('#slider .slides li#slide-'+slideID).animate({'opacity':0,'left':'1900px'},0);
					$('#slider .slides li#slide-'+currentslideID).animate({'opacity':0,'left':'-1000px'},500,'easeInOutExpo');
					$('#slider .slides li#slide-'+slideID).animate({'opacity':1,'left':'92px'},500,'easeInOutExpo',function(){
						animationOn = false;
						currentslideID = slideID;
					});
				} else {
					$('#slider .slides li#slide-'+slideID).animate({'opacity':0,'left':'-1000px'},0);
					$('#slider .slides li#slide-'+currentslideID).animate({'opacity':0,'left':'1900px'},500,'easeInOutExpo');
					$('#slider .slides li#slide-'+slideID).animate({'opacity':1,'left':'92px'},500,'easeInOutExpo',function(){
						animationOn = false;
						currentslideID = slideID;
					});
				}
							
			}
			
		}
		
		return false;
		
	});
	
	$('.slider-prev').click(function(){
		if (animationOn == false){
			animationOn = true;
			currentslideID = slideID;
			if (slideID == 1) {
				slideID = 4;
			} else {
				slideID = slideID - 1;
			}
			$('.custom-nav a[rel=' + slideID + ']').addClass('active');
			$('.custom-nav a[rel=' + currentslideID + ']').removeClass('active');

			$('#slider .slides li#slide-'+slideID).animate({'opacity':0,'left':'-1000px'},0);
			$('#slider .slides li#slide-'+currentslideID).animate({'opacity':0,'left':'1900px'},500,'easeInOutExpo');
			$('#slider .slides li#slide-'+slideID).animate({'opacity':1,'left':'92px'},500,'easeInOutExpo',function(){
				animationOn = false;
				currentslideID = slideID;
			});
		}
	});
	
	$('.slider-next').click(function(){
		if (animationOn == false){
			animationOn = true;
			currentslideID = slideID;
			if (slideID == 4) {
				slideID = 1;
			} else {
				slideID = parseInt(slideID,10)
				slideID = slideID + 1;
			}
			$('.custom-nav a[rel=' + slideID + ']').addClass('active');
			$('.custom-nav a[rel=' + currentslideID + ']').removeClass('active');

			$('#slider .slides li#slide-'+slideID).animate({'opacity':0,'left':'1900px'},0);
			$('#slider .slides li#slide-'+currentslideID).animate({'opacity':0,'left':'-1000px'},500,'easeInOutExpo');
			$('#slider .slides li#slide-'+slideID).animate({'opacity':1,'left':'92px'},500,'easeInOutExpo',function(){
				animationOn = false;
				currentslideID = slideID;
			});
		}
	});
	
	$('#main-nav li').each(function() {
		if ($(this).find('span').length || $(this).is(':last-child')) {
			return;
		};
		$(this).append('<span class="sep">&nbsp;</span>');
	});
	
	$('.services-list li a').each(function() {
		if ($(this).find('span').length) {
			return;
		};
		var text = $(this).html();
		$(this).html('').append('<span></span>').find('span').html(text);
	});
	
	$('.services-list li:last-child').addClass('last');
	
	$('.search-text a').click(function(){
		$('#search').fadeIn(function(){
			$(this).find('.field').focus();
		});
		$('.search-text a').parent().fadeOut('fast');
	});
		
	Cufon.replace('.who,#slider h1, #under-slider h3,  #main h3, h2.call-us, .news-list .post .date p, #content h1');
}

function callback(carousel) {
	$('#slider .custom-nav li a').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval($(this).parent().index() + 1));
		$('#slider .custom-nav li a').not($(this)).removeClass('active');
		$(this).addClass('active');
        return false;
	});
}
function firstInCallback(instance, item, index) {
	var new_active = $('#slider .custom-nav li').eq(index - 1).find('a');
	$('#slider .custom-nav li a').removeClass('active');
	new_active.addClass('active');
	Cufon.replace('#slider h1');
}
