﻿var NameVal = "";
var EmailVal = "";

var LiLoop = 0;

$(document).ready(function() {


    SlideShowTimer = setInterval(function() { RotateSlideShow(); }, 5000);
    SlideShowTexts = setInterval(function() { RotateSlideTexts(); }, 10000);


	$("a.lightbox").lightBox();

	$("input[type='text']").focus(function() {
		if (this.value == this.defaultValue) this.value = "";
	});
	$("input[type='text']").blur(function() {
		if (this.value == "") this.value = (this.defaultValue ? this.defaultValue : "");
	});

	$("#aboutthumb a").click(function() {
		var ImgId = $(this).children("img").attr("id");
		ChangeAboutPicture(ImgId);
		return false;
	});

	$(".compright a").each(function() {
		if ($(this).attr("href").indexOf("http") != -1) {
			var OpenUrl = $(this).attr("href");
			$("#CompLogoPres").click(function() { window.open(OpenUrl); });
			$("#CompLogoPres").css("cursor", "pointer");
		}

	});

	$("ul.StartLogos li img").css("opacity", "0");
	var LiCount = 0;
	$("ul.StartLogos li").each(function() {
		LiCount++;
	});

	ImgLoaded = setInterval(function() {
		SetStartImage();
	}, 500);


	$("ul.StartLogos li").hover(function() {
		$(this).children("a:last").css("display", "block");
		$(this).children("a:first").css("display", "none");
	}, function() {
		$(this).children("a:first").css("display", "block");
		$(this).children("a:last").css("display", "none");
	});

	NameVal = $("input[name='name']").val();
	EmailVal = $("input[name='email']").val();
	SetEnable();
	$("input[name='name'], input[name='email']").keyup(function() {
		NameVal = $("input[name='name']").val();
		EmailVal = $("input[name='email']").val();
		SetEnable();
	});



	function SetStartImage() {
		$("ul.StartLogos li").each(function() {
			var ImgHeight = Math.round($(this).children("a:first").children("img").height());
			if (ImgHeight > 0) {
				var CurrMarginTop = Math.round($(this).children("a:first").children("img").css("margin-top").replace("px", ""));
				if (CurrMarginTop == 0) {
					LiLoop++;
					var LiHeight = 55;
					var NewMargin = Math.round((LiHeight - ImgHeight) / 2);
					$(this).children("a").children("img").fadeTo("slow", 1);
					$(this).children("a").children("img").css("margin-top", NewMargin + "px");
					if (LiLoop == LiCount) {
						clearInterval(ImgLoaded);
					}
				}
			}
		});
	}


});



function SetEnable() {
	if (NameVal.length > 2 && EmailVal.length > 2) {
		$("#contactsub").removeAttr("disabled").css("opacity", "1")
	} else {
		$("#contactsub").attr("disabled", "disabled").css("opacity", "0.2")
	}
}

function ChangeAboutPicture(NewImgId) {
	var ImgId = NewImgId.replace("SmallImg", "BigImg");
	var CurrImg = "";
	$("#aboutimage img").each(function() {
		if ($(this).css("display") != "none") {
			CurrImg = $(this).attr("id");
		}
	});

	if (CurrImg != ImgId) {

		$("#" + CurrImg).css("z-index", "1");
		$("#" + ImgId).css("z-index", "2");
		$("#" + ImgId).fadeIn(300, function() {
			$("#" + CurrImg).css("display", "none");
		});
	}
}





function RotateSlideShow() {
    var CurrImg = "";
    $("#slideshow img").each(function() {
        if ($(this).css("display") != "none") {
            CurrImg = $(this).attr("id");
        }
    });

    $("#" + CurrImg).css("z-index", "1");
    $("#" + CurrImg).next("img").css("z-index", "2");
    $("#" + CurrImg).next("img").fadeIn(500, function() {
        $("#" + CurrImg).css("display", "none");
        $("#" + CurrImg).clone().appendTo("#slideshow");
        $("#" + CurrImg + ":first").remove();
    });
}

function RotateSlideTexts() {
    var CurrText = "";
    $("#contentbox span").each(function() {
        if ($(this).css("display") != "none") {
            CurrText = $(this).attr("id");
        }
    });

    $("#" + CurrText).fadeOut(500, function() {
        $("#" + CurrText).next("span").fadeIn(500, function() {
            $("#" + CurrText).clone().appendTo("#contentbox");
            $("#" + CurrText + ":first").remove();
        });
    });
}