$(document).ready(function() {
	$("#menu-main > li:last, .block_services ul > li:last").addClass("last");
	$(".block_services ul > li:first").addClass("first");
	
	var width = 955 / $('.accordion li').size(),
		info_w = width - 15;
	
	$('.accordion li').width(width);
	$('.accordion li .small_info').width(info_w);
	
	$('.accordion').kwicks({
		max: 800
	});
	
	$('.accordion li').hover(function() {
		
			$(this).parent().children('li').not('.active').children('a').children('.shadow').stop(false, false).fadeTo('slow', 0);
			
			$(this).children('a').children('.small_info').stop(false, false).animate({
				left: '800'
			}, 500);
			
			$(this).children('a').children('.big_info').stop(false, false).animate({
				right: '0'
			}, 500);
		}, function() {
			
			$(this).parent().children('li').children('a').children('.shadow').stop(false, false).fadeTo('slow', 1);
			
			$(this).children('a').children('.small_info').stop(false, false).animate({
				left: '0'
			}, 500);
			
			$(this).children('a').children('.big_info').stop(false, false).animate({
				right: '800'
			}, 500);
		});
		
	$('.sslider').each(function() {
		$(this).children('li:gt(0)').hide();
		var ul = $(this);
		setInterval(function() {
			var that = $(ul).children('li:first-child');
				$(that).fadeOut('slow').next('li').fadeIn('slow').end().appendTo(ul);
		}, 4000);
	});

	$('.text ul').each(function() {
		$(this).children('li:first').addClass('first');
	});
	$('.text ul').each(function() {
		$(this).children('li:last').addClass('last');
	});
	
	$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'dark_square'});
	
	Cufon.replace('#middle .block h2 .title, #takealook p', {
		textShadow: '#000 1px 1px'
	});
	Cufon.replace('#middle_info h3', {
		color: '-linear-gradient(#ffffff, #a9a9a9)'
	});
	
	$('.images_list li a').hover(function() {
		$(this).children('.hover').stop(true, true).fadeTo('fast', .8);
	}, function() {
		$(this).children('.hover').stop(true, true).fadeTo('fast', 0);
	});
	
	textReplacement($('#s'));
	$(".preload").preloader();
	
	$('.contact').each(function() {
		var main = $(this);
		$(this).find('.submit').click(function() {
			var input_name = $(main).find('.name').val(),
				input_email = $(main).find('.email').val(),
				input_message = $(main).find('.message').val(),
				input_to = $(main).find('.to').val(),
				status_ok = $(main).find('.status_ok').val(),
				status_bad = $(main).find('.status_bad').val(),
				status_email = $(main).find('.status_email').val(),
				status_submit = $(main).find('.status_submit').val(),
				url = $(main).find('.url').val(),
				ajax_loader = '<img src="'+url+'/images/ajax-loader.gif" alt=""/>';
				
			$(main).find('.response').hide();
			
			$(main).find('.loader').html(ajax_loader);
			
			$.post(url+'/send_mail.php', {to: input_to, name: input_name, email: input_email, message: input_message, status_ok: status_ok, status_bad: status_bad, status_email: status_email, status_submit: status_submit}, function(data){
				
				$('.loader img').fadeOut(1000, function(){
					$(main).find('.response').html(data).show();
				});
			});
			return false;
		});
	});
	
	$('#anythingSlider').anythingSlider();
	
	$('#navigation div ul li').children('ul').hide();
	
	$('#navigation div ul li').hover(function() {
		$(this).find('> ul').stop(true, true).slideDown('fast');
	}, function() {
		$(this).find('> ul').stop(true, true).hide();
	});
	
	$("#the_list li").children('.slist_top').show().end().children('.slist_bottom').hide();
	$("#the_list li .slist_top").click(function() {
		$(this).stop(true, true).slideUp('slow');
		$(this).parent('li').children('.slist_bottom').stop(true, true).slideDown('slow');
		$(this).parent('li').addClass('expanded');
	});
	$("#the_list li .slist_bottom .subtract").click(function() {
		$(this).parent('div').stop(true, true).slideUp('slow');
		$(this).parent('div').parent('li').children('.slist_top').stop(true, true).slideDown('slow');
		$(this).parent('div').parent('li').removeClass('expanded');
	});
	$("#servs_buttons p a").click(function() {
		if($(this).hasClass('expand')) {
			$("#the_list li .slist_top").stop(true, true).slideUp('slow');
			$("#the_list li .slist_bottom").stop(true, true).slideDown('slow');
			$("#the_list li").addClass('expanded');
		}
		if($(this).hasClass('suctract')) {
			$("#the_list li .slist_bottom").stop(true, true).slideUp('slow');
			$("#the_list li .slist_top").stop(true, true).slideDown('slow');
			$("#the_list li").removeClass('expanded');
		}
		return false;
	});
	$("#the_list li .slist_top").hover(function() {
		$(this).children('.hover').stop(true, true).fadeTo('fast', 1);
	}, function() {
		$(this).children('.hover').stop(true, true).fadeTo('fast', 0);
	});
	if(window.location.hash) {
		$("#the_list "+window.location.hash).addClass('expanded');
		$("#the_list "+window.location.hash).children('.slist_top').stop(true, true).slideUp('slow');
		$("#the_list "+window.location.hash).children('.slist_bottom').stop(true, true).slideDown('slow');
	}
	
	$('#top_testimonials .top_testi').each(function() {
		var height = $('#top_testimonials').height();
		$(this).css({"marginTop": (height - $(this).height())});
	});
	
	$('.portfolio_list .port .port_img').hover(function() {
		if($(this).children('span').hasClass('desc')) {
			$(this).children('span').stop(true, true).animate({left: 0}, 200);
		} else if($(this).children('span').hasClass('zoom') || $(this).children('span').hasClass('more') || $(this).children('span').hasClass('video')) {
			$(this).children('span').stop(true, true).fadeTo('fast', .8);
		}
	}, function() {
		if($(this).children('span').hasClass('desc')) {
			$(this).children('span').stop(true, true).animate({left: -280}, 200);
		} else if($(this).children('span').hasClass('zoom') || $(this).children('span').hasClass('more') || $(this).children('span').hasClass('video')) {
			$(this).children('span').stop(true, true).fadeTo('fast', 0);
		}
	});

});

function textReplacement(input){
	var originalvalue = input.val();
	input.focus( function(){
		if( $.trim(input.val()) == originalvalue ){ input.val(''); }
	});
	input.blur( function(){
		if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
	});
}
