function fixPNG(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;

      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src)
      {
        src = src[1];
        element.runtimeStyle.backgroundImage="none";
      }
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
  }
}

function loadPageContent(targetId, pageId, ajaxUrl)
{
    ajaxUrl = ajaxUrl + "&ajaxPageId=" + pageId;
    $.get(ajaxUrl, null,
            function(data)
            {
                $('#' + targetId).html(data); 
	            $('#footer').removeClass( 'index' );
				resizeContent();
            },
            "html"
        );
}

function selectNavItem(id)
{
    selectGroupItem(id, 'navBtn');
}

// group -> selected item id
var selectedItem = new Array();

// group -> selected item need restore
var needToRestoreItem = new Array();

function selectGroupItem(id, groupPrefix)
{
    deHighlightGroup(groupPrefix);
    $('#' + groupPrefix + id).addClass( 'selected' );
    selectedItem[groupPrefix] = id;
}

function highlightNavItem(id)
{
    highlightGroupItem(id, 'navBtn');
}

function restoreSelectedNavItem()
{
    restoreSelectedGroupItem('navBtn');
}

function restoreSelectedGroupItem(groupPrefix)
{
    needToRestoreItem[groupPrefix] = true;
    var restore = function()
    {
        if( needToRestoreItem[groupPrefix] )
            highlightGroupItem(selectedItem[groupPrefix], groupPrefix);
    };
    setTimeout(restore, 300);
}

function deHighlightNav()
{
    deHighlightGroup('navBtn');
}

function highlightGroupItem(id, groupPrefix)
{
    needToRestoreItem[groupPrefix] = false;
    deHighlightGroup(groupPrefix);
    $('#' + groupPrefix + id).addClass( 'selected' );
}

function deHighlightGroup(groupPrefix)
{
    $('.' + groupPrefix + 'A').removeClass( 'selected' );
}


// default height
var contentHeight = 705;
var navigationHeight = 310;

function setNavigationHeight(naviHeight)
{
    navigationHeight = naviHeight;
}

function addContentResizeEventControl()
{
    resizeContent();
    addEventSimple(window, 'resize', resizeContent);
}

function resizeContent()
{
    var ih = (window.innerHeight)? window.innerHeight : document.body.clientHeight;
    var height = ih - navigationHeight;
    /* note: also change max-height in style.css, .pageContentContainer element */
    if( height < (contentHeight - navigationHeight) )
        height = (contentHeight - navigationHeight);
    $('.pageContentContainer').css( 'max-height', height + 'px' );
}

/**
 * Add event listeners (Based on Peter-Paul Koch solution: http://www.quirksmode.org/js/eventSimple.html)
 */

function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}



