var flag = 0; 		// =1 if a mousevent has taken place
var flag2 = 0; 		// =1 if a scheduled fadeout has started
var flag3 = 0; 		// =1 if a mouseevent fadein is taking place
var flag4 = 0; 		// =1 if a scheduled fadeout has been interrupted
var i = 2; 			// The index of the image in the slideshow
var x = 0; 			// The current image displayed
var cs_total = 3; 	// The total number of slideshow items
var name = ""; 		//
var stringname = ""; // Used for the URL of the background image
var linkname = "";
var PageUrl = "";
// Start cycle and set starting positions
function Start() {
	setTimeout("Cycle()", 4000);
	jQuery(".case_study_1").animate({ backgroundPosition: "-14px 0px" }, 0);

	jQuery(".case_study_image").attr("src", jQuery(".Image1").attr("src"));
	jQuery(".case_study_image").attr("alt", "Case Study");
	jQuery(".case_studies_box").attr("href", jQuery(".HyperLink1").attr("href"));
	//jQuery(".box1").fadeIn(0);
}

// Begins the cycle
function Cycle() {
	if (flag == 0) {
		flag2 = 1;
		stringname = jQuery(".Image" + i).attr("src");
		linkname = jQuery(".HyperLink" + i).attr("href");
		//stringname = Image1.src;  // "images/case_studies_" + i + ".jpg";
		//jQuery(".box").fadeOut(0);
		jQuery(".case_study_image").fadeTo(1000, 0, function() {
			Cycle2();
		});
	}
};

// Changes the chosen icon
function Changeicon() {
	if (flag == 0) {
		name = ".case_study_" + i;
		jQuery(".case_study").animate({ backgroundPosition: "0px 0px" }, 0);
		jQuery(name).animate({ backgroundPosition: "-14px 0px" }, 0);
	}
}

// Second half of cycle
function Cycle2() {
	jQuery(".case_study_image").attr("src", stringname);
	jQuery(".case_studies_box").attr("href", linkname);
	Changeicon();
	flag2 = 0;
	jQuery(".case_study_image").fadeTo(1000, 1, function() {
		Fadein();
		// Set cycle index
		if (i >= cs_total) {
			i = 1;
		}
		else if (i < cs_total) {
			i++;
		}
	});
	if (flag4 == 0) {
		setTimeout("Cycle()", 5000);
	}
};

// Fades in text
function Fadein() {
	if (flag != 1) { jQuery((".box" + i)).fadeIn(0); }
};

jQuery(document).ready(function() {
	// What happens on click
	jQuery(".case_study").click(function() {

		x = (this.className).charAt(((this.className).length) - 1);


		stringname = jQuery(".Image" + x).attr("src");

		linkname = jQuery(".HyperLink" + x).attr("href");

		if (flag2 != 0) {

			i = x;

			flag4 = 1;
		}

		else if (flag2 == 0) {
			flag = 1
			jQuery(".box").fadeOut(0);
			flag2 = 1;
			jQuery(".case_study_image").fadeTo(1000, 0, function() {
				jQuery(".case_study_image").attr("src", stringname);
				jQuery(".case_studies_box").attr("href", linkname);
				flag = 0;
				flag2 = 0;
				flag3 = 1;
			});
			jQuery(".case_study_image").fadeTo(1000, 1, function() {
				flag3 = 0;
				if (flag != 1) {
					jQuery((".box" + x)).fadeIn(0);
					flag = 1;
				}
			});
		}

		jQuery(".case_study").animate({ backgroundPosition: "0px 0px" }, 0);
		jQuery(this).animate({ backgroundPosition: "-14px 0px" }, 0);
	});
	jQuery(".TextSize01").click(function() {
		jQuery("p").css({ "font-size": "100%" });
		jQuery("li").css({ "font-size": "100%" });
		jQuery("h1").css({ "font-size": "150%" });
		jQuery(".TextSize").css({ "color": "gray" });
		jQuery(this).css({ "color": "black" });
		var PageUrl = jQuery(location).attr("href");
		if (PageUrl.indexOf("/News.aspx") != -1) {
			CloseAll();
			jQuery(".NewsItem .NewsItemRight .NewsItemBody").each(function(i) {
				jQuery(this).css("height", "auto");
				jQuery(this).css("overflow", "visible");
				jQuery(this).parent().children().find(".NewsItemReadMore").css({ "font-size": "100%" });
				NewsBodyCurrentHeight = jQuery(this).height();
				jQuery(this).attr("id", NewsBodyCurrentHeight);
				if (jQuery(this).height() > 109) {
					jQuery(this).parent().children().find(".NewsItemReadMore").show();
					jQuery(this).css("height", "109px");
					jQuery(this).css("overflow", "hidden");
				}
				else {
					jQuery(this).parent().children().find(".NewsItemReadMore").hide();
					jQuery(this).css("height", "auto");
					jQuery(this).css("overflow", "visible");
				}
			});
		}
	});

	jQuery(".TextSize02").click(function() {
		jQuery("p").css({ "font-size": "115%" });
		jQuery("li").css({ "font-size": "115%" });
		jQuery("h1").css({ "font-size": "175%" });
		jQuery(".TextSize").css({ "color": "gray" });
		jQuery(this).css({ "color": "black" });
		var PageUrl = jQuery(location).attr("href");
		if (PageUrl.indexOf("/News.aspx") != -1) {
			CloseAll();
			jQuery(".NewsItem .NewsItemRight .NewsItemBody").each(function(i) {
				jQuery(this).css("height", "auto");
				jQuery(this).css("overflow", "visible");
				jQuery(this).parent().children().find(".NewsItemReadMore").css({ "font-size": "115%" });
				NewsBodyCurrentHeight = jQuery(this).height();
				jQuery(this).attr("id", NewsBodyCurrentHeight);
				if (jQuery(this).height() > 105) {
					jQuery(this).parent().children().find(".NewsItemReadMore").show();
					jQuery(this).css("height", "105px");
					jQuery(this).css("overflow", "hidden");
				}
				else {
					jQuery(this).parent().children().find(".NewsItemReadMore").hide();
					jQuery(this).css("height", "auto");
					jQuery(this).css("overflow", "visible");
				}
			});
		}
	});

	jQuery(".TextSize03").click(function() {
		jQuery("p").css({ "font-size": "130%" });
		jQuery("li").css({ "font-size": "130%" });
		jQuery("h1").css({ "font-size": "200%" });
		jQuery(".TextSize").css({ "color": "gray" });
		jQuery(this).css({ "color": "black" });
		var PageUrl = jQuery(location).attr("href");
		if (PageUrl.indexOf("/News.aspx") != -1) {
			CloseAll();
			jQuery(".NewsItem .NewsItemRight .NewsItemBody").each(function(i) {
				jQuery(this).css("height", "auto");
				jQuery(this).css("overflow", "visible");
				jQuery(this).parent().children().find(".NewsItemReadMore").css({ "font-size": "130%" });
				NewsBodyCurrentHeight = jQuery(this).height();
				jQuery(this).attr("id", NewsBodyCurrentHeight);
				if (jQuery(this).height() > 109) {
					jQuery(this).parent().children().find(".NewsItemReadMore").show();
					jQuery(this).css("height", "109px");
					jQuery(this).css("overflow", "hidden");
				}
				else {
					jQuery(this).parent().children().find(".NewsItemReadMore").hide();
					jQuery(this).css("height", "auto");
					jQuery(this).css("overflow", "visible");
				}
			});
		}
	});



	jQuery(".facebook").hover(
   function() {
   	jQuery(this).animate({ "background-position": "0px" }, "fast");
   	jQuery(".facebook_shadow").animate({ "background-position": "-6px" }, "fast");
   },
function() {
	jQuery(this).animate({ "background-position": "-17px" }, "fast");
	jQuery(".facebook_shadow").animate({ "background-position": "10px" }, "fast");
}
  );

	jQuery(".twitter").hover(
   function() {
   	jQuery(this).animate({ "background-position": "0px" }, "fast");
   	jQuery(".twitter_shadow").animate({ "background-position": "-6px" }, "fast");
   },
function() {
	jQuery(this).animate({ "background-position": "-17px" }, "fast");
	jQuery(".twitter_shadow").animate({ "background-position": "10px" }, "fast");
}
  );

	jQuery(".linkedin").hover(
   function() {
   	jQuery(this).animate({ "background-position": "0px" }, "fast");
   	jQuery(".linkedin_shadow").animate({ "background-position": "-6px" }, "fast");
   },
function() {
	jQuery(this).animate({ "background-position": "-17px" }, "fast");
	jQuery(".linkedin_shadow").animate({ "background-position": "10px" }, "fast");
}
  );

	jQuery(".newsbytes").hover(
   function() {
   	jQuery(this).animate({ "opacity": "0.7" }, "fast");
   	jQuery(".newsbytes_shadow").animate({ "opacity": "0.7" }, "fast");
   }, function() {
   	jQuery(this).animate({ "opacity": "1.0" }, "fast");
   	jQuery(".newsbytes_shadow").animate({ "opacity": "1.0" }, "fast");
   }
  );

	var inspiremeactive = 0;


	jQuery(".inspireme").click(function() {

		if (inspiremeactive == 0) {

			jQuery(".csmainimage").fadeTo(1000, 0.2);
			jQuery(".[class^=inspireme_insert_]").fadeTo(1000, 1, function() 
				{
					inspiremeactive = 1;
				}
			);
		}
		else {
			inspiremeactive = 0;
			jQuery(".csmainimage").fadeTo(1000, 1);
			jQuery(".[class^=inspireme_insert_]").fadeOut(1000);
			jQuery(".[class^=technology_insert_]").fadeOut(1000);
		}
	});

	jQuery(".technology").click(function() {
		if (inspiremeactive == 0) {

			jQuery(".csmainimage").fadeTo(1000, 0.2);
			jQuery(".[class^=technology_insert_]").fadeTo(1000, 1, function() 
				{
					inspiremeactive = 1;
				});
		}
		else {
			inspiremeactive = 0;
			jQuery(".csmainimage").fadeTo(1000, 1);
			jQuery(".[class^=inspireme_insert_]").fadeOut(1000);
			jQuery(".[class^=technology_insert_]").fadeOut(1000);
		}
	});

	jQuery(".[class^=case_study_mainbox_frame_]").parent().click(function() {
		if(inspiremeactive == 1){
		jQuery(".csmainimage").fadeTo(1000, 1);
		jQuery(".[class^=inspireme_insert_]").fadeOut(1000);
		jQuery(".[class^=technology_insert_]").fadeOut(1000);
				inspiremeactive = 0;
				}
	});

});




