/*==================FUNCTIONS================*/

// Slideshow for the logos
function slideShow() {
	
	// Defining the first image of the slideshow
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // Pulling the images in the order that they appear in the markup
    var $next =  $active.next('img').length ? $active.next('img') : $('#slideshow IMG:first');
	var top = 75 - ($next.height() / 2);
	var left = 150 - ($next.width() / 2);
	
	// Animating logos with a fade out of the current image followed by the fading in of the next image
    $active.animate({opacity: 0.0}, 750, function(){
		$next.css({opacity: 0.0, top: top, left: left}).addClass('active').animate({opacity: 1.0}, 750, function(){
	 		$active.removeClass('active last-active');
		});
	});
}

// Popup window for the video
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=500');");
}

/*==================PRE LOAD=================*/
// Fixing the positioning on the first image of the slideshow
$('#slideshow img:eq(0)').addClass('active');
$('.active').css({top: 75 - ($('.active').height() / 2), left: 150 - ($('.active').width() / 2)});

// Fixing styles
$('#nav .page_item ul').parents('li').addClass('drop-down');

/*==================ON LOAD==================*/
$(function(){

	// Starting the slideshow
    setInterval( "slideShow()", 5000 );
    
    $('form#contact').submit(function(){
    	if($('#full_name').length){
			var fullname = $('#full_name').val();
			var fullname = fullname.split(' ');
			var firstname = fullname[0];
			var lastname = fullname[1];
			$('#first_name').val(firstname);
			$('#last_name').val(lastname);
		}
    	var action = $(this).attr('action');
    	var data = $(this).serialize();
    	
    	$('#contact-bottom').load(action+data);
    	
    	var position = $(this).position();
    	var top = (($(this).height() / 2) - 50) + position.top;
    	var width = $(this).width();
    	$('#thankyou').css({
    		width: width,
    		position: 'absolute',
    		left: position.left,
    		top: top
    	});
    	
    	
    	$('#contact-close').click(function(){
    		$('#thankyou').fadeOut('fast',function(){$('#contact fieldset, #contact-bottom').fadeTo('fast',1)});
    	})
    	
    	$(this).children('fieldset, #contact-bottom').fadeTo('fast',0.1,function(){
    		$('#thankyou').fadeIn('fast')
    		
    	});
    	return false;
    });
    	    
});
