﻿var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
var closetab;
var bodyWidth = 0;
var modalWidth = 0, modalHeight = 0;
//var currentBanner = 1;

function jsddm_open() {
    jsddm_canceltimer();
    jsddm_close();
    closetab = $(this).addClass("hover");
    ddmenuitem = $(this).find('ul').css('visibility', 'visible'); //$(this).find('ul').css('visibility', 'visible');
}

function jsddm_close() {
    if (ddmenuitem) {
        ddmenuitem.css('visibility', 'hidden');
        closetab.removeClass('hover');              
    }
}

function jsddm_timer() {   
    closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    } 
}

function ClearSalesMenu() {
	$(".sales-menu div").each(function() {
		$(this).removeClass();
	});
	
	$("#contactbottom span").each(function() {
		$(this).css("display", "none");
	});
}



// All hover images with on and off states
function ImageHover(name, ext, state) {    
    if (state == "on")
        $("#" + name).attr("src", ("/images/right-column/" + name + "_on." + ext));
    else
        $("#" + name).attr("src", ("/images/right-column/" + name + "_off." + ext));
}

function homeImageHover(name, ext, state) {
    if (state == "on")
        $("#" + name).attr("src", ("/images/homepage/" + name + "_on." + ext));
    else
        $("#" + name).attr("src", ("/images/homepage/" + name + "_off." + ext));
}

function openWin(path) {
    window.open(path, "softlayer", "width=900,height=600");
}

function adjustModal() {
	var style = "width: " + modalWidth + "px; height: " + modalHeight + "px; display: block;";
	$('#modal').attr('style', (style + " left: " + returnLeftAlignment(modalWidth) + "px;"));
}

function openModal(path, width, height) {
	if (width == null) width = 900;	
	if (height == null) height = 600;

	var style = "width: " + width + "px; height: " + height + "px;";
		
	var containerId = document.getElementById("modal");	
	containerId.setAttribute('style', (style + " left: " + returnLeftAlignment(width) + "px;"));

	var modalContent = document.getElementById("modal-content");
	containerId.appendChild(modalContent);
	modalContent.setAttribute('style', style);
	
	modalContent.innerHTML = "";	// remove any HTML in the modal div.
	
	var ifrm = document.createElement("iframe");
	ifrm.setAttribute("src", path);
	ifrm.setAttribute("frameBorder", "0");
	ifrm.setAttribute('border', '0');
	ifrm.setAttribute('width', width + "px");
	ifrm.setAttribute('height', height + "px");
	
	modalContent.appendChild(ifrm);	
	
	$("#modal").jqmShow();
	
	// set global width values for possible adjustment on resize.
	bodyWidth = $("body").css("width");
	modalWidth = width;
	modalHeight = height;
}

function returnLeftAlignment(modalWidth) {
	return Math.round(($('body').width() / 2) - (modalWidth / 2));
}


function imageSwap(id, imageUrl) {
	$('#configuration').attr('src', imageUrl);

	$('h2 span a').each(function() {
		$(this).removeClass('active');
	});

	$('#' + id).addClass('active');
}

function toCurrentNetworkMap()
{   
    //alert ($('#current-network-map').html());
    $('#network-map-title').html($('#current-network-title').html());
    $('#network-map-content').html($('#current-network-map').html());
}

function toFutureNetworkMap()
{
    $('#network-map-title').html($('#new-network-title').html());
    $('#network-map-content').html($('#new-network-map').html());
}

//SWF Detect from Adobe -----------------------

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;




$(function() {
	bodyWidth = $('body').width();
		   
	// DropDown Menus
	$('#jsddm > li').bind('mouseover', jsddm_open)
	$('#jsddm > li').bind('mouseout', jsddm_timer)

	$("#phone-content").show();

	$(".sales-menu #chat").mouseover(function() {
		ClearSalesMenu();

		$("#chat").addClass("chat-active");
		$("#email").addClass("email-inactive");
		$("#phone").addClass("phone-inactive");

		$("#contactbottom #chat-content").css("display", "block");
	});

	$(".sales-menu #email").mouseover(function() {
		ClearSalesMenu();

		$("#email").addClass("email-active");
		$("#chat").addClass("chat-inactive");
		$("#phone").addClass("phone-inactive");

		$("#contactbottom #email-content").css("display", "block");
	});

	$(".sales-menu #phone").mouseover(function() {
		ClearSalesMenu();

		$("#phone").addClass("phone-active");
		$("#email").addClass("email-inactive");
		$("#chat").addClass("chat-inactive");

		$("#contactbottom #phone-content").css("display", "block");
	});


	// bottom row additional resources links
	$("#download-datasheet").click(function() {
		location.href = "/resources/datasheets/";
	});

    $(".sales-menu #chat").click(function() {
		
	});



	// resize even on the body to handle modal dialog height/scroll changes.
	$(window).resize(function() {
		adjustModal();
	});


    
  
   
    
    //Link event banner to event page
    $('#home-event-banner').click(function() {
       location.href = '/about/event-schedule';
    });
   
	// sub page button hover/active functionality
	$(".button-container a").hover(
    function() {
    	var id = $(this).attr("id");
    	var isDefault = $(this).children("img").attr("id");

    	if (isDefault != "default-button") {
    		$(this).children("img").attr("src", "/images/button-tabs/navbox_" + id + "_on.jpg");
    	}
    },
    function() {
    	var id = $(this).attr("id");
    	var isDefault = $(this).children("img").attr("id");

    	if (isDefault != "default-button") {
    		$(this).children("img").attr("src", "/images/button-tabs/navbox_" + id + "_off.jpg");
    	} else {
    		$(this).children("img").attr("src", "/images/button-tabs/navbox_" + id + "_on.jpg");
    	}
    });
    
});

document.onclick = jsddm_close;

