var horizontalPadding = 270;
var verticalPadding = 170;

document.write('<style type="text\/css"> .submenu, #download_catalogues span {display:none;} <\/style>');


window.onload=function(){
 	init_submenus();
	resizeElements();
	if (document.getElementById('cloudlinks')) {
		init_new_window_links('cloudlinks', 'resizable=yes,width=500,height=580');
	}
}

window.onresize=function(){
	resizeElements();
}


function resizeElements(elements_array) {
	resizeElement('faq', -38, -6);
	resizeElement('faq_background', 0, 0);
	resizeElement('spnet', 0, 0);
	resizeElement('testimonials', -38, -6);
	//resizeElement('calendar', 0, 0);
}

function resizeElement(elementId,offsetWidth,offsetHeight) {
		if (element = document.getElementById(elementId)) {
			element.style.width = getDimensions()[0]-horizontalPadding+offsetWidth+'px';
			element.style.height = getDimensions()[1]-verticalPadding+offsetHeight+'px';
		}
}

function init_submenus() { // hides the submenus, adds mouseovers

	productsmenu = document.getElementById('products_menu');
	spans = productsmenu.getElementsByTagName('span');
	
	as = productsmenu.getElementsByTagName('a');
	for (var i=0; i < as.length; i++) {   // add mouseovers to menu headings
		if (as[i].className.indexOf('top') >= 0) {
			as[i].parentNode.onmouseover = function() {show_submenu(this)};
			as[i].parentNode.onmouseout = function() {hide_submenu(this)};
		}
	}
	
	//download catalogs addition
	
	pdf_link = document.getElementById('download_catalogues').getElementsByTagName('img')[0];
	pdf_link.parentNode.onmouseover = function() {show_submenu(this)};
	pdf_link.parentNode.onmouseout = function() {hide_submenu(this)};
	
}

function hide_submenu (parent_span) {
	submenu = parent_span.getElementsByTagName('span')[0];
	submenu.style.display = 'none';
}

function show_submenu (parent_span) {
	submenu = parent_span.getElementsByTagName('span')[0];
	submenu.style.display = 'inline';
}



function getDimensions() {  //returns the width and height of the browser's viewable area 
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Array(myWidth,myHeight);
}

function init_new_window_links(container_id, features) {
	var container = document.getElementById(container_id); //get the container
	var cloud_links = container.getElementsByTagName('a'); // get list of links from the container
	
	for (var i = 0; i < cloud_links.length; i++) { // go through the list
		cloud_links[i].onclick = function () {
			window.open (this.href, '', features); //attach onclick events to each link
			return false; // stop the link from loading the page in the same window
		}
	}
}


/*
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
*/
