// JavaScript Document

//set the array for the images on the home page.
var imgArray=new Array("#img1", "#img2", "#img3", "#img4", "#img5");
var imageCount = 2;
var imageId;
var fiberText = "Information regarding design, engineering, construction, and implementation of our fiber networks.";
var techText = "Learn about our IT Management, Network Engineering, Software Development, Security and Hosting Services.";
var subscriberText = "For subscribers searching for technical support, wanting to check webmail or change account settings.";
var aboutText = "Discover who we are, what we do and the vision that inspires us.";

jQuery(document).ready(function() 
{

	//Start the Carousel if we are on the main home page
	if ( $("body").attr("id") == "home_page" ) 
	{
		startCarousel();
	}
	
	var linkId;
	
	$("#left_nav_list a").hover ( 
		function() 
		{
			linkId = $(this).parent().attr('id');
			$('#' + linkId).children('.list_divider_hover').css({"background-image": "url(assets/templates/secondarymenu_hover.jpg)"});
		}, 
		function()
		{
			if ( $('#' + linkId).children('#hoverSet').attr('id') != 'hoverSet' )
			{
				$('#' + linkId).children('.list_divider_hover').css('background-image', 'none');
			}
		}
	);
		
	
	//When hovering on the menu bar, the links will animate their opacity from 0% to 100% over a short time
	$("#navlist a").hover ( 
		function() 
		{
			if ( jQuery.support.opacity )
			{
				$(this).stop().animate({"opacity": "1"}, 500); //Normal Browsers
			} 
			else 
			{
				$(this).stop().animate({"filter": "alpha(opacity=100)"}, 500); //IE5-7
				//$(this).stop().fadeIn({"filter": "alpha(opacity=100)"}, 500); //IE5-7
				//$(this).stop().fadeIn({"-ms-filter": "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"}, 500); //IE8
				$(this).stop().animate({"-ms-filter": "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"}, 500); //IE8
			}
			
			//animate the menu info popups
			$("#menu_hover_text").css('display', 'none');
			//$("#menu_hover_text").css('opacity', '.55').fadeIn("slow");
			//$("#menu_hover_text").css('filter', 'alpha(opacity="55")').fadeIn("slow");
			//$("#menu_hover_text").css('-ms-filter', 'progid:DXImageTransform.Microsoft.Alpha(Opacity=5)').fadeIn("slow");
			$("#menu_hover_text").customFadeIn(300);
			
			$("#menu_hover_text").css('display', 'inline');

			switch( $(this).parent().attr("id") )
			{
				case 'fiber':
				$('#menu_hover_text').text( fiberText );
				break;
				
				case 'tech':
				$('#menu_hover_text').text( techText );
				break;
				
				case 'subscribers':
				$('#menu_hover_text').text( subscriberText );
				break;
				
				case 'about':
				$('#menu_hover_text').text( aboutText );
				break;
			}
			
		},
		function() 
		{
			if ( jQuery.support.opacity )
			{
				$(this).stop().animate({"opacity": "0"}, 1); //Normal Browsers
			} else
			{
				$(this).stop().animate({"filter": "alpha(opacity=0)"}, 500); //IE5-7
				$(this).stop().animate({"-ms-filter": "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"}, 500); //IE8
			}
			
			//animate the menu info popups
			//$("#menu_hover_text").fadeOut(100, function() { fadeInUse = "false" } );
		}
	);
	
	//when clicking the image selector, we both change the image and update the imageCount so that the 
	// next run of the carousel gets stuck on the correct image
	$(".img_selector_link").click(function()
	{
		var linkId = $(this).attr("id");
		linkId = "#" + linkId;
		updateImg(linkId);
		var tempString = linkId.split("img");
		imageCount = tempString[1];
	});

});

function updateInfoText()
{
	$("#menu_hover_text").css('display', 'inline');
}

function updateImg(imgId)
{
	//here we update the background image after the image gets clicked or the auto function of the jcarousel runs
	$.each(imgArray, function(index, value)
		{
			if ( value != imgId )
			{
				$(value).css({"background-image": "url(assets/carousal/carousel_off.png)"});
			}
			else
			{
				$(value).css({"background-image": "url(assets/carousal/carousel_on.png)"});
			}
		});
}

function startCarousel() 
{	
	imageCount = 2;
	//Home page Carousel, with easing effects
	jQuery("#imgCarousel").jCarouselLite(
	{
		auto: 8000,
		speed: 800,
		btnGo: imgArray,
		easing: 'easeInOutExpo',
		afterEnd: function(a) 
		{
			//updateImg(a);

			if ( imageCount == 6 )
			{
				imageCount = 1;
			}
			
			//The following will reposition the image maps for the Carousel images as the images change 
			if ( imageCount == 1 )
			{
				$("#main_img_map_container").css("left", "335px" );
				$("#main_img_map_container").css("top", "280px" );
				$("#main_img_map_container").css("width", "340px" );
				$("#main_img_map").attr("href", "fibersystems.php");
				updateImg("#img" + imageCount);
			}
			if ( imageCount == 2 )
			{
				$("#main_img_map_container").css("left", "398px" );
				$("#main_img_map_container").css("top", "275px" );
				$("#main_img_map_container").css("width", "290px" );
				$("#main_img_map").attr("href", "fibersystems.php");
				updateImg("#img" + imageCount);
			}
			if ( imageCount == 3 )
			{
				$("#main_img_map_container").css("left", "425px" );
				$("#main_img_map_container").css("top", "273px" );
				$("#main_img_map_container").css("width", "245px" );
				$("#main_img_map").attr("href", "fiber_ftth.php");
				updateImg("#img" + imageCount);
			}
			if ( imageCount == 4 )
			{
				$("#main_img_map_container").css("left", "470px" );
				$("#main_img_map_container").css("top", "272px" );
				$("#main_img_map_container").css("width", "75px" );
				$("#main_img_map").attr("href", "subscribers.php");
				updateImg("#img" + imageCount);
			}
			if ( imageCount == 5 )
			{
				$("#main_img_map_container").css("left", "360px" );
				$("#main_img_map_container").css("top", "277px" );
				$("#main_img_map_container").css("width", "165px" );
				$("#main_img_map").attr("href", "computertech.php");
				updateImg("#img" + imageCount);
			}

			imageCount++;	
		}
	});
};

(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeTo = function(speed,to,callback) {
		return this.animate({opacity: to}, speed, function() {
			if (to == 1 && jQuery.browser.msie)
				this.style.removeAttribute('filter');
			if (jQuery.isFunction(callback))
				callback();
		});
	};
})(jQuery);
	
/* pop-up window code */
function popUpwin(page, name, w, h, scroll) {
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;
   winprop  = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
   win = window.open(page, name, winprop)
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

