// Fix background image flickering in IE
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) { }

/* begin - Navigation Primary */
var NavigationPrimary = {
  init: function() {
    if ($.browser.msie) // iframe to fix dropdowns over select items
        $('#NavigationPrimary li').append('');
		
		var c = this;
		var n = $('#NavigationPrimary');
		// Mark parent elements so that we can style them with CSS
		$('> li', n).each(function() { c.markParents(this); });
  	
    $('li', n).hover(
      function() {
        $(this).addClass('over').children('a').addClass('over');
        if ($.browser.msie)
        {
          var u = $('> ul', $(this));
          var h = u.height();
          var w = u.width();
          var i = $(this).children('iframe');
          var l = u.css('left');
          var t = u.css('top');
          if (i.length > 0 && h != null && w != null)
            i.height(h).width(w).css({ left: l, top: t }).show();  
        }
      },
      function() {
        $(this).removeClass('over').children('a').removeClass('over');
        if ($.browser.msie)
          $(this).children('iframe').hide();
      }
    );
  },
  markParents: function(li) {
    var c = this;
    if ($('> ul', li).size() > 0)
	    $(li).addClass('parent').find('> a').addClass('parent').end().find('> ul li').each( function() { c.markParents(this); });
	}
	
};
$(function() { NavigationPrimary.init(); });
/* end - Primary Navigation */

function toggledivs() {
  var inc, endInc=arguments.length;
  for (inc=0; inc<endInc; inc+=2) {
    var id = arguments[inc];
    if (arguments[inc+1] == 'none') param = "none";
    else if(arguments[inc+1]=='block') param = "block";
    if (document.layers) document.layers['container'].layers[id].visibility = param;
    else if (document.all) eval("document.all." + id + ".style.display = \"" + param + "\"");
    else if (document.getElementById) eval("document.getElementById(id).style.display = \"" + param + "\"");
  }
}

function imageover(el,which){
  el.src=el.getAttribute(which || "off");
}

function imageswap(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var over = x[i].getAttribute("over");
    if (!over) continue;
      
    // preload image
    x[i].over_img = new Image();
    x[i].over_img.src=over;
    // set event handlers
    x[i].onmouseover = new Function("imageover(this,'over');");
    x[i].onmouseout = new Function("imageover(this);");
    // save original src
    x[i].setAttribute("off",x[i].src);
  }
}

function PopUp(url, Hor, Vrt){
	var now = new Date()
    var hours = now.getHours()
    var minutes = now.getMinutes()
    var seconds = now.getSeconds()
	var NameOfWin = hours*minutes*seconds*Hor*Vrt
	msgWindow = window.open(url, NameOfWin,"resizable=yes,width="+Hor+",height="+Vrt+", status=no,location=no,toolbar=no,menubar=no,directories=no,scrollbars=no,screenX=0,screenY=0");
		msgWindow.focus();
        }
				
/* begin function for the expandable lists */
var expandableList = {
	init: function() {
		$('#ExpandableList div.content').hide().find('a[@href=#hide]').hide();
		$('a[@href=#hide]').click(
			function() {
			  expandableList.hideInfo($(this).parent());
				return false;
			}
		);
		$('a[@href=#show]').click(
			function() {
			  expandableList.showInfo($(this).parent());
				return false;
			}
		);
		// Need to make this state aware if we show some info on page load
		$('a.title,a.header').toggle(
			function() {
			  expandableList.showInfo($(this).parent());
				return false;
			},
			function() {
			  expandableList.hideInfo($(this).parent());
				return false;
			}
		);
	},
	showInfo: function(el) {
		// el is the div that contains the title to show info for
		var el2 = el.removeClass('head').addClass('infoVisible').next().show().next();
		if (el2.is('.openedbot')) // Support different markup on download-center page
			el2.show();
		el.find('a[@href=#hide]').show();
		el.find('a[@href=#show]').hide();
	},
	hideInfo: function(el) {
		// el is the div that contains the title to hide info for
		var el2 = el.removeClass('infoVisible').addClass('head').next().hide().next();
		if (el2.is('.openedbot')) // Support different markup on download-center page
			el2.hide();
		el.find('a[@href=#show]').show();
		el.find('a[@href=#hide]').hide();
	}
};
$(function() { expandableList.init(); });
/* end function for the expandable list */

function scroll(selector) { // Scroll to anchor on feature
	$.scrollTo( $(selector), { speed: 2500 } );			
}
function scrollParent(selector) { // Scroll to anchor on feature
	$.scrollTo( $(selector).parent(), { speed: 2500 } );			
}


// Open some items on page load by parsing query string
var downloadCenter = {
	init: function() {
		if ($('body.downloadCenter').length == 0)
			return false; // Only run on download center page
		var id = $.getURLParam('dl');
		if (id == '')
			return false;
		var el = $('#' + id);
		if (el.length > 0)
		{
			// Trigger the item to open
			$('a.header', el).click();
			setTimeout("scrollParent('#" + id +"')", 500);
		}
	}
};
$(function() { downloadCenter.init(); });

var professionalServices = {
	init: function() {
		if ($('body.profServices').length == 0)
			return false; // Only run on professional services page
		var id = $.getURLParam('srv');
		if (id == '')
			return false;
		var el = $('#' + id);
		if (el.length > 0)
		{
			// Trigger the item to open
			$('a.title', el).click();
			setTimeout("scrollParent('#" + id +"')", 500);
		}
	}
};
$(function() { professionalServices.init(); });


/* popup windows */
$(function() {
	$('#Wrapper a[@href$=.pdf]').popupwindow(); // PDFs by URL	
	$('#Wrapper a[@href$=.jpg]').popupwindow(); // Screenshots
	$('#Wrapper a.popup').popupwindow(); // Other internal links
	$('#Wrapper a[@href^=https://]').popupwindow(); // Secure HTTP connection links
	$('#Wrapper a[@href^=http://]') // Fully qualified links	
		.not($('a[@href^=http://www.roguewave.com]'))
		.not($('a[@href^=http://www2.roguewave.com]'))
		.not($('a[@href^=http://roguewave.com]'))
		.popupwindow(); 
});

/* end popup windows */

/* Special search behavior */
var Search = {
	prompt: "Search", // default value - should get real value from markup
	init: function() { this.prompt = $('#search-box,#search-box-alt').focus(this.focus).blur(this.blur).val(); },
	focus: function() { if (this.value == Search.prompt) { this.value = ''; } },
	blur: function() { if (this.value.length == 0) { this.value = Search.prompt} }
};
$(function() { Search.init(); });
