﻿/// <reference path="jquery-1.6.1-vsdoc.js" />
$(window).bind("load", function () {
	if (window.location.hash != "")
	{
    	loadFromHash();
	}
});
$(function(){
	$("a[linkType=navLink]").live("click", function (e) {
        e.preventDefault();
        var navPath = $(this).attr("href");
        window.location.hash = "/" + navPath.replace(".php", "");
		loadFromHash();
    });	
});

function loadFromHash() {
    var navPath = window.location.hash;
    navPath = navPath.substring(2);
    $("#fadeLayer").fadeOut(200);
		$("#pageBG").attr("style","");
		$("#bgimg").fadeOut(200);
        $("a[linkType=navLink]").removeClass().addClass("footerLink");
        //$(this).removeClass().addClass("footerLinkActive");
        $("#contentConainer").animate({
			opacity: 0.30,
			top: '+=50'
		  }, 400, function() {
			$("#contentConainer").css("opacity","1").css("left","50%").html("").load(navPath+".php?mode=split");
			$(".contentContainer").attr("style", "");
    });
}


function setLogo(logoClass) {
    $("#logoContainer").fadeOut(200, function () {
        $("#logoContainer").removeClass().addClass("logo").addClass(logoClass).fadeIn(1000);
    });
}

function initBG(bgColor, bgImage, fadeLayerImage) {
    $("#contentConainer").fadeIn(50);
    $("#trash").html("<img src='images/bgz/" + bgImage + "' id='tmpBG' /><img src='images/bgz/" + fadeLayerImage + "' id='tmpLayer' />");
    $('#tmpBG').load(function () {
        $("#pageBG").fadeOut(200, function () {
            $("#pageBG").css("opacity", "1");
            $("#pageBG").css("background-color", bgColor);
			$("#bgimg").attr("src", "images/bgz/" + bgImage);
            $("#bgimg").fadeIn(50, function () {
				$("#pageBG").fadeIn(500);
                if (fadeLayerImage) {
                    $("#fadeLayer").css("background-image", "url(images/bgz/" + fadeLayerImage + ")");
                }
                else {
                    $("#fadeLayer").css("background-image", "url(images/bgz/fade-filter.png)");
                }
                $("#fadeLayer").delay(1200).fadeIn(500, function () {

                    $("#fadeLayer").css("display", "block");
                    $(".pageBody").fadeIn(500, function () {
                        $(".pageBody").css("display", "block");
                    });
                });
            });
        });
    });
}

function initTabs(tabCapClass) {
    $("a[linkType=tabLink]").live("click", function (e) {
        e.preventDefault();
        var activeTab = $(this).attr("href");
        $("a[linkType=tabLink]").removeClass().addClass(tabCapClass);
        $(this).removeClass().addClass(tabCapClass+"Active");
        $(".tabDetail").hide().stop(true);
                $("#" + activeTab + "").fadeIn(500, function () {
                    $("#" + activeTab + "").css("display", "block").css("opacity","1");
                });
    });
    $("a[linkType=tabLink]").first().click();

}

function FullScreenBackground(theItem){
	var winWidth=$(window).width();
	var winHeight=$(window).height();
	var imageWidth=$(theItem).width();
	var imageHeight=$(theItem).height();
	var picHeight = imageHeight / imageWidth;
	var picWidth = imageWidth / imageHeight;
	if ((winHeight / winWidth) < picHeight) {
	$(theItem).css("width",winWidth);
	if (!$.browser.msie) { $(theItem).css("height",picHeight*winWidth); }
	} else {
	$(theItem).css("height",winHeight);
	$(theItem).css("width",picWidth*winHeight);
	};
	$(theItem).css("margin-left", 0 );
	if (!$.browser.msie) { $(theItem).css("margin-top", (winHeight - $(theItem).height())/2 ); }
}
window.onload = function () {
	FullScreenBackground('#bgimg');
}
$(window).resize(function() {
	FullScreenBackground('#bgimg');
});

$("input[kind=popTrigger]").live("click", function(){
	var path = $(this).attr("path");
	$(".popContainer").html("").load(path);
	$(".popBGLayer").fadeIn("fast", function(){
		$(".popContainer").fadeIn("fast");
	});
});

$(".imgClose").live("click", function(){
	$(".popContainer").fadeOut("fast", function(){
		$(".popBGLayer").fadeOut("fast");
	});
});

$("textarea[kind=postcardField]").live("blur", function(){
	if ($(this).val() != "")
	{
		$(this).removeClass("redBox");
	}
});

$("input[kind=postcardField]").live("blur", function(){
	if ($(this).val() == "")
	{
		$(this).removeClass("pageLine");
	}
	else
	{
		$(this).addClass("pageLine");
		$(this).removeClass("redBox");
	}
});

function validateContactUs()
{
	var errorTrigger = false;
	var fName = $("#name").val();
	var fEmail = $("#email").val();
	var fPhone = $("#phone").val();
	var fCompany = $("#company").val();
	var fEnquiry = $("#enquiry").val();
	
	if (fName == ""){ $("#name").addClass("redBox"); errorTrigger = true; }
	if (fEmail == ""){ $("#email").addClass("redBox"); errorTrigger = true; }
	if (fEnquiry == ""){ $("#enquiry").addClass("redBox"); errorTrigger = true; }
	
	if (errorTrigger == false)
	{
		$(".stamp").animate({ opacity: 1 }, 400);
		$.post("contact.php", { name: fName, email: fEmail, phone: fPhone, company: fCompany, enquiry: fEnquiry },
		   function(data) {
			 var result = jQuery.parseJSON(data);
			 showAlert(result);
			 $("#frmReset").click();
		});
	}
}

function validateCareers()
{
	var errorTrigger = false;
	var fName = $("#fullName").val();
	var fEmail = $("#fromEmail").val();
	var fPhone = $("#phoneNumber").val();
	var jobPosition = $("#jobPosition").val();
	var Experience = $("#experience").val();
	var DegreeName = $("#bsDegreeName").val();
	var University = $("#bsUniversityName").val();
	var cv = $("#resume_attachment").val();
	if (fName == ""){ $("#fullName").css('background-color', '#FCA6A9'); errorTrigger = true; } else {$("#fullName").css('background-color', '#FFF'); }
	if (fEmail == ""){ $("#fromEmail").css('background-color', '#FCA6A9'); errorTrigger = true; } else {$("#fromEmail").css('background-color', '#FFF'); }
	if (fPhone == ""){ $("#phoneNumber").css('background-color', '#FCA6A9'); errorTrigger = true; } else {$("#phoneNumber").css('background-color', '#FFF'); }
	if (jobPosition == '0'){ $("#jobPosition").css('background-color', '#FCA6A9'); errorTrigger = true; } else {$("#jobPosition").css('background-color', '#FFF'); }
	
	if (Experience == '0'){ $("#experience").css('background-color', '#FCA6A9'); errorTrigger = true; } else {$("#experience").css('background-color', '#FFF'); }
	if (DegreeName == '0'){ $("#bsDegreeName").css('background-color', '#FCA6A9'); errorTrigger = true; } else {$("#bsDegreeName").css('background-color', '#FFF'); }
	if (University == ""){ $("#bsUniversityName").css('background-color', '#FCA6A9'); errorTrigger = true; } else {$("#bsUniversityName").css('background-color', '#FFF'); }
	if (cv == ""){ $("#resume_attachment").css('background-color', '#FCA6A9'); errorTrigger = true; } else {$("#resume_attachment").css('background-color', '#FFF'); }
	if (errorTrigger == false)
	{
		document.forms["jobApplicationForm"].submit();
	}
	/*if (errorTrigger == false)
	{
		$(".stamp").animate({ opacity: 1 }, 400);
		$.post("career.php", { name: fName},
		   function(data) {
			 alert(data);
		});
	}*/
}

function showAlert(result)
{
	if (result.type == "success")
	{
		$(".alertContainer").addClass("successPlug");
	}
	if (result.type == "failure")
	{
		$(".alertContainer").addClass("failurePlug");
	}
	$(".alertText").text(result.message);
	$(".popBGLayer").fadeIn("fast", function(){
		$(".alertContainer").fadeIn("fast");
	});
}

function closeAlertContact()
{
	$(".alertContainer").fadeOut("fast", function(){
		$(".alertContainer").removeClass("successPlug");
		$(".alertContainer").removeClass("failurePlug");
		$(".popBGLayer").fadeOut("fast");
	});
	$(".stamp").animate({ opacity: 0 }, 400);
}
