/* 
 * STUDIO ONE AG
 * www.studio1.ch
 * 
 */

google.setOnLoadCallback(function() {

	$(document).ready(function(){

		/* ------ */
		/* COLORS */
		/* ------ */

			var f 		= new Array();
			
			f["weiss"] 	= "#FFFFFF";
			f["rot"] 	= "#FF0000";
			f["gelb"] 	= "#fdc613";


		/* ------ */
		/* SLOGAN */
		/* ------ */

			$("#slogan").fadeIn(5000);



		/* ---------- */
		/* REFERENCES */
		/* ---------- */

			$(".teaserList.references a.item").click(function() {
			
				var title 	= $(this).children("span.desc").children("span.title").text();
				var type 	= $(this).children("span.desc").children("span.type").text();
				var url		= $(this).children("span.desc").children("span.url").text();
				var folder	= $(this).children("span.desc").children("span.folder").text();
				
				if ($(this).hasClass("news")) {
					title = title + " " + type;
				} else if ($(this).hasClass("reference")){
					if (url != "") {url = " - " + url;}
					title = title + " (" + type + ")" + url;
				}
				
				$(this).colorbox({
					opacity: 0.6,
					title: title,
					inline: true,
					href: ".refDetail." + folder
				});		
				
			});	

			var config = {sensitivity: 3, interval: 50, over: mouseEnter, timeout: 50, out: mouseLeave};
			
			var fadeSpeed = 400;		
			
			$(".teaserList.references a.item").hoverIntent(config);
	
			function mouseEnter() {
				$(this).children("img").fadeTo(fadeSpeed, 1);
				$(this).children("span.desc").fadeOut(fadeSpeed);
			}		
			
			function mouseLeave() {
				$(this).children("img").fadeTo(fadeSpeed, 0.7);
				$(this).children("span.desc").fadeIn(fadeSpeed);
			}		
		
		
		
		/* ------------ */
		/* CONTACT-FORM */
		/* ------------ */
				
			$("a.contact").click(function(){
				
				$.colorbox({
					opacity: 0.6,					
					inline: true,
					href: "#contactForm",
					innerWidth: "660px"
				});
				
				return false;				
			});					
			
			$("#contactForm input.fld_input, #contactForm textarea.fld_textarea").focus(function () {
				$(this).css("border", "1px solid " + f["gelb"]);
				$(this).css("color", f["gelb"]);
				$(this).parent(".fldItem").parent(".formItem").children(".labItem").children("label").css("color", f["gelb"]);
			}).blur(function () {
				$(this).css("border", "1px solid " + f["weiss"]);
				$(this).css("color", f["weiss"]);
				$(this).parent(".fldItem").parent(".formItem").children(".labItem").children("label").css("color", f["weiss"]);
			});		
			
			$("#contactForm input.fld_submit").click(function () {
				
				formValid = true;
				
				$(this).css("visibility", "hidden");
				
				if ($("#contactForm input#name").val().length < 2) {
					$("#contactForm label[for=name]").css("color", f["rot"]);
					$("#contactForm input#name").css("border-color", f["rot"]);
					formValid = false;
				} else {
					$("#contactForm label[for=name]").css("color", f["weiss"]);
					$("#contactForm input#name").css("border-color", f["weiss"]);
				}		
						
				if ($("#contactForm input#address").val().length < 2) {
					$("#contactForm label[for=address]").css("color", f["rot"]);
					$("#contactForm input#address").css("border-color", f["rot"]);
					formValid = false;
				} else {
					$("#contactForm label[for=address]").css("color", f["weiss"]);
					$("#contactForm input#address").css("border-color", f["weiss"]);
				}		
						
				if ($("#contactForm input#ziploc").val().length < 5) {
					$("#contactForm label[for=ziploc]").css("color", f["rot"]);
					$("#contactForm input#ziploc").css("border-color", f["rot"]);
					formValid = false;
				} else {
					$("#contactForm label[for=ziploc]").css("color", f["weiss"]);
					$("#contactForm input#ziploc").css("border-color", f["weiss"]);
				}	
							
				if ($("#contactForm input#phone").val().length < 9) {
					$("#contactForm label[for=phone]").css("color", f["rot"]);
					$("#contactForm input#phone").css("border-color", f["rot"]);
					formValid = false;
				} else {
					$("#contactForm label[for=phone]").css("color", f["weiss"]);
					$("#contactForm input#phone").css("border-color", f["weiss"]);
				}				

				if ($("#contactForm input#email").val().indexOf("@") < 0) {
					$("#contactForm label[for=email]").css("color", f["rot"]);
					$("#contactForm input#email").css("border-color", f["rot"]);
					formValid = false;
				} else {
					$("#contactForm label[for=email]").css("color", f["weiss"]);
					$("#contactForm input#email").css("border-color", f["weiss"]);
				}

				if ($("#contactForm textarea#message").val().length < 10) {
					$("#contactForm label[for=message]").css("color", f["rot"]);
					$("#contactForm textarea#message").css("border-color", f["rot"]);
					formValid = false;
				} else {
					$("#contactForm label[for=message]").css("color", f["weiss"]);
					$("#contactForm textarea#message").css("border-color", f["weiss"]);
				}				

				if (formValid) {
					
					$.ajax({
						type: "POST",
						url: "inc/ajax_mailSend.php",
						data: {
							company: 	$("#contactForm input#company").val(), 
							name: 		$("#contactForm input#name").val(), 
							address: 	$("#contactForm input#address").val(), 
							ziploc: 	$("#contactForm input#ziploc").val(),
							phone: 		$("#contactForm input#phone").val(),
							email:		$("#contactForm input#email").val(),
							message:	$("#contactForm textarea#message").val() 
						},
						success: function(succMsg) {
							
							if (succMsg == "ok") {
								statusText = "Ihre Nachricht wurde erfolgreich &uuml;bermittelt.<br /><br />Besten Dank f&uuml;r Ihre Kontaktaufnahme.";
							} else {
								statusText = "Es ist ein Fehler beim Senden der Nachricht aufgetreten.";
							}
							
							$("#contactForm .formItem").css("display", "none");
							$("#contactForm").children(".text").after("<br /><span class='orange'>" + statusText + "</span>");
							
						}
					});	
										
				} else {
					
					$(this).css("visibility", "visible");
					
				}
				
			});
			
	});

});	
