// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

$(document).ready(function(){
	$("#link_contact .menulink").click(function(){
			openContact();
			return false;
	});
}
);


function openContact(){
	var target = ($('#contact').height() != 0)? 0 : ($('#contact .default_content').height()+50);
	$('#contact').animate({height: target}, 500);
}

var currentSlide;

function setupSlideshow(obj){
	if(!obj){
		$('.slide').click(function() {
			if($(this).outerWidth() != 800) {
				var offset = ($('#branding').offset().left+11)-$(this).offset().left;
				$(this).data('offset', offset);
				$('#slides').animate({left: '+='+offset}, 500);
				$(this).animate({width: '800'}, 500);
				currentSlide = $(this);
				stopSlideshow(true);
				return false;
			} else {
				var offset = $('#slides').animate({left: '-='+$(this).data('offset')}, 500);
				$(this).data('offset', 0);
				$(this).animate({width: '152'}, 500);
				stopSlideshow(false);
				return false;
			}
		});
		$('.slide').mouseleave(function() {
			return false;
		});
		$('.slide').mouseout(function() {
			return false;
		});
		// $('.next').click(function() {
		// 	stopSlideshow(false);
		// });
		// $('.prev').mouseout(function() {
		// 	stopSlideshow(false);
		// });
	}
}

function stopSlideshow(bol){
	var api = $("#branding").data("scrollable");
	if(bol){
		api.stop();
	} else {
		// var offset = $('#slides').animate({left: '-='+currentSlide.data('offset')}, 500);
		// currentSlide.data('offset', 0);
		// currentSlide.animate({width: '152'}, 500);
		api.play();
	}
}

function scrollPeople(id){
	var person = $(id); 
	var position = (id != 0)? '-='+person.position().top : 0;
	var heightPerson = (id != 0)? $(id).outerHeight() : 355;
	var api = $("#branding").data("scrollable");
	if(id != 0){
		//api.stop();
		var slide = id.replace('#', '#slide_');
		var offset = ($('#branding').offset().left+11)-$(slide).offset().left;
		$(slide).data('offset', offset);
		$("#branding").data('slide', slide);
		$('#overlay_caption').animate({opacity: 0}, 500);
		$('#slides').animate({left: '+='+offset}, 500);
		$(slide).animate({width: '800'}, 500);
	} else {
		var slide = $("#branding").data('slide');
		var offset = $('#slides').animate({left: '-='+$(slide).data('offset')}, 500);
		$(slide).data('offset', 0);
		$(slide).animate({width: '152'}, 500);
		//$('#slides').animate({left: '+='+offset}, 500);
		$('#overlay_caption').animate({opacity: 0.8}, 500);
		//api.play();
	}
	$('#content .default_content').animate({top: position}, 500);
	$('#content').animate({height: heightPerson}, 500);
}

function scrollClients(id){
	var client = $(id); 
	var position = (id != 0)? '-='+client.position().top : 0;
	var heightClient = (id != 0)? $(id).outerHeight() : 1300;
	var opacity = (id != 0)? 0.3 : 1;
	var api = $("#branding").data("scrollable");
	if(id != 0){
		stopSlideshow(true);
	} else {
		stopSlideshow(false);
	}
	$('#slides').animate({opacity: opacity}, 500);
	$('#content .default_content').animate({top: position}, 500);
	$('#content').animate({height: heightClient}, 500);
}

