//General functions for SI
$(document).ready(function()
{
	$('a.open_signup').fancybox({		
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'overlayColor': '#000',
		'overlayOpacity': '0.9',		
		'titleShow'			: false,
		'scrolling'			: 'no',
		'autoDimensions'	: true,
		'margin'			: '0',
		'padding'			: '0',
		'centerOnScroll'	: false,
		'hideOnOverlayClick': false
	});
	
	$('a.generic_link').hover(function() {
	$(this).css('color','#FF8B00');
	},function() { //mouseout
		$(this).animate({
			'color': '#BEFF00'	
		},500);
	});	
	
	$('#home_port').mouseenter(function() {
		$('#hover_home').show();
	});
	
	$('#hover_home').mouseleave(function() {
		$('#hover_home').hide(); 
	});
	
	$('#s_name').focus(function() 
	{
		$('#c_name').addClass('selected');
		
	});
	
	$('#s_name').blur(function() 
	{
		$('#c_name').removeClass('selected');
		
	});
	
	$('#s_email').focus(function() 
	{
		$('#c_email').addClass('selected');
		
	});
	
	$('#s_email').blur(function() 
	{
		$('#c_email').removeClass('selected');
		
	});


	$('#signup_form').submit(function (e) 
	{ 
		
		if($('#s_name').val()==""||$('#s_email').val()=="")
		{
			$('#signup_intro').html('<div id="errors" style="display: block;background-color:#FFCECE;margin-right:20px;">Please complete both fields!</div>');				
			problem = 2;
		}		
		else
		{
			$('#signup_form_submit_container').html('<img src="/images/contact/loading.gif" alt="Please wait..." />');	
			return true;
		}	
		return false;
	});
	//Open any link with the class "newtab" in a new tab ( _blank xhtml )
	$('a.newtab').click(function (e) 
	{ 
		e.preventDefault();			
		window.open($(this).attr('href'));
	});
	
	$('input[type="text"]').hint();
	$('textarea').hint();

	if($('#images_container').length != 0)
	{
	//PORTFOLIO FADER
	function slider_set_index(id) 
	{ 
		current_item_index=id; 	
		$('#active_image').html(current_item_index);
		$("a.active").removeClass("active");
		$('a#image_'+current_item_index).addClass("active");
	}
	
	function slider_pause() 
	{
		clearInterval(slider_interval);
	}
	
	function slider_start() 
	{
		slider_interval = setInterval(slider_scroll, 5000);
	}
	
	function slider_scroll() 
	{		
		current_item_index++;		
		if(current_item_index == 6) 
		{
			current_item_index = 1;
			var prev_index = 5;
		}
		else
		{ var prev_index = current_item_index - 1; }
		
		$('#site_'+prev_index).fadeOut(1000);
		slider_set_index(current_item_index);
		$('#site_'+current_item_index).fadeIn(1000);		
	}
	
	if($('a#site_1').css('display') == "block") 
	{
		var total_scrollable_items 	= 5;
		var current_item_index 		= 1;
	
		$('#image_controls a').each(function(index,value) 
		{
			$(value).bind("click",function(event)
			{
				event.preventDefault();	
				var id = value.id.split("_")[1];
				slider_set_index(id);
				slider_pause();
				
				//look for any elements that are visible and hide them				
				$('#images_container a').each(function() 
				{
					
					if($(this).css('display') == 'block')
					{						 
						$(this).fadeOut(500);
					}
				});
				
				$('#site_'+current_item_index).fadeIn(500,function()
				{ 
						slider_set_index(id);
						slider_start();						
				});
			});								   								   
		});
		slider_start();
	} //end slider
	//END PORTFOLIO FADER
	}//end is there a slider?
	
}); //END DOCUMENT READY


