$(document).ready(function(){ 
	
	//prepare document
	/*$('.noscript').removeClass('noscript');
	
	if(!$.browser.msie){
		$('#shareit-welcome-text').animate({opacity: 1}, 450);
	} else {
		$('.shareit-homepage-intro').hide();
		$('#shareit-welcome-text').show();
	}*/
	
	//var curLastSelector = '#shareit-welcome-text';
	//var curCitySelector = '#shareit-welcome-text';
	
	curObject = 0;
	nextObject = 1;
	curSlideObject = 0;
	nextSlideObject = 1;
	
	

	$('#shareit-slideshow-box .slide-wrapper:eq(0) img').animate({opacity: 1}, 950);
	$('#shareit-speaker-box .speakerwrapper:eq(0) img').delay(150).animate({opacity: 1}, 950);
	
	$.curObjectName = $('#shareit-slideshow-box .shareit-slideshow-name:eq(0)');
	if ($.curObjectName.height() > 25) {
		labelDistance = 42;
	} else {
		labelDistance = 25;
	}
	$.curObjectName.animate({bottom: labelDistance}, 850);
	
	
	$.curObjectName = $('#shareit-speaker-box .shareit-speaker-name:eq(0)');
	if ($.curObjectName.height() > 25) {
		labelDistance = 42;
	} else {
		labelDistance = 25;
	}
	$.curObjectName.delay(150).animate({bottom: labelDistance}, 850);
			
			
			
	$('#shareit-image-credits li:eq(0)').animate({opacity: 1}, 950);
			
			
			
			
			
	/*$('#city-selector-sheffield').click(function(){
		animateText('sheffield');	
	});		  
	$('#city-selector-copenhagen').click(function(){
		animateText('copenhagen');
	});	
	$('#city-selector-sofia').click(function(){
		animateText('sofia');
	});	
	$('#city-selector-stuttgart').click(function(){
		animateText('stuttgart');
	});*/
					
	function animateText(city) {
	
		// the current and last city selected
		curLastSelector = curCitySelector;
		
		curCitySelector = '#shareit-' + city + '-text';
		
	
		// if not the current city
		if (curLastSelector != curCitySelector) {
		
			if(!$.browser.msie){
				$(curLastSelector).animate({opacity: 0}, 450);
				$(curCitySelector).animate({opacity: 1}, 450);
			} else {
				$(curLastSelector).hide();
				$(curCitySelector).show();
			}	
				
		}
		
		//changes the cites list
		$("#shareit-cities-selector .active").removeClass('active');
		$("#city-selector-" + city).addClass('active');
	}					   




});
	
setInterval ("startSpeakerFade()", 6900);
setInterval ("startImageFade()", 6400);
	
function startSpeakerFade() {

	wrapper = '#shareit-speaker-box .speakerwrapper';
	name = '.shareit-speaker-name';
	speakerFade(wrapper, name);
}

function startImageFade() {

	wrapper = '#shareit-slideshow-box .slide-wrapper';
	name = '.shareit-slideshow-name';
	
	slideshowFade(wrapper, name);
	
}

function slideshowFade(wrapper, name, singleHeight, doubleHeight){
	
	// speaker initial animation
	numObjects = $(wrapper).size();
	
	
	
	
	singleHeight = 25;
	doubleHeight = 42;
	
	nameString = wrapper + ' ' + name;
	
	if (curSlideObject == numObjects) { curSlideObject = 0; }
	if (nextSlideObject == numObjects) { nextSlideObject = 0; }
	
	
	//FADE OUT
	$(nameString + ':eq(' + curSlideObject  + ')').animate({bottom: 0}, 650);
	$(wrapper + ':eq(' + curSlideObject + ') img').delay(450).animate({opacity: 0}, 850);
	$('#shareit-image-credits li:eq(' + curSlideObject  + ')').delay(450).animate({opacity: 0}, 850);

	//FADE IN	
	$(wrapper + ':eq(' + nextSlideObject  + ') img').delay(1200).animate({opacity: 1}, 950);
	
		
	$.curSlideObjectName = $(nameString + ':eq(' + nextSlideObject  + ')');
	if ($.curSlideObjectName.height() > singleHeight) {
		labelDistance = doubleHeight;
	} else {
		labelDistance = singleHeight;
	}
	$.curSlideObjectName.delay(1800).animate({bottom: labelDistance}, 850);
	$('#shareit-image-credits li:eq(' + nextSlideObject  + ')').delay(1800).animate({opacity: 1}, 850);

	
	
	// Next Object
	curSlideObject = curSlideObject + 1;
	nextSlideObject = nextSlideObject + 1;
	
	
}

function speakerFade(wrapper, name, singleHeight, doubleHeight){
	
	// speaker initial animation
	numObjects = $(wrapper).size();
	
	
	
	
	singleHeight = 25;
	doubleHeight = 42;
	
	nameString = wrapper + ' ' + name;
	
	if (curObject == numObjects) { curObject = 0; }
	if (nextObject == numObjects) { nextObject = 0; }
	
	//FADE OUT
	$(nameString + ':eq(' + curObject  + ')').animate({bottom: 0}, 650);
	$(wrapper + ':eq(' + curObject + ') img').delay(450).animate({opacity: 0}, 850);
	

	//FADE IN	
	$(wrapper + ':eq(' + nextObject  + ') img').delay(1200).animate({opacity: 1}, 950);
	
	$.curObjectName = $(nameString + ':eq(' + nextObject  + ')');
	
	if ($.curObjectName.height() > singleHeight) {
		labelDistance = doubleHeight;
	} else {
		labelDistance = singleHeight;
	}
	$.curObjectName.delay(1800).animate({bottom: labelDistance}, 850);
	
	// Next Object
	curObject = curObject + 1;
	nextObject = nextObject + 1;
	
	
}

/*function startIntroFade() {
	setInterval ( "introFade()", 4500);
}

function introFade() {
		alert(currentIntroText);

	if (currentIntroText == 4) {
		currentIntroText = 0;	
	}
	
	switch(currentIntroText) {
	
		case 0:
			animateText('sheffield');
			break;
			
		case 1:
			animateText('copenhagen');
			break;
			
		case 2:
			animateText('sofia');
			break;
			
		case 3:
			animateText('stuttgart');
			break;
		
		
	}
	
	currentIntroText = currentIntroText + 1;
	
}*/