var checkFields = new Array('check');
	 
$(document).ready(function() {

//	 if($('#testimonial_pagination_block').length > 0) {
//		 load_paginator('#testimonial_pagination_block');
//	 }
	 
	 enable_administration();
	 
	 handle_default_values();
	 
	 handle_humanForms();
	 
	 showSending();

	 applyFilter();

	 handleTopMessages();

	 showHelpDescription();

	 animateListDescription();

	 animateSideChildren();

	 loadShowVideo();

	 loadBlogPosts();
	 
//	 load_flip();


	$(".twitter-feed").tweet({
    	username: "vertexgroup",
        avatar_size: 32,
        count: 1,
        loading_text: "loading tweets..."
     });
	 
});

$(window).load(function() {
	
//	 drop_shadow();
	 
//	 fix_partner_height();
	 
});




function loadBlogPosts()
{
	if($('.latest_post').length > 0) {
		$.get(baseUrl+'/support/blog-posts', function(data) {
			if(data) {
				$('.latest_post').html(data);
				if ($.browser.mozilla) {
					$('.latest_post').css('white-space', 'normal');
				}
			}
		});
	}
}



function loadShowVideo()
{
	$('.show_video').click(function(){

		var url = $(this).attr('href');

		$.post(baseUrl+'/support/video', {video:url}, function(data) {
			if(data){
				$.fancybox(data,
					{
						'centerOnScroll': true
					}
				);
			}
		});

		return false;
	});
}


function animateSideChildren()
{
	var config = {
		 over: startAnimateSideChildren,
		 timeout: 200,
		 interval: 50,
		 out: endAnimateSideChildren
	};

	$('.module_children_items span.module_children_item a').hoverIntent(config);
	
}

function startAnimateSideChildren()
{
	$(this).animate({
		'background-color': '#C31088',
		'padding-left': '15px',
		'padding-right': '15px'
	}, 200);
}

function endAnimateSideChildren()
{
	$(this).animate({
		'background-color': '#B62570',
		'padding-left': '10px',
		'padding-right': '10px'
	}, 200);
}


function animateListDescription()
{
	var config = {
		 over: startAnimateListDescription,
		 timeout: 200,
		 interval: 50,
		 out: endAnimateListDescription
	};

	$('.module_parent_items_list .item_block').hoverIntent(config);
}

function startAnimateListDescription()
{
	var listObj = this;

	var image = $(listObj).find('a .image img.border');

	if(image) {
		image.animate({
			'background-color': '#817362'
		}, 200, function(){
			continueStartAnimateListDescription(listObj);
		});
	}
}

function continueStartAnimateListDescription(listObj)
{
	var title = $(listObj).find('.title');
	var description = $(listObj).find('.description');

	if(listObj) {
		$(listObj).animate({
			'background-color': '#817362'
		}, 150, function() {
			if(title) {
				title.css('color', '#FFFFFF');
			}
			if(description) {
				description.css('color', '#C8BAA9');
			}
		});
	}
}

function endAnimateListDescription()
{
	var listObj = this;

	var title = $(listObj).find('.title');
	var description = $(listObj).find('.description');

	$(listObj).animate({
		'background-color': 'transparent'
	}, 150, function() {
		if(title) {
			title.css('color', '#9B8B83');
		}
		if(description) {
			description.css('color', '#9B8B83');
		}
		continueEndAnimateListDescription(listObj);
	});
}

function continueEndAnimateListDescription(listObj)
{
	if(listObj) {
		var image = $(listObj).find('a .image img.border');

		if(image) {
			image.animate({
				'background-color': '#EDEAE4'
			}, 200);
		}
	}
}



function showHelpDescription()
{
	var config = {
		 over: showDescriptionBlock,
		 timeout: 200,
		 interval: 50,
		 out: hideDescriptionBlock
	};

	$('.how_can_we_help .help_block').hoverIntent(config);

}

function showDescriptionBlock()
{
	var description = $(this).find('a .image .description');
	
	if(description) {
		description.css('display', 'block');
		description.show('blind');
	}
}

function hideDescriptionBlock()
{
	var description = $(this).find('a .image .description');
	
	if(description) {
		description.hide('blind');
	}
}



var currentMsg = 0;
var countMsg = 0;
var animateMsg = 1;
var firstTimeout = 7000;
var nextTimeouts = 6000;

timer_1 = null;
timer_2 = null;
timer_3 = null;

function handleTopMessages()
{
	$('.show_top_msg_button').click(function(){

		var id = $(this).attr('id');

		$('.message_block').hide();
		$('.'+id).show();

		$('.show_top_msg_button').removeClass('active');
		$(this).addClass('active');

		currentMsg = id.charAt( id.length-1 );

		clearTimeout(timer_1);
		clearTimeout(timer_2);
		clearTimeout(timer_3);
		
		animateMsg = 0;

		timer_1 = window.setTimeout('startTopMessagesSlideshow()', firstTimeout);

		return false;
	});

	countMsg = $('.message_block').length;

	timer_2 = window.setTimeout('startTopMessagesSlideshow()', firstTimeout);
}

function startTopMessagesSlideshow()
{
	animateMsg = 1;
	topMessagesSlideshow();
}

function topMessagesSlideshow()
{
	if(animateMsg)
	{
		currentMsg++;

		if(currentMsg >= countMsg) {
			currentMsg = 0;
		}

		if ( $.browser.msie ) {
			$('.message_block').hide();
			$('.show_top_msg_'+currentMsg).show();
		} else {
			$('.message_block').hide(1000);
			$('.show_top_msg_'+currentMsg).show(1000);
		}

		$('.show_top_msg_button').removeClass('active');
		$('#show_top_msg_'+currentMsg).addClass('active');


		timer_3 = window.setTimeout('topMessagesSlideshow()', nextTimeouts);
	}
}




function applyFilter()
{
	$('.children_items_select').change(function(){
		$('.children_items_form').submit();
//		window.location = '/'+moduleName+'/set-filter/'+$(this).val();
	});

}
 
function fix_partner_height()
{

	if($('.content_holder .partner').length > 0)
	{
		var partnerHeight = $('.content_holder .partner').height();
		
		var separatorHeight = 639 - partnerHeight;
		
		if(separatorHeight < 0) {
			separatorHeight = 0;
		}
		
		$('.empty_separator').height(separatorHeight);
	}
}

var flipTimeOut = 450;
var scrollTopIsSet = false;
var goToPage = '';

function load_flip()
{
	//improvement for slow server
	$('.search_items .paginator a').click(function() {
		flipTimeOut = 150;
	});
	
	$('a.next').click(function() {
		
		handle_flip(this, 'lr');

		return false;
	})
	
	$('a.previous').click(function() {
		
		handle_flip(this, 'rl');
		
		return false;
	})
	
}

function handle_flip(obj, direction)
{
	gotoPage = $(obj).attr('href');
	
	set_scroll_top();
	
	$(".flip_item").flip({
		direction: direction,
		speed: 600,
		color: '#3D3D3D'
//		content:'this is my new content'
	});
}

function set_scroll_top()
{
	var scrollTop = $(window).scrollTop();
	
	setTimeout('go_to_page()', flipTimeOut);
	
	$.post(baseUrl+'/index/set-scroll-top', {scrollTop:scrollTop}, function(result){
		scrollTopIsSet = true;
	});
}

function go_to_page()
{
	if(scrollTopIsSet) {
		location.href = gotoPage;
	} else {
		setTimeout('go_to_page()', 100);
	}

}



function drop_shadow()
{
	$('.drop_shadow').dropShadow({
		left    : 4,
		top     : 4,
		blur    : 1,
		opacity : 0.4,
		color   : '#000000',
		swap    : false
	});
	
	$('.drop_shadow_2').dropShadow({
		left    : 4,
		top     : 4,
		blur    : 1,
		opacity : 0.4,
		color   : '#000000',
		swap    : false
	});
}


function showSending()
{
	$('form #Send').click(function(){
		$('.sending').show();
	});

	$('form #Submit').click(function(){
		$('.sending').show();
	});
}



function enable_administration()
{
	$(".hide_admin_block").unbind();
	
//	if($('.admin_block_add').length > 0) {
//		$(".admin_block_add").parents('.admin_block_holder').addClass('admin_block_holder_add');
//	}
	 
	if($('.hide_admin_block').length > 0)
	{
		var config = {    
		     over: show_admin_block,
		     timeout: 400,
		     interval: 50,
		     out: hide_admin_block
		};
	
		$(".hide_admin_block").hoverIntent(config);
	}

 }
 
 function show_admin_block()
 {
	 $(this).children('.admin_block').show();
 }
 
 function hide_admin_block()
 {
	 $(this).children('.admin_block').hide();
 }
 
 
 
 function handle_humanForms()
 {
	 var count = checkFields.length;
	 
	 $('.check_form input').focus(function()
	 {
		 var form = $(this).parents('form');
		 
		 if(!$(form).hasClass('human'))
		 {
			$(form).addClass('human');
			
			var formId = $(form).attr('id');
			
			var i = 0;
			for(i = 0; i < count; i++)
			{
				var checkFieldSelector = '#'+formId+' input[name="'+checkFields[i]+'"]';
				if($(checkFieldSelector).length > 0) {
					$(checkFieldSelector).attr('value', formId);
					break;
				} 
			}
		 }
	 });
 }
 
 
 
 function load_paginator(selector)
 {
	$(selector+' .paginator a.page_item').click(function(){
		 
		var url = $(this).attr('href');
		
		$.post(url, function(data) {
			$(selector+" .animate_block").animate(
				{
					opacity: 0.1
				}, 
				300,
				function(){
					$(selector).parent('.pagination_block_replace').html(data);
					load_paginator(selector);
				}
			);
		});
		 
		return false;
	});
 }
 
 
 function handle_default_values()
 {
	$('.default_value').addClass('default_value_color');
	
	$('.default_value').focus(function() {
		if($(this).val() == $(this).attr('title')) {
			$(this).val('');
			$(this).removeClass('default_value_color');
		}
	});
	
	$('.default_value').blur(function() {
		if($(this).val() == '') {
			$(this).val($(this).attr('title'));
			$(this).addClass('default_value_color');
		}
	});

	$('.default_value_submit').click(function() {
		var form_inputs = $(this).parents('form').find(':input[type="text"]');
		if(form_inputs) {
			$(form_inputs).each(function(i) {
				if($(this).hasClass('default_value')) {
					if($(this).attr('value') == $(this).attr('title')) {
						$(this).val('');
					}
				}
			});
		}
	});

 }
 
 
function set_form_defaults(form)
{
	var form_inputs = $(form).find(':input[type="text"]');
	
	if(form_inputs) {
		$(form_inputs).each(function(i) {
			if($(this).hasClass('default_value')) {
				$(this).val($(this).attr('title'));
			}
		});
	}
	
}



