/*
		Social Capital Partners Home Scripts
		January 2009
*/


// DOM ready
$(document).ready(function(){
	add_sidebar_round_corners();
	add_imagemap_swap();
});

function add_sidebar_round_corners(){
		// insert top 2 corner images
		$('#sidebar p').append('<img src="/images/submenu-corners.png" class="corner corner-tl" alt="" width="1" height="1"/><img src="/images/submenu-corners.png" class="corner corner-tr" alt="" width="1" height="1"/><img src="/images/submenu-corners.png" class="corner corner-br" alt="" width="1" height="1"/><img src="/images/submenu-corners.png" class="corner corner-bl" alt="" width="1" height="1"/>');
}

function add_imagemap_swap(){
	// hide steps
	$('#content .step2').hide();
	$('#content .step3').hide();
	$('#content .step4').hide();
	// watch image map for hover

	$('area').hover(function(){
			// get step from alt attribute
			var step = $(this).attr('alt');

			// hide all steps
			$('#content img.steps').hide();
			$('#content h4').hide();
			$('#content p').not('#content p.more').hide();

			// show hovered step
                        $('#content #circle_img'+step).show();
			$('#content img.'+step).show();
			$('#content h4.'+step).show();
			$('#content p.'+step).show();
	});	
}

window.onerror=function(desc,page,line,chr){
/* alert('JavaScript error occurred! \n'
  +'\nError description: \t'+desc
  +'\nPage address:      \t'+page
  +'\nLine number:       \t'+line
 );*/
}

$(document).ready(function() {		
	// Execute the slideShow
	var intervalID = slideShow();
        $("#interval").attr('value',intervalID);
});

function slideShow() 
{
	// Set the opacity of all images to 0
	$('#gallery a').css({opacity: 0.0});
	$('#gallery #slide-nav a').css({opacity: 1.0});
	
	// Get the first image and display it (set it to full opacity)
	$('#gallery a:first').css({opacity: 1.0});
		
	// Call the gallery function to run the slideshow, 7000 = change to next image after 7 seconds
	return setInterval('gallery()',7000);
}

function gallery() 
{
	// if no IMGs have the show class, grab the first image
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));

	// Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('slide-controls'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));	
	
	// Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');

	// Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
}

function changePicture(image)
{
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));
	var next = $("#gallery a."+ image);

        if($("#gallery a."+ image).hasClass('show'))
        {
             return false;
        }

	// Set the fade in effect for the next image, show class has higher z-index
        var intervalID = $("#interval").attr('value');
        clearInterval(intervalID);

	// Hide the current image
        current.animate({opacity: 0.0}, 1000).removeClass('show');
        next.addClass('show').animate({opacity: 1.0}, 1000);
        
	intervalID = setInterval('gallery()',7000);
        $("#interval").attr('value',intervalID);
}


