document.write('<style type="text/css">.cufon, .relatedProductGroups ul ul { visibility: hidden; } .cufon span, .relatedProductGroups ul ul { visibility: visible; }</style>');
$(function() { 
	$(".mainMenu ul.M1").lavaLamp({ fx: "easeOutBack", speed: 1500, autoReturn: true });
//$(".subMenu ul.M1 .M2:first, .subMenu ul.M1 .M5:first").addClass('firstItem');

        $('.relatedProductGroups ul ul').hide();  
        $('.relatedProductGroups ul .groupName a.expand').click(function() {
          $(this).toggleClass('active');
          $(this).next('ul').slideToggle('fast')
          .siblings('ul:visible').slideUp('fast');
return false;
         });
	

$("ul.productMenu ul.submenuLevel4 .firstItem:first, ul.submenuIndustries .productFinder:first").next().addClass('keyArea');
$("ul.productMenu ul.submenuLevel4 .firstItem:first").addClass('ProductArea');

clearInput('.hasDefault');  

$('#mCycle p').cycle();
$('#mCycle a').cycle();
$('#mCycle').cycle();

Cufon.replace('h1.cufon, .subpageMainContent .newsBox h2, h3');

$("div.categoryBox, div.categoryBox2, div.categoryBox3").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});



$(".matrix a.thickbox").click(function(){
  if($('div.contentHolderProduct div.matrix').length) {
    var groups = [],
        items = [],
        itemExists = '<img src="Files/System/images/alsiano/icons/matrix_dot.gif" />';
    $('div.contentHolderProduct div.relatedProductGroups').each(function(i) {
      var groupId = i; 
          productGroup = $(this);
      groups.push(productGroup.find('li.groupName a.expand').text());
      productGroup.find('ul ul li a').each(function() {
        items.push({ groupId: groupId, name: $(this).text() });
      });
    });
    items.sort(sortfunction);
    if(groups.length && items.length) {
      var table = $('<table cellpadding="0" cellspacing="0"><thead><tr><th>&nbsp;</th></tr></thead><tbody></tbody></table>'),
          tbody = table.find('tbody'),
          theadCols = '',
          emptyrow = '';
      $.each(groups, function(i) {
        theadCols += '<th align="right" valign="middle" class="groupId'+ i +' headCols"><nobr>'+ groups[i] +'</nobr></th>';
        emptyrow += '<td>&nbsp;</td>';
      });
      table.find('thead tr').append(theadCols);
      $.each(items, function(i) {
        var itemName = items[i].name,
            itemClass = itemName.replace(/[^a-z0-9]*/gi, '');
            groupId = parseInt(items[i].groupId, 10),
            row = tbody.find('tr.'+ itemClass);
        if(row.length) {
          row.find('td:eq('+ (groupId + 1) +')').html(itemExists);
        } else {
          row = $('<tr class="'+ itemClass +'"><td>'+ itemName +'</td>'+ emptyrow +'</tr>');
		  row.find('td:first('+ (groupId + 1) +')').addClass('firstItem');
          row.find('td:eq('+ (groupId + 1) +')').html(itemExists).addClass('hasImage');
          tbody.append(row);
        }  
      });
      $('#TB_ajaxContent').prepend(table);
    }
  }
});

$('.sitemap').hide();  

dynamicSelect("quickIndustry", "quickSegment");
dynamicSelect("quickSegment", "quickApplication");

});

function sortfunction(a, b) {
  if(a === b) { return 0; }
  var array = [a.name.toLowerCase(), b.name.toLowerCase()];
  if(array[0] === array.sort()[0]) {
    return -1;
  } else {
    return 1;
  }
}

function dynamicSelect(id1, id2) {
	// Browser and feature tests to see if there is enough W3C DOM support
	var agt = navigator.userAgent.toLowerCase();
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_mac = (agt.indexOf("mac") != -1);
	if (!(is_ie && is_mac) && document.getElementById && document.getElementsByTagName) {
		// Obtain references to both select boxes
		var sel1 = document.getElementById(id1);
		var sel2 = document.getElementById(id2);
		// Clone the dynamic select box
		if(sel1 && sel2){
		var clone = sel2.cloneNode(true);
		// Obtain references to all cloned options 
		var clonedOptions = clone.getElementsByTagName("option");
		// Onload init: call a generic function to display the related options in the dynamic select box
		refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		// Onchange of the main select box: call a generic function to display the related options in the dynamic select box
		sel1.onchange = function() {
			var val = $(sel1).val();
			if(val.match('.aspx')) {
				document.location = val;
			} else {
				refreshDynamicSelectOptions(sel1, sel2, clonedOptions);				
			}
		};
		}
	}
}
function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
	// Delete all options of the dynamic select box
	while (sel2.options.length) {
		sel2.remove(0);
	}
	// Create regular expression objects for "select" and the value of the selected option of the main select box as class names
	var pattern1 = /( |^)(select)( |$)/;
	var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
	// Iterate through all cloned options
	for (var i = 0; i < clonedOptions.length; i++) {
		// If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box
		if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
			// Clone the option from the hidden option pool and append it to the dynamic select box
			sel2.appendChild(clonedOptions[i].cloneNode(true));
		}
	}
}

function shortcut(form){
var destsite
destsite=(form.elementThree.options[form.elementThree.selectedIndex].value)
	if (destsite=="Select"){
		alert("You must select an application")
	}else{
		location.href=destsite
	} 
}


function clearInput (cssClass) {
	// Get the input field and assign it to a variable
	var focusField = $(cssClass);
	
	focusField.focus( function(){
		var el = $(this);
		var val = el.val();
		
		if (!el.data('placeholder')) {
			el.data('placeholder', val);
		}
		
		if(val === el.data('placeholder')) {
			el.val('');
		}
	});
	
	focusField.blur( function () {
		var el = $(this);
		if (el.val() === '') {
			el.val(el.data('placeholder') || '');
		}
	});
}
