// allgemeine Variablen
shortTime = 300;
longTime = 800;

referencesOvervies = true;
teamOverview = true;
jobOverview = true;

currentPerson = 1;
anzahlPersonen = 0;

currentReferenz = 1;
anzahlReferenz = 0;

host = window.location.hostname;
if (host == 'localhost') {
	localhost = true;
	rootPath = 'http://localhost:8888/Alex%20Schmid/html/';
} else {
	localhost = false;
	rootPath = 'http://www.alex-schmid.ch/'; // muss dringend für neue website angepasst werden.
}

$(document).ready(function() {
// Tiny Scrollbar update
	$('#scrollDiv').tinyscrollbar();
	$('img').load(function() {
		$('#scrollDiv').tinyscrollbar_update();
	})
	
// Printer
	$('#printer').click(function() {
		JavaScript:window.print();
	});

// Störer mit link
$('#stoerer').click(function() {
	window.open('http://www.dialogin.ch', '_blank');
});

// Neues Menu und Navigation auf der Seite
	$('.menu li.link, .button').click(function() {
		navigationsLink = $(this).attr('link');
		window.open(rootPath + navigationsLink, '_self');
	})
	
	// Buttons
	$('.button').mouseenter(function() {
		$('#loader').css('backgroundPosition', '0 -30px');
		//wenn in feld kommst
	//	buttonID = $(this).attr('id');
	//	thisButton = '#' +buttonID;
		
	//	var popup = $("<p>").attr('class', 'popup').attr('id', buttonID + '-popup').appendTo(thisButton).fadeIn(shortTime);
	//	$('<span>').text(buttonID).appendTo(popup);
		
	}).mouseleave(function() {
		$('#loader').css('backgroundPosition', '0 0px');
		// wenn feld verlässt
		$('#'+buttonID + '-popup').fadeOut(shortTime).delay(longTime, function() {$(this).remove();})
	});
	
// remove all hover when mouseentering
$('.menu').live('mouseenter', function() {
	$('ul.menu li').each(function() {$(this).removeClass('hover')});
});


// job 
$('ul#jobOverview li').click(function() {
	thisJob = $(this).attr('id')
	$('#jobDetail').attr('job', thisJob).load(rootPath+ 'agentur/jobs/tinysites/'+thisJob+'.html');
	overviewSwitch('job');
});

$('#menuJobDetail').click(function() {
	overviewSwitch('job');
});

	
// referenzen
	$('#referenzenOverview li').click(function() {
		consumer = $(this).attr('consumer');
		//alert(consumer);
		
		$.getJSON(rootPath + '_script/php/ajax.php?currentConsumer=' + consumer,
			function(data) {				
				//einfache Angaben
					//anzahl referenzen
					anzahlReferenz = data.length+1;
					
					//Ausgabe der einzelen Referenzen
					$('#referenzenDetail').html('<ul><li><h1 id="consumerName">'+ data[1].name +'</h1><p id="consumerInfo">'+ data[1].consumerDescription +'</p></li>')
						
					for (var x = 0; x < data.length; x++) {	
						//create a container for each comment
						var referenceList = $("<li>").attr('id', data[x].project).appendTo("#referenzenDetail ul");
		
						//add author name and comment to container
						$("<img>").attr("src", rootPath + "referenzen/links/"+ data[x].link).appendTo(referenceList);
						referenceInfo = $('<p>').attr('class', 'refInfo').html(data[x].project +' ' + data[x].element).appendTo(referenceList);
						
						if (data[x].prize) {
							var prize = $('<span>').attr('class', 'prize').html(data[x].prizeDescription).appendTo(referenceInfo);
						};
					};
			}
		);
		
		//content switch
		overviewSwitch('ref');
		
	});
	
	$('#menuRefDetail').live('click', function() {
		overviewSwitch('ref');
	});
	
	// referenzen blättern
		// weiter
		$('#next.ref').live('click', function(){
			referenzen('next');
		});
		
		// back
		$('#prevous.ref').live('click', function(){
			referenzen('prevous')
		});
	
// Wheel
	$('#wheel-up').mouseover(function() {
		$('#wheel').css('background-image', 'url('+rootPath + '_img/buttons/wheel-up.png)');
	}).mouseleave(function() {
		$('#wheel').css('background-image', 'none');
	});
	$('#wheel-right').mouseover(function() {
		$('#wheel').css('background-image', 'url('+rootPath + '_img/buttons/wheel-right.png)');
	}).mouseleave(function() {
		$('#wheel').css('background-image', 'none');
	});
	$('#wheel-down').mouseover(function() {
		$('#wheel').css('background-image', 'url('+rootPath + '_img/buttons/wheel-down.png)');
	}).mouseleave(function() {
		$('#wheel').css('background-image', 'none');
	});
	$('#wheel-left').mouseover(function() {
		$('#wheel').css('background-image', 'url('+rootPath + '_img/buttons/wheel-left.png)');
	}).mouseleave(function() {
		$('#wheel').css('background-image', 'none');
	});
	
	$('#kontaktinfo_hide').click(function() {
		$('#kontaktinfo').fadeOut(500)
	});
		
	
}).everyTime(3000, function(i) {
	loading();
});
