﻿var optyva = {
	Initialize: function() {
		this.CurrentPage = "home";
		var detailsPageParam = (location.href).split('#')[1];
		if (typeof (detailsPageParam) != 'undefined') {
			if (detailsPageParam == "services" || detailsPageParam == "ourphilosophy" || detailsPageParam == "experience" || detailsPageParam == "contactus") {
				this.LoadDetailsPagesFromHomepage(detailsPageParam);
			}
			else {
				$("#homePage").css("display", "block");
			}
		}
		else {
			$("#homePage").css("display", "block");
		}
	},
	LoadDetailsPagesFromHomepage: function(detailsPageName) {
		this.CurrentPage = detailsPageName;
		$("#homePage").fadeOut(800, function() { optyva.AnimateInDetailsPage() });
	},
	AnimateInDetailsPage: function() {
		if ($("#detailsPage").css("display") != "block") {
			$("#detailsPage").css("display", "block");
			$("#detailsPage_TopNav_RootContainerDiv_Wrapper").css({ "display": "block", "margin-top": "-210px" });
			$("#detailsPage_Body").css({ "display": "block", "margin-top": "1200px" });
			$("#detailsPage_TopNav_RootContainerDiv").css("display", "none");
			$("#detailsPage_Body_RootContainerDiv").css("display", "none");

			$("#detailsPage_Body_RootContainerDiv div").css("display", "none");
			$("#detailsPage_Body_Content_" + this.CurrentPage).css("display", "block");
			$("#detailsPage_Body_Content_" + this.CurrentPage + " div").css("display", "block");


			$("#detailsPage_TopNav_RootContainerDiv_Wrapper").animate({ marginTop: "0px" }, 800,
			function() {
				$("#detailsPage_TopNav_RootContainerDiv").fadeIn(500);
				$("#detailsPage_TopNav_NavItems div a span").removeClass("greenfont");
				$("#detailsPage_TopNav_NavItem_" + optyva.CurrentPage + " a span").addClass("greenfont");
			});

			$("#detailsPage_Body").animate({ marginTop: "0px" }, 700, function() { $("#detailsPage_Body_RootContainerDiv").fadeIn(500); });

			if (this.CurrentPage == "services") {
				servicesPageContent.Initialize();
			} else {
				servicesPageContent.Destroy;
			}
		}
	},
	AnimateDetailsContent: function(pageName) {
		var currentPageToFadeOut = this.CurrentPage;
		this.CurrentPage = pageName;
		$("#detailsPage_TopNav_NavItems div a span").removeClass("greenfont");
		$("#detailsPage_TopNav_NavItem_" + this.CurrentPage + " a span").addClass("greenfont");
		$("#detailsPage_Body_Content_" + currentPageToFadeOut).fadeOut(500, function() {
			$("#detailsPage_Body_Content_" + optyva.CurrentPage).fadeIn(500);
			$("#detailsPage_Body_Content_" + optyva.CurrentPage + " div").fadeIn(500);
		});

		if (this.CurrentPage == "services") {
			servicesPageContent.Initialize();
		} else {
			servicesPageContent.Destroy;
		}
	}
};


var rotatingContent = {
	Initialize: function() {
		this._SlidesIDArray = new Array();
		this._SlidesIDArray[0] = $("#animatingContentHomePage_AnimatingDiv_Content1");
		this._SlidesIDArray[1] = $("#animatingContentHomePage_AnimatingDiv_Content2");
		this._SlidesIDArray[2] = $("#animatingContentHomePage_AnimatingDiv_Content3");
		this._SlidesContentIndexArray = new Array();
		this._SlidesContentIndexArray[0] = 0;
		this._SlidesContentIndexArray[1] = 3;
		this._SlidesContentIndexArray[2] = 5;

		this._CurrentSlide = 0;

		this._ContentArray = new Array();
		this._ContentArray[0] = "business optimization consulting";
		this._ContentArray[1] = "Web analytics";
		this._ContentArray[2] = "online communications and social media strategy";
		this._ContentArray[3] = "project / program management";
		this._ContentArray[4] = "financial and business performance analysis";
		this._ContentArray[5] = "custom website design / development";
		this._ContentArray[6] = "customer relationship management (CRM) and targeting strategy";
		this._ContentArray[7] = "specialized online tools and management solutions";

		this._RotateInterval = setInterval("rotatingContent.AnimateOut()", 3000);
	},
	AnimateOut: function() {
		if (typeof (this._SlidesIDArray) == 'undefined')
			return;

			this._SlidesIDArray[this._CurrentSlide].fadeOut(800,
			function() {
				rotatingContent.AnimateIn();
			});
	},
	AnimateIn: function() {
		if (typeof (this._SlidesIDArray) == 'undefined')
			return;

		this._SlidesContentIndexArray[this._CurrentSlide]++;
		if (this._SlidesContentIndexArray[this._CurrentSlide] == this._ContentArray.length)
			this._SlidesContentIndexArray[this._CurrentSlide] = 0;

			this._SlidesIDArray[this._CurrentSlide].html("<strong>" + this._ContentArray[this._SlidesContentIndexArray[this._CurrentSlide]] + "</strong>");
			this._SlidesIDArray[this._CurrentSlide].fadeIn(800);

		this._CurrentSlide++;
		if (this._CurrentSlide == this._SlidesIDArray.length)
			this._CurrentSlide = 0;
	},
	Destroy: function() {
		clearInterval(this._RotateInterval);
		this._SlidesIDArray = null;
		this._ContentArray = null;
	}
};

var servicesPageContent = {
	Initialize: function() {
		this._ContentIDArray = new Array();
		this._ContentIDArray[0] = $("#fadingBulletListContent_Content_1");
		this._ContentIDArray[1] = $("#fadingBulletListContent_Content_2");
		this._ContentIDArray[2] = $("#fadingBulletListContent_Content_3");
		this._ContentIDArray[3] = $("#fadingBulletListContent_Content_4");
		this._ContentIDArray[4] = $("#fadingBulletListContent_Content_5");
		this._ContentIDArray[5] = $("#fadingBulletListContent_Content_6");
		this._ContentIDArray[6] = $("#fadingBulletListContent_Content_7");
		this._ContentIDArray[7] = $("#fadingBulletListContent_Content_8");
		this._CurrentContentShownID = 1;

		$("#fadingBulletListContent #fadingBulletListContent_List ul li").each(function(i, li) {
			var jqueryli = $(li);
			jqueryli.bind("click", function() { servicesPageContent.OnListItemClick(jqueryli); });
			jqueryli.bind("mouseover", function() { servicesPageContent.OnListItemMouseOver(jqueryli); });
			jqueryli.bind("mouseout", function() { servicesPageContent.OnListItemMouseOut(jqueryli); });
		});
		this._AutoRotateInterval = setInterval("servicesPageContent.OnAutoRotate()", 10000);
	},
	Destroy: function() {
	},
	OnListItemClick: function(listItemElement) {
		this.DisplayContent(listItemElement);
	},
	OnListItemMouseOver: function(listItemElement) {
		clearInterval(this._AutoRotateInterval);
		this.DisplayContent(listItemElement);
	},
	OnListItemMouseOut: function() {
		this._AutoRotateInterval = setInterval("servicesPageContent.OnAutoRotate()", 10000);
	},
	DisplayContent: function(listItemElement) {
		//hide previous content and show moused over content
		$("#fadingBulletListContent_Content_" + this._CurrentContentShownID).addClass("hidden");
		$("#fadingBulletListContent_Content_" + this._CurrentContentShownID + " ul li").addClass("hidden");
		var id = listItemElement.attr("id").replace("fadingBulletListContent_Item_", "");
		$("#fadingBulletListContent_Content_" + id).removeClass("hidden");
		$("#fadingBulletListContent_Content_" + id + " ul li").removeClass("hidden");

		//make selected item green
		$("#fadingBulletListContent_Item_" + this._CurrentContentShownID).removeClass("greenfont");
		$("#fadingBulletListContent_Item_" + id).addClass("greenfont");

		this._CurrentContentShownID = parseInt(id);
	},
	OnAutoRotate: function() {
		if (this._CurrentContentShownID + 1 > this._ContentIDArray.length)
			this.DisplayContent($("#fadingBulletListContent_Item_1"));
		else
			this.DisplayContent($("#fadingBulletListContent_Item_" + (this._CurrentContentShownID + 1)));
	}
};


var contactUsForm = {
	Submit: function() {
		var nameText = $("#nameTextBox").val();
		var emailText = $("#emailaddressTextBox").val();
		var phoneText = $("#phoneTextBox").val();
		var businessNameText = $("#businessnameTextBox").val();
		var mailingAddressText = $("#mailingaddressTextBox").val();
		var faxText = $("#faxTextBox").val();
		var hearAboutText = $("#hearaboutTextBox").val();
		var interestedInText = $("#interestedInTextBox").val();
		var questionsCommentsText = $("#questionCommentsText").text();

		var passedValidation = true;
		if (nameText == "") {
			$("#detailsPage_Body_Content_contactus_nameRequired").css("display", "block");
			passedValidation = false;
		}
		if (emailText == "") {
			$("#detailsPage_Body_Content_contactus_emailRequired").css("display", "block");
			passedValidation = false;
		}
		if (phoneText == "") {
			$("#detailsPage_Body_Content_contactus_phoneRequired").css("display", "block");
			passedValidation = false;
		}
		if (hearAboutText == "") {
			$("#detailsPage_Body_Content_contactus_hearAboutRequired").css("display", "block");
			passedValidation = false;
		}
		if (interestedInText == "") {
			$("#detailsPage_Body_Content_contactus_interestedInRequired").css("display", "block");
			passedValidation = false;
		}

		if (passedValidation) {
			document.cookie = "name=" + nameText;
			document.cookie = "email=" + emailText;
			document.cookie = "phone=" + phoneText;
			document.cookie = "businessName=" + businessNameText;
			document.cookie = "mailingAddress=" + mailingAddressText;
			document.cookie = "fax=" + faxText;
			document.cookie = "hearAbout=" + hearAboutText;
			document.cookie = "interestedIn=" + interestedInText;
			document.cookie = "questionsComments=" + questionsCommentsText;
			$.get("SubmitContactFormHandler.ashx");
			$(".thankyouRedText").css("display", "block");
		}
	}
}
