
function SubMenu(){
 if(navigator.appVersion.indexOf("MSIE")==-1){return;}
 var i,k,g,lg,r=/\s*p7hvr/,nn='',c,cs='p7hvr',bv='subnav';
 for(i=0;i<10;i++){g=document.getElementById(bv+nn);if(g){
 lg=g.getElementsByTagName("LI");if(lg){for(k=0;k<lg.length;k++){
 lg[k].onmouseover=function(){c=this.className;cl=(c)?c+' '+cs:cs;
 this.className=cl;};lg[k].onmouseout=function(){c=this.className;
 this.className=(c)?c.replace(r,''):'';};}}}nn=i+1;}
}


function setTall() {
	if (document.getElementById('content_with_infobox')) {
		// the divs array contains references to each column's div element.  
		// Replace 'center' 'right' and 'left' with your own.  
		// Or remove the last one entirely if you've got 2 columns.  Or add another if you've got 4!
		var divs = new Array(document.getElementById('content_with_infobox'), document.getElementById('infobox_spacer'));
		
		// Let's determine the maximum height out of all columns specified
		var maxHeight = 0;
		for (var i = 0; i < divs.length; i++) {
			if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
		}
		
		// Let's set all columns to that maximum height
		for (var i = 0; i < divs.length; i++) {
			divs[i].style.height = maxHeight + 'px';

			// Now, if the browser's in standards-compliant mode, the height property
			// sets the height excluding padding, so we figure the padding out by subtracting the
			// old maxHeight from the new offsetHeight, and compensate!  So it works in Safari AND in IE 5.x
			if (divs[i].offsetHeight > maxHeight) {
				divs[i].style.height = (maxHeight - (divs[i].offsetHeight - maxHeight)) + 'px';
			}
		}
	}
}

window.onload = function() {
	SubMenu();
	setTall();
}

window.onresize = function(){
	setTall();
}

function trim(str) {
  var str = str.replace(/^\s\s*/, ''),
    ws = /\s/,
    i = str.length;
  while (ws.test(str.charAt(--i)));
  return str.slice(0, i + 1);
}

jQuery.fn.exists = function(){return jQuery(this).length>0;}

$(function(){
	/*if(jQuery('#download_tabs li a').length > 0){
		$('#download_tabs li a').live('click',function(){
			var language_code = $('#language_code').attr('value');
			
			$('#download_tabs li a').removeClass('selected');
			$(this).addClass('selected');
			
			$('#language_'+language_code+' .download_products').hide();
			$('#language_'+language_code+' .download_sections').hide();
			
			$('#download_'+$(this).parent('li').attr('class')+'_'+language_code).show();
			$('#tab_code').attr('value', $(this).attr('href'));
			
			return false;
		});
	}
	
	jQuery('.download_section h3 a').click(function(){
		var links_div = $(this).parent('h3').next('.product_sections');

		// hide or show section products		
		if($(this).hasClass('selected')){
			$(this).removeClass('selected');
			$(links_div).hide();
		}else{
			$(this).addClass('selected');
			$(links_div).show();
		}
		return false;
	});
	
	jQuery('#show_links').click(function(){
		$('#download_process').hide();
		$('#download_page').show();
		
		return false;
	});
	
	jQuery('.download-language-select .choose a').click(function(){
		if($(this).hasClass('selected')){
			$(this).removeClass('selected');
		}else{
			$(this).addClass('selected');
		}
		
		// show/hide list
		$($(this).parent().next()).toggle();
		
		return false;
	});
	
	jQuery('#language_bar .choose a').click(function(){
		if($(this).hasClass('selected')){
			$(this).removeClass('selected');
		}
		else{
			$(this).addClass('selected');
		}
		$('#language_selection').toggle();
		
		return false;
	});
	
	jQuery('#language_popup a').click(function(){
		$('#language_code').attr('value', $(this).attr('rel'));
		
		$('.documentation_sections').hide();
		$('.download_sections').hide();
		
		$('#language_'+$(this).attr('rel')).show();
		$('#language_'+$('#tab_code').attr('value')+'_'+$(this).attr('rel')).show();
		
		$('#selected_documentation_lang').html($(this).html());
		$('#language_selected').html($(this).html());
		
		$('#language_bar .choose a').removeClass('selected');
		$('#download_language .choose a').removeClass('selected');
		
		//Reset to home tab
		$('#download_tabs li a').removeClass('selected');
		$('#download_tabs li.home a').addClass('selected');
		
		$('#language_selection').hide();
	});*/
	
	jQuery('.documentation_sections .item_section h3 a').click(function(){
		if($(this).hasClass('selected')){
			$(this).removeClass('selected');
		}
		else{
			$(this).addClass('selected');
		}
		
		var links_div = $(this).parent('h3').next('div');
		
		$(links_div).toggle();
		
		return false;
	});
	
	jQuery('.page_banner_business ul li a.business_banner_link').click(function(){
		$('.business_articles').hide();
		$('.page_banner_business ul li a').removeClass('selected');
		
		$('#business_article_'+$(this).attr('rel')).show();
		$(this).addClass('selected');
		
		return false;
	});
});

var ESET_Downloads = (function(){
	// default language and section
	var _defaultLanguage = 0;
	var _defaultType = 0;
	
	// selected language and section
	var _language = 0;
	var _type = 0;

	/**
	 * Parse element ID
	 * 
	 * @param String id
	 * @return Object|false
	 */
	function _parseId(id){
		if(!id || id.length < 1){ return false; }
		var exp = id.split('_');
		
		// read language and section from ID
		var language = exp.length > 1 ? exp[1] : _language;
		var type = exp.length > 2 ? exp[2] : _type;
		
		return {
			'language': language, 'type': type
		};
	}
	
	/**
	 * Get current language
	 * 
	 * @return int
	 */
	function _getCurrentLanguage(){
		return _language > 0 ? _language : _defaultLanguage;
	}
	
	/**
	 * Get current download type
	 * 
	 * @return int
	 */
	function _getCurrentType(){
		return _type > 0 ? _type : _defaultType;
	}
	
	return {
		/**
		 * Set default language and section ID
		 * 
		 * @param int language
		 * @param int type
		 * @return void
		 */
		setDefaults: function(language, type){
			_defaultLanguage = parseInt(language);
			_defaultType = parseInt(type);
			
			// show default download type and language
			this.showLanguage(_defaultLanguage);
		},
		
		/**
		 * Display download type
		 * 
		 * @param int type
		 * @return void
		 */
		showType: function(type){
			type = parseInt(type)
			
			// hide all download types and remove active state
			jQuery('#download_page .download-type').hide();
			jQuery('a', '#download_tabs').removeClass('selected');
			
			// show selected download type
			var id = '#download_' + _getCurrentLanguage() + '_' + type;
			jQuery(id, '#download_page').show();
			jQuery('a[href="#' + type + '"]', '#download_tabs').addClass('selected');
			
			// set current type
			_type = type;
		},
		
		/**
		 * Display language
		 * 
		 * @param int language
		 * @return void
		 */
		showLanguage: function(language){
			language = parseInt(language);
			
			// hide all languages
			jQuery('#download-page .download-language').hide();
			
			// show selected language
			var id = '#download_' + language;
			jQuery(id, '#download_page').show();
			
			// set current language
			_language = language;
			
			// show current download type
			this.showType(_getCurrentType());
		},
		
		/**
		 * Initialize events
		 * 
		 * @return void
		 */
		initEvents: function(){
			// apply toggle (open/close) event to download sections
			jQuery('.download_section h3 a', '#download_page').click(function(){
				// hide or show section products		
				if($(this).hasClass('selected')){
					$(this).removeClass('selected');
				}else{
					$(this).addClass('selected');
				}
				
				// toggle links
				var links_div = $(this).parent('h3').next('.product_sections');
				links_div.toggle();
				
				return false;
			});
			
			// add language switcher click event
			jQuery('.download-language-select .choose a', '#download_page').click(function(){
				if($(this).hasClass('selected')){
					$(this).removeClass('selected');
				}else{
					$(this).addClass('selected');
				}
				
				// show/hide list
				$($(this).parent().next()).toggle();
				
				return false;
			});
			
			// add language selection click event
			jQuery('.download-language-select .language-list li a', '#download_page').click(function(){
				// hide language list
				jQuery('.download-language-select .language-list', '#download_page').hide();
				jQuery('.download-language-select .choose a').removeClass('selected');
				
				// toggle language sections
				var href = jQuery(this).attr('href');
				var language = parseInt(href.substr(1, href.length));
				language = language > 0 ? language : _defaultLanguage;
				ESET_Downloads.showLanguage(language);
				
				return false;
			});
		}
	}
})();

