$(document).ready(function(){
	    
	jQuery.fn.exists = function(){ return jQuery(this).length>0; }
	
	//	SERVICES
	
	$('#servicesbox h2').animate({opacity: 0}, 0);
	
	var count = 1;
	
	$('#services li').each(function()
	{
		var id = count;
		
		//	Initialize
		
		$(this).find('a').addClass('service-'+id).animate({opacity: 0.7}, 0);
		if ( ! $.browser.msie )
		{
			$(this).find('a').append('<span></span>');
			$(this).find('a span').animate({opacity: 0}, 0);
		}
		
		//	controllers
		
		$(this).find('a').mouseover(function()
		{
			$(this).animate({opacity: 1}, 'fast');
			if ( ! $.browser.msie ) $(this).find('span').animate({opacity: 1}, 'fast');
			$('#servicesbox h2').html( $(this).html() ).animate({opacity: 1}, 'fast');
		});
		$(this).find('a').mouseout(function()
		{
			if ( ! $(this).hasClass('current') ) {
				$(this).animate({opacity: 0.7}, 'fast');
				if ( ! $.browser.msie ) $(this).find('span').animate({opacity: 0}, 'fast');
			}
			
			if ( $('#services li a.current').exists() ) $('#servicesbox h2').html( $('#services').find('li a.current').html() );
			else $('#servicesbox h2').html('&nbsp;');
		});
		$(this).find('a').focus(function(){ $(this).blur(); });
		$(this).find('a').click(function()
		{
			if ( ! $(this).hasClass('current') )
			{
				$(this).blur();
				if ( ! $.browser.msie ) $('#services').find('li a.current').animate({opacity: 0.7}, 'fast').find('span').animate({opacity: 0}, 'fast');
				else $('#services').find('li a.current').animate({opacity: 0.7}, 'fast');
    			$('#services').find('li a.current').removeClass('current');
    			$(this).addClass('current');
    			$(this).animate({'margin-top': '-15px'}, 'fast', f=function(){ $(this).animate({'margin-top': '0px'}, {duration: 'slow', easing: 'easeOutBounce'}); });
    			$('#slides').animate({'left': -1*((id-1)*600)+'px'}, {duration: 'slow', easing: 'easeOutCubic'});
    			if ( ! $.browser.msie )
    			{
    				$('#details div.current').animate({opacity: 0}, 'fast').hide().removeClass('current');
    				$('#details div.detail:nth-child('+(id+1)+')').show().animate({opacity: 1}, 'fast').addClass('current');
    			}
    			else
    			{
    				$('#details div.current').hide().removeClass('current');
    				$('#details div.detail:nth-child('+(id+1)+')').show().addClass('current');
    			}
    		}
		});
		count++;
	});
	
	//	SUBMENU SLIDES
	
	$('#slides div.slide li a').each(function()
	{	    	
		$(this).css('background-image','url(modules/services_home/images/subicons/subicon-'+$(this).attr('rel')+'-bg.png)');
		$(this).animate({opacity: 0.6}, 0);
		
		$(this).mouseover(function()
    	{
    		$(this).animate({opacity: 1}, 'fast');
    		$(this).parent('li').append('<span class="label"></span>');
			$(this).parent('li').find('span.label').html( $(this).html() );
			$(this).parent('li').find('span.label').animate({opacity: 0}, 0, function(){ $(this).animate({opacity: 1}, 'fast'); });
    	});
    	$(this).mouseout(function()
    	{
    		$(this).animate({opacity: 0.6}, 'fast');
    		$(this).parent('li').find('span').animate({opacity: 0}, 0, function(){ $(this).remove(); });
    	});
	});
	
	//	DETAILS TEXTS
	
	if ( ! $.browser.msie )
	{
		$('#details div.detail').each(function()
    	{
    		$(this).hide();
    		$(this).animate({opacity: 0}, 0);
    	});
    	$('#details div.detail:nth-child(1)').show();
    	$('#details div.detail:nth-child(1)').animate({opacity: 1}, 'fast').addClass('current');
	}
	else
	{
		$('#details div.detail').each(function()
    	{
    		$(this).hide();
    	});
    	$('#details div.detail:nth-child(1)').show().addClass('current');
	}
	
	setContent();
});

$(window).resize(function() { setContent(); });