(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

jQuery(function($) {	
	$.preLoadImages("/images/overlay_corner.png", "/images/overlay_top.png",
"/images/overlay_join.png", "/images/overlay_join_ie7.png", "/images/overlay_join.png", "/images/overlay_corner_indent.gif", "/images/overlay_left.png", "/images/overlay_right.png", "/images/overlay_bg.jpg", "/images/submenu_closebtn.gif", "/images/overlay_divider.gif", "/images/overlay_r_left.jpg", "/images/overlay_r_bg.jpg", "/images/overlay_btn_login_off.gif", "/images/overlay_btn_reg_off.gif", "/images/overlay_btn_login_on.gif", "/images/overlay_btn_reg_on.gif", "/sites/dotcom/images/overlay_corner.png", "/sites/dotcom/images/overlay_top.png",
"/sites/dotcom/images/overlay_join.png", "/sites/dotcom/images/overlay_join_ie7.png", "/sites/dotcom/images/overlay_join.png", "/sites/dotcom/images/overlay_corner_indent.gif", "/sites/dotcom/images/overlay_left.png", "/sites/dotcom/images/overlay_right.png", "/sites/dotcom/images/overlay_bg.jpg", "/sites/dotcom/images/submenu_closebtn.gif", "/sites/dotcom/images/overlay_divider.gif", "/sites/dotcom/images/overlay_r_left.jpg", "/sites/dotcom/images/overlay_r_bg.jpg", "/sites/dotcom/images/overlay_btn_login_off.gif", "/sites/dotcom/images/overlay_btn_reg_off.gif", "/sites/dotcom/images/overlay_btn_login_on.gif", "/sites/dotcom/images/overlay_btn_reg_on.gif","/sites/dotcom/images/iface/bg-intl-select-top.gif","/sites/dotcom/images/iface/bg-intl-select-btm.gif","/sites/dotcom/images/Company/btn_sales_off.gif","/sites/dotcom/images/Company/btn_sales_on.gif","/sites/dotcom/images/Company/btn_partner_off.gif","/sites/dotcom/images/Company/btn_partner_on.gif","/images/iface/bg-intl-select-top.gif","/images/iface/bg-intl-select-btm.gif","/images/Company/btn_sales_off.gif","/images/Company/btn_sales_on.gif","/images/Company/btn_partner_off.gif","/images/Company/btn_partner_on.gif");
});



$(document).ready(function(){
	$("li#internationalSites").hover(
		function () {
		 $("div#intlSelectHeader").show("fast");
		 $("div#intlSelect").show("fast");
      }, 
      function () {
		 	$("div#intlSelectHeader").hide('slow');
			$("div#intlSelect").hide('slow');
      }
    );
	
	// set text field and textarea classes
	$("input[type='text'][class='']").addClass("input-text");
	$("textarea[class='']").addClass("input-textarea");
	
	// create moreinfo boxes
	var baseHtml = '<div class="moreInfo"><div class="tl"><div class="tr">&nbsp;</div></div><div class="content">{$mesh}</div><div class="bl"><div class="br">&nbsp;</div></div></div>';
	var meshSettings =
			{
				base:baseHtml,
				replace:true
			};
			
	$('p.moreInfo').meshtml(meshSettings);
	
	$('#siteContent > *').find('a[href^=javascript:openPopup]').removeAttr("target");
	
	// to add icon beside external links to identify them
	$('#siteContent > *').find('a[href^=http]:not("[href*=://www.brocade.com],[href*=://wwwpreview.brocade.com],[href*=://newsroom.brocade.com],[href*=://www.brcd.com],[href*=://community.brocade.com],[href*=://www.brocade.apply2jobs.com],[href*=://www.brocadeconnect.com],[href*=://blogs.brocade.com], [href*=://brocade.force.com/]")').each(function(){
		if ($(this).children('img').size() == 0) 
			$(this).addClass("elink").attr('target', '_blank').wrapInner("<span></span>").append("<span class='extlink'></span>");
		else
			$(this).attr('target', '_blank')
		
	});
	
});

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};

if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}

function toInt ( x )
{
	return ( x > 0 ? Math.floor( x ) : Math.ceil ( x ) )
}

function changeControlCase(control) {
		for (i=0; i <document.getElementById(control).options.length; i++) {		
			var optionValue = document.getElementById(control).options[i].value;
			var lStr = optionValue.toLowerCase();
			var tStr = lStr.toTitleCase();
			var optionName;
			if(tStr == '') {
				optionName= new Option("Select...","", true); 
			}
			else{
				optionName = new Option(tStr, optionValue, false);
			}
			document.getElementById(control).options[i] = optionName ;			
		}
	}

	
String.prototype.toTitleCase = function() {
    return this.replace(/([\w&`'‘’"“.@:\/\{\(\[<>_]+-? *)/g, function(match, p1, index, title) {
        if (index > 0 && title.charAt(index - 2) !== ":" &&
        	match.search(/^(a(nd?|s|t)?|b(ut|y)|en|for|i[fn]|o[fnr]|t(he|o)|vs?\.?|via)[ \-]/i) > -1)
            return match.toLowerCase();
        if (title.substring(index - 1, index + 1).search(/['"_{(\[]/) > -1)
            return match.charAt(0) + match.charAt(1).toUpperCase() + match.substr(2);
        if (match.substr(1).search(/[A-Z]+|&|[\w]+[._][\w]+/) > -1 || 
        	title.substring(index - 1, index + 1).search(/[\])}]/) > -1)
            return match;
        return match.charAt(0).toUpperCase() + match.substr(1);
    });
};

function openPopup(URL, popupwidth, popupheight) {

var parameters = 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+popupwidth+',height='+popupheight;

  window.open(URL,'popup',parameters);

}

jQuery(function($) {				
	$(".btn_readmore").bind('click',function(event) {
		obj = $(event.target);
		if(obj.parent().prev().height() == "65")
			obj.parent().prev().css('height','100%');
		else
			obj.parent().prev().css('height','65px')
		
		obj.toggleClass('btn_collapsereadmore')
		
	});
	$(".link_showhide").bind('click',function(event) {
		obj = $(event.target);
		if(obj.parents('div.description').height() == "65")
		{
			obj.parents('div.description').css('height','100%');
			obj.parent().hide();
		}
		else
		{
			obj.parents('div.description').css('height','65px');
			obj.parents('div.description').find('span.ShowAll').show();
		}
		return false;
	});
});

function showBannerOverlayVideo(titleText, imgPath, vidPath, MaxVidTime) {
	var vWidth = 394; //Flash Container Width - 29
	var vHeight = 288; //Flash Container Height - 12
	var decodedtitleText = uriDecode(titleText)
	var url = "/sites/dotcom/common/banner_enlarged_video_container.html?titleText="+decodedtitleText+"&imgPath="+imgPath+"&vidPath="+vidPath+"&MaxVidTime="+MaxVidTime+"&pageName="+s.pageName+"&TB_iframe=true&height="+vHeight+"&width="+vWidth+"&scroll=no"
	tb_show('',url,'');
	/*if($.browser.msie){
		window.location = '#top';
	}
	if(typeof DD_belatedPNG != "undefined")
		DD_belatedPNG.fix('#TB_closeWindowButton');*/
	return false;
}






